@knitui/dates 0.5.0 → 0.6.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/lib/commonjs/DatesProvider/DatesProvider.js +33 -4
- package/lib/commonjs/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/commonjs/Day/Day.js +45 -7
- package/lib/commonjs/Day/Day.js.map +1 -1
- package/lib/commonjs/Month/Month.js +266 -80
- package/lib/commonjs/Month/Month.js.map +1 -1
- package/lib/commonjs/MonthLevel/MonthLevel.js +19 -3
- package/lib/commonjs/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/commonjs/MonthsList/MonthsList.js +160 -60
- package/lib/commonjs/MonthsList/MonthsList.js.map +1 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js +15 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/commonjs/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/commonjs/YearsList/YearsList.js +155 -60
- package/lib/commonjs/YearsList/YearsList.js.map +1 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/commonjs/internal/are-cell-props-equal.js +64 -0
- package/lib/commonjs/internal/are-cell-props-equal.js.map +1 -0
- package/lib/commonjs/internal/date-string-fast-path.js +98 -0
- package/lib/commonjs/internal/date-string-fast-path.js.map +1 -0
- package/lib/commonjs/internal/memoize-control-props.js +54 -0
- package/lib/commonjs/internal/memoize-control-props.js.map +1 -0
- package/lib/commonjs/internal/month-days-cache.js +71 -0
- package/lib/commonjs/internal/month-days-cache.js.map +1 -0
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js +17 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/module/DatesProvider/DatesProvider.js +34 -5
- package/lib/module/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/module/Day/Day.js +46 -8
- package/lib/module/Day/Day.js.map +1 -1
- package/lib/module/Month/Month.js +267 -82
- package/lib/module/Month/Month.js.map +1 -1
- package/lib/module/MonthLevel/MonthLevel.js +19 -3
- package/lib/module/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/module/MonthsList/MonthsList.js +159 -60
- package/lib/module/MonthsList/MonthsList.js.map +1 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControl.js +15 -1
- package/lib/module/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/module/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/module/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/module/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/module/YearsList/YearsList.js +154 -60
- package/lib/module/YearsList/YearsList.js.map +1 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/module/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/module/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/module/internal/are-cell-props-equal.js +60 -0
- package/lib/module/internal/are-cell-props-equal.js.map +1 -0
- package/lib/module/internal/date-string-fast-path.js +91 -0
- package/lib/module/internal/date-string-fast-path.js.map +1 -0
- package/lib/module/internal/memoize-control-props.js +50 -0
- package/lib/module/internal/memoize-control-props.js.map +1 -0
- package/lib/module/internal/month-days-cache.js +68 -0
- package/lib/module/internal/month-days-cache.js.map +1 -0
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/module/utils/is-same-month/is-same-month.js +17 -1
- package/lib/module/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/typescript/Calendar/pick-calendar-props/pick-calendar-props.d.ts +1 -1
- package/lib/typescript/CalendarHeader/CalendarHeader.d.ts +14 -14
- package/lib/typescript/DatesProvider/DatesProvider.d.ts.map +1 -1
- package/lib/typescript/Day/Day.d.ts +31 -31
- package/lib/typescript/Day/Day.d.ts.map +1 -1
- package/lib/typescript/DecadeLevel/DecadeLevel.d.ts +7 -7
- package/lib/typescript/DecadeLevelGroup/DecadeLevelGroup.d.ts +7 -7
- package/lib/typescript/InlineDateTimePicker/InlineDateTimePicker.d.ts +4 -4
- package/lib/typescript/MiniCalendar/MiniCalendar.d.ts +18 -18
- package/lib/typescript/Month/Month.d.ts +9 -8
- package/lib/typescript/Month/Month.d.ts.map +1 -1
- package/lib/typescript/MonthLevel/MonthLevel.d.ts +10 -10
- package/lib/typescript/MonthLevel/MonthLevel.d.ts.map +1 -1
- package/lib/typescript/MonthLevelGroup/MonthLevelGroup.d.ts +10 -10
- package/lib/typescript/MonthsList/MonthsList.d.ts +3 -2
- package/lib/typescript/MonthsList/MonthsList.d.ts.map +1 -1
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts +6 -0
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/PickerControl/PickerControl.d.ts +10 -10
- package/lib/typescript/TimeControlsList/TimeControl.d.ts +13 -0
- package/lib/typescript/TimeControlsList/TimeControl.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControlsList.d.ts.map +1 -1
- package/lib/typescript/TimeGrid/TimeGrid.d.ts +7 -7
- package/lib/typescript/TimePicker/TimePicker.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresetGroup.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts +6 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts.map +1 -1
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts +6 -6
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts.map +1 -1
- package/lib/typescript/YearLevel/YearLevel.d.ts +7 -7
- package/lib/typescript/YearLevelGroup/YearLevelGroup.d.ts +7 -7
- package/lib/typescript/YearsList/YearsList.d.ts +3 -2
- package/lib/typescript/YearsList/YearsList.d.ts.map +1 -1
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts +6 -0
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/_reference/ExampleControl.d.ts +8 -8
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts +12 -0
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts.map +1 -1
- package/lib/typescript/hooks/use-dates-state/use-dates-state.d.ts.map +1 -1
- package/lib/typescript/internal/are-cell-props-equal.d.ts +21 -0
- package/lib/typescript/internal/are-cell-props-equal.d.ts.map +1 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts +35 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts.map +1 -0
- package/lib/typescript/internal/memoize-control-props.d.ts +12 -0
- package/lib/typescript/internal/memoize-control-props.d.ts.map +1 -0
- package/lib/typescript/internal/month-days-cache.d.ts +19 -0
- package/lib/typescript/internal/month-days-cache.d.ts.map +1 -0
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts +9 -1
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts +6 -0
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts +6 -0
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts +13 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/DatesProvider/DatesProvider.tsx +27 -5
- package/src/Day/Day.tsx +51 -10
- package/src/Month/Month.tsx +357 -80
- package/src/MonthLevel/MonthLevel.tsx +35 -16
- package/src/MonthsList/MonthsList.tsx +201 -55
- package/src/MonthsList/get-month-in-tab-order/get-month-in-tab-order.ts +12 -1
- package/src/TimeControlsList/TimeControl.tsx +16 -1
- package/src/TimeControlsList/TimeControlsList.tsx +15 -3
- package/src/WeekdaysRow/WeekdaysRow.tsx +29 -5
- package/src/YearsList/YearsList.tsx +196 -55
- package/src/YearsList/get-year-in-tab-order/get-year-in-tab-order.ts +12 -1
- package/src/hooks/use-dates-state/is-in-range/is-in-range.ts +22 -0
- package/src/hooks/use-dates-state/use-dates-state.ts +27 -11
- package/src/internal/are-cell-props-equal.ts +63 -0
- package/src/internal/date-string-fast-path.ts +94 -0
- package/src/internal/memoize-control-props.ts +54 -0
- package/src/internal/month-days-cache.ts +77 -0
- package/src/utils/get-date-in-tab-order/get-date-in-tab-order.ts +17 -2
- package/src/utils/is-after-min-date/is-after-min-date.ts +16 -1
- package/src/utils/is-before-max-date/is-before-max-date.ts +16 -1
- package/src/utils/is-same-month/is-same-month.ts +18 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-before-max-date.d.ts","sourceRoot":"","sources":["../../../../src/utils/is-before-max-date/is-before-max-date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-before-max-date.d.ts","sourceRoot":"","sources":["../../../../src/utils/is-before-max-date/is-before-max-date.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,eAAe,GAAG,SAAS,GACnC,OAAO,CAUT"}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { DateStringValue } from "../../types";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Whether two dates fall in the same calendar month. Mirrors @mantine/dates
|
|
4
|
+
* `isSameMonth`.
|
|
5
|
+
*
|
|
6
|
+
* This is one of the hottest comparisons in the package — `Month` calls it once
|
|
7
|
+
* per cell (42×) to decide `outside`, and `getDateInTabOrder` calls it again per
|
|
8
|
+
* cell whenever `hideOutsideDates` is on (which `DatePicker` enables
|
|
9
|
+
* automatically for multiple columns). The dayjs spelling cost 2 instances plus
|
|
10
|
+
* 2 `format("YYYY-MM")` calls (locale lookup + regex replace) EACH TIME; for the
|
|
11
|
+
* canonical `YYYY-MM-DD` strings that are the actual inputs, comparing the
|
|
12
|
+
* `YYYY-MM` prefix is exact and allocates nothing. `Date` inputs (and any
|
|
13
|
+
* non-canonical string) keep the original dayjs path.
|
|
14
|
+
*/
|
|
3
15
|
export declare function isSameMonth(date: DateStringValue | Date, comparison: DateStringValue | Date): boolean;
|
|
4
16
|
//# sourceMappingURL=is-same-month.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-same-month.d.ts","sourceRoot":"","sources":["../../../../src/utils/is-same-month/is-same-month.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-same-month.d.ts","sourceRoot":"","sources":["../../../../src/utils/is-same-month/is-same-month.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,eAAe,GAAG,IAAI,EAC5B,UAAU,EAAE,eAAe,GAAG,IAAI,GACjC,OAAO,CAMT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knitui/dates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Date and time components for Knit UI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "The Haus <joost@the.haus>",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"source": "./src/index.ts",
|
|
28
28
|
"main": "./src/index.ts",
|
|
29
29
|
"module": "./src/index.ts",
|
|
30
|
-
"types": "./
|
|
30
|
+
"types": "./lib/typescript/index.d.ts",
|
|
31
31
|
"react-native": "./src/index.ts",
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"source": "./src/index.ts",
|
|
35
35
|
"react-native": "./src/index.ts",
|
|
36
|
-
"types": "./
|
|
36
|
+
"types": "./lib/typescript/index.d.ts",
|
|
37
37
|
"default": "./src/index.ts"
|
|
38
38
|
},
|
|
39
39
|
"./src/*.stories": {
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"sideEffects": false,
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"dayjs": "^1.11.13",
|
|
58
|
-
"@knitui/components": "0.
|
|
59
|
-
"@knitui/core": "0.
|
|
60
|
-
"@knitui/hooks": "0.
|
|
58
|
+
"@knitui/components": "0.6.1",
|
|
59
|
+
"@knitui/core": "0.6.1",
|
|
60
|
+
"@knitui/hooks": "0.6.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": "*",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// the ported `@mantine/dates` build (the upstream `tz`/dayjs-timezone layer is
|
|
19
19
|
// not part of this port).
|
|
20
20
|
// ───────────────────────────────────────────────────────────────────────────
|
|
21
|
-
import { createContext, type ReactNode } from "react";
|
|
21
|
+
import { createContext, type ReactNode, useMemo } from "react";
|
|
22
22
|
|
|
23
23
|
import type { DayOfWeek } from "../types";
|
|
24
24
|
|
|
@@ -70,11 +70,33 @@ export interface DatesProviderProps {
|
|
|
70
70
|
* Components read it through `useDatesContext`.
|
|
71
71
|
*/
|
|
72
72
|
export function DatesProvider({ settings, children }: DatesProviderProps) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
// The context value MUST keep a stable identity across renders. A context change
|
|
74
|
+
// propagates past every `React.memo` boundary below it, so an inline
|
|
75
|
+
// `value={{ ...defaults, ...settings }}` — a fresh object each render — defeats
|
|
76
|
+
// the memoized day cell (`Month`'s `MonthDayCell`) for all 42 cells of every
|
|
77
|
+
// month grid, which is exactly the boundary that keeps a web hover from
|
|
78
|
+
// re-rendering the whole calendar.
|
|
79
|
+
//
|
|
80
|
+
// `settings` itself is documented (and used throughout the stories/tests) as an
|
|
81
|
+
// INLINE literal, so memoizing on its identity would never hit. We therefore
|
|
82
|
+
// depend on the individual fields: the four primitives by value, and
|
|
83
|
+
// `weekendDays` by its joined value rather than its identity so an inlined
|
|
84
|
+
// `weekendDays={[0, 6]}` does not invalidate on every render either.
|
|
85
|
+
const { locale, firstDayOfWeek, weekendDays, labelSeparator, consistentWeeks } = settings;
|
|
86
|
+
const weekendDaysKey = weekendDays?.join(",");
|
|
87
|
+
|
|
88
|
+
const value = useMemo<DatesProviderValue>(
|
|
89
|
+
// The merge is kept verbatim (rather than rebuilt from the destructured
|
|
90
|
+
// locals) so the exact spread semantics are preserved — including a key that
|
|
91
|
+
// is present with an explicit `undefined`, which overrides its default.
|
|
92
|
+
() => ({ ...DATES_PROVIDER_DEFAULT_SETTINGS, ...settings }),
|
|
93
|
+
// `settings` is read inside but deliberately NOT a dependency — that is the
|
|
94
|
+
// whole point (see above); `weekendDays` is depended on via `weekendDaysKey`.
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
[locale, firstDayOfWeek, weekendDaysKey, labelSeparator, consistentWeeks],
|
|
77
97
|
);
|
|
98
|
+
|
|
99
|
+
return <DatesProviderContext.Provider value={value}>{children}</DatesProviderContext.Provider>;
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
DatesProvider.displayName = "@knitui/dates/DatesProvider";
|
package/src/Day/Day.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import dayjs from "dayjs";
|
|
3
|
+
import dayjs, { type Dayjs } from "dayjs";
|
|
4
4
|
|
|
5
5
|
import { Text, UnstyledButton } from "@knitui/components";
|
|
6
6
|
import { createStyledContext, type GetProps, styled, withStaticProperties } from "@knitui/core";
|
|
7
7
|
|
|
8
8
|
import { type CalendarSize, CELL_FONT, CELL_WIDTH } from "../cell-metrics";
|
|
9
|
-
import {
|
|
9
|
+
import { DatesProviderContext } from "../DatesProvider";
|
|
10
10
|
import { controlA11yProps } from "../internal/a11y";
|
|
11
11
|
import { webCursor } from "../internal/web-cursor";
|
|
12
12
|
import type { DateStringValue } from "../types";
|
|
@@ -51,6 +51,26 @@ const dayFontVariant = {
|
|
|
51
51
|
|
|
52
52
|
const DayContext = createStyledContext<{ size: DaySize }>({ size: "md" });
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Whether `day` falls on today's LOCAL calendar date, compared without
|
|
56
|
+
* allocating a single extra dayjs instance.
|
|
57
|
+
*
|
|
58
|
+
* `day.isSame(new Date(), "day")` — the obvious spelling — costs a `Date`, a
|
|
59
|
+
* dayjs instance wrapping it, and two more clones for dayjs' internal
|
|
60
|
+
* `startOf`/`endOf` bracket, i.e. ~4 allocations PER CELL (×42 cells, every
|
|
61
|
+
* render). Reading the three calendar fields off the instance we already have
|
|
62
|
+
* is exact (`year`/`month`/`date` are plain field reads, no clone) and costs
|
|
63
|
+
* only the one `Date` for "now".
|
|
64
|
+
*/
|
|
65
|
+
function isSameDayAsToday(day: Dayjs): boolean {
|
|
66
|
+
const now = new Date();
|
|
67
|
+
return (
|
|
68
|
+
day.date() === now.getDate() &&
|
|
69
|
+
day.month() === now.getMonth() &&
|
|
70
|
+
day.year() === now.getFullYear()
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
54
74
|
/**
|
|
55
75
|
* The atomic calendar cell — an `UnstyledButton`-based control composed via
|
|
56
76
|
* `styled`. Accent comes from the active theme's palette ramp via the `theme`
|
|
@@ -281,16 +301,37 @@ const DayComponent = DayFrame.styleable<DayProps>(function Day(props, ref) {
|
|
|
281
301
|
...rest
|
|
282
302
|
} = props;
|
|
283
303
|
|
|
284
|
-
|
|
304
|
+
// The RAW context, not `useDatesContext()`. The hook's four `useCallback` getter
|
|
305
|
+
// helpers are convenience for components that resolve several settings; `Day`
|
|
306
|
+
// needs exactly one value — the locale for its fallback label — and it is the
|
|
307
|
+
// grid's hottest leaf (42 instances per month × `numberOfColumns`, all
|
|
308
|
+
// re-rendering on a hover frame). Going through the hook there cost 42 extra
|
|
309
|
+
// hook subscriptions and ~168 freshly allocated closures per grid render for a
|
|
310
|
+
// single string read. `locale || ctx.locale` below is the getter's body verbatim
|
|
311
|
+
// (`getLocale = (input) => input || ctx.locale`), so a standalone `<Day>`
|
|
312
|
+
// resolves its locale exactly as before.
|
|
313
|
+
const ctx = React.useContext(DatesProviderContext);
|
|
285
314
|
const day = dayjs(date);
|
|
286
|
-
|
|
315
|
+
|
|
316
|
+
// Only the `highlightToday` border consults "is this today", so the comparison
|
|
317
|
+
// is skipped entirely when the border is off (the default).
|
|
318
|
+
const isToday = highlightToday && isSameDayAsToday(day);
|
|
287
319
|
|
|
288
320
|
// Locale-aware default label, read from `DatesProvider`. A static (display-only)
|
|
289
|
-
// day announces nothing — it is not an interactive date.
|
|
290
|
-
//
|
|
291
|
-
|
|
321
|
+
// day announces nothing — it is not an interactive date.
|
|
322
|
+
//
|
|
323
|
+
// An explicit `aria-label` WINS, so it is read up-front and the fallback is
|
|
324
|
+
// only built when there is none: `Month` always passes its own `aria-label`
|
|
325
|
+
// through `...rest` (spread last), which means computing the fallback there
|
|
326
|
+
// was pure waste — a locale clone plus `format("D MMMM YYYY")`, the most
|
|
327
|
+
// expensive token set in the file, for a string that was always discarded,
|
|
328
|
+
// ×42 cells every render. Reading the explicit label here also means NATIVE
|
|
329
|
+
// (`accessibilityLabel` below) now announces the same custom label web does,
|
|
330
|
+
// instead of the generic date it used to fall back to.
|
|
331
|
+
const explicitAriaLabel = props["aria-label"];
|
|
332
|
+
const ariaLabel = isStatic
|
|
292
333
|
? undefined
|
|
293
|
-
: day.locale(ctx.
|
|
334
|
+
: (explicitAriaLabel ?? day.locale(locale || ctx.locale).format("D MMMM YYYY"));
|
|
294
335
|
|
|
295
336
|
// Mirror Mantine's data-attribute gating: a disabled day shows none of the
|
|
296
337
|
// selection/range/weekend/outside styling, and today's border is suppressed
|
|
@@ -327,7 +368,7 @@ const DayComponent = DayFrame.styleable<DayProps>(function Day(props, ref) {
|
|
|
327
368
|
fullWidth={fullWidth}
|
|
328
369
|
disabled={disabled}
|
|
329
370
|
role={isStatic ? "presentation" : "button"}
|
|
330
|
-
aria-label={
|
|
371
|
+
aria-label={ariaLabel}
|
|
331
372
|
aria-selected={isSelected || undefined}
|
|
332
373
|
aria-disabled={disabled || undefined}
|
|
333
374
|
aria-hidden={hidden || undefined}
|
|
@@ -335,7 +376,7 @@ const DayComponent = DayFrame.styleable<DayProps>(function Day(props, ref) {
|
|
|
335
376
|
// a static display cell announces nothing interactive (`role="none"`).
|
|
336
377
|
{...controlA11yProps({
|
|
337
378
|
role: isStatic ? "none" : "button",
|
|
338
|
-
label:
|
|
379
|
+
label: ariaLabel,
|
|
339
380
|
selected: isSelected,
|
|
340
381
|
disabled,
|
|
341
382
|
})}
|