mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 17:00:36 +01:00
feat(Button): handle avatar prop
This commit is contained in:
@@ -5,6 +5,7 @@ import _appConfig from '#build/app.config'
|
||||
import theme from '#build/ui/button'
|
||||
import type { LinkProps } from './Link.vue'
|
||||
import type { UseComponentIconsProps } from '../composables/useComponentIcons'
|
||||
import type { AvatarProps } from '../types'
|
||||
import type { PartialString } from '../types/utils'
|
||||
import { formLoadingInjectionKey } from '../composables/useFormField'
|
||||
|
||||
@@ -99,6 +100,7 @@ const ui = computed(() => button({
|
||||
>
|
||||
<slot name="leading">
|
||||
<UIcon v-if="isLeading && leadingIconName" :name="leadingIconName" :class="ui.leadingIcon({ class: props.ui?.leadingIcon })" />
|
||||
<UAvatar v-else-if="!!avatar" :size="((props.ui?.leadingAvatarSize || ui.leadingAvatarSize()) as AvatarProps['size'])" v-bind="avatar" :class="ui.leadingAvatar({ class: props.ui?.leadingAvatar })" />
|
||||
</slot>
|
||||
|
||||
<slot>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { computed, toValue, type MaybeRefOrGetter } from 'vue'
|
||||
import { useAppConfig } from '#imports'
|
||||
import type { AvatarProps } from '../types'
|
||||
|
||||
export interface UseComponentIconsProps {
|
||||
/** Display an icon based on the `leading` and `trailing` props. */
|
||||
icon?: string
|
||||
/** Display an avatar on the left side. */
|
||||
avatar?: AvatarProps
|
||||
/** When `true`, the icon will be displayed on the left side. */
|
||||
leading?: boolean
|
||||
/** Display an icon on the left side. */
|
||||
|
||||
@@ -7,6 +7,7 @@ export default (options: Required<ModuleOptions>) => ({
|
||||
label: 'truncate',
|
||||
leadingIcon: 'shrink-0',
|
||||
leadingAvatar: 'shrink-0',
|
||||
leadingAvatarSize: '',
|
||||
trailingIcon: 'shrink-0'
|
||||
},
|
||||
variants: {
|
||||
@@ -27,32 +28,38 @@ export default (options: Required<ModuleOptions>) => ({
|
||||
xs: {
|
||||
base: 'px-2 py-1 text-xs gap-1',
|
||||
leadingIcon: 'size-4',
|
||||
leadingAvatarSize: '3xs',
|
||||
trailingIcon: 'size-4'
|
||||
},
|
||||
sm: {
|
||||
base: 'px-2.5 py-1.5 text-xs gap-1.5',
|
||||
leadingIcon: 'size-4',
|
||||
leadingAvatarSize: '3xs',
|
||||
trailingIcon: 'size-4'
|
||||
},
|
||||
md: {
|
||||
base: 'px-2.5 py-1.5 text-sm gap-1.5',
|
||||
leadingIcon: 'size-5',
|
||||
leadingAvatarSize: '2xs',
|
||||
trailingIcon: 'size-5'
|
||||
},
|
||||
lg: {
|
||||
base: 'px-3 py-2 text-sm gap-2',
|
||||
leadingIcon: 'size-5',
|
||||
leadingAvatarSize: '2xs',
|
||||
trailingIcon: 'size-5'
|
||||
},
|
||||
xl: {
|
||||
base: 'px-3 py-2 text-base gap-2',
|
||||
leadingIcon: 'size-6',
|
||||
leadingAvatarSize: 'xs',
|
||||
trailingIcon: 'size-6'
|
||||
}
|
||||
},
|
||||
block: {
|
||||
true: {
|
||||
base: 'w-full justify-center',
|
||||
leadingAvatarSize: 'xs',
|
||||
trailingIcon: 'ms-auto'
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user