Skip to content

Commit

Permalink
feat: add option to configure icon with array
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Aug 12, 2024
1 parent 688761b commit d99737e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
36 changes: 19 additions & 17 deletions lib/components/PhosphorIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<script setup lang="ts">
import { computed, ref, shallowRef, defineAsyncComponent, watch } from 'vue'
import isArray from 'lodash/isArray'
import isObject from 'lodash/isObject'
import camelCase from 'lodash/camelCase'
import upperFirst from 'lodash/upperFirst'
Expand All @@ -69,7 +70,7 @@ const WEIGHTS = Object.freeze({
const props = defineProps({
name: {
type: [String, Object],
type: [String, Object, Array],
required: true
},
size: {
Expand Down Expand Up @@ -141,28 +142,29 @@ function findComponentByName(name: string) {
})
}
const component = shallowRef(null)
const component = shallowRef()
watch(
() => props.name,
() => {
component.value = isObject(props.name) ? props.name : findComponentByName(props.name)
},
{ immediate: true }
)
const setComponent = (icon: Array<any> | string | object) => {
if (isArray(icon)) {
setComponent(icon[0])
} else if (isObject(icon)) {
component.value = icon
} else {
component.value = findComponentByName(icon)
}
}
const currentHover = ref(false)
watch(() => props.name, setComponent, { immediate: true })
watch(
() => props.hover,
() => {
currentHover.value = props.hover
},
{ immediate: true }
)
const currentHover = ref(false)
watch(() => props.hover, () => { currentHover.value = props.hover }, { immediate: true })
const weight = computed(() => {
if (isArray(props.name) && props.name.length > 1) {
return WEIGHTS[props.name[1]]
}
if (currentHover.value && props.hoverWeight) {
return WEIGHTS[props.hoverWeight]
}
Expand Down
11 changes: 10 additions & 1 deletion stories/murmur/components/PhosphorIcon.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PhHorse } from "@phosphor-icons/vue"
import { PhHorse, PhWindowsLogo } from "@phosphor-icons/vue"

import { PhosphorIcon } from '@/components'

Expand Down Expand Up @@ -105,6 +105,15 @@ export const WithComponent = {
}
}


export const WithArray = {
args: {
name: ['windows-logo', 'fill'],
variant: 'primary',
size: '2xl'
}
}

export const HoverWeight = {
args: {
name: 'lego',
Expand Down

0 comments on commit d99737e

Please sign in to comment.