@coreui/vue-pro 4.1.4 → 4.3.0-beta.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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/dist/components/button/CButton.d.ts +29 -2
  3. package/dist/components/calendar/CCalendar.d.ts +185 -0
  4. package/dist/components/calendar/index.d.ts +6 -0
  5. package/dist/components/date-picker/CDatePicker.d.ts +406 -0
  6. package/dist/components/date-picker/index.d.ts +6 -0
  7. package/dist/components/date-range-picker/CDateRangePicker.d.ts +480 -0
  8. package/dist/components/date-range-picker/index.d.ts +6 -0
  9. package/dist/components/dropdown/CDropdown.d.ts +25 -0
  10. package/dist/components/dropdown/CDropdownToggle.d.ts +35 -1
  11. package/dist/components/index.d.ts +5 -0
  12. package/dist/components/multi-select/CMultiSelect.d.ts +2 -2
  13. package/dist/components/picker/CPicker.d.ts +11 -0
  14. package/dist/components/picker/index.d.ts +6 -0
  15. package/dist/components/popover/CPopover.d.ts +1 -1
  16. package/dist/components/sidebar/CSidebar.d.ts +1 -1
  17. package/dist/components/smart-table/CSmartTable.d.ts +35 -99
  18. package/dist/components/smart-table/CSmartTableInterface.d.ts +3 -3
  19. package/dist/components/time-picker/CTimePicker.d.ts +10 -0
  20. package/dist/components/time-picker/CTimePickerRollCol.d.ts +27 -0
  21. package/dist/components/time-picker/index.d.ts +6 -0
  22. package/dist/components/toast/CToast.d.ts +1 -1
  23. package/dist/index.es.js +3726 -1646
  24. package/dist/index.es.js.map +1 -1
  25. package/dist/index.js +3734 -1644
  26. package/dist/index.js.map +1 -1
  27. package/dist/utils/calendar.d.ts +21 -0
  28. package/dist/utils/time.d.ts +17 -0
  29. package/package.json +9 -9
  30. package/src/components/accordion/CAccordionButton.ts +1 -0
  31. package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.ts.snap +1 -1
  32. package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.ts.snap +1 -1
  33. package/src/components/button/CButton.ts +30 -1
  34. package/src/components/button/__tests__/__snapshots__/CButton.spec.ts.snap +1 -1
  35. package/src/components/calendar/CCalendar.ts +546 -0
  36. package/src/components/calendar/index.ts +10 -0
  37. package/src/components/close-button/CCloseButton.ts +4 -1
  38. package/src/components/date-picker/CDatePicker.ts +243 -0
  39. package/src/components/date-picker/index.ts +10 -0
  40. package/src/components/date-range-picker/CDateRangePicker.ts +635 -0
  41. package/src/components/date-range-picker/index.ts +10 -0
  42. package/src/components/dropdown/CDropdown.ts +48 -49
  43. package/src/components/dropdown/CDropdownMenu.ts +52 -7
  44. package/src/components/dropdown/CDropdownToggle.ts +93 -29
  45. package/src/components/dropdown/__tests__/CDropdownMenu.spec.ts +7 -7
  46. package/src/components/dropdown/__tests__/CDropdownToggle.spec.ts +4 -5
  47. package/src/components/dropdown/__tests__/__snapshots__/CDropdownToggle.spec.ts.snap +2 -2
  48. package/src/components/form/CFormCheck.ts +2 -1
  49. package/src/components/form/CFormSwitch.ts +1 -7
  50. package/src/components/form/__tests__/__snapshots__/CFormCheck.spec.ts.snap +2 -8
  51. package/src/components/index.ts +5 -0
  52. package/src/components/modal/__tests__/__snapshots__/CModal.spec.ts.snap +2 -1
  53. package/src/components/pagination/CSmartPagination.ts +4 -4
  54. package/src/components/picker/CPicker.ts +220 -0
  55. package/src/components/picker/index.ts +10 -0
  56. package/src/components/sidebar/__tests__/__snapshots__/CSidebar.spec.ts.snap +8 -2
  57. package/src/components/smart-table/CSmartTable.ts +17 -49
  58. package/src/components/smart-table/CSmartTableInterface.ts +5 -3
  59. package/src/components/time-picker/CTimePicker.ts +410 -0
  60. package/src/components/time-picker/CTimePickerRollCol.ts +58 -0
  61. package/src/components/time-picker/index.ts +10 -0
  62. package/src/components/toast/__tests__/__snapshots__/CToastClose.spec.ts.snap +1 -1
  63. package/src/utils/calendar.ts +193 -0
  64. package/src/utils/time.ts +58 -0
@@ -0,0 +1,21 @@
1
+ export declare const convertToLocalDate: (d: Date, locale: string, options?: {}) => string;
2
+ export declare const convertToLocalTime: (d: Date, locale: string, options?: {}) => string;
3
+ export declare const createGroupsInArray: (arr: any[], numberOfGroups: number) => any[][];
4
+ export declare const getCurrentYear: () => number;
5
+ export declare const getCurrentMonth: () => number;
6
+ export declare const getMonthName: (month: number, locale: string) => string;
7
+ export declare const getMonthsNames: (locale: string) => string[];
8
+ export declare const getYears: (year: number) => number[];
9
+ export declare const getMonthDetails: (year: number, month: number, firstDayOfWeek: number) => {
10
+ date: Date;
11
+ month: string;
12
+ }[][];
13
+ export declare const isDateDisabled: (date: Date, min?: Date | null | undefined, max?: Date | null | undefined, dates?: Date[] | Date[][] | undefined) => boolean | undefined;
14
+ export declare const isDateInRange: (date: Date, start: Date | null, end: Date | null) => boolean | null;
15
+ export declare const isDateSelected: (date: Date, start: Date | null, end: Date | null) => boolean | null;
16
+ export declare const isEndDate: (date: Date, start: Date | null, end: Date | null) => boolean | null;
17
+ export declare const isLastDayOfMonth: (date: Date) => boolean;
18
+ export declare const isSameDateAs: (date: Date, date2: Date) => boolean;
19
+ export declare const isStartDate: (date: Date, start: Date | null, end: Date | null) => boolean | null;
20
+ export declare const isToday: (date: Date) => boolean;
21
+ export declare const isValidDate: (date: string) => number | false;
@@ -0,0 +1,17 @@
1
+ export declare const convert12hTo24h: (abbr: 'am' | 'pm', hour: number) => number;
2
+ export declare const convert24hTo12h: (hour: number) => number;
3
+ export declare const convertTimeToDate: (time: Date | string | null | undefined) => Date | null;
4
+ export declare const getAmPm: (date: Date, locale: string) => "am" | "pm";
5
+ export declare const getListOfHours: (locale: string) => {
6
+ value: number;
7
+ label: string;
8
+ }[];
9
+ export declare const getMinutesOrSeconds: (locale: string) => {
10
+ value: number;
11
+ label: string;
12
+ }[];
13
+ export declare const getSelectedHour: (date: Date | null, locale: string) => number | "";
14
+ export declare const getSelectedMinutes: (date: Date | null) => number | "";
15
+ export declare const getSelectedSeconds: (date: Date | null) => number | "";
16
+ export declare const isAmPm: (locale: string) => boolean;
17
+ export declare const isValidTime: (time: string) => number | false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/vue-pro",
3
- "version": "4.1.4",
3
+ "version": "4.3.0-beta.1",
4
4
  "description": "UI Components Library for Vue.js",
5
5
  "keywords": [
6
6
  "vue",
@@ -35,18 +35,18 @@
35
35
  "watch": "rollup -c -w"
36
36
  },
37
37
  "config": {
38
- "version_short": "4.1"
38
+ "version_short": "4.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@popperjs/core": "^2.11.2",
42
- "@rollup/plugin-commonjs": "^21.0.1",
41
+ "@popperjs/core": "^2.11.4",
42
+ "@rollup/plugin-commonjs": "^21.0.2",
43
43
  "@rollup/plugin-node-resolve": "^13.1.3",
44
- "@rollup/plugin-typescript": "^8.3.0",
45
- "@vue/test-utils": "^2.0.0-0",
46
- "rollup": "^2.66.0",
44
+ "@rollup/plugin-typescript": "^8.3.1",
45
+ "@vue/test-utils": "^2.0.0-rc.17",
46
+ "rollup": "^2.70.1",
47
47
  "rollup-plugin-vue": "^6.0.0",
48
- "typescript": "^4.5.5",
49
- "vue": "^3.2.24",
48
+ "typescript": "^4.6.2",
49
+ "vue": "^3.2.31",
50
50
  "vue-types": "^4.1.1"
51
51
  },
52
52
  "peerDependencies": {
@@ -10,6 +10,7 @@ const CAccordionButton = defineComponent({
10
10
  h(
11
11
  'button',
12
12
  {
13
+ type: 'button',
13
14
  'aria-expanded': !visible.value,
14
15
  class: ['accordion-button', { ['collapsed']: !visible.value }],
15
16
  onClick: () => toggleVisibility(),
@@ -1,3 +1,3 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Loads and display CAccordionButton component renders correctly 1`] = `"<button aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button>"`;
3
+ exports[`Loads and display CAccordionButton component renders correctly 1`] = `"<button type=\\"button\\" aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button>"`;
@@ -1,3 +1,3 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Loads and display CAccordionHeader component renders correctly 1`] = `"<div class=\\"accordion-header\\"><button aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button></div>"`;
3
+ exports[`Loads and display CAccordionHeader component renders correctly 1`] = `"<div class=\\"accordion-header\\"><button type=\\"button\\" aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button></div>"`;
@@ -60,6 +60,20 @@ export const CButton = defineComponent({
60
60
  return ['sm', 'lg'].includes(value)
61
61
  },
62
62
  },
63
+ /**
64
+ * Specifies the type of button. Always specify the type attribute for the `<button>` element.
65
+ * Different browsers may use different default types for the `<button>` element.
66
+ *
67
+ * @values 'button', 'submit', 'reset'
68
+ */
69
+ type: {
70
+ type: String,
71
+ default: 'button',
72
+ required: false,
73
+ validator: (value: string) => {
74
+ return ['button', 'submit', 'reset'].includes(value)
75
+ },
76
+ },
63
77
  /**
64
78
  * Set the button variant to an outlined button or a ghost button.
65
79
  *
@@ -74,7 +88,20 @@ export const CButton = defineComponent({
74
88
  },
75
89
  },
76
90
  },
77
- setup(props, { slots }) {
91
+ emits: [
92
+ /**
93
+ * Event called when the user clicks on the button.
94
+ */
95
+ 'click',
96
+ ],
97
+ setup(props, { emit, slots }) {
98
+ const handleClick = () => {
99
+ if (props.disabled) {
100
+ return
101
+ }
102
+
103
+ emit('click')
104
+ }
78
105
  return () =>
79
106
  h(
80
107
  props.component,
@@ -92,6 +119,8 @@ export const CButton = defineComponent({
92
119
  disabled: props.disabled && props.component !== 'a',
93
120
  ...(props.component === 'a' && props.disabled && { 'aria-disabled': true, tabIndex: -1 }),
94
121
  ...(props.component === 'a' && props.href && { href: props.href }),
122
+ ...(props.component === 'button' && { type: props.type }),
123
+ onClick: handleClick,
95
124
  },
96
125
  slots.default && slots.default(),
97
126
  )
@@ -4,4 +4,4 @@ exports[`Customize (number two) CButton component renders correctly 1`] = `"<a c
4
4
 
5
5
  exports[`Customize CButton component renders correctly 1`] = `"<div class=\\"btn btn-outline-warning btn-lg active disabled rounded-pill\\" disabled=\\"true\\">Default slot</div>"`;
6
6
 
7
- exports[`Loads and display CButton component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\">Default slot</button>"`;
7
+ exports[`Loads and display CButton component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\" type=\\"button\\">Default slot</button>"`;
@@ -0,0 +1,546 @@
1
+ import { defineComponent, h, PropType, ref, watch } from 'vue'
2
+
3
+ import { CButton } from '../button'
4
+
5
+ import {
6
+ createGroupsInArray,
7
+ getMonthDetails,
8
+ getMonthsNames,
9
+ getYears,
10
+ isDateDisabled,
11
+ isDateInRange,
12
+ isDateSelected,
13
+ isLastDayOfMonth,
14
+ isSameDateAs,
15
+ isToday,
16
+ isStartDate,
17
+ isEndDate,
18
+ } from '../../utils/calendar'
19
+
20
+ const CCalendar = defineComponent({
21
+ name: 'CCalendar',
22
+ props: {
23
+ /**
24
+ * Default date of the component
25
+ */
26
+ calendarDate: {
27
+ type: [Date, String],
28
+ },
29
+ /**
30
+ * Specify the list of dates that cannot be selected.
31
+ */
32
+ disabledDates: {
33
+ type: Array as PropType<Date[] | Date[][]>,
34
+ },
35
+ /**
36
+ * Initial selected to date (range).
37
+ */
38
+ endDate: {
39
+ type: [Date, String],
40
+ },
41
+ /**
42
+ * Sets the day of start week.
43
+ * - 0 - Sunday,
44
+ * - 1 - Monday,
45
+ * - 2 - Tuesday,
46
+ * - 3 - Wednesday,
47
+ * - 4 - Thursday,
48
+ * - 5 - Friday,
49
+ * - 6 - Saturday,
50
+ * - 7 - Sunday
51
+ */
52
+ firstDayOfWeek: {
53
+ type: Number,
54
+ default: 1,
55
+ },
56
+ /**
57
+ * Sets the default locale for components. If not set, it is inherited from the navigator.language.
58
+ */
59
+ locale: {
60
+ type: String,
61
+ default: 'default',
62
+ },
63
+ /**
64
+ * Max selectable date.
65
+ */
66
+ maxDate: {
67
+ type: [Date, String],
68
+ },
69
+ /**
70
+ * Min selectable date.
71
+ */
72
+ minDate: {
73
+ type: [Date, String],
74
+ },
75
+ /**
76
+ * Show arrows navigation.
77
+ */
78
+ navigation: {
79
+ type: Boolean,
80
+ default: true,
81
+ },
82
+ /**
83
+ * Allow range selection.
84
+ */
85
+ range: Boolean,
86
+ /**
87
+ * Toggle select mode between start and end date.
88
+ */
89
+ selectEndDate: Boolean,
90
+ /**
91
+ * Initial selected date.
92
+ */
93
+ startDate: {
94
+ type: [Date, String],
95
+ },
96
+ /**
97
+ * Set length or format of day name.
98
+ *
99
+ * @type number | 'long' | 'narrow' | 'short'
100
+ */
101
+ weekdayFormat: {
102
+ type: [Number, String],
103
+ default: 2,
104
+ validator: (value: string | number) => {
105
+ if (typeof value === 'string') {
106
+ return ['long', 'narrow', 'short'].includes(value)
107
+ }
108
+ if (typeof value === 'number') {
109
+ return true
110
+ }
111
+ return false
112
+ },
113
+ },
114
+ },
115
+ emits: [
116
+ /**
117
+ * Callback fired when the user hovers over the calendar cell.
118
+ *
119
+ * @property {Date | null} date
120
+ */
121
+ 'calendar-cell-hover',
122
+ /**
123
+ * Callback fired when the calendar date changed.
124
+ *
125
+ * @property {Date | null} date
126
+ */
127
+ 'calendar-date-change',
128
+ /**
129
+ * Callback fired when the start date changed.
130
+ *
131
+ * @property {Date | null} date
132
+ */
133
+ 'start-date-change',
134
+ /**
135
+ * Callback fired when the end date changed.
136
+ *
137
+ * @property {Date | null} date
138
+ */
139
+ 'end-date-change',
140
+ ],
141
+ setup(props, { slots, emit }) {
142
+ const calendarDate = ref(props.calendarDate ? new Date(props.calendarDate) : new Date())
143
+ const startDate = ref(props.startDate ? new Date(props.startDate) : null)
144
+ const endDate = ref(props.endDate ? new Date(props.endDate) : null)
145
+ const selectEndDate = ref(props.selectEndDate)
146
+ const view = ref('days')
147
+
148
+ const maxDate = props.maxDate ? new Date(props.maxDate) : null
149
+ const minDate = props.minDate ? new Date(props.minDate) : null
150
+
151
+ watch(
152
+ () => props.calendarDate,
153
+ () => {
154
+ if (props.calendarDate) calendarDate.value = new Date(props.calendarDate)
155
+ },
156
+ )
157
+
158
+ watch(
159
+ () => props.startDate,
160
+ () => {
161
+ if (props.startDate === null) {
162
+ startDate.value = null
163
+ return
164
+ }
165
+
166
+ if (props.startDate) {
167
+ const d = new Date(props.startDate)
168
+ if (startDate.value === null) {
169
+ startDate.value = d
170
+ return
171
+ }
172
+
173
+ if (startDate.value && !isSameDateAs(d, startDate.value)) {
174
+ startDate.value = d
175
+ }
176
+ }
177
+ },
178
+ )
179
+
180
+ watch(
181
+ () => props.endDate,
182
+ () => {
183
+ if (props.endDate === null) {
184
+ endDate.value = null
185
+ return
186
+ }
187
+
188
+ if (props.endDate) {
189
+ const d = new Date(props.endDate)
190
+ if (endDate.value === null) {
191
+ endDate.value = d
192
+ return
193
+ }
194
+
195
+ if (endDate.value && !isSameDateAs(d, endDate.value)) {
196
+ endDate.value = d
197
+ }
198
+ }
199
+ },
200
+ )
201
+
202
+ watch(
203
+ () => props.selectEndDate,
204
+ () => {
205
+ selectEndDate.value = props.selectEndDate
206
+ },
207
+ )
208
+
209
+ watch(startDate, () => {
210
+ emit('start-date-change', startDate.value)
211
+ })
212
+
213
+ watch(endDate, () => {
214
+ emit('end-date-change', endDate.value)
215
+ })
216
+
217
+ const setCalendarPage = (years: number, months = 0) => {
218
+ const year = calendarDate.value.getFullYear()
219
+ const month = calendarDate.value.getMonth()
220
+ const d = new Date(year, month, 1)
221
+
222
+ years && d.setFullYear(d.getFullYear() + years)
223
+ months && d.setMonth(d.getMonth() + months)
224
+
225
+ calendarDate.value = d
226
+
227
+ emit('calendar-date-change', d)
228
+ }
229
+
230
+ const handleCellOnClick = (date: Date) => {
231
+ if (isDateDisabled(date, minDate, maxDate, props.disabledDates)) {
232
+ return
233
+ }
234
+
235
+ if (props.range) {
236
+ if (selectEndDate.value) {
237
+ // If endDate > date
238
+ if (startDate.value && startDate.value > date) {
239
+ endDate.value = startDate.value
240
+ startDate.value = date
241
+ } else {
242
+ endDate.value = date
243
+ }
244
+ selectEndDate.value = false
245
+ } else {
246
+ startDate.value = date
247
+ selectEndDate.value = true
248
+ }
249
+ } else {
250
+ startDate.value = date
251
+ }
252
+ }
253
+
254
+ const handleCellMouseEnter = (date: Date) => {
255
+ if (isDateDisabled(date, minDate, maxDate, props.disabledDates)) {
256
+ return
257
+ }
258
+ emit('calendar-cell-hover', date)
259
+ }
260
+
261
+ const handleCellMouseLeave = () => {
262
+ emit('calendar-cell-hover', null)
263
+ }
264
+
265
+ const handleNavigationOnClick = (direction: string, double = false) => {
266
+ if (direction === 'prev') {
267
+ if (double) {
268
+ setCalendarPage(view.value !== 'days' ? -10 : -1)
269
+ return
270
+ }
271
+ if (view.value !== 'days') {
272
+ setCalendarPage(-1)
273
+ return
274
+ }
275
+ setCalendarPage(0, -1)
276
+ return
277
+ }
278
+ if (direction === 'next') {
279
+ if (double) {
280
+ setCalendarPage(view.value !== 'days' ? 10 : 1)
281
+ return
282
+ }
283
+ if (view.value !== 'days') {
284
+ setCalendarPage(1)
285
+ return
286
+ }
287
+ setCalendarPage(0, 1)
288
+ return
289
+ }
290
+ }
291
+
292
+ const Calendar = () => {
293
+ const monthDetails = getMonthDetails(
294
+ calendarDate.value.getFullYear(),
295
+ calendarDate.value.getMonth(),
296
+ props.firstDayOfWeek,
297
+ )
298
+ const listOfMonths = createGroupsInArray(getMonthsNames(props.locale), 4)
299
+ const listOfYears = createGroupsInArray(getYears(calendarDate.value.getFullYear()), 4)
300
+ const weekDays = monthDetails[0]
301
+
302
+ return h('table', {}, [
303
+ view.value === 'days' &&
304
+ h(
305
+ 'thead',
306
+ {},
307
+ h(
308
+ 'tr',
309
+ {},
310
+ weekDays.map(({ date }: { date: Date }) => {
311
+ return h(
312
+ 'th',
313
+ { class: 'calendar-cell' },
314
+ h(
315
+ 'div',
316
+ {
317
+ class: 'calendar-header-cell-inner',
318
+ },
319
+ props.weekdayFormat === 'string'
320
+ ? date.toLocaleDateString(props.locale, { weekday: props.weekdayFormat })
321
+ : date
322
+ .toLocaleDateString(props.locale, { weekday: 'long' })
323
+ .slice(0, props.weekdayFormat),
324
+ ),
325
+ )
326
+ }),
327
+ ),
328
+ ),
329
+ h('tbody', {}, [
330
+ view.value === 'days' &&
331
+ monthDetails.map((week) => {
332
+ return h(
333
+ 'tr',
334
+ {},
335
+ week.map(({ date, month }: { date: Date; month: string }) => {
336
+ return h(
337
+ 'td',
338
+ {
339
+ class: [
340
+ 'calendar-cell',
341
+ {
342
+ today: isToday(date),
343
+ disabled: isDateDisabled(date, minDate, maxDate, props.disabledDates),
344
+ next: month === 'next',
345
+ previous: month === 'previous',
346
+ last: isLastDayOfMonth(date),
347
+ range:
348
+ month === 'current' &&
349
+ isDateInRange(date, startDate.value, endDate.value),
350
+ selected: isDateSelected(date, startDate.value, endDate.value),
351
+ start: isStartDate(date, startDate.value, endDate.value),
352
+ end: isEndDate(date, startDate.value, endDate.value),
353
+ },
354
+ ],
355
+ title: date.toLocaleDateString(props.locale),
356
+ onClick: () => handleCellOnClick(date),
357
+ onmouseenter: () => handleCellMouseEnter(date),
358
+ onmouseleave: () => handleCellMouseLeave(),
359
+ },
360
+ h(
361
+ 'div',
362
+ {
363
+ class: 'calendar-cell-inner',
364
+ },
365
+ date.toLocaleDateString(props.locale, { day: 'numeric' }),
366
+ ),
367
+ )
368
+ }),
369
+ )
370
+ }),
371
+ view.value === 'months' &&
372
+ listOfMonths.map((row, index) => {
373
+ return h(
374
+ 'tr',
375
+ {},
376
+ row.map((month, idx) => {
377
+ return h(
378
+ 'td',
379
+ {
380
+ class: 'calendar-cell month',
381
+ onClick: () => {
382
+ setCalendarPage(0, index * 3 + idx)
383
+ view.value = 'days'
384
+ },
385
+ },
386
+ h('div', { class: 'calendar-cell-inner' }, month),
387
+ )
388
+ }),
389
+ )
390
+ }),
391
+ view.value === 'years' &&
392
+ listOfYears.map((row) => {
393
+ return h(
394
+ 'tr',
395
+ {},
396
+ row.map((year) => {
397
+ return h(
398
+ 'td',
399
+ {
400
+ class: 'calendar-cell year',
401
+ onClick: () => {
402
+ calendarDate.value = new Date(
403
+ year,
404
+ calendarDate.value.getMonth(),
405
+ calendarDate.value.getDate(),
406
+ )
407
+ view.value = 'months'
408
+ },
409
+ },
410
+ h('div', { class: 'calendar-cell-inner' }, year),
411
+ )
412
+ }),
413
+ )
414
+ }),
415
+ ]),
416
+ ])
417
+ }
418
+
419
+ const Navigation = () => {
420
+ return h('div', { class: 'calendar-nav' }, [
421
+ props.navigation &&
422
+ h(
423
+ 'div',
424
+ {
425
+ class: 'calendar-nav-prev',
426
+ },
427
+ [
428
+ h(
429
+ CButton,
430
+ {
431
+ color: 'transparent',
432
+ size: 'sm',
433
+ onClick: () => handleNavigationOnClick('prev', true),
434
+ },
435
+ {
436
+ /**
437
+ * @slot Location for double previous icon.
438
+ */
439
+ default: () =>
440
+ slots.navPrevDoubleIcon
441
+ ? slots.navPrevDoubleIcon()
442
+ : h('span', { class: 'calendar-nav-icon calendar-nav-icon-double-prev' }),
443
+ },
444
+ ),
445
+ view.value === 'days' &&
446
+ h(
447
+ CButton,
448
+ {
449
+ color: 'transparent',
450
+ size: 'sm',
451
+ onClick: () => handleNavigationOnClick('prev'),
452
+ },
453
+ {
454
+ /**
455
+ * @slot Location for previous icon.
456
+ */
457
+ default: () =>
458
+ slots.navPrevIcon
459
+ ? slots.navPrevIcon()
460
+ : h('span', { class: 'calendar-nav-icon calendar-nav-icon-prev' }),
461
+ },
462
+ ),
463
+ ],
464
+ ),
465
+ h(
466
+ 'div',
467
+ {
468
+ class: 'calendar-nav-date',
469
+ },
470
+ [
471
+ view.value === 'days' &&
472
+ h(
473
+ CButton,
474
+ {
475
+ color: 'transparent',
476
+ size: 'sm',
477
+ onClick: () => {
478
+ if (props.navigation) view.value = 'months'
479
+ },
480
+ },
481
+ () => calendarDate.value.toLocaleDateString(props.locale, { month: 'long' }),
482
+ ),
483
+ h(
484
+ CButton,
485
+ {
486
+ color: 'transparent',
487
+ size: 'sm',
488
+ onClick: () => {
489
+ if (props.navigation) view.value = 'years'
490
+ },
491
+ },
492
+ () => calendarDate.value.toLocaleDateString(props.locale, { year: 'numeric' }),
493
+ ),
494
+ ],
495
+ ),
496
+ props.navigation &&
497
+ h(
498
+ 'div',
499
+ {
500
+ class: 'calendar-nav-next',
501
+ },
502
+ [
503
+ view.value === 'days' &&
504
+ h(
505
+ CButton,
506
+ {
507
+ color: 'transparent',
508
+ size: 'sm',
509
+ onClick: () => handleNavigationOnClick('next'),
510
+ },
511
+ {
512
+ /**
513
+ * @slot Location for next icon.
514
+ */
515
+ default: () =>
516
+ slots.navNextIcon
517
+ ? slots.navNextIcon()
518
+ : h('span', { class: 'calendar-nav-icon calendar-nav-icon-next' }),
519
+ },
520
+ ),
521
+ h(
522
+ CButton,
523
+ {
524
+ color: 'transparent',
525
+ size: 'sm',
526
+ onClick: () => handleNavigationOnClick('next', true),
527
+ },
528
+ {
529
+ /**
530
+ * @slot Location for double next icon.
531
+ */
532
+ default: () =>
533
+ slots.navNextDoubleIcon
534
+ ? slots.navNextDoubleIcon()
535
+ : h('span', { class: 'calendar-nav-icon calendar-nav-icon-double-next' }),
536
+ },
537
+ ),
538
+ ],
539
+ ),
540
+ ])
541
+ }
542
+ return () => h('div', { class: ['calendar', view.value] }, [h(Navigation), h(Calendar)])
543
+ },
544
+ })
545
+
546
+ export { CCalendar }