diff --git a/src/runtime/components/elements/Alert.vue b/src/runtime/components/elements/Alert.vue index d3aa5a6852..13072fdd6d 100644 --- a/src/runtime/components/elements/Alert.vue +++ b/src/runtime/components/elements/Alert.vue @@ -39,12 +39,11 @@ import UIcon from '../elements/Icon.vue' import UAvatar from '../elements/Avatar.vue' import UButton from '../elements/Button.vue' import { useUI } from '../../composables/useUI' -import type { Avatar, Button, NestedKeyOf, Strategy } from '../../types' +import type { Avatar, Button, AlertColor, AlertVariant, Strategy } from '../../types' import { mergeConfig } from '../../utils' // @ts-expect-error import appConfig from '#build/app.config' import { alert } from '#ui/ui.config' -import colors from '#ui-colors' const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.alert, alert) @@ -81,14 +80,14 @@ export default defineComponent({ default: () => [] }, color: { - type: String as PropType, + type: String as PropType, default: () => config.default.color, validator (value: string) { return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value) } }, variant: { - type: String as PropType>, + type: String as PropType, default: () => config.default.variant, validator (value: string) { return [ diff --git a/src/runtime/components/elements/AvatarGroup.ts b/src/runtime/components/elements/AvatarGroup.ts index 38dc2401ac..269abdd312 100644 --- a/src/runtime/components/elements/AvatarGroup.ts +++ b/src/runtime/components/elements/AvatarGroup.ts @@ -17,7 +17,7 @@ export default defineComponent({ inheritAttrs: false, props: { size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(avatarConfig.size).includes(value) diff --git a/src/runtime/components/elements/Kbd.vue b/src/runtime/components/elements/Kbd.vue index d149a156ca..52d92890aa 100644 --- a/src/runtime/components/elements/Kbd.vue +++ b/src/runtime/components/elements/Kbd.vue @@ -10,7 +10,7 @@ import type { PropType } from 'vue' import { twMerge, twJoin } from 'tailwind-merge' import { useUI } from '../../composables/useUI' import { mergeConfig } from '../../utils' -import type { Strategy } from '../../types' +import type { KbdSize, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { kbd } from '#ui/ui.config' @@ -25,7 +25,7 @@ export default defineComponent({ default: null }, size: { - type: String as PropType, + type: String as PropType, default: () => config.default.size, validator (value: string) { return Object.keys(config.size).includes(value) diff --git a/src/runtime/components/forms/FormGroup.vue b/src/runtime/components/forms/FormGroup.vue index 4a93e117c9..897f010f91 100644 --- a/src/runtime/components/forms/FormGroup.vue +++ b/src/runtime/components/forms/FormGroup.vue @@ -42,7 +42,7 @@ import { computed, defineComponent, provide, inject, ref, toRef } from 'vue' import type { Ref, PropType } from 'vue' import { useUI } from '../../composables/useUI' import { mergeConfig } from '../../utils' -import type { FormError, InjectedFormGroupValue, Strategy } from '../../types' +import type { FormError, InjectedFormGroupValue, FormGroupSize, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { formGroup } from '#ui/ui.config' @@ -57,7 +57,7 @@ export default defineComponent({ default: null }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) diff --git a/src/runtime/components/forms/Input.vue b/src/runtime/components/forms/Input.vue index 94e856d4c4..2da9bcb19d 100644 --- a/src/runtime/components/forms/Input.vue +++ b/src/runtime/components/forms/Input.vue @@ -41,11 +41,10 @@ import { defu } from 'defu' import { useUI } from '../../composables/useUI' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig, looseToNumber } from '../../utils' -import type { NestedKeyOf, Strategy } from '../../types' +import type { InputSize, InputColor, InputVariant, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { input } from '#ui/ui.config' -import colors from '#ui-colors' const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.input, input) @@ -124,21 +123,21 @@ export default defineComponent({ default: true }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) } }, color: { - type: String as PropType, + type: String as PropType, default: () => config.default.color, validator (value: string) { return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value) } }, variant: { - type: String as PropType>, + type: String as PropType, default: () => config.default.variant, validator (value: string) { return [ @@ -171,7 +170,7 @@ export default defineComponent({ const { emitFormBlur, emitFormInput, size, color, inputId, name } = useFormGroup(props, config) const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false })) - + const input = ref(null) const autoFocus = () => { diff --git a/src/runtime/components/forms/Range.vue b/src/runtime/components/forms/Range.vue index 14d4088f51..9bbbbd842f 100644 --- a/src/runtime/components/forms/Range.vue +++ b/src/runtime/components/forms/Range.vue @@ -26,7 +26,7 @@ import { twMerge, twJoin } from 'tailwind-merge' import { useUI } from '../../composables/useUI' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig } from '../../utils' -import type { Strategy } from '../../types' +import type { RangeSize, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { range } from '#ui/ui.config' @@ -66,7 +66,7 @@ export default defineComponent({ default: 1 }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) diff --git a/src/runtime/components/forms/Select.vue b/src/runtime/components/forms/Select.vue index 7cc7f90295..89d84d18f5 100644 --- a/src/runtime/components/forms/Select.vue +++ b/src/runtime/components/forms/Select.vue @@ -61,11 +61,10 @@ import UIcon from '../elements/Icon.vue' import { useUI } from '../../composables/useUI' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig, get } from '../../utils' -import type { NestedKeyOf, Strategy } from '../../types' +import type { SelectSize, SelectColor, SelectVariant, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { select } from '#ui/ui.config' -import colors from '#ui-colors' const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.select, select) @@ -136,21 +135,21 @@ export default defineComponent({ default: () => [] }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) } }, color: { - type: String as PropType, + type: String as PropType, default: () => config.default.color, validator (value: string) { return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value) } }, variant: { - type: String as PropType>, + type: String as PropType, default: () => config.default.variant, validator (value: string) { return [ diff --git a/src/runtime/components/forms/SelectMenu.vue b/src/runtime/components/forms/SelectMenu.vue index 37d5370dff..21fbfa5b6b 100644 --- a/src/runtime/components/forms/SelectMenu.vue +++ b/src/runtime/components/forms/SelectMenu.vue @@ -86,17 +86,17 @@ aria-hidden="true" /> - + {{ ['string', 'number'].includes(typeof option) ? option : option[optionAttribute] }} - + - +
  • @@ -141,11 +141,10 @@ import { useUI } from '../../composables/useUI' import { usePopper } from '../../composables/usePopper' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig } from '../../utils' -import type { PopperOptions, NestedKeyOf, Strategy } from '../../types' +import type { SelectSize, SelectColor, SelectVariant, PopperOptions, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { select, selectMenu } from '#ui/ui.config' -import colors from '#ui-colors' const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.select, select) @@ -256,21 +255,21 @@ export default defineComponent({ default: true }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) } }, color: { - type: String as PropType, + type: String as PropType, default: () => config.default.color, validator (value: string) { return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value) } }, variant: { - type: String as PropType>, + type: String as PropType, default: () => config.default.variant, validator (value: string) { return [ diff --git a/src/runtime/components/forms/Textarea.vue b/src/runtime/components/forms/Textarea.vue index d3dff6a31e..9b10d6c9c1 100644 --- a/src/runtime/components/forms/Textarea.vue +++ b/src/runtime/components/forms/Textarea.vue @@ -27,11 +27,10 @@ import { defu } from 'defu' import { useUI } from '../../composables/useUI' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig, looseToNumber } from '../../utils' -import type { NestedKeyOf, Strategy } from '../../types' +import type { TextareaSize, TextareaColor, TextareaVariant, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { textarea } from '#ui/ui.config' -import colors from '#ui-colors' const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.textarea, textarea) @@ -87,21 +86,21 @@ export default defineComponent({ default: true }, size: { - type: String as PropType, + type: String as PropType, default: null, validator (value: string) { return Object.keys(config.size).includes(value) } }, color: { - type: String as PropType, + type: String as PropType, default: () => config.default.color, validator (value: string) { return [...appConfig.ui.colors, ...Object.keys(config.color)].includes(value) } }, variant: { - type: String as PropType>, + type: String as PropType, default: () => config.default.variant, validator (value: string) { return [ @@ -181,7 +180,7 @@ export default defineComponent({ const onInput = (event: InputEvent) => { autoResize() - if (!modelModifiers.value.lazy) { + if (!modelModifiers.value.lazy) { updateInput((event.target as HTMLInputElement).value) } } diff --git a/src/runtime/components/forms/Toggle.vue b/src/runtime/components/forms/Toggle.vue index dce1982b4d..5338b8e2f9 100644 --- a/src/runtime/components/forms/Toggle.vue +++ b/src/runtime/components/forms/Toggle.vue @@ -27,7 +27,7 @@ import UIcon from '../elements/Icon.vue' import { useUI } from '../../composables/useUI' import { useFormGroup } from '../../composables/useFormGroup' import { mergeConfig } from '../../utils' -import type { Strategy } from '../../types' +import type { ToggleSize, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { toggle } from '#ui/ui.config' @@ -78,7 +78,7 @@ export default defineComponent({ default: undefined }, size: { - type: String as PropType, + type: String as PropType, default: config.default.size, validator (value: string) { return Object.keys(config.size).includes(value) diff --git a/src/runtime/components/navigation/Pagination.vue b/src/runtime/components/navigation/Pagination.vue index bd4950991d..75e64ed39f 100644 --- a/src/runtime/components/navigation/Pagination.vue +++ b/src/runtime/components/navigation/Pagination.vue @@ -71,7 +71,7 @@ import type { PropType } from 'vue' import UButton from '../elements/Button.vue' import { useUI } from '../../composables/useUI' import { mergeConfig } from '../../utils' -import type { Button, Strategy } from '../../types' +import type { Button, ButtonSize, Strategy } from '../../types' // @ts-expect-error import appConfig from '#build/app.config' import { pagination, button } from '#ui/ui.config' @@ -106,7 +106,7 @@ export default defineComponent({ } }, size: { - type: String as PropType, + type: String as PropType, default: () => config.default.size, validator (value: string) { return Object.keys(buttonConfig.size).includes(value) diff --git a/src/runtime/types/alert.d.ts b/src/runtime/types/alert.d.ts new file mode 100644 index 0000000000..bf9c717c81 --- /dev/null +++ b/src/runtime/types/alert.d.ts @@ -0,0 +1,7 @@ +import { alert } from '../ui.config' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' +import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' + +export type AlertColor = keyof typeof alert.color | ExtractDeepKey | typeof colors[number] +export type AlertVariant = keyof typeof alert.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> diff --git a/src/runtime/types/avatar.d.ts b/src/runtime/types/avatar.d.ts index a0c9d9ed8e..79b3d628d5 100644 --- a/src/runtime/types/avatar.d.ts +++ b/src/runtime/types/avatar.d.ts @@ -1,7 +1,9 @@ import { avatar } from '../ui.config' +import type { ExtractDeepKey } from '.' import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' -export type AvatarSize = keyof typeof avatar.size +export type AvatarSize = keyof typeof avatar.size | ExtractDeepKey export type AvatarChipColor = 'gray' | typeof colors[number] export type AvatarChipPosition = keyof typeof avatar.chip.position diff --git a/src/runtime/types/badge.d.ts b/src/runtime/types/badge.d.ts index 5bfc5c29d1..5755863e34 100644 --- a/src/runtime/types/badge.d.ts +++ b/src/runtime/types/badge.d.ts @@ -1,10 +1,11 @@ import { badge } from '../ui.config' -import type { NestedKeyOf } from '.' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' -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 +export type BadgeSize = keyof typeof badge.size | ExtractDeepKey +export type BadgeColor = keyof typeof badge.color | ExtractDeepKey | typeof colors[number] +export type BadgeVariant = keyof typeof badge.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> export interface Badge { label?: string diff --git a/src/runtime/types/button.d.ts b/src/runtime/types/button.d.ts index 65ac2f6774..8a45c37b32 100644 --- a/src/runtime/types/button.d.ts +++ b/src/runtime/types/button.d.ts @@ -1,11 +1,12 @@ import type { Link } from './link' import { button } from '../ui.config' -import type { NestedKeyOf } from '.' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' -export type ButtonSize = keyof typeof button.size -export type ButtonColor = keyof typeof button.color | typeof colors[number] -export type ButtonVariant = keyof typeof button.variant | NestedKeyOf +export type ButtonSize = keyof typeof button.size | ExtractDeepKey +export type ButtonColor = keyof typeof button.color | ExtractDeepKey | typeof colors[number] +export type ButtonVariant = keyof typeof button.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> export interface Button extends Link { type?: string diff --git a/src/runtime/types/form-group.d.ts b/src/runtime/types/form-group.d.ts new file mode 100644 index 0000000000..95af3e7f98 --- /dev/null +++ b/src/runtime/types/form-group.d.ts @@ -0,0 +1,5 @@ +import { formGroup } from '../ui.config' +import type { ExtractDeepKey } from '.' +import type { AppConfig } from 'nuxt/schema' + +export type FormGroupSize = keyof typeof formGroup.size | ExtractDeepKey diff --git a/src/runtime/types/form.d.ts b/src/runtime/types/form.d.ts index c9cc405524..c3e1507fa3 100644 --- a/src/runtime/types/form.d.ts +++ b/src/runtime/types/form.d.ts @@ -1,4 +1,4 @@ -import { Ref } from 'vue' +import type { Ref } from 'vue' export interface FormError { path: T diff --git a/src/runtime/types/index.d.ts b/src/runtime/types/index.d.ts index e274f25e92..e76895a79d 100644 --- a/src/runtime/types/index.d.ts +++ b/src/runtime/types/index.d.ts @@ -1,4 +1,5 @@ export * from './accordion' +export * from './alert' export * from './avatar' export * from './badge' export * from './breadcrumb' @@ -6,12 +7,19 @@ export * from './button' export * from './clipboard' export * from './command-palette' export * from './dropdown' +export * from './form-group' export * from './form' +export * from './input' +export * from './kbd' export * from './link' export * from './meter' export * from './notification' export * from './popper' export * from './progress' +export * from './range' +export * from './select' export * from './tabs' +export * from './textarea' +export * from './toggle' export * from './vertical-navigation' export * from './utils' diff --git a/src/runtime/types/input.d.ts b/src/runtime/types/input.d.ts new file mode 100644 index 0000000000..2aed00ca37 --- /dev/null +++ b/src/runtime/types/input.d.ts @@ -0,0 +1,8 @@ +import { input } from '../ui.config' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' +import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' + +export type InputSize = keyof typeof input.size | ExtractDeepKey +export type InputColor = keyof typeof input.color | ExtractDeepKey | typeof colors[number] +export type InputVariant = keyof typeof input.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> diff --git a/src/runtime/types/kbd.d.ts b/src/runtime/types/kbd.d.ts new file mode 100644 index 0000000000..ad9d6bec6b --- /dev/null +++ b/src/runtime/types/kbd.d.ts @@ -0,0 +1,5 @@ +import { kbd } from '../ui.config' +import type { ExtractDeepKey } from '.' +import type { AppConfig } from 'nuxt/schema' + +export type KbdSize = keyof typeof kbd.size | ExtractDeepKey diff --git a/src/runtime/types/range.d.ts b/src/runtime/types/range.d.ts new file mode 100644 index 0000000000..7de5fbe369 --- /dev/null +++ b/src/runtime/types/range.d.ts @@ -0,0 +1,5 @@ +import { range } from '../ui.config' +import type { ExtractDeepKey } from '.' +import type { AppConfig } from 'nuxt/schema' + +export type RangeSize = keyof typeof range.size | ExtractDeepKey diff --git a/src/runtime/types/select.d.ts b/src/runtime/types/select.d.ts new file mode 100644 index 0000000000..9696470fd4 --- /dev/null +++ b/src/runtime/types/select.d.ts @@ -0,0 +1,8 @@ +import { select } from '../ui.config' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' +import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' + +export type SelectSize = keyof typeof select.size | ExtractDeepKey +export type SelectColor = keyof typeof select.color | ExtractDeepKey | typeof colors[number] +export type SelectVariant = keyof typeof select.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> diff --git a/src/runtime/types/textarea.d.ts b/src/runtime/types/textarea.d.ts new file mode 100644 index 0000000000..f8a74b59b7 --- /dev/null +++ b/src/runtime/types/textarea.d.ts @@ -0,0 +1,8 @@ +import { textarea } from '../ui.config' +import type { NestedKeyOf, ExtractDeepKey, ExtractDeepObject } from '.' +import colors from '#ui-colors' +import type { AppConfig } from 'nuxt/schema' + +export type TextareaSize = keyof typeof textarea.size | ExtractDeepKey +export type TextareaColor = keyof typeof textarea.color | ExtractDeepKey | typeof colors[number] +export type TextareaVariant = keyof typeof textarea.variant | ExtractDeepKey | NestedKeyOf | NestedKeyOf> diff --git a/src/runtime/types/toggle.d.ts b/src/runtime/types/toggle.d.ts new file mode 100644 index 0000000000..f341bafdde --- /dev/null +++ b/src/runtime/types/toggle.d.ts @@ -0,0 +1,5 @@ +import { toggle } from '../ui.config' +import type { ExtractDeepKey } from '.' +import type { AppConfig } from 'nuxt/schema' + +export type ToggleSize = keyof typeof toggle.size | ExtractDeepKey diff --git a/src/runtime/types/utils.d.ts b/src/runtime/types/utils.d.ts index 91a64270d6..ab8a70cb99 100644 --- a/src/runtime/types/utils.d.ts +++ b/src/runtime/types/utils.d.ts @@ -1,11 +1,28 @@ -export type Strategy = 'merge' | 'override'; +export type Strategy = 'merge' | 'override' export type NestedKeyOf = { [Key in keyof ObjectType]: ObjectType[Key] extends object ? NestedKeyOf - : Key; -}[keyof ObjectType]; + : Key +}[keyof ObjectType] export type DeepPartial = Partial<{ - [P in keyof T]: DeepPartial | { [key: string]: string | object }; -}>; + [P in keyof T]: DeepPartial | { [key: string]: string | object } +}> + +type DeepKey = + Keys extends [infer First, ...infer Rest] + ? First extends keyof T + ? Rest extends string[] + ? DeepKey + : never + : never + : T + +export type ExtractDeepKey = DeepKey extends infer Result + ? Result extends object ? keyof Result : never + : never + +export type ExtractDeepObject = DeepKey extends infer Result + ? Result extends object ? Result : never + : never diff --git a/src/runtime/utils/index.ts b/src/runtime/utils/index.ts index 1af846261f..31139c634a 100644 --- a/src/runtime/utils/index.ts +++ b/src/runtime/utils/index.ts @@ -39,7 +39,7 @@ export function hexToRgb (hex: string) { export function getSlotsChildren (slots: any) { let children = slots.default?.() - if (children.length) { + if (children?.length) { children = children.flatMap(c => { if (typeof c.type === 'symbol') { if (typeof c.children === 'string') { @@ -53,7 +53,7 @@ export function getSlotsChildren (slots: any) { return c }).filter(Boolean) } - return children + return children || [] } /**