@box-kite/react 2.2.5 → 2.2.6
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/.claude/rules/box-kite-rules.md +3 -1
- package/.claude/skills/box-kite/SKILL.md +3 -1
- package/.claude/skills/box-kite/references/components.md +34 -0
- package/.cursor/rules/box-kite.mdc +3 -1
- package/AGENTS.md +3 -1
- package/BOX_AI_CONTEXT.md +95 -5
- package/BOX_KITE_AI_CONTEXT.md +95 -5
- package/box.cjs +1 -1
- package/box.mjs +7 -7
- package/catalog.cjs +1 -1
- package/catalog.mjs +521 -0
- package/client.cjs +1 -1
- package/client.mjs +94 -106
- package/components/calendar.cjs +1 -0
- package/components/calendar.d.ts +77 -0
- package/components/calendar.mjs +483 -0
- package/components/dataGrid/components/dataGridBooleanValue.d.ts +11 -0
- package/components/dataGrid/components/dataGridDateParts.d.ts +40 -0
- package/components/dataGrid/components/dataGridDateValue.d.ts +14 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +38 -11
- package/components/dataGrid/models/columnModel.d.ts +3 -1
- package/components/dataGrid/models/editModel.d.ts +3 -1
- package/components/dataGrid/models/localeText.d.ts +4 -0
- package/components/dataGrid/useDateParts.d.ts +17 -0
- package/components/dataGrid.cjs +3 -3
- package/components/dataGrid.mjs +797 -664
- package/components/dateField.cjs +1 -0
- package/components/dateField.d.ts +78 -0
- package/components/dateField.mjs +313 -0
- package/components/datePicker.cjs +1 -0
- package/components/datePicker.d.ts +120 -0
- package/components/datePicker.mjs +529 -0
- package/components/dateTime.cjs +1 -0
- package/components/dateTime.d.ts +23 -0
- package/components/dateTime.mjs +34 -0
- package/components/dialog.cjs +1 -1
- package/components/dialog.mjs +87 -75
- package/components/overlay.cjs +1 -1
- package/components/overlay.mjs +1 -1
- package/components/semantics.d.ts +29 -29
- package/components/timeZoneSelect.cjs +1 -0
- package/components/timeZoneSelect.d.ts +52 -0
- package/components/timeZoneSelect.mjs +74 -0
- package/components/toaster.cjs +1 -1
- package/components/toaster.mjs +1 -1
- package/dataGridDateParts.cjs +1 -0
- package/dataGridDateParts.mjs +223 -0
- package/dataGridList.cjs +1 -1
- package/dataGridList.mjs +328 -365
- package/dataGridListLayout.cjs +1 -0
- package/dataGridListLayout.mjs +49 -0
- package/date-environment.cjs +1 -0
- package/date-environment.mjs +29 -0
- package/date-input.cjs +1 -0
- package/date-input.mjs +346 -0
- package/date-math.cjs +1 -0
- package/date-math.mjs +317 -0
- package/date.cjs +1 -0
- package/date.d.ts +40 -0
- package/date.mjs +4 -0
- package/dates.cjs +1 -0
- package/dates.mjs +689 -0
- package/docs/components.md +6 -1
- package/package.json +118 -26
- package/react/boxComponent.d.ts +1 -1
- package/react/date/dateChange.d.ts +18 -0
- package/react/date/dateEnvironment.d.ts +34 -0
- package/react-shared.cjs +1 -1
- package/react-shared.mjs +1 -1
- package/ssg.cjs +1 -1
- package/ssg.mjs +1 -1
- package/utils/date/calendar.d.ts +44 -0
- package/utils/date/calendarModel.d.ts +46 -0
- package/utils/date/dateTime.d.ts +144 -0
- package/utils/date/fieldModel.d.ts +74 -0
- package/utils/date/format.d.ts +39 -0
- package/utils/date/iso.d.ts +40 -0
- package/utils/date/locale.d.ts +17 -0
- package/utils/date/parse.d.ts +20 -0
- package/utils/date/settings.d.ts +26 -0
- package/utils/date/value.d.ts +43 -0
- package/utils/date/zoneOptions.d.ts +19 -0
- package/utils/date/zones.d.ts +32 -0
package/client.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { l as e, u as t } from "./react-shared.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { applyThemeToElement as
|
|
7
|
-
import { jsx as
|
|
8
|
-
import { flushSync as
|
|
2
|
+
import { t as n, u as r } from "./platform.mjs";
|
|
3
|
+
import { t as i } from "./effects.mjs";
|
|
4
|
+
import a from "./box.mjs";
|
|
5
|
+
import o, { useCallback as s, useContext as c, useEffect as l, useLayoutEffect as u, useMemo as d, useRef as f, useState as p } from "react";
|
|
6
|
+
import { applyThemeToElement as m, clearStoredTheme as h, defaultThemeName as g, documentRoot as _, getDefaultEngine as v, getSystemTheme as y, pauseTransitions as b, prepareReveal as x, readStoredTheme as S, transitionTheme as C, watchSystemTheme as w, writeStoredTheme as T } from "@box-kite/core";
|
|
7
|
+
import { jsx as E, jsxs as D } from "react/jsx-runtime";
|
|
8
|
+
import { flushSync as O } from "react-dom";
|
|
9
9
|
//#region src/react/clientRuntime.ts
|
|
10
|
-
var
|
|
11
|
-
function
|
|
12
|
-
if (typeof e.createContext != "function") throw Error(
|
|
10
|
+
var k = "[box-kite] The client build was loaded into a React Server Component graph, where React has no createContext. Import '@box-kite/react' by its package name — the react-server condition resolves it to a Box that renders on the server — and import the components that hold state (Dropdown, Tooltip, DataGrid, Checkbox, Select, Form) from a 'use client' module. See https://github.com/box-kite/box-kite#react-server-components-react-19";
|
|
11
|
+
function A(e) {
|
|
12
|
+
if (typeof e.createContext != "function") throw Error(k);
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/react/componentsContext.ts
|
|
16
|
-
|
|
17
|
-
var
|
|
16
|
+
A(o);
|
|
17
|
+
var j = o.createContext(void 0);
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/react/componentsProvider.tsx
|
|
20
|
-
function
|
|
21
|
-
return /* @__PURE__ */
|
|
20
|
+
function M({ value: e, children: t }) {
|
|
21
|
+
return /* @__PURE__ */ E(j.Provider, {
|
|
22
22
|
value: e,
|
|
23
23
|
children: t
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region src/react/hooks/useVisibility.ts
|
|
28
|
-
function
|
|
29
|
-
let { node: t = null, event: n = "click", hideOnScroll:
|
|
30
|
-
return
|
|
28
|
+
function N(e) {
|
|
29
|
+
let { node: t = null, event: n = "click", hideOnScroll: i = !1, hideOnResize: a = !1, hideOnEscape: o = !0 } = e ?? {}, [s, c] = p(!1), u = f(null);
|
|
30
|
+
return l(() => {
|
|
31
31
|
function e(e) {
|
|
32
|
-
let n = t ??
|
|
33
|
-
n && !
|
|
32
|
+
let n = t ?? u.current;
|
|
33
|
+
n && !r(e, [n]) && c(!1);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function l() {
|
|
36
36
|
c(!1);
|
|
37
37
|
}
|
|
38
38
|
function d(e) {
|
|
39
39
|
e.key === "Escape" && c(!1);
|
|
40
40
|
}
|
|
41
41
|
let f = new AbortController();
|
|
42
|
-
return s && (window.addEventListener(n, e, f), o && window.addEventListener("keydown", d, f), a && window.addEventListener("resize",
|
|
42
|
+
return s && (window.addEventListener(n, e, f), o && window.addEventListener("keydown", d, f), a && window.addEventListener("resize", l, f), i && window.addEventListener("scroll", e, {
|
|
43
43
|
signal: f.signal,
|
|
44
44
|
capture: !0
|
|
45
45
|
})), () => {
|
|
@@ -51,156 +51,144 @@ function F(e) {
|
|
|
51
51
|
n,
|
|
52
52
|
o,
|
|
53
53
|
a,
|
|
54
|
-
|
|
54
|
+
i
|
|
55
55
|
]), [
|
|
56
56
|
s,
|
|
57
57
|
c,
|
|
58
|
-
|
|
58
|
+
u
|
|
59
59
|
];
|
|
60
60
|
}
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/react/useStyles.ts
|
|
63
|
-
var
|
|
64
|
-
function
|
|
65
|
-
let { classNames: r, signature: i, styleElements: a } = e(t, n,
|
|
66
|
-
return
|
|
67
|
-
|
|
63
|
+
var P = i;
|
|
64
|
+
function F(t, n) {
|
|
65
|
+
let { classNames: r, signature: i, styleElements: a } = e(t, n, c(j));
|
|
66
|
+
return P(() => {
|
|
67
|
+
v().flushSync();
|
|
68
68
|
}, [i ?? t]), {
|
|
69
69
|
classNames: r,
|
|
70
70
|
styleElements: a
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
let r = e ?
|
|
75
|
-
return
|
|
76
|
-
|
|
73
|
+
function I(e, n) {
|
|
74
|
+
let r = e ? v().addGlobalStyles(e, n) : void 0;
|
|
75
|
+
return P(() => {
|
|
76
|
+
v().flushSync();
|
|
77
77
|
}, [e, n]), t(r);
|
|
78
78
|
}
|
|
79
|
-
var
|
|
79
|
+
var L;
|
|
80
80
|
//#endregion
|
|
81
81
|
//#region src/react/theme/themeContext.ts
|
|
82
82
|
(function(e) {
|
|
83
83
|
function t() {
|
|
84
|
-
|
|
84
|
+
v().flushSync();
|
|
85
85
|
}
|
|
86
86
|
e.flushSync = t;
|
|
87
87
|
function n() {
|
|
88
|
-
|
|
88
|
+
v().clear();
|
|
89
89
|
}
|
|
90
90
|
e.clear = n;
|
|
91
91
|
function r() {
|
|
92
|
-
return
|
|
92
|
+
return v().getStyles();
|
|
93
93
|
}
|
|
94
94
|
e.getStyles = r;
|
|
95
95
|
function i() {
|
|
96
|
-
return
|
|
96
|
+
return v().getStyleTag();
|
|
97
97
|
}
|
|
98
98
|
e.getStyleTag = i;
|
|
99
99
|
function a() {
|
|
100
|
-
return
|
|
100
|
+
return v().styleElementId;
|
|
101
101
|
}
|
|
102
102
|
e.styleElementId = a;
|
|
103
103
|
function o(e) {
|
|
104
|
-
|
|
104
|
+
v().configure(e);
|
|
105
105
|
}
|
|
106
106
|
e.configure = o;
|
|
107
|
-
})(
|
|
108
|
-
var
|
|
107
|
+
})(L ||= {}), A(o);
|
|
108
|
+
var R = o.createContext({
|
|
109
109
|
theme: "",
|
|
110
110
|
setTheme: () => {}
|
|
111
111
|
});
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/react/theme/theme.tsx
|
|
114
|
-
function
|
|
115
|
-
let { theme: t, use: n = "local", storageKey: r, globalStyles:
|
|
116
|
-
value:
|
|
114
|
+
function z(e) {
|
|
115
|
+
let { theme: t, use: n = "local", storageKey: r, globalStyles: o, viewTransition: c, components: d } = e, v = d ? /* @__PURE__ */ E(M, {
|
|
116
|
+
value: d,
|
|
117
117
|
children: e.children
|
|
118
|
-
}) : e.children,
|
|
118
|
+
}) : e.children, k = I(n === "global" ? o : void 0, "html"), [A, j] = p(t ?? g), [N, P] = p(t !== void 0), F = f(null), L = f(A), z = f(null), B = f(void 0), V = s((e) => {
|
|
119
119
|
let t = () => {
|
|
120
|
-
e === null ? (r &&
|
|
120
|
+
e === null ? (r && h(r), P(!1)) : (r && T(r, e), j(e), P(!0));
|
|
121
121
|
};
|
|
122
|
-
if (
|
|
123
|
-
let e =
|
|
124
|
-
|
|
122
|
+
if (c) {
|
|
123
|
+
let e = C(() => O(t), c === "reveal" ? "reveal" : "fade");
|
|
124
|
+
B.current = e.finished, e.finished.then(() => B.current = void 0, () => B.current = void 0);
|
|
125
125
|
} else t();
|
|
126
|
-
}, [r,
|
|
127
|
-
|
|
128
|
-
let [U, W] =
|
|
129
|
-
return t !== U && (W(t), t === void 0 ?
|
|
130
|
-
if (
|
|
131
|
-
let e = r ?
|
|
132
|
-
if (t !==
|
|
133
|
-
|
|
126
|
+
}, [r, c]), H = c === "reveal";
|
|
127
|
+
l(() => H ? x() : void 0, [H]);
|
|
128
|
+
let [U, W] = p(t);
|
|
129
|
+
return t !== U && (W(t), t === void 0 ? P(!1) : (j(t), P(!0))), u(() => {
|
|
130
|
+
if (N) return;
|
|
131
|
+
let e = r ? S(r) : null, t = e ?? y();
|
|
132
|
+
if (t !== L.current && (F.current = t), j(t), e) {
|
|
133
|
+
P(!0);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
return
|
|
137
|
-
}, [
|
|
138
|
-
|
|
139
|
-
}, [
|
|
140
|
-
if (
|
|
136
|
+
return w(j);
|
|
137
|
+
}, [N, r]), i(() => {
|
|
138
|
+
A !== L.current && (z.current ??= b());
|
|
139
|
+
}, [A]), u(() => {
|
|
140
|
+
if (L.current = A, F.current !== null && F.current !== A) return;
|
|
141
141
|
F.current = null;
|
|
142
|
-
let e =
|
|
143
|
-
|
|
144
|
-
let t = n === "global" ?
|
|
145
|
-
return e?.(
|
|
146
|
-
}, [
|
|
142
|
+
let e = z.current;
|
|
143
|
+
z.current = null;
|
|
144
|
+
let t = n === "global" ? _() : null, r = t ? m(t, A) : void 0;
|
|
145
|
+
return e?.(B.current), r;
|
|
146
|
+
}, [A, n]), n === "local" ? /* @__PURE__ */ D(R.Provider, {
|
|
147
147
|
value: {
|
|
148
|
-
theme:
|
|
148
|
+
theme: A,
|
|
149
149
|
setTheme: V
|
|
150
150
|
},
|
|
151
|
-
children: [
|
|
152
|
-
className:
|
|
153
|
-
props: { "data-theme":
|
|
154
|
-
children:
|
|
151
|
+
children: [k, /* @__PURE__ */ E(a, {
|
|
152
|
+
className: A,
|
|
153
|
+
props: { "data-theme": A },
|
|
154
|
+
children: v
|
|
155
155
|
})]
|
|
156
|
-
}) : /* @__PURE__ */
|
|
156
|
+
}) : /* @__PURE__ */ D(R.Provider, {
|
|
157
157
|
value: {
|
|
158
|
-
theme:
|
|
158
|
+
theme: A,
|
|
159
159
|
setTheme: V
|
|
160
160
|
},
|
|
161
|
-
children: [
|
|
161
|
+
children: [k, v]
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
(function(e) {
|
|
165
165
|
function t() {
|
|
166
|
-
let { theme: e, setTheme: t } =
|
|
166
|
+
let { theme: e, setTheme: t } = c(R);
|
|
167
167
|
return [e, t];
|
|
168
168
|
}
|
|
169
169
|
e.useTheme = t;
|
|
170
|
-
})(
|
|
171
|
-
var
|
|
172
|
-
function
|
|
173
|
-
let t =
|
|
174
|
-
return t || (t = /* @__PURE__ */ new Map(),
|
|
170
|
+
})(z ||= {});
|
|
171
|
+
var B = z, V = /* @__PURE__ */ new WeakMap();
|
|
172
|
+
function H(e) {
|
|
173
|
+
let t = V.get(e);
|
|
174
|
+
return t || (t = /* @__PURE__ */ new Map(), V.set(e, t)), t;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
let [t] =
|
|
176
|
+
function U(e = !0) {
|
|
177
|
+
let [t] = B.useTheme(), r = d(() => {
|
|
178
178
|
if (!e) return null;
|
|
179
|
-
let t =
|
|
179
|
+
let t = n();
|
|
180
180
|
if (!t) return null;
|
|
181
|
-
let
|
|
182
|
-
return i || (i = document.createElement("div"), i.id =
|
|
181
|
+
let r = "box-kite-portal", i = t.getElementById(r);
|
|
182
|
+
return i || (i = document.createElement("div"), i.id = r, document.body.appendChild(i)), i;
|
|
183
183
|
}, [e]);
|
|
184
|
-
return
|
|
185
|
-
if (!t || !
|
|
186
|
-
let e =
|
|
187
|
-
return e.set(t,
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
-
};
|
|
191
|
-
}, [n, t]), n;
|
|
192
|
-
}
|
|
193
|
-
//#endregion
|
|
194
|
-
//#region src/react/dialog/useScrollLock.ts
|
|
195
|
-
var K = 0;
|
|
196
|
-
function q(e) {
|
|
197
|
-
let { classNames: t, styleElements: r } = L({ overflow: "hidden" }, !1), i = t.slice(1).join(" ");
|
|
198
|
-
return a(() => {
|
|
199
|
-
let t = n();
|
|
200
|
-
if (!(!e || !t || !i)) return K += 1, t.classList.add(i), () => {
|
|
201
|
-
--K, K === 0 && t.classList.remove(i);
|
|
184
|
+
return u(() => {
|
|
185
|
+
if (!t || !r) return;
|
|
186
|
+
let e = H(r), n = e.get(t) ?? 0;
|
|
187
|
+
return e.set(t, n + 1), n === 0 && r.classList.add(t), () => {
|
|
188
|
+
let n = (e.get(t) ?? 1) - 1;
|
|
189
|
+
n <= 0 ? (e.delete(t), r.classList.remove(t)) : e.set(t, n);
|
|
202
190
|
};
|
|
203
|
-
}, [
|
|
191
|
+
}, [r, t]), r;
|
|
204
192
|
}
|
|
205
193
|
//#endregion
|
|
206
|
-
export {
|
|
194
|
+
export { N as a, F as i, B as n, M as o, L as r, U as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs"),r=require("../identity.cjs"),i=require("../dates.cjs"),a=require("../date-math.cjs"),o=require("./svg.cjs"),s=require("../date-environment.cjs"),c=require("./visuallyHidden.cjs");let l=require("react"),u=require("react/jsx-runtime");function d(e){let t=i.f(e);return t&&t.kind===`date`?t.fields:null}function f(e){return i.w({...e,...i.V})}function ee(e,t,n){let r={year:e,month:t,day:1},a=i.U(r,-i.Q(i.G(r)-n,7));return Array.from({length:6},(e,r)=>{let o=Array.from({length:7},(e,n)=>{let o=i.U(a,r*7+n);return{date:f(o),day:o.day,outside:o.month!==t}}),s=i.U(a,r*7+i.Q(4-n,7));return{week:i.Z(s).week,days:o}})}function te(e,t,n,r){let a=r.rtl?`ArrowLeft`:`ArrowRight`,o=r.rtl?`ArrowRight`:`ArrowLeft`;switch(t){case a:return i.U(e,1);case o:return i.U(e,-1);case`ArrowDown`:return i.U(e,7);case`ArrowUp`:return i.U(e,-7);case`Home`:return i.U(e,-i.Q(i.G(e)-r.firstDay,7));case`End`:return i.U(e,6-i.Q(i.G(e)-r.firstDay,7));case`PageUp`:return i.W(e,n?-12:-1);case`PageDown`:return i.W(e,n?12:1);default:return null}}function ne(e,t){return t.min!=null&&i.q(e)<i.q(t.min)||t.max!=null&&i.q(e)>i.q(t.max)}function p(e,t){return t.min&&i.q(e)<i.q(t.min)?t.min:t.max&&i.q(e)>i.q(t.max)?t.max:e}function m(e,t){return i.q(e)<=i.q(t)?[e,t]:[t,e]}function re(e,t,n){if(!t||!n)return t&&i.q(e)===i.q(t)?`start`:null;let[r,a]=m(t,n),o=i.q(e);return o===i.q(r)?`start`:o===i.q(a)?`end`:o>i.q(r)&&o<i.q(a)?`middle`:null}function ie(e,t,n){let[r,a]=m(e,t);for(let e=i.q(r);e<=i.q(a);e++)if(n(f(i.U({year:1970,month:1,day:1},e))))return!0;return!1}var ae=`data-date`,h=12;function g(e,t){return e!==null&&t!==null&&i.q(e)===i.q(t)}function _(o){let{mode:_=`single`,value:y,defaultValue:S=null,onValueChange:se,min:ce,max:C,isDateUnavailable:w,locale:le,zone:ue,firstDayOfWeek:de,months:T=1,weekNumbers:E=!1,showOutsideDays:fe=!0,focusedDate:pe,defaultFocusedDate:me,onFocusedDateChange:he,disabled:D=!1,readOnly:ge=!1,autoFocus:_e=!1,label:ve,previousLabel:ye=`Previous`,nextLabel:be=`Next`,props:xe,...Se}=o,O=s.n({locale:le,zone:ue}),{locale:k}=O,A=d(a.N(O.zone)),j=de??i.S(k).firstDay,M=e=>oe(k).format(e),N=_===`range`,P=(0,l.useMemo)(()=>({min:d(ce),max:d(C)}),[ce,C]),[F,Ce]=n.i({value:y,defaultValue:S,onChange:(e,t)=>{se?.(e,N?t:{...t,...a.x(e,O.zone)})}}),I=N?null:d(F),L=N&&F?F:null,[R,z]=(0,l.useState)(null),[we,B]=(0,l.useState)(null),Te=f(p(d(me)??I??d(L?.start)??A,P)),[V,H]=n.i({value:pe,defaultValue:Te,onChange:he}),U=d(V)??A,[W,G]=(0,l.useState)(`day`),[K,q]=(0,l.useState)(()=>v(U)),J=K;(v(U)<K||v(U)>K+T-1)&&(J=v(U)<K?v(U):v(U)-T+1,q(J));let Ee=(0,l.useRef)(null),Y=(0,l.useRef)(_e),De=r.t(`calendar`);(0,l.useEffect)(()=>{Y.current&&(Y.current=!1,Ee.current?.querySelector(`[${ae}="${V}"]`)?.focus())});let Oe=e=>ne(e,P),ke=e=>w?.(f(e))??!1,X=(e,t,n)=>{Y.current=n,H(f(p(e,P)),{reason:t})},Ae=(e,t)=>{if(D||ge||Oe(e)||ke(e))return;if(X(e,`keyboard`,!1),!N){Ce(f(e),{reason:`select`,event:t});return}if(!R){z(e),B(e);return}let[n,r]=m(R,e);z(null),B(null),!(w&&ie(n,r,w))&&Ce({start:f(n),end:f(r)},{reason:`select`,event:t})},je=n.a(t=>{if(D)return;if(t.key===`Enter`||t.key===` `){t.preventDefault(),Ae(U,t);return}if(t.key===`Escape`&&R){t.preventDefault(),t.stopPropagation(),z(null),B(null);return}let n=te(U,t.key,t.shiftKey,{rtl:e.d(t.currentTarget),firstDay:j});n&&(t.preventDefault(),X(n,`keyboard`,!0),R&&B(p(n,P)))}),Me=e=>{W===`day`?(q(J+e*T),X(i.W(U,e*T),`navigate`,!1)):X(i.W(U,e*(W===`month`?12:144)),`navigate`,!1)},Z=Array.from({length:T},(e,t)=>({year:Math.floor((J+t)/12),month:(J+t)%12+1,day:1})),Q=`${De}-title`,Ne=W===`day`&&T>1,Pe=W===`day`?Z.map(e=>i.t(f(e),{locale:k,month:`long`,year:`numeric`})).join(` – `):W===`month`?M(U.year):`${M(b(U.year))} – ${M(b(U.year)+h-1)}`,Fe=i.C(k,`short`),Ie=Fe.some(e=>e.length>4)?i.C(k,`narrow`):Fe,Le=i.C(k,`long`),Re=Array.from({length:7},(e,t)=>(j+t)%7),ze=R?we??R:null,Be=R??d(L?.start),$=R?ze:d(L?.end),Ve=e=>{let n=d(e.date),r=Oe(n),a=ke(n),o=N?re(n,Be,$):null,s=N?o!==null:g(n,I),c=g(n,A),l=g(n,U);return e.outside&&(!fe||T>1)?(0,u.jsx)(t.default,{tag:`td`,component:`calendar.cell`,display:`table-cell`,props:{role:`gridcell`}},e.date):(0,u.jsx)(t.default,{tag:`td`,component:`calendar.cell`,display:`table-cell`,p:0,py:.5,variant:{rangeStart:o===`start`&&$!==null&&!g(Be,$),rangeEnd:o===`end`,rangeMiddle:o===`middle`},props:{role:`gridcell`,"aria-selected":s||void 0,"aria-disabled":r||D||void 0,"aria-current":c?`date`:void 0},children:(0,u.jsx)(t.default,{component:`calendar.day`,display:`flex`,ai:`center`,jc:`center`,width:9,height:9,mx:`auto`,borderRadius:999,fontSize:14,css:{fontVariantNumeric:`tabular-nums`},variant:{today:c,selected:s&&o!==`middle`,outside:e.outside,blocked:r||D,unavailable:a},props:{[ae]:e.date,tabIndex:l&&!r&&!D?0:-1,"aria-label":i.t(e.date,{locale:k,dateStyle:`full`}),onClick:e=>Ae(n,e),onPointerEnter:()=>R&&B(n)},children:M(e.day)})},e.date)},He=(t,n,r,i,a,o)=>{let s=e.d(t.currentTarget),c={ArrowUp:-r,ArrowDown:r,[s?`ArrowRight`:`ArrowLeft`]:-1,[s?`ArrowLeft`:`ArrowRight`]:1};t.key===`Enter`||t.key===` `?(t.preventDefault(),i(o)):t.key in c&&(t.preventDefault(),a(Math.max(0,Math.min(n-1,o+c[t.key])),t.currentTarget.parentElement))},Ue=()=>{let e=i.x(k,`short`),n=b(U.year),r=W===`month`?e.map((e,t)=>({label:e,active:t+1===U.month,current:A.year===U.year&&A.month===t+1})):Array.from({length:h},(e,t)=>({label:M(n+t),active:n+t===U.year,current:A.year===n+t})),a=e=>W===`month`?{...U,month:e+1,day:1}:{...U,year:n+e,day:1},o=e=>{let t=a(e);Y.current=!0,H(f(p({...t,day:Math.min(U.day,28)},P)),{reason:`navigate`}),G(W===`year`?`month`:`day`)},s=(e,t)=>{let n=a(e);H(f({...n,day:Math.min(U.day,28)}),{reason:`keyboard`}),t?.querySelector(`[data-zoom="${e}"]`)?.focus()};return(0,u.jsx)(t.default,{display:`grid`,gridTemplateColumns:3,gap:1,props:{role:`group`,"aria-labelledby":Q},children:r.map((e,n)=>(0,u.jsx)(t.default,{tag:`button`,component:`calendar.zoomItem`,variant:{selected:e.active,today:e.current},py:2,borderRadius:2,disabled:D,props:{type:`button`,"data-zoom":n,tabIndex:e.active?0:-1,"aria-pressed":e.active,onClick:()=>o(n),onKeyDown:e=>He(e,r.length,3,o,s,n)},children:e.label},e.label))})},We=(e,n)=>{let r=ee(e.year,e.month,j),a=i.t(f(e),{locale:k,month:`long`,year:`numeric`});return(0,u.jsxs)(t.default,{tag:`table`,css:{borderCollapse:`collapse`,tableLayout:`fixed`},props:{role:`grid`,"aria-label":T>1?a:void 0,"aria-labelledby":T>1?void 0:Q,"aria-readonly":ge||void 0,onKeyDown:je},children:[(0,u.jsx)(t.default,{tag:`thead`,display:`table-header-group`,children:(0,u.jsxs)(t.default,{tag:`tr`,display:`table-row`,children:[E&&(0,u.jsx)(t.default,{tag:`th`,display:`table-cell`,component:`calendar.weekday`,props:{"aria-hidden":!0}}),Re.map(e=>(0,u.jsx)(t.default,{tag:`th`,display:`table-cell`,component:`calendar.weekday`,pb:1,fontSize:12,props:{scope:`col`,abbr:Le[e]},children:Ie[e]},e))]})}),(0,u.jsx)(t.default,{tag:`tbody`,display:`table-row-group`,children:r.map(e=>(0,u.jsxs)(t.default,{tag:`tr`,display:`table-row`,children:[E&&(0,u.jsx)(t.default,{tag:`td`,display:`table-cell`,component:`calendar.weekNumber`,fontSize:11,textAlign:`center`,props:{role:`rowheader`},children:M(e.week)}),e.days.map(Ve)]},e.days[0].date))})]},n)};return(0,u.jsxs)(t.default,{ref:Ee,component:`calendar`,display:`inline-block`,...Se,variant:[Se.variant,{disabled:D}],props:{role:ve?`group`:void 0,"aria-label":ve,...xe,onPointerLeave:()=>R&&B(R)},children:[(0,u.jsxs)(t.default,{position:`relative`,minHeight:8,mb:2,children:[(0,u.jsx)(t.default,{tag:`button`,component:`calendar.nav`,position:`absolute`,top:0,insetStart:0,display:`inline-flex`,ai:`center`,jc:`center`,width:8,height:8,borderRadius:2,disabled:D,props:{type:`button`,"aria-label":ye,onClick:()=>Me(-1)},children:(0,u.jsx)(x,{direction:-1})}),Ne?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(t.default,{display:`flex`,gap:4,children:Z.map(e=>(0,u.jsx)(t.default,{flex1:!0,textAlign:`center`,py:1.5,fontSize:14,fontWeight:600,props:{"aria-hidden":!0},children:i.t(f(e),{locale:k,month:`long`,year:`numeric`})},f(e)))}),(0,u.jsx)(c.default,{id:Q,props:{"aria-live":`polite`},children:Pe})]}):(0,u.jsx)(t.default,{display:`flex`,jc:`center`,px:9,children:(0,u.jsx)(t.default,{tag:`button`,component:`calendar.title`,py:1.5,px:3,borderRadius:2,fontSize:14,id:Q,disabled:D||W===`year`,props:{type:`button`,"aria-live":`polite`,onClick:()=>G(W===`day`?`month`:`year`)},children:Pe})}),(0,u.jsx)(t.default,{tag:`button`,component:`calendar.nav`,position:`absolute`,top:0,insetEnd:0,display:`inline-flex`,ai:`center`,jc:`center`,width:8,height:8,borderRadius:2,disabled:D,props:{type:`button`,"aria-label":be,onClick:()=>Me(1)},children:(0,u.jsx)(x,{direction:1})})]}),W===`day`?(0,u.jsx)(t.default,{display:`flex`,gap:4,ai:`start`,children:Z.map(We)}):Ue()]})}function v(e){return e.year*12+e.month-1}var y=new Map;function oe(e){let t=y.get(e);return t||(t=new Intl.NumberFormat(e,{useGrouping:!1}),y.set(e,t)),t}function b(e){return e-(e%h+h)%h}function x({direction:e}){return(0,u.jsx)(o.Svg,{viewBox:`0 0 16 16`,width:`1rem`,height:`1rem`,rtl:{flip:`xAxis`},props:{fill:`none`},children:(0,u.jsx)(o.Path,{d:e===1?`M6 3l5 5-5 5`:`M10 3L5 8l5 5`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`})})}var S=_;S.displayName=`Calendar`,exports.default=S;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BoxProps } from '../box';
|
|
2
|
+
import { ChangeHandler } from '../react/a11y/useControllableState';
|
|
3
|
+
import { DateChangeDetails, DateChangeReason } from '../react/date/dateChange';
|
|
4
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
5
|
+
import { ZoneInput } from '../utils/date/zones';
|
|
6
|
+
/** A span of days, both ends included, `start` never after `end`. */
|
|
7
|
+
export interface DateRange {
|
|
8
|
+
start: string;
|
|
9
|
+
end: string;
|
|
10
|
+
}
|
|
11
|
+
/** Which grid is on show: days, the months of a year, or a run of years. */
|
|
12
|
+
export type CalendarView = 'day' | 'month' | 'year';
|
|
13
|
+
type CalendarBoxProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'div', TKey>, 'onChange' | 'disabled' | 'defaultValue' | 'readOnly'>;
|
|
14
|
+
interface BaseProps<TKey extends keyof ComponentsAndVariants> extends CalendarBoxProps<TKey> {
|
|
15
|
+
/** The earliest day that can be chosen, `YYYY-MM-DD`. The arrows stop there too. */
|
|
16
|
+
min?: string | null;
|
|
17
|
+
/** The latest day that can be chosen. */
|
|
18
|
+
max?: string | null;
|
|
19
|
+
/** Days that can be reached but not chosen — a weekend, a holiday. A range is refused across one. */
|
|
20
|
+
isDateUnavailable?: (date: string) => boolean;
|
|
21
|
+
/** The language of the month and weekday names, and whose week it is. Default the reader's. */
|
|
22
|
+
locale?: string;
|
|
23
|
+
/** Whose "today" is marked. Default the reader's zone. */
|
|
24
|
+
zone?: ZoneInput;
|
|
25
|
+
/** The day the week starts on, 0 for Sunday. Default the locale's. */
|
|
26
|
+
firstDayOfWeek?: number;
|
|
27
|
+
/** How many months side by side. Default 1. */
|
|
28
|
+
months?: 1 | 2 | 3;
|
|
29
|
+
/** A leading column of ISO week numbers. */
|
|
30
|
+
weekNumbers?: boolean;
|
|
31
|
+
/** Whether the days that complete the first and last weeks are drawn. Default `true`. */
|
|
32
|
+
showOutsideDays?: boolean;
|
|
33
|
+
/** The day the keyboard is on, which decides the month on show. Controlled. */
|
|
34
|
+
focusedDate?: string;
|
|
35
|
+
/** Where the keyboard starts when the calendar owns it. Default the value, or today. */
|
|
36
|
+
defaultFocusedDate?: string;
|
|
37
|
+
/** Fires when the keyboard or the paging buttons move to another day. */
|
|
38
|
+
onFocusedDateChange?: ChangeHandler<string, 'keyboard' | 'navigate'>;
|
|
39
|
+
/** Nothing can be chosen and nothing is focusable. */
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
/** Can be read and navigated, but not chosen in. */
|
|
42
|
+
readOnly?: boolean;
|
|
43
|
+
/** Focus the day the keyboard is on, on mount — what a picker's panel wants. */
|
|
44
|
+
autoFocus?: boolean;
|
|
45
|
+
/** The calendar's accessible name, which a screen reader hears before the month. */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** What the paging buttons are called. Default `'Previous'` and `'Next'`. */
|
|
48
|
+
/** The previous-page button's name. Default `'Previous'`. */
|
|
49
|
+
previousLabel?: string;
|
|
50
|
+
/** The next-page button's name. Default `'Next'`. */
|
|
51
|
+
nextLabel?: string;
|
|
52
|
+
}
|
|
53
|
+
/** One day at a time, which is the default: the value is a `YYYY-MM-DD` string or `null`. */
|
|
54
|
+
interface SingleProps {
|
|
55
|
+
/** One day (default), or `'range'` for a start and an end. */
|
|
56
|
+
mode?: 'single';
|
|
57
|
+
/** The chosen day, `YYYY-MM-DD`, or `null`. Controlled. */
|
|
58
|
+
value?: string | null;
|
|
59
|
+
/** The day it starts with when the calendar owns its value. */
|
|
60
|
+
defaultValue?: string | null;
|
|
61
|
+
/** Fires with the day and its readings. */
|
|
62
|
+
onValueChange?: ChangeHandler<string | null, DateChangeReason, DateChangeDetails>;
|
|
63
|
+
}
|
|
64
|
+
/** A start and an end: the first press anchors the range and the second ends it, whichever way round. */
|
|
65
|
+
interface RangeProps {
|
|
66
|
+
/** `'range'` is what turns the value into `{ start, end }`. */
|
|
67
|
+
mode: 'range';
|
|
68
|
+
/** The chosen span, or `null`. Controlled. */
|
|
69
|
+
value?: DateRange | null;
|
|
70
|
+
/** The span it starts with when the calendar owns its value. */
|
|
71
|
+
defaultValue?: DateRange | null;
|
|
72
|
+
/** Fires once both ends are chosen, start first whichever was picked first. */
|
|
73
|
+
onValueChange?: ChangeHandler<DateRange | null, DateChangeReason>;
|
|
74
|
+
}
|
|
75
|
+
export type CalendarProps<TKey extends keyof ComponentsAndVariants = 'calendar'> = BaseProps<TKey> & (SingleProps | RangeProps);
|
|
76
|
+
declare const _default: <TKey extends keyof ComponentsAndVariants = "calendar">(props: CalendarProps<TKey>) => React.ReactNode;
|
|
77
|
+
export default _default;
|