mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
feat(ContextMenu/DropdownMenu): handle loading field in items
This commit is contained in:
@@ -24,6 +24,7 @@ export interface ContextMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'custo
|
||||
*/
|
||||
type?: 'label' | 'separator' | 'link' | 'checkbox'
|
||||
slot?: string
|
||||
loading?: boolean
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
open?: boolean
|
||||
@@ -43,6 +44,11 @@ export interface ContextMenuProps<T> extends Omit<ContextMenuRootProps, 'dir'> {
|
||||
* @defaultValue appConfig.ui.icons.check
|
||||
*/
|
||||
checkedIcon?: string
|
||||
/**
|
||||
* The icon displayed when an item is loading.
|
||||
* @defaultValue appConfig.ui.icons.loading
|
||||
*/
|
||||
loadingIcon?: string
|
||||
/** The content of the menu. */
|
||||
content?: Omit<ContextMenuContentProps, 'as' | 'asChild' | 'forceMount'>
|
||||
/**
|
||||
@@ -113,6 +119,7 @@ const ui = computed(() => contextMenu({
|
||||
:portal="portal"
|
||||
:label-key="labelKey"
|
||||
:checked-icon="checkedIcon"
|
||||
:loading-icon="loadingIcon"
|
||||
>
|
||||
<template v-for="(_, name) in proxySlots" #[name]="slotData: any">
|
||||
<slot :name="name" v-bind="slotData" />
|
||||
|
||||
@@ -12,6 +12,7 @@ interface ContextMenuContentProps<T> extends Omit<RadixContextMenuContentProps,
|
||||
sub?: boolean
|
||||
labelKey: string
|
||||
checkedIcon?: string
|
||||
loadingIcon?: string
|
||||
class?: any
|
||||
ui: typeof _contextMenu
|
||||
uiOverride?: any
|
||||
@@ -51,7 +52,8 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
|
||||
<DefineItemTemplate v-slot="{ item, active, index }">
|
||||
<slot :name="item.slot || 'item'" :item="(item as T)" :index="index">
|
||||
<slot :name="item.slot ? `${item.slot}-leading`: 'item-leading'" :item="(item as T)" :active="active" :index="index">
|
||||
<UIcon v-if="item.icon" :name="item.icon" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, active })" />
|
||||
<UIcon v-if="item.loading" :name="loadingIcon || appConfig.ui.icons.loading" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, loading: true })" />
|
||||
<UIcon v-else-if="item.icon" :name="item.icon" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, active })" />
|
||||
<UAvatar v-else-if="item.avatar" :size="((props.uiOverride?.itemLeadingAvatarSize || ui.itemLeadingAvatarSize()) as AvatarProps['size'])" v-bind="item.avatar" :class="ui.itemLeadingAvatar({ class: uiOverride?.itemLeadingAvatar, active })" />
|
||||
</slot>
|
||||
|
||||
@@ -106,6 +108,8 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
|
||||
:items="item.children"
|
||||
:align-offset="-4"
|
||||
:label-key="labelKey"
|
||||
:checked-icon="checkedIcon"
|
||||
:loading-icon="loadingIcon"
|
||||
v-bind="item.content"
|
||||
>
|
||||
<template v-for="(_, name) in proxySlots" #[name]="slotData: any">
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface DropdownMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'cust
|
||||
*/
|
||||
type?: 'label' | 'separator' | 'link' | 'checkbox'
|
||||
slot?: string
|
||||
loading?: boolean
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
open?: boolean
|
||||
@@ -43,6 +44,11 @@ export interface DropdownMenuProps<T> extends Omit<DropdownMenuRootProps, 'dir'>
|
||||
* @defaultValue appConfig.ui.icons.check
|
||||
*/
|
||||
checkedIcon?: string
|
||||
/**
|
||||
* The icon displayed when an item is loading.
|
||||
* @defaultValue appConfig.ui.icons.loading
|
||||
*/
|
||||
loadingIcon?: string
|
||||
/**
|
||||
* The content of the menu.
|
||||
* @defaultValue { side: 'bottom', sideOffset: 8 }
|
||||
@@ -123,6 +129,7 @@ const ui = computed(() => dropdownMenu({
|
||||
:portal="portal"
|
||||
:label-key="labelKey"
|
||||
:checked-icon="checkedIcon"
|
||||
:loading-icon="loadingIcon"
|
||||
>
|
||||
<template v-for="(_, name) in proxySlots" #[name]="slotData: any">
|
||||
<slot :name="name" v-bind="slotData" />
|
||||
|
||||
@@ -13,6 +13,7 @@ interface DropdownMenuContentProps<T> extends Omit<RadixDropdownMenuContentProps
|
||||
sub?: boolean
|
||||
labelKey: string
|
||||
checkedIcon?: string
|
||||
loadingIcon?: string
|
||||
class?: any
|
||||
ui: typeof _dropdownMenu
|
||||
uiOverride?: any
|
||||
@@ -57,7 +58,8 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
|
||||
<DefineItemTemplate v-slot="{ item, active, index }">
|
||||
<slot :name="item.slot || 'item'" :item="(item as T)" :index="index">
|
||||
<slot :name="item.slot ? `${item.slot}-leading`: 'item-leading'" :item="(item as T)" :active="active" :index="index">
|
||||
<UIcon v-if="item.icon" :name="item.icon" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, active })" />
|
||||
<UIcon v-if="item.loading" :name="loadingIcon || appConfig.ui.icons.loading" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, loading: true })" />
|
||||
<UIcon v-else-if="item.icon" :name="item.icon" :class="ui.itemLeadingIcon({ class: uiOverride?.itemLeadingIcon, active })" />
|
||||
<UAvatar v-else-if="item.avatar" :size="((props.uiOverride?.itemLeadingAvatarSize || ui.itemLeadingAvatarSize()) as AvatarProps['size'])" v-bind="item.avatar" :class="ui.itemLeadingAvatar({ class: uiOverride?.itemLeadingAvatar, active })" />
|
||||
</slot>
|
||||
|
||||
@@ -115,6 +117,8 @@ const groups = computed(() => props.items?.length ? (Array.isArray(props.items[0
|
||||
:align-offset="-4"
|
||||
:side-offset="3"
|
||||
:label-key="labelKey"
|
||||
:checked-icon="checkedIcon"
|
||||
:loading-icon="loadingIcon"
|
||||
v-bind="item.content"
|
||||
>
|
||||
<template v-for="(_, name) in proxySlots" #[name]="slotData: any">
|
||||
|
||||
@@ -28,6 +28,11 @@ export default (options: Required<ModuleOptions>) => ({
|
||||
itemLeadingIcon: ['text-[var(--ui-text-dimmed)] group-data-highlighted:text-[var(--ui-text)] group-data-[state=open]:text-[var(--ui-text)]', options.theme.transitions && 'transition-colors']
|
||||
}
|
||||
},
|
||||
loading: {
|
||||
true: {
|
||||
itemLeadingIcon: 'animate-spin'
|
||||
}
|
||||
},
|
||||
size: {
|
||||
xs: {
|
||||
label: 'p-1 text-xs gap-1',
|
||||
|
||||
@@ -29,6 +29,11 @@ export default (options: Required<ModuleOptions>) => ({
|
||||
itemLeadingIcon: ['text-[var(--ui-text-dimmed)] group-data-highlighted:text-[var(--ui-text)] group-data-[state=open]:text-[var(--ui-text)]', options.theme.transitions && 'transition-colors']
|
||||
}
|
||||
},
|
||||
loading: {
|
||||
true: {
|
||||
itemLeadingIcon: 'animate-spin'
|
||||
}
|
||||
},
|
||||
size: {
|
||||
xs: {
|
||||
label: 'p-1 text-xs gap-1',
|
||||
|
||||
Reference in New Issue
Block a user