@shohojdhara/atomix 0.2.1 → 0.2.3
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 +1 -28
- package/dist/atomix.css +1500 -241
- package/dist/atomix.min.css +6 -6
- package/dist/index.d.ts +1052 -194
- package/dist/index.esm.js +12201 -6066
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5481 -2827
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/themes/boomdevs.css +1500 -301
- package/dist/themes/boomdevs.min.css +60 -8
- package/dist/themes/esrar.css +1500 -241
- package/dist/themes/esrar.min.css +6 -6
- package/dist/themes/mashroom.css +1496 -237
- package/dist/themes/mashroom.min.css +8 -8
- package/dist/themes/shaj-default.css +1451 -192
- package/dist/themes/shaj-default.min.css +6 -6
- package/package.json +66 -15
- package/src/components/Accordion/Accordion.stories.tsx +137 -0
- package/src/components/Accordion/Accordion.tsx +33 -3
- package/src/components/AtomixGlass/AtomixGlass.stories.tsx +3011 -0
- package/src/components/AtomixGlass/AtomixGlass.test.tsx +199 -0
- package/src/components/AtomixGlass/AtomixGlass.tsx +1281 -0
- package/src/components/AtomixGlass/AtomixGlassComprehensivePreview.stories.tsx +1369 -0
- package/src/components/AtomixGlass/README.md +134 -0
- package/src/components/AtomixGlass/index.ts +10 -0
- package/src/components/AtomixGlass/shader-utils.ts +140 -0
- package/src/components/AtomixGlass/utils.ts +8 -0
- package/src/components/Badge/Badge.stories.tsx +169 -0
- package/src/components/Badge/Badge.tsx +27 -2
- package/src/components/Button/Button.stories.tsx +345 -0
- package/src/components/Button/Button.tsx +35 -3
- package/src/components/Button/README.md +216 -0
- package/src/components/Callout/Callout.stories.tsx +813 -78
- package/src/components/Callout/Callout.test.tsx +368 -0
- package/src/components/Callout/Callout.tsx +26 -7
- package/src/components/Callout/README.md +409 -0
- package/src/components/Card/Card.stories.tsx +140 -0
- package/src/components/Card/Card.tsx +19 -3
- package/src/components/DatePicker/DatePicker copy.tsx +551 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +188 -0
- package/src/components/DatePicker/DatePicker.tsx +379 -332
- package/src/components/DatePicker/readme.md +110 -1
- package/src/components/DatePicker/types.ts +8 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +145 -0
- package/src/components/Dropdown/Dropdown.tsx +34 -5
- package/src/components/Footer/Footer.stories.tsx +388 -0
- package/src/components/Footer/Footer.tsx +197 -0
- package/src/components/Footer/FooterLink.tsx +72 -0
- package/src/components/Footer/FooterSection.tsx +87 -0
- package/src/components/Footer/FooterSocialLink.tsx +117 -0
- package/src/components/Footer/README.md +261 -0
- package/src/components/Footer/index.ts +13 -0
- package/src/components/Form/Checkbox.stories.tsx +101 -0
- package/src/components/Form/Checkbox.tsx +26 -2
- package/src/components/Form/Input.stories.tsx +124 -0
- package/src/components/Form/Input.tsx +36 -7
- package/src/components/Form/Radio.stories.tsx +139 -0
- package/src/components/Form/Radio.tsx +26 -2
- package/src/components/Form/Select.stories.tsx +110 -0
- package/src/components/Form/Select.tsx +26 -2
- package/src/components/Form/Textarea.stories.tsx +104 -0
- package/src/components/Form/Textarea.tsx +36 -7
- package/src/components/Hero/Hero.stories.tsx +54 -1
- package/src/components/Hero/Hero.tsx +70 -11
- package/src/components/Modal/Modal.stories.tsx +235 -0
- package/src/components/Modal/Modal.tsx +64 -35
- package/src/components/Pagination/Pagination.stories.tsx +101 -0
- package/src/components/Pagination/Pagination.tsx +25 -1
- package/src/components/Popover/Popover.stories.tsx +94 -0
- package/src/components/Popover/Popover.tsx +30 -4
- package/src/components/Rating/Rating.stories.tsx +112 -0
- package/src/components/Rating/Rating.tsx +25 -1
- package/src/components/SectionIntro/SectionIntro.tsx +9 -11
- package/src/components/Slider/Slider.stories.tsx +634 -50
- package/src/components/Slider/Slider.tsx +5 -3
- package/src/components/Steps/Steps.stories.tsx +119 -0
- package/src/components/Steps/Steps.tsx +32 -1
- package/src/components/Tab/Tab.stories.tsx +88 -0
- package/src/components/Tab/Tab.tsx +32 -1
- package/src/components/Toggle/Toggle.stories.tsx +92 -0
- package/src/components/Toggle/Toggle.tsx +32 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +131 -0
- package/src/components/Tooltip/Tooltip.tsx +43 -7
- package/src/components/VideoPlayer/VideoPlayer.stories.tsx +1002 -196
- package/src/components/VideoPlayer/VideoPlayer.tsx +161 -4
- package/src/components/index.ts +14 -0
- package/src/layouts/Grid/Grid.stories.tsx +226 -159
- package/src/lib/composables/index.ts +4 -0
- package/src/lib/composables/useAtomixGlass.ts +71 -0
- package/src/lib/composables/useButton.ts +3 -1
- package/src/lib/composables/useCallout.ts +4 -1
- package/src/lib/composables/useFooter.ts +85 -0
- package/src/lib/composables/useGlassContainer.ts +168 -0
- package/src/lib/composables/useSlider.ts +191 -4
- package/src/lib/constants/components.ts +173 -0
- package/src/lib/types/components.ts +622 -0
- package/src/lib/utils/displacement-generator.ts +86 -0
- package/src/styles/01-settings/_index.scss +1 -0
- package/src/styles/01-settings/_settings.accordion.scss +20 -19
- package/src/styles/01-settings/_settings.animations.scss +5 -5
- package/src/styles/01-settings/_settings.avatar-group.scss +1 -1
- package/src/styles/01-settings/_settings.avatar.scss +17 -18
- package/src/styles/01-settings/_settings.background.scss +10 -0
- package/src/styles/01-settings/_settings.badge.scss +1 -1
- package/src/styles/01-settings/_settings.breadcrumb.scss +8 -2
- package/src/styles/01-settings/_settings.callout.scss +7 -7
- package/src/styles/01-settings/_settings.card.scss +2 -2
- package/src/styles/01-settings/_settings.chart.scss +7 -7
- package/src/styles/01-settings/_settings.checkbox-group.scss +5 -2
- package/src/styles/01-settings/_settings.checkbox.scss +10 -4
- package/src/styles/01-settings/_settings.countdown.scss +6 -4
- package/src/styles/01-settings/_settings.dropdown.scss +9 -7
- package/src/styles/01-settings/_settings.edge-panel.scss +3 -2
- package/src/styles/01-settings/_settings.footer.scss +125 -0
- package/src/styles/01-settings/_settings.form-group.scss +3 -1
- package/src/styles/01-settings/_settings.form.scss +4 -2
- package/src/styles/01-settings/_settings.hero.scss +9 -7
- package/src/styles/01-settings/_settings.input.scss +9 -7
- package/src/styles/01-settings/_settings.list-group.scss +4 -2
- package/src/styles/01-settings/_settings.list.scss +4 -2
- package/src/styles/01-settings/_settings.menu.scss +10 -8
- package/src/styles/01-settings/_settings.messages.scss +19 -17
- package/src/styles/01-settings/_settings.modal.scss +6 -4
- package/src/styles/01-settings/_settings.nav.scss +6 -4
- package/src/styles/01-settings/_settings.navbar.scss +8 -5
- package/src/styles/01-settings/_settings.pagination.scss +5 -3
- package/src/styles/01-settings/_settings.popover.scss +6 -4
- package/src/styles/01-settings/_settings.rating.scss +5 -3
- package/src/styles/01-settings/_settings.river.scss +8 -6
- package/src/styles/01-settings/_settings.sectionintro.scss +8 -6
- package/src/styles/01-settings/_settings.select.scss +7 -5
- package/src/styles/01-settings/_settings.side-menu.scss +15 -13
- package/src/styles/01-settings/_settings.spacing.scss +4 -0
- package/src/styles/01-settings/_settings.steps.scss +7 -5
- package/src/styles/01-settings/_settings.tabs.scss +7 -5
- package/src/styles/01-settings/_settings.testimonials.scss +6 -4
- package/src/styles/01-settings/_settings.toggle.scss +3 -1
- package/src/styles/01-settings/_settings.tooltip.scss +5 -3
- package/src/styles/01-settings/_settings.upload.scss +22 -20
- package/src/styles/02-tools/_tools.animations.scss +19 -0
- package/src/styles/02-tools/_tools.background.scss +87 -0
- package/src/styles/02-tools/_tools.glass.scss +1 -0
- package/src/styles/02-tools/_tools.rem.scss +18 -5
- package/src/styles/02-tools/_tools.utility-api.scss +32 -26
- package/src/styles/03-generic/_generic.root.scss +15 -2
- package/src/styles/04-elements/_elements.body.scss +6 -0
- package/src/styles/06-components/_components.accordion.scss +24 -4
- package/src/styles/06-components/_components.atomix-glass.scss +0 -0
- package/src/styles/06-components/_components.avatar-group.scss +2 -1
- package/src/styles/06-components/_components.avatar.scss +2 -1
- package/src/styles/06-components/_components.badge.scss +36 -1
- package/src/styles/06-components/_components.breadcrumb.scss +2 -1
- package/src/styles/06-components/_components.button.scss +14 -3
- package/src/styles/06-components/_components.callout.scss +44 -4
- package/src/styles/06-components/_components.card.scss +21 -2
- package/src/styles/06-components/_components.chart.scss +3 -2
- package/src/styles/06-components/_components.checkbox.scss +2 -1
- package/src/styles/06-components/_components.color-mode-toggle.scss +3 -2
- package/src/styles/06-components/_components.countdown.scss +2 -1
- package/src/styles/06-components/_components.data-table.scss +7 -6
- package/src/styles/06-components/_components.datepicker.scss +20 -1
- package/src/styles/06-components/_components.dropdown.scss +11 -4
- package/src/styles/06-components/_components.edge-panel.scss +4 -3
- package/src/styles/06-components/_components.footer.scss +825 -0
- package/src/styles/06-components/_components.form-group.scss +1 -0
- package/src/styles/06-components/_components.hero.scss +4 -4
- package/src/styles/06-components/_components.image-gallery.scss +1 -0
- package/src/styles/06-components/_components.input.scss +33 -2
- package/src/styles/06-components/_components.list-group.scss +3 -2
- package/src/styles/06-components/_components.list.scss +2 -1
- package/src/styles/06-components/_components.menu.scss +5 -4
- package/src/styles/06-components/_components.messages.scss +8 -7
- package/src/styles/06-components/_components.modal.scss +3 -2
- package/src/styles/06-components/_components.nav.scss +6 -5
- package/src/styles/06-components/_components.navbar.scss +4 -3
- package/src/styles/06-components/_components.pagination.scss +2 -1
- package/src/styles/06-components/_components.photoviewer.scss +4 -3
- package/src/styles/06-components/_components.popover.scss +3 -2
- package/src/styles/06-components/_components.product-review.scss +3 -2
- package/src/styles/06-components/_components.progress.scss +3 -2
- package/src/styles/06-components/_components.river.scss +3 -2
- package/src/styles/06-components/_components.sectionintro.scss +2 -1
- package/src/styles/06-components/_components.select.scss +5 -4
- package/src/styles/06-components/_components.side-menu.scss +8 -7
- package/src/styles/06-components/_components.skeleton.scss +3 -2
- package/src/styles/06-components/_components.slider.scss +7 -6
- package/src/styles/06-components/_components.spinner.scss +1 -0
- package/src/styles/06-components/_components.steps.scss +3 -2
- package/src/styles/06-components/_components.tabs.scss +4 -3
- package/src/styles/06-components/_components.testimonials.scss +2 -1
- package/src/styles/06-components/_components.todo.scss +3 -2
- package/src/styles/06-components/_components.toggle.scss +5 -4
- package/src/styles/06-components/_components.tooltip.scss +3 -2
- package/src/styles/06-components/_components.upload.scss +4 -3
- package/src/styles/06-components/_components.video-player.scss +50 -27
- package/src/styles/06-components/_index.scss +2 -0
- package/src/styles/99-utilities/_utilities.glass-fixes.scss +48 -0
- package/dist/themes/yabai.css +0 -13711
- package/dist/themes/yabai.min.css +0 -189
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { DatePickerProps, DatePickerRef } from './types';
|
|
3
|
+
import { useDatePicker } from '../../lib/composables/useDatePicker';
|
|
4
|
+
import { formatDate } from './utils';
|
|
5
|
+
import { Icon } from '../Icon/Icon';
|
|
6
|
+
import { AtomixGlass } from '../AtomixGlass/AtomixGlass';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DatePicker component for selecting dates from a calendar interface.
|
|
10
|
+
* Supports various display modes, date ranges, and customization options.
|
|
11
|
+
*/
|
|
12
|
+
export const DatePicker = forwardRef<DatePickerRef, DatePickerProps>(
|
|
13
|
+
(
|
|
14
|
+
{
|
|
15
|
+
value,
|
|
16
|
+
onChange,
|
|
17
|
+
selectionMode = 'single',
|
|
18
|
+
startDate,
|
|
19
|
+
endDate,
|
|
20
|
+
onRangeChange,
|
|
21
|
+
format = 'MM/dd/yyyy',
|
|
22
|
+
minDate,
|
|
23
|
+
maxDate,
|
|
24
|
+
placeholder = 'Select date...',
|
|
25
|
+
disabled = false,
|
|
26
|
+
readOnly = false,
|
|
27
|
+
clearable = true,
|
|
28
|
+
showTodayButton = true,
|
|
29
|
+
showWeekNumbers = false,
|
|
30
|
+
inline = false,
|
|
31
|
+
id,
|
|
32
|
+
name,
|
|
33
|
+
className = '',
|
|
34
|
+
placement = 'bottom-start',
|
|
35
|
+
inputClassName = '',
|
|
36
|
+
size = 'md',
|
|
37
|
+
glass,
|
|
38
|
+
...props
|
|
39
|
+
},
|
|
40
|
+
ref
|
|
41
|
+
) => {
|
|
42
|
+
const {
|
|
43
|
+
// State
|
|
44
|
+
isOpen,
|
|
45
|
+
inputValue,
|
|
46
|
+
rangeInputValue,
|
|
47
|
+
viewMode,
|
|
48
|
+
currentMonth,
|
|
49
|
+
currentYear,
|
|
50
|
+
selectionMode: activeSelectionMode,
|
|
51
|
+
rangeSelectionState,
|
|
52
|
+
|
|
53
|
+
// Refs
|
|
54
|
+
datePickerRef,
|
|
55
|
+
inputRef,
|
|
56
|
+
|
|
57
|
+
// Range state
|
|
58
|
+
startDate: rangeStartDate,
|
|
59
|
+
endDate: rangeEndDate,
|
|
60
|
+
|
|
61
|
+
// Methods
|
|
62
|
+
setIsOpen,
|
|
63
|
+
handleInputChange,
|
|
64
|
+
handleInputFocus,
|
|
65
|
+
handleClear,
|
|
66
|
+
handleDateSelect,
|
|
67
|
+
handleTodayClick,
|
|
68
|
+
handlePrevMonth,
|
|
69
|
+
handleNextMonth,
|
|
70
|
+
handlePrevYear,
|
|
71
|
+
handleNextYear,
|
|
72
|
+
// View mode handlers
|
|
73
|
+
switchToMonthView,
|
|
74
|
+
switchToYearView,
|
|
75
|
+
selectMonth,
|
|
76
|
+
selectYear,
|
|
77
|
+
|
|
78
|
+
// Utility methods
|
|
79
|
+
generateDays,
|
|
80
|
+
generateMonths,
|
|
81
|
+
generateYears,
|
|
82
|
+
isDateSelectable,
|
|
83
|
+
isDateSelected,
|
|
84
|
+
isDateInSelectedRange,
|
|
85
|
+
isToday,
|
|
86
|
+
getWeekNumber,
|
|
87
|
+
} = useDatePicker({
|
|
88
|
+
value,
|
|
89
|
+
onChange,
|
|
90
|
+
selectionMode,
|
|
91
|
+
startDate,
|
|
92
|
+
endDate,
|
|
93
|
+
onRangeChange,
|
|
94
|
+
minDate,
|
|
95
|
+
maxDate,
|
|
96
|
+
format,
|
|
97
|
+
inline,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Expose the ref API
|
|
101
|
+
useImperativeHandle(ref, () => ({
|
|
102
|
+
open: () => setIsOpen(true),
|
|
103
|
+
close: () => setIsOpen(false),
|
|
104
|
+
clear: handleClear,
|
|
105
|
+
focus: () => inputRef.current?.focus(),
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
// Prepare class names
|
|
109
|
+
const datepickerClassName =
|
|
110
|
+
`c-datepicker ${className} ${inline ? 'c-datepicker--inline' : ''}`.trim();
|
|
111
|
+
const inputClasses = `c-datepicker__input c-input c-input--${size} ${inputClassName}`.trim();
|
|
112
|
+
|
|
113
|
+
// Create unique ID for accessibility
|
|
114
|
+
const datepickerId = id || `datepicker-${Math.random().toString(36).substring(2, 9)}`;
|
|
115
|
+
const calendarId = `${datepickerId}-calendar`;
|
|
116
|
+
|
|
117
|
+
// Get the appropriate input value based on selection mode
|
|
118
|
+
const displayValue = selectionMode === 'single' ? inputValue : rangeInputValue;
|
|
119
|
+
|
|
120
|
+
// Helper function to get placeholder based on selection mode
|
|
121
|
+
const getPlaceholder = () => {
|
|
122
|
+
if (selectionMode === 'single') {
|
|
123
|
+
return placeholder;
|
|
124
|
+
} else {
|
|
125
|
+
return rangeSelectionState === 'start'
|
|
126
|
+
? 'Select start date...'
|
|
127
|
+
: rangeStartDate
|
|
128
|
+
? `${formatDate(rangeStartDate, format)} - Select end date...`
|
|
129
|
+
: 'Select date range...';
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Utility functions
|
|
134
|
+
const getMonthName = (monthIndex: number): string => {
|
|
135
|
+
const months = [
|
|
136
|
+
'January',
|
|
137
|
+
'February',
|
|
138
|
+
'March',
|
|
139
|
+
'April',
|
|
140
|
+
'May',
|
|
141
|
+
'June',
|
|
142
|
+
'July',
|
|
143
|
+
'August',
|
|
144
|
+
'September',
|
|
145
|
+
'October',
|
|
146
|
+
'November',
|
|
147
|
+
'December',
|
|
148
|
+
];
|
|
149
|
+
return months[monthIndex] || '';
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const getDaysOfWeek = (): string[] => {
|
|
153
|
+
return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const isDateDisabled = (date: Date): boolean => {
|
|
157
|
+
if (minDate && date < minDate) return true;
|
|
158
|
+
if (maxDate && date > maxDate) return true;
|
|
159
|
+
return false;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const isDateToday = (date: Date): boolean => {
|
|
163
|
+
const today = new Date();
|
|
164
|
+
return (
|
|
165
|
+
date.getDate() === today.getDate() &&
|
|
166
|
+
date.getMonth() === today.getMonth() &&
|
|
167
|
+
date.getFullYear() === today.getFullYear()
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const isSameDate = (date1: Date, date2: Date): boolean => {
|
|
172
|
+
return (
|
|
173
|
+
date1.getDate() === date2.getDate() &&
|
|
174
|
+
date1.getMonth() === date2.getMonth() &&
|
|
175
|
+
date1.getFullYear() === date2.getFullYear()
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const generateCalendar = () => {
|
|
180
|
+
const days = generateDays();
|
|
181
|
+
const weeks = [];
|
|
182
|
+
for (let i = 0; i < days.length; i += 7) {
|
|
183
|
+
weeks.push(days.slice(i, i + 7));
|
|
184
|
+
}
|
|
185
|
+
return weeks;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const handlePrevDecade = () => {
|
|
189
|
+
// This would need to be implemented in the hook or handled differently
|
|
190
|
+
// For now, we'll work with what we have
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const handleNextDecade = () => {
|
|
194
|
+
// This would need to be implemented in the hook or handled differently
|
|
195
|
+
// For now, we'll work with what we have
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const switchToDayView = () => {
|
|
199
|
+
// This would need to be implemented in the hook or handled differently
|
|
200
|
+
// For now, we'll work with what we have
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Helper function to render calendar content
|
|
204
|
+
const renderCalendarContent = () => (
|
|
205
|
+
<>
|
|
206
|
+
<div className="c-datepicker__header">
|
|
207
|
+
{viewMode === 'days' && (
|
|
208
|
+
<>
|
|
209
|
+
<button
|
|
210
|
+
type="button"
|
|
211
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--prev-year"
|
|
212
|
+
onClick={handlePrevYear}
|
|
213
|
+
aria-label="Previous year"
|
|
214
|
+
>
|
|
215
|
+
<Icon name="CaretDoubleLeft" size="sm" />
|
|
216
|
+
</button>
|
|
217
|
+
<button
|
|
218
|
+
type="button"
|
|
219
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--prev-month"
|
|
220
|
+
onClick={handlePrevMonth}
|
|
221
|
+
aria-label="Previous month"
|
|
222
|
+
>
|
|
223
|
+
<Icon name="CaretLeft" size="sm" />
|
|
224
|
+
</button>
|
|
225
|
+
<button
|
|
226
|
+
type="button"
|
|
227
|
+
className="c-datepicker__view-switch"
|
|
228
|
+
onClick={switchToMonthView}
|
|
229
|
+
aria-label={`${getMonthName(currentMonth)} ${currentYear}`}
|
|
230
|
+
>
|
|
231
|
+
{getMonthName(currentMonth)} {currentYear}
|
|
232
|
+
</button>
|
|
233
|
+
<button
|
|
234
|
+
type="button"
|
|
235
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--next-month"
|
|
236
|
+
onClick={handleNextMonth}
|
|
237
|
+
aria-label="Next month"
|
|
238
|
+
>
|
|
239
|
+
<Icon name="CaretRight" size="sm" />
|
|
240
|
+
</button>
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--next-year"
|
|
244
|
+
onClick={handleNextYear}
|
|
245
|
+
aria-label="Next year"
|
|
246
|
+
>
|
|
247
|
+
<Icon name="CaretDoubleRight" size="sm" />
|
|
248
|
+
</button>
|
|
249
|
+
</>
|
|
250
|
+
)}
|
|
251
|
+
|
|
252
|
+
{viewMode === 'months' && (
|
|
253
|
+
<>
|
|
254
|
+
<button
|
|
255
|
+
type="button"
|
|
256
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--prev-year"
|
|
257
|
+
onClick={handlePrevYear}
|
|
258
|
+
aria-label="Previous year"
|
|
259
|
+
>
|
|
260
|
+
<Icon name="CaretDoubleLeft" size="sm" />
|
|
261
|
+
</button>
|
|
262
|
+
<button
|
|
263
|
+
type="button"
|
|
264
|
+
className="c-datepicker__view-switch"
|
|
265
|
+
onClick={switchToYearView}
|
|
266
|
+
aria-label={`Year ${currentYear}`}
|
|
267
|
+
>
|
|
268
|
+
{currentYear}
|
|
269
|
+
</button>
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--next-year"
|
|
273
|
+
onClick={handleNextYear}
|
|
274
|
+
aria-label="Next year"
|
|
275
|
+
>
|
|
276
|
+
<Icon name="CaretDoubleRight" size="sm" />
|
|
277
|
+
</button>
|
|
278
|
+
</>
|
|
279
|
+
)}
|
|
280
|
+
|
|
281
|
+
{viewMode === 'years' && (
|
|
282
|
+
<>
|
|
283
|
+
<button
|
|
284
|
+
type="button"
|
|
285
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--prev-decade"
|
|
286
|
+
onClick={handlePrevDecade}
|
|
287
|
+
aria-label="Previous decade"
|
|
288
|
+
>
|
|
289
|
+
<Icon name="CaretDoubleLeft" size="sm" />
|
|
290
|
+
</button>
|
|
291
|
+
<button type="button" className="c-datepicker__view-switch" onClick={switchToDayView}>
|
|
292
|
+
{generateYears()[0]} - {generateYears()[generateYears().length - 1]}
|
|
293
|
+
</button>
|
|
294
|
+
<button
|
|
295
|
+
type="button"
|
|
296
|
+
className="c-datepicker__nav-button c-datepicker__nav-button--next-decade"
|
|
297
|
+
onClick={handleNextDecade}
|
|
298
|
+
aria-label="Next decade"
|
|
299
|
+
>
|
|
300
|
+
<Icon name="CaretDoubleRight" size="sm" />
|
|
301
|
+
</button>
|
|
302
|
+
</>
|
|
303
|
+
)}
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
<div className="c-datepicker__body">
|
|
307
|
+
{viewMode === 'days' && (
|
|
308
|
+
<>
|
|
309
|
+
<div
|
|
310
|
+
className={`c-datepicker__weekdays${showWeekNumbers ? ' c-datepicker__weekdays--has-weeknumber' : ''}`}
|
|
311
|
+
role="row"
|
|
312
|
+
>
|
|
313
|
+
{showWeekNumbers && <div className="c-datepicker__weekday">Wk</div>}
|
|
314
|
+
{getDaysOfWeek().map(day => (
|
|
315
|
+
<div key={day} className="c-datepicker__weekday" role="columnheader">
|
|
316
|
+
{day}
|
|
317
|
+
</div>
|
|
318
|
+
))}
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<div
|
|
322
|
+
className={`c-datepicker__days${showWeekNumbers ? ' c-datepicker__days--has-weeknumber' : ''}`}
|
|
323
|
+
role="grid"
|
|
324
|
+
>
|
|
325
|
+
{(() => {
|
|
326
|
+
const allElements = [];
|
|
327
|
+
const days = generateDays();
|
|
328
|
+
|
|
329
|
+
for (let i = 0; i < days.length; i++) {
|
|
330
|
+
const dateObj = days[i];
|
|
331
|
+
if (!dateObj) continue;
|
|
332
|
+
|
|
333
|
+
const dateValue = new Date(dateObj.year, dateObj.month, dateObj.day);
|
|
334
|
+
const isSelectable = isDateSelectable(dateObj.year, dateObj.month, dateObj.day);
|
|
335
|
+
const isSelected = isDateSelected(dateObj.year, dateObj.month, dateObj.day);
|
|
336
|
+
const isTodayDate = isToday(dateObj.year, dateObj.month, dateObj.day);
|
|
337
|
+
const isInRange = isDateInSelectedRange(
|
|
338
|
+
dateObj.year,
|
|
339
|
+
dateObj.month,
|
|
340
|
+
dateObj.day
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
// Add week number at the start of each week
|
|
344
|
+
if (showWeekNumbers && i % 7 === 0) {
|
|
345
|
+
const weekNum = getWeekNumber(dateValue);
|
|
346
|
+
allElements.push(
|
|
347
|
+
<div
|
|
348
|
+
key={`weeknumber-${Math.floor(i / 7)}`}
|
|
349
|
+
className="c-datepicker__weeknumber"
|
|
350
|
+
role="rowheader"
|
|
351
|
+
>
|
|
352
|
+
{weekNum}
|
|
353
|
+
</div>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Add the day button
|
|
358
|
+
allElements.push(
|
|
359
|
+
<button
|
|
360
|
+
key={`day-${i}`}
|
|
361
|
+
type="button"
|
|
362
|
+
className={`c-datepicker__day
|
|
363
|
+
${!dateObj.isCurrentMonth ? 'c-datepicker__day--outside' : ''}
|
|
364
|
+
${isSelected ? 'c-datepicker__day--selected' : ''}
|
|
365
|
+
${isInRange ? 'c-datepicker__day--in-range' : ''}
|
|
366
|
+
${isTodayDate ? 'c-datepicker__day--today' : ''}
|
|
367
|
+
${!isSelectable ? 'c-datepicker__day--disabled' : ''}`}
|
|
368
|
+
onClick={() => isSelectable && handleDateSelect(dateObj.day)}
|
|
369
|
+
disabled={!isSelectable}
|
|
370
|
+
tabIndex={dateObj.isCurrentMonth ? 0 : -1}
|
|
371
|
+
aria-label={dateValue.toLocaleDateString()}
|
|
372
|
+
aria-selected={isSelected ? 'true' : 'false'}
|
|
373
|
+
role="gridcell"
|
|
374
|
+
>
|
|
375
|
+
{dateObj.day}
|
|
376
|
+
</button>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return allElements;
|
|
381
|
+
})()}
|
|
382
|
+
</div>
|
|
383
|
+
</>
|
|
384
|
+
)}
|
|
385
|
+
|
|
386
|
+
{viewMode === 'months' && (
|
|
387
|
+
<div className="c-datepicker__months" role="grid">
|
|
388
|
+
{generateMonths().map((monthObj, index) => {
|
|
389
|
+
const isSelected =
|
|
390
|
+
value &&
|
|
391
|
+
value.getMonth() === monthObj.month &&
|
|
392
|
+
value.getFullYear() === currentYear;
|
|
393
|
+
|
|
394
|
+
return (
|
|
395
|
+
<button
|
|
396
|
+
key={`month-${index}`}
|
|
397
|
+
type="button"
|
|
398
|
+
className={`c-datepicker__month ${isSelected ? 'c-datepicker__month--selected' : ''}`}
|
|
399
|
+
onClick={() => selectMonth(monthObj.month)}
|
|
400
|
+
aria-selected={isSelected ? 'true' : 'false'}
|
|
401
|
+
role="gridcell"
|
|
402
|
+
>
|
|
403
|
+
{monthObj.name.substring(0, 3)}
|
|
404
|
+
</button>
|
|
405
|
+
);
|
|
406
|
+
})}
|
|
407
|
+
</div>
|
|
408
|
+
)}
|
|
409
|
+
|
|
410
|
+
{viewMode === 'years' && (
|
|
411
|
+
<div className="c-datepicker__years" role="grid">
|
|
412
|
+
{generateYears().map((year, index) => {
|
|
413
|
+
const isSelected = value && value.getFullYear() === year;
|
|
414
|
+
|
|
415
|
+
return (
|
|
416
|
+
<button
|
|
417
|
+
key={`year-${index}`}
|
|
418
|
+
type="button"
|
|
419
|
+
className={`c-datepicker__year ${isSelected ? 'c-datepicker__year--selected' : ''}`}
|
|
420
|
+
onClick={() => selectYear(year)}
|
|
421
|
+
aria-selected={isSelected ? 'true' : 'false'}
|
|
422
|
+
role="gridcell"
|
|
423
|
+
>
|
|
424
|
+
{year}
|
|
425
|
+
</button>
|
|
426
|
+
);
|
|
427
|
+
})}
|
|
428
|
+
</div>
|
|
429
|
+
)}
|
|
430
|
+
</div>
|
|
431
|
+
|
|
432
|
+
{viewMode === 'days' && (
|
|
433
|
+
<div className="c-datepicker__footer">
|
|
434
|
+
{selectionMode === 'range' && (
|
|
435
|
+
<div className="c-datepicker__range-status c-badge c-badge--sm c-badge--info u-w-100">
|
|
436
|
+
Selecting {rangeSelectionState === 'start' ? 'start' : 'end'} date
|
|
437
|
+
</div>
|
|
438
|
+
)}
|
|
439
|
+
|
|
440
|
+
{showTodayButton && (
|
|
441
|
+
<button
|
|
442
|
+
type="button"
|
|
443
|
+
className="c-datepicker__today-button c-btn c-btn--sm c-btn--outline-primary"
|
|
444
|
+
onClick={handleTodayClick}
|
|
445
|
+
aria-label="Go to today"
|
|
446
|
+
>
|
|
447
|
+
Today
|
|
448
|
+
</button>
|
|
449
|
+
)}
|
|
450
|
+
|
|
451
|
+
{!inline && (
|
|
452
|
+
<button
|
|
453
|
+
type="button"
|
|
454
|
+
className="c-datepicker__close-button c-btn c-btn--sm c-btn--outline-error"
|
|
455
|
+
onClick={() => setIsOpen(false)}
|
|
456
|
+
aria-label="Close calendar"
|
|
457
|
+
>
|
|
458
|
+
Close
|
|
459
|
+
</button>
|
|
460
|
+
)}
|
|
461
|
+
</div>
|
|
462
|
+
)}
|
|
463
|
+
</>
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
return (
|
|
467
|
+
<div className={datepickerClassName} ref={datePickerRef} {...props}>
|
|
468
|
+
{!inline && (
|
|
469
|
+
<div className="c-datepicker__input-wrapper">
|
|
470
|
+
<input
|
|
471
|
+
id={datepickerId}
|
|
472
|
+
name={name}
|
|
473
|
+
ref={inputRef}
|
|
474
|
+
type="text"
|
|
475
|
+
className={inputClasses}
|
|
476
|
+
placeholder={getPlaceholder()}
|
|
477
|
+
value={displayValue}
|
|
478
|
+
onChange={handleInputChange}
|
|
479
|
+
onFocus={handleInputFocus}
|
|
480
|
+
disabled={disabled}
|
|
481
|
+
readOnly={readOnly}
|
|
482
|
+
aria-haspopup="dialog"
|
|
483
|
+
aria-expanded={isOpen}
|
|
484
|
+
aria-controls={calendarId}
|
|
485
|
+
/>
|
|
486
|
+
{clearable && displayValue && (
|
|
487
|
+
<button
|
|
488
|
+
type="button"
|
|
489
|
+
className="c-datepicker__clear-button"
|
|
490
|
+
onClick={handleClear}
|
|
491
|
+
aria-label="Clear date"
|
|
492
|
+
>
|
|
493
|
+
<Icon name="X" size="sm" />
|
|
494
|
+
</button>
|
|
495
|
+
)}
|
|
496
|
+
<span className="c-datepicker__calendar-icon" aria-hidden="true">
|
|
497
|
+
<Icon name="Calendar" size="sm" color="var(--atomix-secondary-text-emphasis)" />
|
|
498
|
+
</span>
|
|
499
|
+
</div>
|
|
500
|
+
)}
|
|
501
|
+
|
|
502
|
+
{(isOpen || inline) && (
|
|
503
|
+
<>
|
|
504
|
+
{glass ? (
|
|
505
|
+
<div
|
|
506
|
+
id={calendarId}
|
|
507
|
+
className={`c-datepicker__calendar c-datepicker__calendar--${placement} c-datepicker__calendar--glass`}
|
|
508
|
+
role="dialog"
|
|
509
|
+
aria-modal={!inline ? 'true' : undefined}
|
|
510
|
+
aria-label="Date picker"
|
|
511
|
+
>
|
|
512
|
+
<AtomixGlass
|
|
513
|
+
{...(glass === true
|
|
514
|
+
? {
|
|
515
|
+
displacementScale: 50,
|
|
516
|
+
blurAmount: 3,
|
|
517
|
+
saturation: 160,
|
|
518
|
+
aberrationIntensity: 0,
|
|
519
|
+
cornerRadius: 12,
|
|
520
|
+
overLight: false,
|
|
521
|
+
elasticity: 0,
|
|
522
|
+
mode: 'standard' as const,
|
|
523
|
+
}
|
|
524
|
+
: glass)}
|
|
525
|
+
>
|
|
526
|
+
<div className="c-datepicker__glass-content">{renderCalendarContent()}</div>
|
|
527
|
+
</AtomixGlass>
|
|
528
|
+
</div>
|
|
529
|
+
) : (
|
|
530
|
+
<div
|
|
531
|
+
id={calendarId}
|
|
532
|
+
className={`c-datepicker__calendar c-datepicker__calendar--${placement}`}
|
|
533
|
+
role="dialog"
|
|
534
|
+
aria-modal={!inline ? 'true' : undefined}
|
|
535
|
+
aria-label="Date picker"
|
|
536
|
+
>
|
|
537
|
+
{renderCalendarContent()}
|
|
538
|
+
</div>
|
|
539
|
+
)}
|
|
540
|
+
</>
|
|
541
|
+
)}
|
|
542
|
+
</div>
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
export type { DatePickerProps };
|
|
548
|
+
|
|
549
|
+
DatePicker.displayName = 'DatePicker';
|
|
550
|
+
|
|
551
|
+
export default DatePicker;
|