daisy-ui-kit 5.0.0-pre.30 → 5.0.0-pre.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed, inject, provide, ref, useId, watch } from 'vue'
|
|
3
3
|
|
|
4
4
|
const props = defineProps<{
|
|
5
|
+
id?: string
|
|
5
6
|
variant?: 'arrow' | 'plus'
|
|
6
7
|
arrow?: boolean
|
|
7
8
|
plus?: boolean
|
|
@@ -20,7 +21,7 @@ const useAccordion = accordionValue.value !== null
|
|
|
20
21
|
const internalChecked = ref(props.open || false)
|
|
21
22
|
|
|
22
23
|
// Generate unique ID for checkbox
|
|
23
|
-
const checkboxId = `collapse-${useId()}`
|
|
24
|
+
const checkboxId = props.id || `collapse-${useId()}`
|
|
24
25
|
provide('collapseCheckboxId', checkboxId)
|
|
25
26
|
provide('collapseToggle', props.toggle || useAccordion)
|
|
26
27
|
|
|
@@ -17,10 +17,6 @@ interface DaisyThemeOptions {
|
|
|
17
17
|
defaultTheme?: string
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// Global state (client only)
|
|
21
|
-
let globalThemes: Ref<DaisyThemeMeta[]> | null = null
|
|
22
|
-
let globalTheme: Ref<string> | null = null
|
|
23
|
-
|
|
24
20
|
function normalizeTheme(input: DaisyThemeInput): DaisyThemeMeta {
|
|
25
21
|
if (typeof input === 'string') {
|
|
26
22
|
return { theme: input }
|
|
@@ -28,40 +24,53 @@ function normalizeTheme(input: DaisyThemeInput): DaisyThemeMeta {
|
|
|
28
24
|
return { ...input }
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
//
|
|
32
|
-
function
|
|
33
|
-
|
|
27
|
+
// SSR state using Nuxt's useState for proper hydration
|
|
28
|
+
function useSSRState<T>(key: string, init: () => T): Ref<T> {
|
|
29
|
+
// Use Nuxt's useState if available (works on both server and client with proper hydration)
|
|
30
|
+
if (typeof useState !== 'undefined') {
|
|
31
|
+
try {
|
|
32
|
+
return useState(key, init)
|
|
33
|
+
} catch {
|
|
34
|
+
// Fallback if useState is not available
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return ref(init()) as Ref<T>
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
// Global storage ref - set once in app.vue, reused elsewhere
|
|
41
|
+
let globalStorageRef: Ref<string> | null = null
|
|
42
|
+
|
|
36
43
|
/**
|
|
37
44
|
* useDaisyTheme composable
|
|
38
45
|
* @param storage Optional. Ref factory for persistence (e.g., useCookie, useLocalStorage, or ref). Defaults to ref.
|
|
39
46
|
* @param options Optional. Theme options (themes, defaultTheme, etc.).
|
|
40
47
|
*
|
|
41
|
-
* Calling with arguments (in app.vue/root): initializes global state
|
|
42
|
-
* Calling with no arguments (in any component): reuses global state
|
|
48
|
+
* Calling with arguments (in app.vue/root): initializes global state.
|
|
49
|
+
* Calling with no arguments (in any component): reuses global state.
|
|
43
50
|
*/
|
|
44
51
|
export function useDaisyTheme(storage?: <T>(key: string, initial: T) => Ref<T>, options?: DaisyThemeOptions) {
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
const isClient = typeof window !== 'undefined'
|
|
48
|
-
|
|
49
|
-
// Only initialize global state if provided options (themes, etc.)
|
|
50
|
-
if (isClient && options) {
|
|
51
|
-
globalThemes = ref(options.themes?.map(normalizeTheme) ?? [])
|
|
52
|
-
globalTheme = null // reset theme so it will be re-initialized below
|
|
53
|
-
}
|
|
52
|
+
// Use SSR-safe state that hydrates properly
|
|
53
|
+
const themes = useSSRState('daisy-themes', () => options?.themes?.map(normalizeTheme) ?? [])
|
|
54
54
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
// If options provided, update themes
|
|
56
|
+
if (options?.themes) {
|
|
57
|
+
themes.value = options.themes.map(normalizeTheme)
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
// Theme name
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
// Theme name - use provided storage or reuse global ref
|
|
61
|
+
let theme: Ref<string>
|
|
62
|
+
if (storage) {
|
|
63
|
+
// Initialize with provided storage (e.g., useCookie in app.vue)
|
|
64
|
+
theme = storage('theme', options?.defaultTheme ?? themes.value[0]?.theme ?? 'light')
|
|
65
|
+
globalStorageRef = theme
|
|
66
|
+
} else if (globalStorageRef) {
|
|
67
|
+
// Reuse the existing storage ref
|
|
68
|
+
theme = globalStorageRef
|
|
69
|
+
} else {
|
|
70
|
+
// Fallback to SSR state if no storage was ever provided
|
|
71
|
+
theme = useSSRState('daisy-theme', () => options?.defaultTheme ?? themes.value[0]?.theme ?? 'light')
|
|
72
|
+
globalStorageRef = theme
|
|
73
|
+
}
|
|
65
74
|
|
|
66
75
|
// System dark mode
|
|
67
76
|
const preferredDark = usePreferredDark()
|