@knitui/dates 0.14.0 → 1.0.0
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/lib/commonjs/Calendar/Calendar.js +4 -4
- package/lib/commonjs/Calendar/Calendar.js.map +1 -1
- package/lib/commonjs/CalendarHeader/CalendarHeader.js +24 -152
- package/lib/commonjs/CalendarHeader/CalendarHeader.js.map +1 -1
- package/lib/commonjs/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/DatePickerInput/DatePickerInput.js +1 -1
- package/lib/commonjs/DateTimePicker/DateTimePicker.js +1 -1
- package/lib/commonjs/DatesProvider/DatesProvider.js +1 -1
- package/lib/commonjs/Day/Day.js +74 -142
- package/lib/commonjs/Day/Day.js.map +1 -1
- package/lib/commonjs/DecadeLevel/DecadeLevel.js +5 -5
- package/lib/commonjs/DecadeLevel/DecadeLevel.js.map +1 -1
- package/lib/commonjs/InlineDateTimePicker/InlineDateTimePicker.js +16 -7
- package/lib/commonjs/InlineDateTimePicker/InlineDateTimePicker.js.map +1 -1
- package/lib/commonjs/LevelsGroup/LevelsGroup.js +3 -3
- package/lib/commonjs/LevelsGroup/LevelsGroup.js.map +1 -1
- package/lib/commonjs/MiniCalendar/MiniCalendar.js +37 -173
- package/lib/commonjs/MiniCalendar/MiniCalendar.js.map +1 -1
- package/lib/commonjs/Month/Month.js +15 -62
- package/lib/commonjs/Month/Month.js.map +1 -1
- package/lib/commonjs/MonthLevel/MonthLevel.js +5 -5
- package/lib/commonjs/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/commonjs/MonthPicker/MonthPicker.js +1 -1
- package/lib/commonjs/MonthPickerInput/MonthPickerInput.js +1 -1
- package/lib/commonjs/MonthsList/MonthsList.js +8 -9
- package/lib/commonjs/MonthsList/MonthsList.js.map +1 -1
- package/lib/commonjs/PickerControl/PickerControl.js +41 -121
- package/lib/commonjs/PickerControl/PickerControl.js.map +1 -1
- package/lib/commonjs/PickerInputBase/PickerInputBase.js +1 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js +19 -48
- package/lib/commonjs/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControlsList.js +1 -1
- package/lib/commonjs/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/commonjs/TimeGrid/TimeGrid.js +50 -97
- package/lib/commonjs/TimeGrid/TimeGrid.js.map +1 -1
- package/lib/commonjs/TimeInput/TimeInput.js +1 -1
- package/lib/commonjs/TimePicker/TimePicker.js +20 -20
- package/lib/commonjs/TimePicker/TimePicker.js.map +1 -1
- package/lib/commonjs/TimePresets/TimePresetControl.js +32 -62
- package/lib/commonjs/TimePresets/TimePresetControl.js.map +1 -1
- package/lib/commonjs/TimePresets/TimePresetGroup.js +5 -5
- package/lib/commonjs/TimePresets/TimePresetGroup.js.map +1 -1
- package/lib/commonjs/TimePresets/TimePresets.js +4 -4
- package/lib/commonjs/TimePresets/TimePresets.js.map +1 -1
- package/lib/commonjs/TimeValue/TimeValue.js +2 -2
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js +7 -38
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/commonjs/YearLevel/YearLevel.js +5 -5
- package/lib/commonjs/YearLevel/YearLevel.js.map +1 -1
- package/lib/commonjs/YearPicker/YearPicker.js +1 -1
- package/lib/commonjs/YearPickerInput/YearPickerInput.js +1 -1
- package/lib/commonjs/YearsList/YearsList.js +8 -9
- package/lib/commonjs/YearsList/YearsList.js.map +1 -1
- package/lib/commonjs/_reference/ExampleControl.js +26 -91
- package/lib/commonjs/_reference/ExampleControl.js.map +1 -1
- package/lib/commonjs/_reference/README.md +3 -3
- package/lib/commonjs/cell-metrics.js +167 -37
- package/lib/commonjs/cell-metrics.js.map +1 -1
- package/lib/commonjs/internal/a11y.js +5 -3
- package/lib/commonjs/internal/a11y.js.map +1 -1
- package/lib/commonjs/internal/get-input-default-date.js +1 -1
- package/lib/commonjs/internal/select-on-focus.js +1 -1
- package/lib/module/Calendar/Calendar.js +5 -5
- package/lib/module/Calendar/Calendar.js.map +1 -1
- package/lib/module/CalendarHeader/CalendarHeader.js +26 -155
- package/lib/module/CalendarHeader/CalendarHeader.js.map +1 -1
- package/lib/module/DatePicker/DatePicker.js +1 -1
- package/lib/module/DatePickerInput/DatePickerInput.js +1 -1
- package/lib/module/DateTimePicker/DateTimePicker.js +1 -1
- package/lib/module/DatesProvider/DatesProvider.js +1 -1
- package/lib/module/Day/Day.js +76 -144
- package/lib/module/Day/Day.js.map +1 -1
- package/lib/module/DecadeLevel/DecadeLevel.js +6 -6
- package/lib/module/DecadeLevel/DecadeLevel.js.map +1 -1
- package/lib/module/InlineDateTimePicker/InlineDateTimePicker.js +16 -7
- package/lib/module/InlineDateTimePicker/InlineDateTimePicker.js.map +1 -1
- package/lib/module/LevelsGroup/LevelsGroup.js +4 -4
- package/lib/module/LevelsGroup/LevelsGroup.js.map +1 -1
- package/lib/module/MiniCalendar/MiniCalendar.js +39 -175
- package/lib/module/MiniCalendar/MiniCalendar.js.map +1 -1
- package/lib/module/Month/Month.js +17 -64
- package/lib/module/Month/Month.js.map +1 -1
- package/lib/module/MonthLevel/MonthLevel.js +6 -6
- package/lib/module/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/module/MonthPicker/MonthPicker.js +1 -1
- package/lib/module/MonthPickerInput/MonthPickerInput.js +1 -1
- package/lib/module/MonthsList/MonthsList.js +9 -10
- package/lib/module/MonthsList/MonthsList.js.map +1 -1
- package/lib/module/PickerControl/PickerControl.js +42 -122
- package/lib/module/PickerControl/PickerControl.js.map +1 -1
- package/lib/module/PickerInputBase/PickerInputBase.js +1 -1
- package/lib/module/TimeControlsList/TimeControl.js +20 -49
- package/lib/module/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControlsList.js +1 -1
- package/lib/module/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/module/TimeGrid/TimeGrid.js +53 -100
- package/lib/module/TimeGrid/TimeGrid.js.map +1 -1
- package/lib/module/TimeInput/TimeInput.js +1 -1
- package/lib/module/TimePicker/TimePicker.js +20 -20
- package/lib/module/TimePicker/TimePicker.js.map +1 -1
- package/lib/module/TimePresets/TimePresetControl.js +36 -65
- package/lib/module/TimePresets/TimePresetControl.js.map +1 -1
- package/lib/module/TimePresets/TimePresetGroup.js +6 -6
- package/lib/module/TimePresets/TimePresetGroup.js.map +1 -1
- package/lib/module/TimePresets/TimePresets.js +4 -4
- package/lib/module/TimePresets/TimePresets.js.map +1 -1
- package/lib/module/TimeValue/TimeValue.js +2 -2
- package/lib/module/WeekdaysRow/WeekdaysRow.js +8 -39
- package/lib/module/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/module/YearLevel/YearLevel.js +6 -6
- package/lib/module/YearLevel/YearLevel.js.map +1 -1
- package/lib/module/YearPicker/YearPicker.js +1 -1
- package/lib/module/YearPickerInput/YearPickerInput.js +1 -1
- package/lib/module/YearsList/YearsList.js +9 -10
- package/lib/module/YearsList/YearsList.js.map +1 -1
- package/lib/module/_reference/ExampleControl.js +28 -93
- package/lib/module/_reference/ExampleControl.js.map +1 -1
- package/lib/module/_reference/README.md +3 -3
- package/lib/module/cell-metrics.js +166 -36
- package/lib/module/cell-metrics.js.map +1 -1
- package/lib/module/internal/a11y.js +5 -3
- package/lib/module/internal/a11y.js.map +1 -1
- package/lib/module/internal/get-input-default-date.js +1 -1
- package/lib/module/internal/select-on-focus.js +1 -1
- package/lib/typescript/Calendar/Calendar.d.ts +28 -21
- package/lib/typescript/Calendar/Calendar.d.ts.map +1 -1
- package/lib/typescript/Calendar/pick-calendar-props/pick-calendar-props.d.ts +1 -1
- package/lib/typescript/CalendarHeader/CalendarHeader.d.ts +190 -53
- package/lib/typescript/CalendarHeader/CalendarHeader.d.ts.map +1 -1
- package/lib/typescript/Day/Day.d.ts +103 -84
- package/lib/typescript/Day/Day.d.ts.map +1 -1
- package/lib/typescript/DecadeLevel/DecadeLevel.d.ts +172 -71
- package/lib/typescript/DecadeLevel/DecadeLevel.d.ts.map +1 -1
- package/lib/typescript/DecadeLevelGroup/DecadeLevelGroup.d.ts +171 -86
- package/lib/typescript/DecadeLevelGroup/DecadeLevelGroup.d.ts.map +1 -1
- package/lib/typescript/InlineDateTimePicker/InlineDateTimePicker.d.ts +64 -12
- package/lib/typescript/InlineDateTimePicker/InlineDateTimePicker.d.ts.map +1 -1
- package/lib/typescript/LevelsGroup/LevelsGroup.d.ts +27 -20
- package/lib/typescript/LevelsGroup/LevelsGroup.d.ts.map +1 -1
- package/lib/typescript/MiniCalendar/MiniCalendar.d.ts +247 -61
- package/lib/typescript/MiniCalendar/MiniCalendar.d.ts.map +1 -1
- package/lib/typescript/Month/Month.d.ts +164 -43
- package/lib/typescript/Month/Month.d.ts.map +1 -1
- package/lib/typescript/MonthLevel/MonthLevel.d.ts +208 -79
- package/lib/typescript/MonthLevel/MonthLevel.d.ts.map +1 -1
- package/lib/typescript/MonthLevelGroup/MonthLevelGroup.d.ts +207 -94
- package/lib/typescript/MonthLevelGroup/MonthLevelGroup.d.ts.map +1 -1
- package/lib/typescript/MonthsList/MonthsList.d.ts +91 -26
- package/lib/typescript/MonthsList/MonthsList.d.ts.map +1 -1
- package/lib/typescript/PickerControl/PickerControl.d.ts +79 -59
- package/lib/typescript/PickerControl/PickerControl.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControl.d.ts +19 -4
- package/lib/typescript/TimeControlsList/TimeControl.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControlsList.d.ts +66 -12
- package/lib/typescript/TimeControlsList/TimeControlsList.d.ts.map +1 -1
- package/lib/typescript/TimeGrid/TimeGrid.d.ts +98 -34
- package/lib/typescript/TimeGrid/TimeGrid.d.ts.map +1 -1
- package/lib/typescript/TimePicker/TimePicker.d.ts +43 -7
- package/lib/typescript/TimePicker/TimePicker.d.ts.map +1 -1
- package/lib/typescript/TimePresets/TimePresetControl.d.ts +65 -10
- package/lib/typescript/TimePresets/TimePresetControl.d.ts.map +1 -1
- package/lib/typescript/TimePresets/TimePresetGroup.d.ts +132 -44
- package/lib/typescript/TimePresets/TimePresetGroup.d.ts.map +1 -1
- package/lib/typescript/TimePresets/TimePresets.d.ts +237 -64
- package/lib/typescript/TimePresets/TimePresets.d.ts.map +1 -1
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts +81 -27
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts.map +1 -1
- package/lib/typescript/YearLevel/YearLevel.d.ts +172 -71
- package/lib/typescript/YearLevel/YearLevel.d.ts.map +1 -1
- package/lib/typescript/YearLevelGroup/YearLevelGroup.d.ts +171 -86
- package/lib/typescript/YearLevelGroup/YearLevelGroup.d.ts.map +1 -1
- package/lib/typescript/YearsList/YearsList.d.ts +91 -26
- package/lib/typescript/YearsList/YearsList.d.ts.map +1 -1
- package/lib/typescript/_reference/ExampleControl.d.ts +163 -43
- package/lib/typescript/_reference/ExampleControl.d.ts.map +1 -1
- package/lib/typescript/cell-metrics.d.ts +120 -0
- package/lib/typescript/cell-metrics.d.ts.map +1 -1
- package/lib/typescript/internal/a11y.d.ts +0 -14
- package/lib/typescript/internal/a11y.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Calendar/Calendar.tsx +6 -5
- package/src/CalendarHeader/CalendarHeader.tsx +32 -74
- package/src/DatePicker/DatePicker.tsx +1 -1
- package/src/DatePickerInput/DatePickerInput.tsx +1 -1
- package/src/DateTimePicker/DateTimePicker.tsx +1 -1
- package/src/DatesProvider/DatesProvider.tsx +1 -1
- package/src/Day/Day.tsx +85 -82
- package/src/DecadeLevel/DecadeLevel.tsx +7 -5
- package/src/InlineDateTimePicker/InlineDateTimePicker.tsx +14 -7
- package/src/LevelsGroup/LevelsGroup.tsx +13 -13
- package/src/MiniCalendar/MiniCalendar.tsx +47 -91
- package/src/Month/Month.tsx +21 -37
- package/src/MonthLevel/MonthLevel.tsx +7 -5
- package/src/MonthPicker/MonthPicker.tsx +1 -1
- package/src/MonthPickerInput/MonthPickerInput.tsx +1 -1
- package/src/MonthsList/MonthsList.tsx +9 -10
- package/src/PickerControl/PickerControl.tsx +44 -89
- package/src/PickerInputBase/PickerInputBase.tsx +1 -1
- package/src/TimeControlsList/TimeControl.tsx +17 -28
- package/src/TimeControlsList/TimeControlsList.tsx +1 -1
- package/src/TimeGrid/TimeGrid.tsx +71 -61
- package/src/TimeInput/TimeInput.tsx +1 -1
- package/src/TimePicker/TimePicker.tsx +15 -15
- package/src/TimePresets/TimePresetControl.tsx +30 -45
- package/src/TimePresets/TimePresetGroup.tsx +7 -5
- package/src/TimePresets/TimePresets.tsx +4 -4
- package/src/TimeValue/TimeValue.tsx +2 -2
- package/src/WeekdaysRow/WeekdaysRow.tsx +9 -17
- package/src/YearLevel/YearLevel.tsx +121 -117
- package/src/YearPicker/YearPicker.tsx +1 -1
- package/src/YearPickerInput/YearPickerInput.tsx +1 -1
- package/src/YearsList/YearsList.tsx +142 -141
- package/src/_reference/ExampleControl.tsx +29 -53
- package/src/_reference/README.md +3 -3
- package/src/cell-metrics.ts +110 -36
- package/src/internal/a11y.ts +6 -3
- package/src/internal/get-input-default-date.ts +1 -1
- package/src/internal/select-on-focus.ts +1 -1
- package/lib/commonjs/internal/web-cursor.js +0 -24
- package/lib/commonjs/internal/web-cursor.js.map +0 -1
- package/lib/module/internal/web-cursor.js +0 -20
- package/lib/module/internal/web-cursor.js.map +0 -1
- package/lib/typescript/internal/web-cursor.d.ts +0 -10
- package/lib/typescript/internal/web-cursor.d.ts.map +0 -1
- package/src/internal/web-cursor.ts +0 -15
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// rules in `_reference/README.md` that apply here: #1 (this header), #2 (shared
|
|
18
18
|
// size context), #7 (`styles` sugar + `getMonthControlProps` passthrough — owned
|
|
19
19
|
// by `MonthsList`), #9 (locale), #10 (min/max bounds), #11 (delegated a11y),
|
|
20
|
-
// #13 (
|
|
20
|
+
// #13 (`styleable()` + typed ref), #14 (`withStaticProperties`), #15 (no dynamic
|
|
21
21
|
// hide styles — none used here). Unlike `DecadeLevel`, a year is NOT the top
|
|
22
22
|
// level: it zooms out to a decade, so the level control stays interactive
|
|
23
23
|
// (`onLevelClick`/`hasNextLevel`).
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
type GetProps,
|
|
33
33
|
slotStyles,
|
|
34
34
|
type SlotStyles,
|
|
35
|
+
styleable,
|
|
35
36
|
styled,
|
|
36
37
|
withStaticProperties,
|
|
37
38
|
} from "@knitui/core";
|
|
@@ -60,10 +61,10 @@ const YearLevelContext = createStyledContext<{ size: CalendarSize }>({ size: "md
|
|
|
60
61
|
|
|
61
62
|
// ── 5/13. Styled root ─────────────────────────────────────────────────────────
|
|
62
63
|
// The level root is a styled `Box` column (the dates norm: a real styled part so
|
|
63
|
-
//
|
|
64
|
+
// `styleable()` can forward a ref + style props onto it). It establishes the
|
|
64
65
|
// shared `size` context; the header and grid own the `size` variant themselves.
|
|
65
66
|
const YearLevelFrame = styled(Box, {
|
|
66
|
-
|
|
67
|
+
displayName: "YearLevel",
|
|
67
68
|
context: YearLevelContext,
|
|
68
69
|
flexDirection: "column",
|
|
69
70
|
|
|
@@ -149,7 +150,7 @@ export interface YearLevelProps extends YearLevelFrameProps, YearLevelSettings {
|
|
|
149
150
|
* locale. All `__onControl*` / `__getControlRef` / `__preventFocus` /
|
|
150
151
|
* `__stopPropagation` plumbing is forwarded straight to the `MonthsList`.
|
|
151
152
|
*
|
|
152
|
-
* Per-slot style sugar: `styles={{ headerControl: { borderRadius: "
|
|
153
|
+
* Per-slot style sugar: `styles={{ headerControl: { borderRadius: "lg" } }}` routes
|
|
153
154
|
* onto the matching part; per-cell tuning stays on `getMonthControlProps(date)`. The
|
|
154
155
|
* month grid's a11y/interaction/sizing are delegated to `MonthsList`/`PickerControl`
|
|
155
156
|
* and the header to `CalendarHeader`. Forwards its ref + style props to the root.
|
|
@@ -157,129 +158,132 @@ export interface YearLevelProps extends YearLevelFrameProps, YearLevelSettings {
|
|
|
157
158
|
* @example
|
|
158
159
|
* <YearLevel year="2024-01-01" onNext={nextYear} onPrevious={prevYear} onLevelClick={zoomOut} />
|
|
159
160
|
*/
|
|
160
|
-
const YearLevelComponent =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
161
|
+
const YearLevelComponent = styleable<YearLevelProps>(
|
|
162
|
+
YearLevelFrame,
|
|
163
|
+
function YearLevel(props, ref) {
|
|
164
|
+
const {
|
|
165
|
+
// MonthsList settings
|
|
166
|
+
year,
|
|
167
|
+
locale,
|
|
168
|
+
minDate,
|
|
169
|
+
maxDate,
|
|
170
|
+
monthsListFormat,
|
|
171
|
+
getMonthControlProps,
|
|
172
|
+
__getControlRef,
|
|
173
|
+
__onControlKeyDown,
|
|
174
|
+
__onControlClick,
|
|
175
|
+
__onControlMouseEnter,
|
|
176
|
+
withCellSpacing,
|
|
174
177
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
178
|
+
// CalendarHeader settings
|
|
179
|
+
__preventFocus,
|
|
180
|
+
__stopPropagation,
|
|
181
|
+
nextIcon,
|
|
182
|
+
previousIcon,
|
|
183
|
+
nextLabel,
|
|
184
|
+
previousLabel,
|
|
185
|
+
onNext,
|
|
186
|
+
onPrevious,
|
|
187
|
+
onLevelClick,
|
|
188
|
+
nextDisabled,
|
|
189
|
+
previousDisabled,
|
|
190
|
+
hasNextLevel,
|
|
191
|
+
levelControlAriaLabel,
|
|
192
|
+
withNext,
|
|
193
|
+
withPrevious,
|
|
194
|
+
headerControlsOrder,
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
// Level-specific
|
|
197
|
+
yearLabelFormat = "YYYY",
|
|
198
|
+
size = "md",
|
|
199
|
+
fullWidth,
|
|
200
|
+
styles,
|
|
201
|
+
...rest
|
|
202
|
+
} = props;
|
|
200
203
|
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
// 7. Typed per-slot accessor (dev-warns unknown keys against the known set).
|
|
205
|
+
const s = slotStyles<YearLevelStyles>(styles, YEAR_LEVEL_SLOT_KEYS, "YearLevel");
|
|
203
206
|
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
// 9. Locale comes from `DatesProvider` (consumer `locale` prop wins).
|
|
208
|
+
const ctx = useDatesContext();
|
|
206
209
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
// 10. Auto-disable the controls at the `minDate`/`maxDate` bounds (an explicit
|
|
211
|
+
// boolean override always wins).
|
|
212
|
+
const _nextDisabled =
|
|
213
|
+
typeof nextDisabled === "boolean"
|
|
214
|
+
? nextDisabled
|
|
215
|
+
: maxDate
|
|
216
|
+
? !dayjs(year).endOf("year").isBefore(maxDate)
|
|
217
|
+
: false;
|
|
215
218
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
const _previousDisabled =
|
|
220
|
+
typeof previousDisabled === "boolean"
|
|
221
|
+
? previousDisabled
|
|
222
|
+
: minDate
|
|
223
|
+
? !dayjs(year).startOf("year").isAfter(minDate)
|
|
224
|
+
: false;
|
|
222
225
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
const label =
|
|
227
|
+
typeof yearLabelFormat === "function"
|
|
228
|
+
? yearLabelFormat(year)
|
|
229
|
+
: dayjs(year).locale(ctx.getLocale(locale)).format(yearLabelFormat);
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
// 7. Route the header-named slots into `CalendarHeader`'s own `styles` map.
|
|
232
|
+
const headerStyles: SlotStyles<CalendarHeaderStyles> = {
|
|
233
|
+
root: s.get("header"),
|
|
234
|
+
control: s.get("headerControl"),
|
|
235
|
+
level: s.get("headerLevel"),
|
|
236
|
+
levelLabel: s.get("headerLevelLabel"),
|
|
237
|
+
icon: s.get("headerIcon"),
|
|
238
|
+
};
|
|
236
239
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
240
|
+
return (
|
|
241
|
+
<YearLevelFrame ref={ref} fullWidth={fullWidth} {...s.merge("root", rest)}>
|
|
242
|
+
<CalendarHeader
|
|
243
|
+
label={label}
|
|
244
|
+
__preventFocus={__preventFocus}
|
|
245
|
+
__stopPropagation={__stopPropagation}
|
|
246
|
+
nextIcon={nextIcon}
|
|
247
|
+
previousIcon={previousIcon}
|
|
248
|
+
nextLabel={nextLabel}
|
|
249
|
+
previousLabel={previousLabel}
|
|
250
|
+
onNext={onNext}
|
|
251
|
+
onPrevious={onPrevious}
|
|
252
|
+
onLevelClick={onLevelClick}
|
|
253
|
+
nextDisabled={_nextDisabled}
|
|
254
|
+
previousDisabled={_previousDisabled}
|
|
255
|
+
hasNextLevel={hasNextLevel}
|
|
256
|
+
levelControlAriaLabel={levelControlAriaLabel}
|
|
257
|
+
withNext={withNext}
|
|
258
|
+
withPrevious={withPrevious}
|
|
259
|
+
headerControlsOrder={headerControlsOrder}
|
|
260
|
+
size={size}
|
|
261
|
+
fullWidth={fullWidth}
|
|
262
|
+
styles={headerStyles}
|
|
263
|
+
/>
|
|
261
264
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
265
|
+
<MonthsList
|
|
266
|
+
year={year}
|
|
267
|
+
locale={locale}
|
|
268
|
+
minDate={minDate}
|
|
269
|
+
maxDate={maxDate}
|
|
270
|
+
monthsListFormat={monthsListFormat}
|
|
271
|
+
getMonthControlProps={getMonthControlProps}
|
|
272
|
+
__getControlRef={__getControlRef}
|
|
273
|
+
__onControlKeyDown={__onControlKeyDown}
|
|
274
|
+
__onControlClick={__onControlClick}
|
|
275
|
+
__onControlMouseEnter={__onControlMouseEnter}
|
|
276
|
+
__preventFocus={__preventFocus}
|
|
277
|
+
__stopPropagation={__stopPropagation}
|
|
278
|
+
withCellSpacing={withCellSpacing}
|
|
279
|
+
size={size}
|
|
280
|
+
fullWidth={fullWidth}
|
|
281
|
+
{...s.get("months")}
|
|
282
|
+
/>
|
|
283
|
+
</YearLevelFrame>
|
|
284
|
+
);
|
|
285
|
+
},
|
|
286
|
+
);
|
|
283
287
|
|
|
284
288
|
// ── 14. Public surface ────────────────────────────────────────────────────────
|
|
285
289
|
// `withStaticProperties` exposes the styled root + the composed parts so consumers
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// subtree — never a dynamic `opacity`/`display` style prop (15). The `<Type>`
|
|
26
26
|
// generic is preserved through `forwardRef` (which would otherwise pin it at
|
|
27
27
|
// `"default"`), so the ref is forwarded via a typed `forwardRef` rather than
|
|
28
|
-
//
|
|
28
|
+
// `styleable()` (13) — the documented sibling-picker pattern.
|
|
29
29
|
// ───────────────────────────────────────────────────────────────────────────
|
|
30
30
|
import * as React from "react";
|
|
31
31
|
import { useRef } from "react";
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
// dropdown subtree `PickerInputBase` owns — never a dynamic `opacity`/`display`
|
|
38
38
|
// style prop (15). The `<Type>` generic is preserved through `forwardRef` (which
|
|
39
39
|
// would otherwise pin it at `"default"`), so the ref is forwarded via a typed
|
|
40
|
-
// `forwardRef` rather than
|
|
40
|
+
// `forwardRef` rather than `styleable()` (13) — the documented sibling-picker
|
|
41
41
|
// pattern (`YearPicker` / `MonthPickerInput` / `DatePickerInput`).
|
|
42
42
|
// ───────────────────────────────────────────────────────────────────────────
|
|
43
43
|
import * as React from "react";
|
|
@@ -24,11 +24,13 @@ import { useMemo } from "react";
|
|
|
24
24
|
import dayjs from "dayjs";
|
|
25
25
|
|
|
26
26
|
import { Box } from "@knitui/components";
|
|
27
|
+
import { hoverProps } from "@knitui/components/control-system";
|
|
27
28
|
import {
|
|
28
29
|
createStyledContext,
|
|
29
30
|
type GetProps,
|
|
30
31
|
slotStyles,
|
|
31
32
|
type SlotStyles,
|
|
33
|
+
styleable,
|
|
32
34
|
styled,
|
|
33
35
|
withStaticProperties,
|
|
34
36
|
} from "@knitui/core";
|
|
@@ -70,7 +72,7 @@ const YearsListContext = createStyledContext<{ size: CalendarSize }>({ size: "md
|
|
|
70
72
|
|
|
71
73
|
/** The grid container — a column of year rows (web `role="grid"`). */
|
|
72
74
|
const YearsListFrame = styled(Box, {
|
|
73
|
-
|
|
75
|
+
displayName: "YearsList",
|
|
74
76
|
context: YearsListContext,
|
|
75
77
|
flexDirection: "column",
|
|
76
78
|
|
|
@@ -89,7 +91,7 @@ const YearsListFrame = styled(Box, {
|
|
|
89
91
|
|
|
90
92
|
/** A single year row (web `role="row"`). */
|
|
91
93
|
const YearsListRow = styled(Box, {
|
|
92
|
-
|
|
94
|
+
displayName: "YearsListRow",
|
|
93
95
|
context: YearsListContext,
|
|
94
96
|
flexDirection: "row",
|
|
95
97
|
|
|
@@ -114,7 +116,7 @@ const YearsListRow = styled(Box, {
|
|
|
114
116
|
* per-render `flexGrow` spread — so the optimiser has nothing dynamic to fold).
|
|
115
117
|
*/
|
|
116
118
|
const YearsListCell = styled(Box, {
|
|
117
|
-
|
|
119
|
+
displayName: "YearsListCell",
|
|
118
120
|
context: YearsListContext,
|
|
119
121
|
alignItems: "center",
|
|
120
122
|
justifyContent: "center",
|
|
@@ -205,12 +207,8 @@ const YearsListControlCell = React.memo(function YearsListControlCell({
|
|
|
205
207
|
onControlKeyDown,
|
|
206
208
|
getControlRef,
|
|
207
209
|
}: YearsListControlCellProps) {
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
// affordances (see `Month`). Native never fires it.
|
|
211
|
-
const hoverHandlers: { onHoverIn?: (event: unknown) => void } = {
|
|
212
|
-
onHoverIn: (event) => onControlMouseEnter(event, year),
|
|
213
|
-
};
|
|
210
|
+
// Range hover preview (see `Month`): `onMouseEnter` on web, `onHoverIn` on native.
|
|
211
|
+
const hoverHandlers = hoverProps({ onHoverIn: (event) => onControlMouseEnter(event, year) });
|
|
214
212
|
|
|
215
213
|
return (
|
|
216
214
|
<YearsListCell role="cell" fullWidth={fullWidth} {...cellProps}>
|
|
@@ -339,148 +337,151 @@ export interface YearsListProps extends YearsListFrameProps, YearsListSettings {
|
|
|
339
337
|
* wrapping a `role="button"` control. (ARIA's `gridcell` would be the ideal child
|
|
340
338
|
* of `role="grid"`, but the cross-platform `Role` type has no `gridcell` member.)
|
|
341
339
|
*/
|
|
342
|
-
const YearsListComponent =
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
grid
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
340
|
+
const YearsListComponent = styleable<YearsListProps>(
|
|
341
|
+
YearsListFrame,
|
|
342
|
+
function YearsList(props, ref) {
|
|
343
|
+
const {
|
|
344
|
+
decade,
|
|
345
|
+
yearsListFormat = "YYYY",
|
|
346
|
+
locale,
|
|
347
|
+
minDate,
|
|
348
|
+
maxDate,
|
|
349
|
+
getYearControlProps,
|
|
350
|
+
__getControlRef,
|
|
351
|
+
__onControlKeyDown,
|
|
352
|
+
__onControlClick,
|
|
353
|
+
__onControlMouseEnter,
|
|
354
|
+
__preventFocus,
|
|
355
|
+
__stopPropagation,
|
|
356
|
+
withCellSpacing = true,
|
|
357
|
+
fullWidth = false,
|
|
358
|
+
size = "md",
|
|
359
|
+
styles,
|
|
360
|
+
...rest
|
|
361
|
+
} = props;
|
|
362
|
+
|
|
363
|
+
// `__stopPropagation` is accepted for Mantine API parity; the cross-platform
|
|
364
|
+
// Escape handling lives at the picker/popover layer, so it is a no-op here
|
|
365
|
+
// (the same reservation `CalendarHeader`/`Month` make for it).
|
|
366
|
+
void __stopPropagation;
|
|
367
|
+
|
|
368
|
+
const ctx = useDatesContext();
|
|
369
|
+
|
|
370
|
+
const minDateString = minDate == null ? undefined : toDateString(minDate);
|
|
371
|
+
const maxDateString = maxDate == null ? undefined : toDateString(maxDate);
|
|
372
|
+
|
|
373
|
+
// 7. Typed per-slot accessor (dev-warns unknown keys against the known set).
|
|
374
|
+
const s = slotStyles<YearsListStyles>(styles, YEARS_LIST_SLOT_KEYS, "YearsList");
|
|
375
|
+
|
|
376
|
+
const resolvedLocale = ctx.getLocale(locale);
|
|
377
|
+
|
|
378
|
+
// The 10 cells' grid, bounds and LABELS depend only on the decade, the locale,
|
|
379
|
+
// the format and the min/max bounds — never on the selection — yet they were
|
|
380
|
+
// rebuilt every render, each cell paying a `dayjs(year).locale(…).format(…)`
|
|
381
|
+
// (parse + locale clone + locale-table format) for a label fixed for the decade.
|
|
382
|
+
const yearsInfo = useMemo(() => {
|
|
383
|
+
const grid = getYearsData(decade);
|
|
384
|
+
return {
|
|
385
|
+
grid,
|
|
386
|
+
cells: grid.map((row) =>
|
|
387
|
+
row.map((year) => ({
|
|
388
|
+
year,
|
|
389
|
+
disabled: isYearDisabled({ year, minDate: minDateString, maxDate: maxDateString }),
|
|
390
|
+
label: dayjs(year).locale(resolvedLocale).format(yearsListFormat),
|
|
391
|
+
})),
|
|
392
|
+
),
|
|
393
|
+
};
|
|
394
|
+
}, [decade, minDateString, maxDateString, resolvedLocale, yearsListFormat]);
|
|
395
|
+
|
|
396
|
+
// ONE per-render cache shared by `getYearInTabOrder` (which consults the getter
|
|
397
|
+
// twice per year) and the cell loop below (a third time). Not memoized across
|
|
398
|
+
// renders — the getter closes over live selection state.
|
|
399
|
+
const resolveControlProps = memoizeByDate(getYearControlProps);
|
|
400
|
+
|
|
401
|
+
const yearInTabOrder = getYearInTabOrder({
|
|
402
|
+
years: yearsInfo.grid,
|
|
403
|
+
minDate: minDateString,
|
|
404
|
+
maxDate: maxDateString,
|
|
405
|
+
getYearControlProps: resolveControlProps,
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const cellGap = withCellSpacing ? CELL_SPACING : 0;
|
|
409
|
+
|
|
410
|
+
// The cell memo can only bail out if every function prop it receives keeps a
|
|
411
|
+
// stable identity. All four of these arrive freshly built each render (the level
|
|
412
|
+
// group builds them per decade, `YearPicker` per render), so they are wrapped once
|
|
413
|
+
// here rather than being stabilised at each of their many call sites.
|
|
414
|
+
const onControlMouseEnter = useCallbackRef(__onControlMouseEnter);
|
|
415
|
+
const onControlClick = useCallbackRef(__onControlClick);
|
|
416
|
+
const onControlKeyDown = useCallbackRef(__onControlKeyDown);
|
|
417
|
+
const getControlRef = useCallbackRef(__getControlRef);
|
|
418
|
+
|
|
419
|
+
const cellSlotProps = s.get("cell");
|
|
420
|
+
|
|
421
|
+
const rows = yearsInfo.cells.map((yearsRow, rowIndex) => {
|
|
422
|
+
const cells = yearsRow.map(({ year, disabled: outOfBounds, label }, cellIndex) => {
|
|
423
|
+
const controlProps = resolveControlProps?.(year);
|
|
424
|
+
// Both sides come from `getYearsData`'s canonical `YYYY-MM-DD`, so the `YYYY`
|
|
425
|
+
// prefix compare is exactly the year-granularity `isSame` it replaces.
|
|
426
|
+
const isYearInTabOrder =
|
|
427
|
+
yearInTabOrder !== undefined && year.slice(0, 4) === yearInTabOrder.slice(0, 4);
|
|
428
|
+
const disabled = outOfBounds || controlProps?.disabled;
|
|
429
|
+
|
|
430
|
+
return (
|
|
431
|
+
<YearsListControlCell
|
|
432
|
+
key={year}
|
|
433
|
+
year={year}
|
|
434
|
+
label={label}
|
|
435
|
+
disabled={disabled}
|
|
436
|
+
rowIndex={rowIndex}
|
|
437
|
+
cellIndex={cellIndex}
|
|
438
|
+
tabIndex={__preventFocus || !isYearInTabOrder ? -1 : 0}
|
|
439
|
+
size={size}
|
|
440
|
+
fullWidth={fullWidth}
|
|
441
|
+
preventFocus={__preventFocus}
|
|
442
|
+
cellProps={cellSlotProps}
|
|
443
|
+
controlProps={controlProps}
|
|
444
|
+
mergedControlProps={s.merge("control", controlProps)}
|
|
445
|
+
onControlMouseEnter={onControlMouseEnter}
|
|
446
|
+
onControlClick={onControlClick}
|
|
447
|
+
onControlKeyDown={onControlKeyDown}
|
|
448
|
+
getControlRef={getControlRef}
|
|
449
|
+
/>
|
|
450
|
+
);
|
|
451
|
+
});
|
|
429
452
|
|
|
430
453
|
return (
|
|
431
|
-
<
|
|
432
|
-
key={
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
disabled={disabled}
|
|
436
|
-
rowIndex={rowIndex}
|
|
437
|
-
cellIndex={cellIndex}
|
|
438
|
-
tabIndex={__preventFocus || !isYearInTabOrder ? -1 : 0}
|
|
439
|
-
size={size}
|
|
454
|
+
<YearsListRow
|
|
455
|
+
key={rowIndex}
|
|
456
|
+
role="row"
|
|
457
|
+
columnGap={cellGap}
|
|
440
458
|
fullWidth={fullWidth}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
onControlMouseEnter={onControlMouseEnter}
|
|
446
|
-
onControlClick={onControlClick}
|
|
447
|
-
onControlKeyDown={onControlKeyDown}
|
|
448
|
-
getControlRef={getControlRef}
|
|
449
|
-
/>
|
|
459
|
+
{...s.get("row")}
|
|
460
|
+
>
|
|
461
|
+
{cells}
|
|
462
|
+
</YearsListRow>
|
|
450
463
|
);
|
|
451
464
|
});
|
|
452
465
|
|
|
453
466
|
return (
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
467
|
+
// The grid CONTAINER roles (`grid`/`row`/`cell`) are WEB-ONLY: React-Native's
|
|
468
|
+
// `accessibilityRole` has no `grid`/`row`/`gridcell` member (same root cause
|
|
469
|
+
// as the closed `role="cell"`→`gridcell` question), so there is no native
|
|
470
|
+
// counterpart to add here. Per-cell native announcement is instead carried
|
|
471
|
+
// by each `PickerControl`'s own `accessibilityRole`/`accessibilityState`.
|
|
472
|
+
<YearsListFrame
|
|
473
|
+
ref={ref}
|
|
474
|
+
role="grid"
|
|
475
|
+
rowGap={cellGap}
|
|
458
476
|
fullWidth={fullWidth}
|
|
459
|
-
{...s.get("
|
|
477
|
+
{...s.get("root")}
|
|
478
|
+
{...rest}
|
|
460
479
|
>
|
|
461
|
-
{
|
|
462
|
-
</
|
|
480
|
+
{rows}
|
|
481
|
+
</YearsListFrame>
|
|
463
482
|
);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return (
|
|
467
|
-
// The grid CONTAINER roles (`grid`/`row`/`cell`) are WEB-ONLY: React-Native's
|
|
468
|
-
// `accessibilityRole` has no `grid`/`row`/`gridcell` member (same root cause
|
|
469
|
-
// as the closed `role="cell"`→`gridcell` question), so there is no native
|
|
470
|
-
// counterpart to add here. Per-cell native announcement is instead carried
|
|
471
|
-
// by each `PickerControl`'s own `accessibilityRole`/`accessibilityState`.
|
|
472
|
-
<YearsListFrame
|
|
473
|
-
ref={ref}
|
|
474
|
-
role="grid"
|
|
475
|
-
rowGap={cellGap}
|
|
476
|
-
fullWidth={fullWidth}
|
|
477
|
-
{...s.get("root")}
|
|
478
|
-
{...rest}
|
|
479
|
-
>
|
|
480
|
-
{rows}
|
|
481
|
-
</YearsListFrame>
|
|
482
|
-
);
|
|
483
|
-
});
|
|
483
|
+
},
|
|
484
|
+
);
|
|
484
485
|
|
|
485
486
|
YearsListComponent.displayName = "@knitui/dates/YearsList";
|
|
486
487
|
|