chore(Badge): add type

This commit is contained in:
Benjamin Canac
2023-09-29 16:17:06 +02:00
parent ee6f0d0c49
commit d46eafb248
3 changed files with 19 additions and 5 deletions

View File

@@ -10,11 +10,10 @@ import type { PropType } from 'vue'
import { twMerge, twJoin } from 'tailwind-merge'
import { useUI } from '../../composables/useUI'
import { mergeConfig } from '../../utils'
import type { NestedKeyOf, Strategy } from '../../types'
import type { BadgeColor, BadgeSize, BadgeVariant, Strategy } from '../../types'
// @ts-expect-error
import appConfig from '#build/app.config'
import { badge } from '#ui/ui.config'
import colors from '#ui-colors'
const config = mergeConfig<typeof badge>(appConfig.ui.strategy, appConfig.ui.badge, badge)
@@ -22,21 +21,21 @@ export default defineComponent({
inheritAttrs: false,
props: {
size: {
type: String as PropType<keyof typeof config.size>,
type: String as PropType<BadgeSize>,
default: () => config.default.size,
validator (value: string) {
return Object.keys(config.size).includes(value)
}
},
color: {
type: String as PropType<keyof typeof config.color | typeof colors[number]>,
type: String as PropType<BadgeColor>,
default: () => config.default.color,
validator (value: string) {
return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
}
},
variant: {
type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
type: String as PropType<BadgeVariant>,
default: () => config.default.variant,
validator (value: string) {
return [

14
src/runtime/types/badge.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
import { badge } from '../ui.config'
import type { NestedKeyOf } from '.'
import colors from '#ui-colors'
export type BadgeSize = keyof typeof badge.size
export type BadgeColor = keyof typeof badge.color | typeof colors[number]
export type BadgeVariant = keyof typeof badge.variant | NestedKeyOf<typeof badge.color>
export interface Badge {
label?: string
size?: BadgeSize
color?: BadgeColor
variant?: BadgeVariant
}

View File

@@ -1,5 +1,6 @@
export * from './accordion'
export * from './avatar'
export * from './badge'
export * from './button'
export * from './clipboard'
export * from './command-palette'