feat(extendLocale): new composable

Resolves #3729
This commit is contained in:
Benjamin Canac
2025-06-11 10:58:11 +02:00
parent 1841e13b32
commit 0f558fc0d0
4 changed files with 132 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { defu } from 'defu'
import type { Locale, Direction } from '../types/locale'
import type { DeepPartial } from '../types/utils'
interface DefineLocaleOptions<M> {
name: string
@@ -12,3 +13,8 @@ interface DefineLocaleOptions<M> {
export function defineLocale<M>(options: DefineLocaleOptions<M>): Locale<M> {
return defu<DefineLocaleOptions<M>, [{ dir: Direction }]>(options, { dir: 'ltr' })
}
/* @__NO_SIDE_EFFECTS__ */
export function extendLocale<M>(locale: Locale<M>, options: Partial<DefineLocaleOptions<DeepPartial<M>>>): Locale<M> {
return defu<Locale<M>, [DefineLocaleOptions<M>]>(options, locale)
}

View File

@@ -1,6 +1,10 @@
import type { VNode } from 'vue'
import type { AcceptableValue as _AcceptableValue } from 'reka-ui'
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] | undefined
}
export type DynamicSlotsKeys<Name extends string | undefined, Suffix extends string | undefined = undefined> = (
Name extends string
? Suffix extends string