Skip to content

Commit

Permalink
feat: support options icon in NeCombobox
Browse files Browse the repository at this point in the history
  • Loading branch information
andre8244 committed Jun 20, 2024
1 parent 04215a1 commit 61fb8ff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/components/NeCombobox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
ComboboxOptions
} from '@headlessui/vue'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faChevronDown as fasChevronDown } from '@fortawesome/free-solid-svg-icons'
import {
faChevronDown as fasChevronDown,
type IconDefinition
} from '@fortawesome/free-solid-svg-icons'
import { faCheck as fasCheck } from '@fortawesome/free-solid-svg-icons'
import { faXmark as fasXmark } from '@fortawesome/free-solid-svg-icons'
import NeBadge from './NeBadge.vue'
Expand All @@ -25,6 +28,7 @@ export interface NeComboboxOption {
id: string
label: string
description?: string
icon?: IconDefinition
rawObj?: any
disabled?: boolean
}
Expand Down Expand Up @@ -372,10 +376,19 @@ onClickOutside(comboboxRef, () => onClickOutsideCombobox())
: 'text-gray-900 dark:text-gray-100'
]"
>
<div class="block truncate">
<span :class="['truncate', optionSelected && 'font-semibold']">
<div class="flex items-center truncate">
<!-- option icon -->
<font-awesome-icon
v-if="option.icon"
:icon="option.icon"
class="mr-2.5 h-4 w-4 shrink-0"
aria-hidden="true"
/>
<!-- option label -->
<span :class="['shrink-0 truncate', optionSelected && 'font-semibold']">
{{ option.label }}
</span>
<!-- option description -->
<span
v-if="option.description && showOptionsType"
:class="['ml-2.5 truncate text-gray-500 dark:text-gray-400']"
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type { Tab } from '@/components/NeTabs.vue'
export type { NeNotification } from '@/components/NeToastNotification.vue'
export type { NeListboxOption } from '@/components/NeListbox.vue'


// library functions export
export {
sortByProperty,
Expand Down
24 changes: 24 additions & 0 deletions stories/NeCombobox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import type { Meta, StoryObj } from '@storybook/vue3'

import { NeCombobox, NeTooltip } from '../src/main'
import { faStar, faBell, faEarthAmericas } from '@fortawesome/free-solid-svg-icons'
import { library } from '@fortawesome/fontawesome-svg-core'

const meta = {
title: 'NeCombobox',
Expand Down Expand Up @@ -175,6 +177,28 @@ export const OptionsWithDescription: Story = {
}
}

library.add(faStar)
library.add(faBell)
library.add(faEarthAmericas)

export const OptionsWithIcon: Story = {
render: (args) => ({
components: { NeCombobox },
setup() {
return { args }
},
template: template
}),
args: {
label: 'Choose',
options: [
{ id: '1', label: 'First option', description: 'Description', icon: faStar },
{ id: '2', label: 'Second option', icon: faBell },
{ id: '3', label: 'Third option', icon: faEarthAmericas }
]
}
}

export const NoOptions: Story = {
render: (args) => ({
components: { NeCombobox },
Expand Down

0 comments on commit 61fb8ff

Please sign in to comment.