mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 11:20:36 +01:00
chore(Badge): add type
This commit is contained in:
@@ -10,11 +10,10 @@ import type { PropType } from 'vue'
|
|||||||
import { twMerge, twJoin } from 'tailwind-merge'
|
import { twMerge, twJoin } from 'tailwind-merge'
|
||||||
import { useUI } from '../../composables/useUI'
|
import { useUI } from '../../composables/useUI'
|
||||||
import { mergeConfig } from '../../utils'
|
import { mergeConfig } from '../../utils'
|
||||||
import type { NestedKeyOf, Strategy } from '../../types'
|
import type { BadgeColor, BadgeSize, BadgeVariant, Strategy } from '../../types'
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
import appConfig from '#build/app.config'
|
import appConfig from '#build/app.config'
|
||||||
import { badge } from '#ui/ui.config'
|
import { badge } from '#ui/ui.config'
|
||||||
import colors from '#ui-colors'
|
|
||||||
|
|
||||||
const config = mergeConfig<typeof badge>(appConfig.ui.strategy, appConfig.ui.badge, badge)
|
const config = mergeConfig<typeof badge>(appConfig.ui.strategy, appConfig.ui.badge, badge)
|
||||||
|
|
||||||
@@ -22,21 +21,21 @@ export default defineComponent({
|
|||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
size: {
|
size: {
|
||||||
type: String as PropType<keyof typeof config.size>,
|
type: String as PropType<BadgeSize>,
|
||||||
default: () => config.default.size,
|
default: () => config.default.size,
|
||||||
validator (value: string) {
|
validator (value: string) {
|
||||||
return Object.keys(config.size).includes(value)
|
return Object.keys(config.size).includes(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
type: String as PropType<keyof typeof config.color | typeof colors[number]>,
|
type: String as PropType<BadgeColor>,
|
||||||
default: () => config.default.color,
|
default: () => config.default.color,
|
||||||
validator (value: string) {
|
validator (value: string) {
|
||||||
return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
|
return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
variant: {
|
variant: {
|
||||||
type: String as PropType<keyof typeof config.variant | NestedKeyOf<typeof config.color>>,
|
type: String as PropType<BadgeVariant>,
|
||||||
default: () => config.default.variant,
|
default: () => config.default.variant,
|
||||||
validator (value: string) {
|
validator (value: string) {
|
||||||
return [
|
return [
|
||||||
|
|||||||
14
src/runtime/types/badge.d.ts
vendored
Normal file
14
src/runtime/types/badge.d.ts
vendored
Normal 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
|
||||||
|
}
|
||||||
1
src/runtime/types/index.d.ts
vendored
1
src/runtime/types/index.d.ts
vendored
@@ -1,5 +1,6 @@
|
|||||||
export * from './accordion'
|
export * from './accordion'
|
||||||
export * from './avatar'
|
export * from './avatar'
|
||||||
|
export * from './badge'
|
||||||
export * from './button'
|
export * from './button'
|
||||||
export * from './clipboard'
|
export * from './clipboard'
|
||||||
export * from './command-palette'
|
export * from './command-palette'
|
||||||
|
|||||||
Reference in New Issue
Block a user