therufa / mdi-vue

Material design icons for vue.js
https://www.npmjs.com/package/mdi-vue
MIT License
88 stars 13 forks source link

Add possibility to use object for property "name" #52

Closed robertfausk closed 3 years ago

robertfausk commented 3 years ago

It would be nice if the following is working:

<mdicon
  :name="{ 'ArrowCollapseVertical': isOpen, 'UnfoldMoreHorizontal': !isOpen }"
/>

but it throws Invalid prop: type check failed for prop "name". Expected String with value "[object Object]", got Object.

Currently i depend on following workaround:


<mdicon
  v-if="isOpen"
  name="ArrowCollapseVertical"
/>
<mdicon
  v-else
  name="UnfoldMoreHorizontal"
/>
therufa commented 3 years ago

hi @robertfausk, Danke, danke for opening this issue :)

I've given it some thought, and I came to the conclusion that the problem is actually solvable using the ternary operator ?: in order to differentiate between the two names.

Here's a working example of this:

<mdicon :name="isOpen ? 'ArrowCollapseVertical' : 'UnfoldMoreHorizontal'" />

The object notation would make sense though if the component would display multiple icons at the same time, but it's not designed to do so.

I'm closing the issue, but if feel free to reopen in case I'm missing the point.