daisy-ui-kit 5.0.0-pre.9 → 5.0.1
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.
- package/README.md +277 -48
- package/app/components/Accordion.vue +8 -5
- package/app/components/Alert.vue +2 -1
- package/app/components/Avatar.vue +10 -7
- package/app/components/AvatarGroup.vue +6 -2
- package/app/components/Badge.vue +19 -1
- package/app/components/Button.vue +66 -46
- package/app/components/Calendar.vue +151 -42
- package/app/components/CalendarInput.vue +229 -130
- package/app/components/CalendarSkeleton.vue +51 -10
- package/app/components/Card.vue +20 -2
- package/app/components/CardActions.vue +1 -1
- package/app/components/CardBody.vue +1 -1
- package/app/components/CardTitle.vue +1 -1
- package/app/components/Carousel.vue +2 -1
- package/app/components/Chat.vue +6 -1
- package/app/components/Checkbox.vue +1 -1
- package/app/components/Collapse.vue +38 -5
- package/app/components/CollapseTitle.vue +11 -1
- package/app/components/Countdown.vue +3 -3
- package/app/components/CountdownTimers.vue +4 -7
- package/app/components/Counter.vue +14 -3
- package/app/components/DaisyLink.vue +33 -15
- package/app/components/Dock.vue +5 -6
- package/app/components/DockItem.vue +5 -3
- package/app/components/Drawer.vue +15 -12
- package/app/components/DrawerContent.vue +9 -6
- package/app/components/DrawerSide.vue +9 -6
- package/app/components/Dropdown.vue +61 -50
- package/app/components/DropdownButton.vue +11 -4
- package/app/components/DropdownContent.vue +90 -20
- package/app/components/DropdownTarget.vue +10 -3
- package/app/components/Fab.vue +16 -0
- package/app/components/FabClose.vue +18 -0
- package/app/components/FabMainAction.vue +5 -0
- package/app/components/FabTrigger.vue +117 -0
- package/app/components/Fieldset.vue +5 -4
- package/app/components/FileInput.vue +1 -1
- package/app/components/Filter.vue +45 -38
- package/app/components/Flex.vue +8 -1
- package/app/components/FlexItem.vue +30 -27
- package/app/components/Footer.vue +16 -12
- package/app/components/FooterTitle.vue +8 -5
- package/app/components/Hero.vue +9 -6
- package/app/components/HeroContent.vue +9 -6
- package/app/components/Hover3D.vue +22 -0
- package/app/components/HoverGallery.vue +11 -0
- package/app/components/Indicator.vue +12 -5
- package/app/components/IndicatorItem.vue +21 -14
- package/app/components/Input.vue +44 -47
- package/app/components/Kbd.vue +2 -1
- package/app/components/Label.vue +32 -29
- package/app/components/MenuExpand.vue +5 -13
- package/app/components/MenuExpandToggle.vue +7 -1
- package/app/components/MenuItem.vue +6 -4
- package/app/components/Modal.vue +23 -17
- package/app/components/Progress.vue +13 -1
- package/app/components/Prose.vue +7 -2
- package/app/components/RadialProgress.vue +8 -8
- package/app/components/Radio.vue +1 -1
- package/app/components/RadioGroup.vue +2 -2
- package/app/components/Range.vue +186 -46
- package/app/components/RangeMeasure.vue +33 -30
- package/app/components/RangeMeasureTick.vue +4 -5
- package/app/components/Rating.vue +70 -53
- package/app/components/Select.vue +44 -47
- package/app/components/SkeletonText.vue +11 -0
- package/app/components/Stack.vue +5 -0
- package/app/components/Steps.vue +7 -2
- package/app/components/Swap.vue +4 -10
- package/app/components/Tab.vue +23 -5
- package/app/components/Text.vue +47 -23
- package/app/components/TextArea.vue +75 -30
- package/app/components/TextRotate.vue +24 -0
- package/app/components/ThemeController.vue +3 -4
- package/app/components/ThemeProvider.vue +47 -32
- package/app/components/TimelineLine.vue +1 -1
- package/app/components/TimelineStart.vue +2 -1
- package/app/components/Toast.vue +3 -8
- package/app/components/Toggle.vue +2 -2
- package/app/components/Tooltip.vue +111 -21
- package/app/components/TooltipContent.vue +279 -1
- package/app/components/TooltipTarget.vue +20 -0
- package/app/composables/__tests__/use-calendar.test.ts +239 -0
- package/app/composables/use-calendar.ts +288 -0
- package/app/composables/use-daisy-theme.ts +140 -0
- package/app/composables/use-toast.ts +345 -0
- package/app/composables/useSearch.ts +22 -0
- package/app/utils/drawer-utils.ts +15 -13
- package/app/utils/position-area.ts +40 -0
- package/nuxt.d.ts +13 -0
- package/nuxt.js +12 -9
- package/package.json +34 -17
- package/app/utils/random-string.ts +0 -19
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { useCalendar } from '../use-calendar'
|
|
3
|
+
|
|
4
|
+
describe('useCalendar', () => {
|
|
5
|
+
describe('initialization', () => {
|
|
6
|
+
it('initializes with null date by default', () => {
|
|
7
|
+
const { selectedDate } = useCalendar()
|
|
8
|
+
expect(selectedDate.value).toBeNull()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('initializes with provided date', () => {
|
|
12
|
+
const date = new Date(2025, 5, 15) // June 15, 2025
|
|
13
|
+
const { selectedDate } = useCalendar(date)
|
|
14
|
+
expect(selectedDate.value?.getFullYear()).toBe(2025)
|
|
15
|
+
expect(selectedDate.value?.getMonth()).toBe(5)
|
|
16
|
+
expect(selectedDate.value?.getDate()).toBe(15)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('sets viewDate to today when no initial date provided', () => {
|
|
20
|
+
const { viewDate } = useCalendar()
|
|
21
|
+
const today = new Date()
|
|
22
|
+
expect(viewDate.value.getFullYear()).toBe(today.getFullYear())
|
|
23
|
+
expect(viewDate.value.getMonth()).toBe(today.getMonth())
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('sets viewDate to initial date when provided', () => {
|
|
27
|
+
const date = new Date(2025, 5, 15)
|
|
28
|
+
const { viewDate } = useCalendar(date)
|
|
29
|
+
expect(viewDate.value.getFullYear()).toBe(2025)
|
|
30
|
+
expect(viewDate.value.getMonth()).toBe(5)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('weekday headers', () => {
|
|
35
|
+
it('returns weekday headers starting with Sunday by default', () => {
|
|
36
|
+
const { weekdayHeaders } = useCalendar()
|
|
37
|
+
expect(weekdayHeaders.value).toEqual(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('returns weekday headers starting with Monday when firstDay is 1', () => {
|
|
41
|
+
const { weekdayHeaders } = useCalendar(null, { firstDay: 1 })
|
|
42
|
+
expect(weekdayHeaders.value).toEqual(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('returns full weekday names for accessibility', () => {
|
|
46
|
+
const { weekdayHeadersFull } = useCalendar()
|
|
47
|
+
expect(weekdayHeadersFull.value).toEqual([
|
|
48
|
+
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
|
49
|
+
])
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('month display', () => {
|
|
54
|
+
it('returns correct month name', () => {
|
|
55
|
+
const date = new Date(2025, 5, 15) // June
|
|
56
|
+
const { monthName } = useCalendar(date)
|
|
57
|
+
expect(monthName.value).toBe('June')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('returns correct short month name', () => {
|
|
61
|
+
const date = new Date(2025, 11, 25) // December
|
|
62
|
+
const { monthNameShort } = useCalendar(date)
|
|
63
|
+
expect(monthNameShort.value).toBe('Dec')
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('calendar days', () => {
|
|
68
|
+
it('generates 42 days (6 weeks)', () => {
|
|
69
|
+
const { calendarDays } = useCalendar(new Date(2025, 5, 15))
|
|
70
|
+
expect(calendarDays.value).toHaveLength(42)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('marks days outside current month', () => {
|
|
74
|
+
const { calendarDays } = useCalendar(new Date(2025, 5, 15)) // June 2025
|
|
75
|
+
const outsideDays = calendarDays.value.filter(d => d.isOutsideMonth)
|
|
76
|
+
expect(outsideDays.length).toBeGreaterThan(0)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('marks the selected date', () => {
|
|
80
|
+
const date = new Date(2025, 5, 15)
|
|
81
|
+
const { calendarDays } = useCalendar(date)
|
|
82
|
+
const selectedDays = calendarDays.value.filter(d => d.isSelected)
|
|
83
|
+
expect(selectedDays).toHaveLength(1)
|
|
84
|
+
expect(selectedDays[0]?.day).toBe(15)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('marks today correctly', () => {
|
|
88
|
+
const today = new Date()
|
|
89
|
+
const { calendarDays, goToDate } = useCalendar()
|
|
90
|
+
goToDate(today)
|
|
91
|
+
const todayDays = calendarDays.value.filter(d => d.isToday && !d.isOutsideMonth)
|
|
92
|
+
expect(todayDays).toHaveLength(1)
|
|
93
|
+
expect(todayDays[0]?.day).toBe(today.getDate())
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('navigation', () => {
|
|
98
|
+
it('navigates to next month', () => {
|
|
99
|
+
const { viewMonth, viewYear, nextMonth } = useCalendar(new Date(2025, 5, 15))
|
|
100
|
+
expect(viewMonth.value).toBe(5)
|
|
101
|
+
nextMonth()
|
|
102
|
+
expect(viewMonth.value).toBe(6)
|
|
103
|
+
expect(viewYear.value).toBe(2025)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('navigates to previous month', () => {
|
|
107
|
+
const { viewMonth, viewYear, prevMonth } = useCalendar(new Date(2025, 5, 15))
|
|
108
|
+
expect(viewMonth.value).toBe(5)
|
|
109
|
+
prevMonth()
|
|
110
|
+
expect(viewMonth.value).toBe(4)
|
|
111
|
+
expect(viewYear.value).toBe(2025)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('handles year rollover when navigating forward', () => {
|
|
115
|
+
const { viewMonth, viewYear, nextMonth } = useCalendar(new Date(2025, 11, 15))
|
|
116
|
+
expect(viewMonth.value).toBe(11)
|
|
117
|
+
nextMonth()
|
|
118
|
+
expect(viewMonth.value).toBe(0)
|
|
119
|
+
expect(viewYear.value).toBe(2026)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('handles year rollover when navigating backward', () => {
|
|
123
|
+
const { viewMonth, viewYear, prevMonth } = useCalendar(new Date(2025, 0, 15))
|
|
124
|
+
expect(viewMonth.value).toBe(0)
|
|
125
|
+
prevMonth()
|
|
126
|
+
expect(viewMonth.value).toBe(11)
|
|
127
|
+
expect(viewYear.value).toBe(2024)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('goes to specific month', () => {
|
|
131
|
+
const { viewMonth, goToMonth } = useCalendar(new Date(2025, 5, 15))
|
|
132
|
+
goToMonth(10)
|
|
133
|
+
expect(viewMonth.value).toBe(10)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('goes to specific year', () => {
|
|
137
|
+
const { viewYear, goToYear } = useCalendar(new Date(2025, 5, 15))
|
|
138
|
+
goToYear(2030)
|
|
139
|
+
expect(viewYear.value).toBe(2030)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('goes to today', () => {
|
|
143
|
+
const { viewMonth, viewYear, goToToday } = useCalendar(new Date(2020, 0, 1))
|
|
144
|
+
const today = new Date()
|
|
145
|
+
goToToday()
|
|
146
|
+
expect(viewMonth.value).toBe(today.getMonth())
|
|
147
|
+
expect(viewYear.value).toBe(today.getFullYear())
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
describe('selection', () => {
|
|
152
|
+
it('selects a date', () => {
|
|
153
|
+
const { selectedDate, selectDate } = useCalendar()
|
|
154
|
+
const date = new Date(2025, 5, 20)
|
|
155
|
+
selectDate(date)
|
|
156
|
+
expect(selectedDate.value?.getDate()).toBe(20)
|
|
157
|
+
expect(selectedDate.value?.getMonth()).toBe(5)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('clears selection', () => {
|
|
161
|
+
const { selectedDate, clearSelection } = useCalendar(new Date(2025, 5, 15))
|
|
162
|
+
expect(selectedDate.value).not.toBeNull()
|
|
163
|
+
clearSelection()
|
|
164
|
+
expect(selectedDate.value).toBeNull()
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('does not select disabled dates', () => {
|
|
168
|
+
const minDate = new Date(2025, 5, 10)
|
|
169
|
+
const { selectedDate, selectDate } = useCalendar(null, { minDate })
|
|
170
|
+
selectDate(new Date(2025, 5, 5)) // Before minDate
|
|
171
|
+
expect(selectedDate.value).toBeNull()
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
describe('date constraints', () => {
|
|
176
|
+
it('marks dates before minDate as disabled', () => {
|
|
177
|
+
const minDate = new Date(2025, 5, 15)
|
|
178
|
+
const { calendarDays } = useCalendar(new Date(2025, 5, 20), { minDate })
|
|
179
|
+
const june14 = calendarDays.value.find(d => d.day === 14 && d.month === 5)
|
|
180
|
+
const june15 = calendarDays.value.find(d => d.day === 15 && d.month === 5)
|
|
181
|
+
expect(june14?.isDisabled).toBe(true)
|
|
182
|
+
expect(june15?.isDisabled).toBe(false)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('marks dates after maxDate as disabled', () => {
|
|
186
|
+
const maxDate = new Date(2025, 5, 15)
|
|
187
|
+
const { calendarDays } = useCalendar(new Date(2025, 5, 10), { maxDate })
|
|
188
|
+
const june15 = calendarDays.value.find(d => d.day === 15 && d.month === 5)
|
|
189
|
+
const june16 = calendarDays.value.find(d => d.day === 16 && d.month === 5)
|
|
190
|
+
expect(june15?.isDisabled).toBe(false)
|
|
191
|
+
expect(june16?.isDisabled).toBe(true)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('formatting', () => {
|
|
196
|
+
it('formats date with default format', () => {
|
|
197
|
+
const { formatDate } = useCalendar(new Date(2025, 5, 15))
|
|
198
|
+
expect(formatDate()).toBe('15 Jun 2025')
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('formats date with custom format', () => {
|
|
202
|
+
const { formatDate } = useCalendar(new Date(2025, 5, 15))
|
|
203
|
+
expect(formatDate('YYYY-MM-DD')).toBe('2025-06-15')
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('formats date with full month name', () => {
|
|
207
|
+
const { formatDate } = useCalendar(new Date(2025, 5, 15))
|
|
208
|
+
expect(formatDate('MMMM D, YYYY')).toBe('June 15, 2025')
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('returns empty string when no date selected', () => {
|
|
212
|
+
const { formatDate } = useCalendar()
|
|
213
|
+
expect(formatDate()).toBe('')
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
describe('utility functions', () => {
|
|
218
|
+
it('isSameDay returns true for same day', () => {
|
|
219
|
+
const { isSameDay } = useCalendar()
|
|
220
|
+
const a = new Date(2025, 5, 15, 10, 30)
|
|
221
|
+
const b = new Date(2025, 5, 15, 20, 45)
|
|
222
|
+
expect(isSameDay(a, b)).toBe(true)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('isSameDay returns false for different days', () => {
|
|
226
|
+
const { isSameDay } = useCalendar()
|
|
227
|
+
const a = new Date(2025, 5, 15)
|
|
228
|
+
const b = new Date(2025, 5, 16)
|
|
229
|
+
expect(isSameDay(a, b)).toBe(false)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('isSameDay handles null values', () => {
|
|
233
|
+
const { isSameDay } = useCalendar()
|
|
234
|
+
expect(isSameDay(null, new Date())).toBe(false)
|
|
235
|
+
expect(isSameDay(new Date(), null)).toBe(false)
|
|
236
|
+
expect(isSameDay(null, null)).toBe(false)
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
})
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { computed, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export interface CalendarOptions {
|
|
4
|
+
/** First day of week: 0 = Sunday, 1 = Monday, etc. */
|
|
5
|
+
firstDay?: number
|
|
6
|
+
/** Minimum selectable date */
|
|
7
|
+
minDate?: Date | null
|
|
8
|
+
/** Maximum selectable date */
|
|
9
|
+
maxDate?: Date | null
|
|
10
|
+
/** Locale for formatting (default: 'en-US') */
|
|
11
|
+
locale?: string
|
|
12
|
+
/** Short month names */
|
|
13
|
+
monthsShort?: string[]
|
|
14
|
+
/** Full month names */
|
|
15
|
+
months?: string[]
|
|
16
|
+
/** Short weekday names */
|
|
17
|
+
weekdaysShort?: string[]
|
|
18
|
+
/** Full weekday names */
|
|
19
|
+
weekdays?: string[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CalendarDay {
|
|
23
|
+
date: Date
|
|
24
|
+
day: number
|
|
25
|
+
month: number
|
|
26
|
+
year: number
|
|
27
|
+
isToday: boolean
|
|
28
|
+
isSelected: boolean
|
|
29
|
+
isDisabled: boolean
|
|
30
|
+
isOutsideMonth: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DEFAULT_MONTHS = [
|
|
34
|
+
'January',
|
|
35
|
+
'February',
|
|
36
|
+
'March',
|
|
37
|
+
'April',
|
|
38
|
+
'May',
|
|
39
|
+
'June',
|
|
40
|
+
'July',
|
|
41
|
+
'August',
|
|
42
|
+
'September',
|
|
43
|
+
'October',
|
|
44
|
+
'November',
|
|
45
|
+
'December',
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
const DEFAULT_MONTHS_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
49
|
+
|
|
50
|
+
const DEFAULT_WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
|
51
|
+
|
|
52
|
+
const DEFAULT_WEEKDAYS_SHORT = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
53
|
+
|
|
54
|
+
export function useCalendar(initialDate: Date | null = null, options: CalendarOptions = {}) {
|
|
55
|
+
const {
|
|
56
|
+
firstDay = 0,
|
|
57
|
+
minDate = null,
|
|
58
|
+
maxDate = null,
|
|
59
|
+
months = DEFAULT_MONTHS,
|
|
60
|
+
monthsShort = DEFAULT_MONTHS_SHORT,
|
|
61
|
+
weekdays = DEFAULT_WEEKDAYS,
|
|
62
|
+
weekdaysShort = DEFAULT_WEEKDAYS_SHORT,
|
|
63
|
+
} = options
|
|
64
|
+
|
|
65
|
+
// The currently selected date
|
|
66
|
+
const selectedDate = ref<Date | null>(initialDate)
|
|
67
|
+
|
|
68
|
+
// The month/year currently being viewed
|
|
69
|
+
const viewDate = ref(initialDate ? new Date(initialDate) : new Date())
|
|
70
|
+
|
|
71
|
+
// Current view month/year
|
|
72
|
+
const viewMonth = computed(() => viewDate.value.getMonth())
|
|
73
|
+
const viewYear = computed(() => viewDate.value.getFullYear())
|
|
74
|
+
|
|
75
|
+
// Month/year display strings
|
|
76
|
+
const monthName = computed(() => months[viewMonth.value])
|
|
77
|
+
const monthNameShort = computed(() => monthsShort[viewMonth.value])
|
|
78
|
+
|
|
79
|
+
// Weekday headers adjusted for firstDay (short names for display)
|
|
80
|
+
const weekdayHeaders = computed(() => {
|
|
81
|
+
const headers: string[] = []
|
|
82
|
+
for (let i = 0; i < 7; i++) {
|
|
83
|
+
headers.push(weekdaysShort[(i + firstDay) % 7] ?? '')
|
|
84
|
+
}
|
|
85
|
+
return headers
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
// Full weekday names for accessibility (title attributes, screen readers)
|
|
89
|
+
const weekdayHeadersFull = computed(() => {
|
|
90
|
+
const headers: string[] = []
|
|
91
|
+
for (let i = 0; i < 7; i++) {
|
|
92
|
+
headers.push(weekdays[(i + firstDay) % 7] ?? '')
|
|
93
|
+
}
|
|
94
|
+
return headers
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Get days in a month
|
|
98
|
+
function getDaysInMonth(year: number, month: number): number {
|
|
99
|
+
return new Date(year, month + 1, 0).getDate()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Check if two dates are the same day
|
|
103
|
+
function isSameDay(a: Date | null, b: Date | null): boolean {
|
|
104
|
+
if (!a || !b) return false
|
|
105
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check if a date is today
|
|
109
|
+
function isToday(date: Date): boolean {
|
|
110
|
+
return isSameDay(date, new Date())
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Check if a date is disabled
|
|
114
|
+
function isDisabled(date: Date): boolean {
|
|
115
|
+
if (minDate && date < minDate) return true
|
|
116
|
+
if (maxDate && date > maxDate) return true
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Generate calendar days for the current view
|
|
121
|
+
const calendarDays = computed<CalendarDay[]>(() => {
|
|
122
|
+
const year = viewYear.value
|
|
123
|
+
const month = viewMonth.value
|
|
124
|
+
const days: CalendarDay[] = []
|
|
125
|
+
|
|
126
|
+
// First day of the month
|
|
127
|
+
const firstOfMonth = new Date(year, month, 1)
|
|
128
|
+
const startDayOfWeek = firstOfMonth.getDay()
|
|
129
|
+
|
|
130
|
+
// Calculate offset based on firstDay option
|
|
131
|
+
const offset = (startDayOfWeek - firstDay + 7) % 7
|
|
132
|
+
|
|
133
|
+
// Days from previous month
|
|
134
|
+
const prevMonth = month === 0 ? 11 : month - 1
|
|
135
|
+
const prevYear = month === 0 ? year - 1 : year
|
|
136
|
+
const daysInPrevMonth = getDaysInMonth(prevYear, prevMonth)
|
|
137
|
+
|
|
138
|
+
for (let i = offset - 1; i >= 0; i--) {
|
|
139
|
+
const day = daysInPrevMonth - i
|
|
140
|
+
const date = new Date(prevYear, prevMonth, day)
|
|
141
|
+
days.push({
|
|
142
|
+
date,
|
|
143
|
+
day,
|
|
144
|
+
month: prevMonth,
|
|
145
|
+
year: prevYear,
|
|
146
|
+
isToday: isToday(date),
|
|
147
|
+
isSelected: isSameDay(date, selectedDate.value),
|
|
148
|
+
isDisabled: isDisabled(date),
|
|
149
|
+
isOutsideMonth: true,
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Days in current month
|
|
154
|
+
const daysInMonth = getDaysInMonth(year, month)
|
|
155
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
156
|
+
const date = new Date(year, month, day)
|
|
157
|
+
days.push({
|
|
158
|
+
date,
|
|
159
|
+
day,
|
|
160
|
+
month,
|
|
161
|
+
year,
|
|
162
|
+
isToday: isToday(date),
|
|
163
|
+
isSelected: isSameDay(date, selectedDate.value),
|
|
164
|
+
isDisabled: isDisabled(date),
|
|
165
|
+
isOutsideMonth: false,
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Days from next month to fill the grid (always 6 rows = 42 cells)
|
|
170
|
+
const nextMonth = month === 11 ? 0 : month + 1
|
|
171
|
+
const nextYear = month === 11 ? year + 1 : year
|
|
172
|
+
const remainingDays = 42 - days.length
|
|
173
|
+
|
|
174
|
+
for (let day = 1; day <= remainingDays; day++) {
|
|
175
|
+
const date = new Date(nextYear, nextMonth, day)
|
|
176
|
+
days.push({
|
|
177
|
+
date,
|
|
178
|
+
day,
|
|
179
|
+
month: nextMonth,
|
|
180
|
+
year: nextYear,
|
|
181
|
+
isToday: isToday(date),
|
|
182
|
+
isSelected: isSameDay(date, selectedDate.value),
|
|
183
|
+
isDisabled: isDisabled(date),
|
|
184
|
+
isOutsideMonth: true,
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return days
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// Navigation
|
|
192
|
+
function prevMonth() {
|
|
193
|
+
const d = new Date(viewDate.value)
|
|
194
|
+
d.setMonth(d.getMonth() - 1)
|
|
195
|
+
viewDate.value = d
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function nextMonth() {
|
|
199
|
+
const d = new Date(viewDate.value)
|
|
200
|
+
d.setMonth(d.getMonth() + 1)
|
|
201
|
+
viewDate.value = d
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function goToMonth(month: number) {
|
|
205
|
+
const d = new Date(viewDate.value)
|
|
206
|
+
d.setMonth(month)
|
|
207
|
+
viewDate.value = d
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function goToYear(year: number) {
|
|
211
|
+
const d = new Date(viewDate.value)
|
|
212
|
+
d.setFullYear(year)
|
|
213
|
+
viewDate.value = d
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function goToDate(date: Date) {
|
|
217
|
+
viewDate.value = new Date(date)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function goToToday() {
|
|
221
|
+
viewDate.value = new Date()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Selection
|
|
225
|
+
function selectDate(date: Date) {
|
|
226
|
+
if (isDisabled(date)) return
|
|
227
|
+
selectedDate.value = new Date(date)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function clearSelection() {
|
|
231
|
+
selectedDate.value = null
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Format selected date
|
|
235
|
+
function formatDate(format: string = 'D MMM YYYY'): string {
|
|
236
|
+
if (!selectedDate.value) return ''
|
|
237
|
+
|
|
238
|
+
const d = selectedDate.value
|
|
239
|
+
const day = d.getDate()
|
|
240
|
+
const month = d.getMonth()
|
|
241
|
+
const year = d.getFullYear()
|
|
242
|
+
|
|
243
|
+
return format
|
|
244
|
+
.replace('YYYY', String(year))
|
|
245
|
+
.replace('YY', String(year).slice(-2))
|
|
246
|
+
.replace('MMMM', months[month] ?? '')
|
|
247
|
+
.replace('MMM', monthsShort[month] ?? '')
|
|
248
|
+
.replace('MM', String(month + 1).padStart(2, '0'))
|
|
249
|
+
.replace('M', String(month + 1))
|
|
250
|
+
.replace('DD', String(day).padStart(2, '0'))
|
|
251
|
+
.replace('D', String(day))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
// State
|
|
256
|
+
selectedDate,
|
|
257
|
+
viewDate,
|
|
258
|
+
viewMonth,
|
|
259
|
+
viewYear,
|
|
260
|
+
|
|
261
|
+
// Display
|
|
262
|
+
monthName,
|
|
263
|
+
monthNameShort,
|
|
264
|
+
weekdayHeaders,
|
|
265
|
+
weekdayHeadersFull,
|
|
266
|
+
calendarDays,
|
|
267
|
+
|
|
268
|
+
// Navigation
|
|
269
|
+
prevMonth,
|
|
270
|
+
nextMonth,
|
|
271
|
+
goToMonth,
|
|
272
|
+
goToYear,
|
|
273
|
+
goToDate,
|
|
274
|
+
goToToday,
|
|
275
|
+
|
|
276
|
+
// Selection
|
|
277
|
+
selectDate,
|
|
278
|
+
clearSelection,
|
|
279
|
+
|
|
280
|
+
// Formatting
|
|
281
|
+
formatDate,
|
|
282
|
+
|
|
283
|
+
// Utilities
|
|
284
|
+
isSameDay,
|
|
285
|
+
isToday,
|
|
286
|
+
isDisabled,
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { usePreferredDark } from '@vueuse/core'
|
|
3
|
+
import { computed, ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
// Type for a theme object
|
|
6
|
+
export interface DaisyThemeMeta {
|
|
7
|
+
theme: string
|
|
8
|
+
cssVars?: string
|
|
9
|
+
name?: string
|
|
10
|
+
[key: string]: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type DaisyThemeInput = string | DaisyThemeMeta
|
|
14
|
+
|
|
15
|
+
interface DaisyThemeOptions {
|
|
16
|
+
themes: DaisyThemeInput[]
|
|
17
|
+
defaultTheme?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeTheme(input: DaisyThemeInput): DaisyThemeMeta {
|
|
21
|
+
if (typeof input === 'string') {
|
|
22
|
+
return { theme: input }
|
|
23
|
+
}
|
|
24
|
+
return { ...input }
|
|
25
|
+
}
|
|
26
|
+
|
|
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>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Global storage ref - set once in app.vue, reused elsewhere
|
|
41
|
+
let globalStorageRef: Ref<string> | null = null
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* useDaisyTheme composable
|
|
45
|
+
* @param storage Optional. Ref factory for persistence (e.g., useCookie, useLocalStorage, or ref). Defaults to ref.
|
|
46
|
+
* @param options Optional. Theme options (themes, defaultTheme, etc.).
|
|
47
|
+
*
|
|
48
|
+
* Calling with arguments (in app.vue/root): initializes global state.
|
|
49
|
+
* Calling with no arguments (in any component): reuses global state.
|
|
50
|
+
*/
|
|
51
|
+
export function useDaisyTheme(storage?: <T>(key: string, initial: T) => Ref<T>, options?: DaisyThemeOptions) {
|
|
52
|
+
// Use SSR-safe state that hydrates properly
|
|
53
|
+
const themes = useSSRState('daisy-themes', () => options?.themes?.map(normalizeTheme) ?? [])
|
|
54
|
+
|
|
55
|
+
// If options provided, update themes
|
|
56
|
+
if (options?.themes) {
|
|
57
|
+
themes.value = options.themes.map(normalizeTheme)
|
|
58
|
+
}
|
|
59
|
+
|
|
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
|
+
}
|
|
74
|
+
|
|
75
|
+
// System dark mode
|
|
76
|
+
const preferredDark = usePreferredDark()
|
|
77
|
+
|
|
78
|
+
// Compute the effective theme for UI/DOM
|
|
79
|
+
const effectiveTheme = computed(() => {
|
|
80
|
+
if (theme.value === 'system') {
|
|
81
|
+
return preferredDark.value ? 'dark' : 'light'
|
|
82
|
+
}
|
|
83
|
+
return theme.value
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// Set theme by name
|
|
87
|
+
function setTheme(name: string) {
|
|
88
|
+
if (themes.value.some(t => t.theme === name) || name === 'system') {
|
|
89
|
+
theme.value = name
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Cycle to next theme
|
|
94
|
+
function cycleTheme() {
|
|
95
|
+
const names = themes.value.map(t => t.theme)
|
|
96
|
+
if (!names.length) {
|
|
97
|
+
return // Guard: no themes
|
|
98
|
+
}
|
|
99
|
+
const idx = names.indexOf(theme.value)
|
|
100
|
+
const nextIdx = (idx + 1) % names.length
|
|
101
|
+
// Only set if defined (TypeScript safety)
|
|
102
|
+
if (typeof names[nextIdx] === 'string') {
|
|
103
|
+
setTheme(names[nextIdx]!)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Register a new theme
|
|
108
|
+
function registerTheme(newTheme: DaisyThemeInput) {
|
|
109
|
+
const meta = normalizeTheme(newTheme)
|
|
110
|
+
if (!themes.value.some(t => t.theme === meta.theme)) {
|
|
111
|
+
themes.value.push(meta)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Remove a theme by name
|
|
116
|
+
function removeTheme(name: string) {
|
|
117
|
+
const idx = themes.value.findIndex(t => t.theme === name)
|
|
118
|
+
if (idx !== -1) {
|
|
119
|
+
themes.value.splice(idx, 1)
|
|
120
|
+
// If current theme was removed, fallback to first
|
|
121
|
+
if (theme.value === name) {
|
|
122
|
+
theme.value = themes.value[0]?.theme ?? 'light'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Get the current theme object
|
|
128
|
+
const themeInfo = computed(() => themes.value.find(t => t.theme === theme.value))
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
themes,
|
|
132
|
+
theme,
|
|
133
|
+
effectiveTheme,
|
|
134
|
+
themeInfo,
|
|
135
|
+
setTheme,
|
|
136
|
+
cycleTheme,
|
|
137
|
+
registerTheme,
|
|
138
|
+
removeTheme,
|
|
139
|
+
}
|
|
140
|
+
}
|