Skip to content

useIconSelect

Headless composable providing the core logic for the icon selector. The presets of FxIconSelect are built on this composable.

Options

UseIconSelectOptions

OptionTypeDefaultDescription
modelValue() => string | undefined() => undefinedGetter function for the currently selected icon name
onSelect(value: string) => void() => {}Callback when an icon is selected
placeholderstring'请选择图标'Placeholder text
heightnumber418Popover height (px)

Return Values

UseIconSelectReturn

PropertyTypeDescription
visibleRef<boolean>Whether the popover is visible
activeTabRef<string>Current active tab key
inputValueComputedRef<string>Input display value
placeholderstringPlaceholder text
tabsComputedRef<IconSelectTab[]>Tab list
iconDataRef<Record<string, string[]>>All icon data
searchTextsRef<Record<string, string>>Search text for each tab
currentPagesRef<Record<string, number>>Current page for each tab
pageSizenumberItems per page (30)
contentHeightComputedRef<number>Popover content height
tabContentHeightComputedRef<number>Tab content area height
iconListHeightComputedRef<number>Icon list height

Methods

MethodParametersDescription
getFilteredIcons(key)key: stringGet filtered icon list
getPaginatedIcons(key)key: stringGet paginated icon list for current page
isSelected(prefix, iconName)prefix: string, iconName: stringCheck if an icon is selected
setListRef(key, el)key: string, el: HTMLElement | nullSet icon list DOM reference
handleInputClick()Toggle popover visibility on input click
handleSelectIcon(prefix, iconName)prefix: string, iconName: stringSelect an icon
closePopover()Close the popover

IconSelectTab

PropertyTypeDescription
keystringTab identifier ('svg' or icon collection prefix)
labelstringTab display text

Example

vue
<template>
  <div>
    <input
      :value="iconSelect.inputValue.value"
      :placeholder="iconSelect.placeholder"
      readonly
      @click="iconSelect.handleInputClick"
    />
    <div v-if="iconSelect.visible.value">
      <div v-for="tab in iconSelect.tabs.value" :key="tab.key">
        <button @click="iconSelect.activeTab.value = tab.key">
          {{ tab.label }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useIconSelect } from '@fuxishi/svg-icon'

const iconName = ref('')

const iconSelect = useIconSelect({
  modelValue: () => iconName.value,
  onSelect: (value) => { iconName.value = value }
})
</script>