Skip to content

Commit

Permalink
feat(Dropdown): handle labelClass and merge iconClass
Browse files Browse the repository at this point in the history
Resolves #716
  • Loading branch information
benjamincanac committed Dec 12, 2023
1 parent 6d8d82a commit 1c9835d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/content/2.elements/6.dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ links:
Pass an array of arrays to the `items` prop of the Dropdown component. Each array represents a group of items. Each item can have the following properties:

- `label` - The label of the item.
- `labelClass` - The class of the item label. :u-badge{label="New" class="!rounded-full" variant="subtle"}
- `icon` - The icon of the item.
- `iconClass` - The class of the icon of the item.
- `iconClass` - The class of the item icon.
- `avatar` - The avatar of the item. You can pass all the props of the [Avatar](/elements/avatar) component.
- `shortcuts` - The shortcuts of the item.
- `slot` - The slot of the item.
Expand Down
9 changes: 6 additions & 3 deletions src/runtime/components/elements/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div v-if="popper.arrow" data-popper-arrow :class="Object.values(ui.arrow)" />
<HMenuItems :class="[ui.base, ui.divide, ui.ring, ui.rounded, ui.shadow, ui.background, ui.height]" static>
<div v-for="(subItems, index) of items" :key="index" :class="ui.padding">
<NuxtLink v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ href, target, rel, navigate, isExternal }" v-bind="omit(item, ['label', 'slot', 'icon', 'iconClass', 'avatar', 'shortcuts', 'disabled', 'click'])" custom>
<NuxtLink v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ href, target, rel, navigate, isExternal }" v-bind="omit(item, ['label', 'labelClass', 'slot', 'icon', 'iconClass', 'avatar', 'shortcuts', 'disabled', 'click'])" custom>
<HMenuItem v-slot="{ active, disabled: itemDisabled, close }" :disabled="item.disabled">
<component
:is="!!href ? 'a' : 'button'"
Expand All @@ -32,10 +32,10 @@
@click="onClick($event, item, { href, navigate, close, isExternal })"
>
<slot :name="item.slot || 'item'" :item="item">
<UIcon v-if="item.icon" :name="item.icon" :class="[ui.item.icon.base, active ? ui.item.icon.active : ui.item.icon.inactive, item.iconClass]" />
<UIcon v-if="item.icon" :name="item.icon" :class="twMerge(twJoin(ui.item.icon.base, active ? ui.item.icon.active : ui.item.icon.inactive), item.iconClass)" />
<UAvatar v-else-if="item.avatar" v-bind="{ size: ui.item.avatar.size, ...item.avatar }" :class="ui.item.avatar.base" />

<span :class="ui.item.label">{{ item.label }}</span>
<span :class="twMerge(ui.item.label, item.labelClass)">{{ item.label }}</span>

<span v-if="item.shortcuts?.length" :class="ui.item.shortcuts">
<UKbd v-for="shortcut of item.shortcuts" :key="shortcut">{{ shortcut }}</UKbd>
Expand All @@ -57,6 +57,7 @@ import { defineComponent, ref, computed, toRef, onMounted, resolveComponent } fr
import type { PropType } from 'vue'
import { Menu as HMenu, MenuButton as HMenuButton, MenuItems as HMenuItems, MenuItem as HMenuItem } from '@headlessui/vue'
import { defu } from 'defu'
import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue'
import UKbd from '../elements/Kbd.vue'
Expand Down Expand Up @@ -214,6 +215,8 @@ export default defineComponent({
onMouseLeave,
onClick,
omit,
twMerge,
twJoin,
NuxtLink
}
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime/types/dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Avatar } from './avatar'

export interface DropdownItem extends NuxtLinkProps {
label: string
labelClass?: string
slot?: string
icon?: string
iconClass?: string
Expand Down

0 comments on commit 1c9835d

Please sign in to comment.