@box-kite/react 2.2.5 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.claude/rules/box-kite-rules.md +5 -1
  2. package/.claude/skills/box-kite/SKILL.md +5 -1
  3. package/.claude/skills/box-kite/references/components.md +34 -0
  4. package/.claude/skills/box-kite/references/extending.md +10 -0
  5. package/.claude/skills/box-kite/references/styling.md +3 -2
  6. package/.cursor/rules/box-kite.mdc +5 -1
  7. package/AGENTS.md +5 -1
  8. package/BOX_AI_CONTEXT.md +147 -7
  9. package/BOX_KITE_AI_CONTEXT.md +147 -7
  10. package/box.cjs +1 -1
  11. package/box.d.ts +5 -0
  12. package/box.mjs +7 -7
  13. package/catalog.cjs +1 -1
  14. package/catalog.mjs +521 -0
  15. package/client.cjs +1 -1
  16. package/client.mjs +136 -117
  17. package/components/calendar.cjs +1 -0
  18. package/components/calendar.d.ts +77 -0
  19. package/components/calendar.mjs +483 -0
  20. package/components/dataGrid/components/dataGridBooleanValue.d.ts +11 -0
  21. package/components/dataGrid/components/dataGridDateParts.d.ts +40 -0
  22. package/components/dataGrid/components/dataGridDateValue.d.ts +14 -0
  23. package/components/dataGrid/contracts/dataGridContract.d.ts +38 -11
  24. package/components/dataGrid/models/columnModel.d.ts +3 -1
  25. package/components/dataGrid/models/editModel.d.ts +3 -1
  26. package/components/dataGrid/models/headerCellModel.d.ts +1 -0
  27. package/components/dataGrid/models/localeText.d.ts +4 -0
  28. package/components/dataGrid/useDateParts.d.ts +17 -0
  29. package/components/dataGrid.cjs +3 -3
  30. package/components/dataGrid.mjs +824 -690
  31. package/components/dateField.cjs +1 -0
  32. package/components/dateField.d.ts +78 -0
  33. package/components/dateField.mjs +313 -0
  34. package/components/datePicker.cjs +1 -0
  35. package/components/datePicker.d.ts +120 -0
  36. package/components/datePicker.mjs +529 -0
  37. package/components/dateTime.cjs +1 -0
  38. package/components/dateTime.d.ts +23 -0
  39. package/components/dateTime.mjs +34 -0
  40. package/components/dialog.cjs +1 -1
  41. package/components/dialog.mjs +87 -75
  42. package/components/overlay.cjs +1 -1
  43. package/components/overlay.mjs +1 -1
  44. package/components/semantics.d.ts +29 -29
  45. package/components/timeZoneSelect.cjs +1 -0
  46. package/components/timeZoneSelect.d.ts +52 -0
  47. package/components/timeZoneSelect.mjs +74 -0
  48. package/components/toaster.cjs +1 -1
  49. package/components/toaster.mjs +1 -1
  50. package/create/src/index.d.ts +1 -0
  51. package/create/src/options.d.ts +27 -0
  52. package/create/src/options.test.d.ts +1 -0
  53. package/create/src/packageManager.d.ts +5 -0
  54. package/create/src/project.d.ts +25 -0
  55. package/create/src/project.test.d.ts +1 -0
  56. package/create/templates/ts/designs/azure.d.ts +5 -0
  57. package/create/templates/ts/designs/ember.d.ts +5 -0
  58. package/create/templates/ts/designs/mono.d.ts +5 -0
  59. package/create/templates/ts/src/App.d.ts +2 -0
  60. package/create/templates/ts/src/design.d.ts +5 -0
  61. package/create/templates/ts/src/main.d.ts +0 -0
  62. package/dataGridDateParts.cjs +1 -0
  63. package/dataGridDateParts.mjs +223 -0
  64. package/dataGridList.cjs +1 -1
  65. package/dataGridList.mjs +335 -372
  66. package/dataGridListLayout.cjs +1 -0
  67. package/dataGridListLayout.mjs +49 -0
  68. package/date-environment.cjs +1 -0
  69. package/date-environment.mjs +29 -0
  70. package/date-input.cjs +1 -0
  71. package/date-input.mjs +346 -0
  72. package/date-math.cjs +1 -0
  73. package/date-math.mjs +317 -0
  74. package/date.cjs +1 -0
  75. package/date.d.ts +40 -0
  76. package/date.mjs +4 -0
  77. package/dates.cjs +1 -0
  78. package/dates.mjs +689 -0
  79. package/docs/components.md +6 -1
  80. package/docs/props.md +19 -19
  81. package/package.json +124 -27
  82. package/react/boxComponent.d.ts +1 -1
  83. package/react/date/dateChange.d.ts +18 -0
  84. package/react/date/dateEnvironment.d.ts +34 -0
  85. package/react/theme/theme.d.ts +9 -0
  86. package/react/theme/themeContext.d.ts +2 -0
  87. package/react-shared.cjs +1 -1
  88. package/react-shared.mjs +1 -1
  89. package/rsc.cjs +1 -1
  90. package/rsc.d.ts +3 -0
  91. package/rsc.mjs +1 -1
  92. package/ssg.cjs +1 -1
  93. package/ssg.mjs +1 -1
  94. package/utils/date/calendar.d.ts +44 -0
  95. package/utils/date/calendarModel.d.ts +46 -0
  96. package/utils/date/dateTime.d.ts +144 -0
  97. package/utils/date/fieldModel.d.ts +74 -0
  98. package/utils/date/format.d.ts +39 -0
  99. package/utils/date/iso.d.ts +40 -0
  100. package/utils/date/locale.d.ts +17 -0
  101. package/utils/date/parse.d.ts +20 -0
  102. package/utils/date/settings.d.ts +26 -0
  103. package/utils/date/value.d.ts +43 -0
  104. package/utils/date/zoneOptions.d.ts +19 -0
  105. 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 { n, t as r, u as i } from "./platform.mjs";
3
- import { n as a, t as o } from "./effects.mjs";
4
- import s from "./box.mjs";
5
- import c, { useCallback as l, useContext as u, useEffect as d, useLayoutEffect as f, useMemo as p, useRef as m, useState as h } from "react";
6
- import { applyThemeToElement as g, clearStoredTheme as _, defaultThemeName as v, documentRoot as y, getDefaultEngine as b, getSystemTheme as x, pauseTransitions as S, prepareReveal as C, readStoredTheme as w, transitionTheme as T, watchSystemTheme as E, writeStoredTheme as D } from "@box-kite/core";
7
- import { jsx as O, jsxs as k } from "react/jsx-runtime";
8
- import { flushSync as A } from "react-dom";
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 { applyDesignToElement as m, applyThemeToElement as h, clearStoredTheme as g, defaultThemeName as _, documentRoot as v, getDefaultEngine as y, getSystemTheme as b, pauseTransitions as x, prepareReveal as S, readStoredTheme as C, transitionTheme as w, watchSystemTheme as T, writeStoredTheme as E } from "@box-kite/core";
7
+ import { jsx as D, jsxs as O } from "react/jsx-runtime";
8
+ import { flushSync as ee } from "react-dom";
9
9
  //#region src/react/clientRuntime.ts
10
- var j = "[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 M(e) {
12
- if (typeof e.createContext != "function") throw Error(j);
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
- M(c);
17
- var N = c.createContext(void 0);
16
+ A(o);
17
+ var j = o.createContext(void 0);
18
18
  //#endregion
19
19
  //#region src/react/componentsProvider.tsx
20
- function P({ value: e, children: t }) {
21
- return /* @__PURE__ */ O(N.Provider, {
20
+ function M({ value: e, children: t }) {
21
+ return /* @__PURE__ */ D(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 F(e) {
29
- let { node: t = null, event: n = "click", hideOnScroll: r = !1, hideOnResize: a = !1, hideOnEscape: o = !0 } = e ?? {}, [s, c] = h(!1), l = m(null);
30
- return d(() => {
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 ?? l.current;
33
- n && !i(e, [n]) && c(!1);
32
+ let n = t ?? u.current;
33
+ n && !r(e, [n]) && c(!1);
34
34
  }
35
- function u() {
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", u, f), r && window.addEventListener("scroll", e, {
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,175 @@ function F(e) {
51
51
  n,
52
52
  o,
53
53
  a,
54
- r
54
+ i
55
55
  ]), [
56
56
  s,
57
57
  c,
58
- l
58
+ u
59
59
  ];
60
60
  }
61
61
  //#endregion
62
62
  //#region src/react/useStyles.ts
63
- var I = o;
64
- function L(t, n) {
65
- let { classNames: r, signature: i, styleElements: a } = e(t, n, u(N));
66
- return I(() => {
67
- b().flushSync();
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
+ y().flushSync();
68
68
  }, [i ?? t]), {
69
69
  classNames: r,
70
70
  styleElements: a
71
71
  };
72
72
  }
73
- function R(e, n) {
74
- let r = e ? b().addGlobalStyles(e, n) : void 0;
75
- return I(() => {
76
- b().flushSync();
73
+ function I(e, n) {
74
+ let r = e ? y().addGlobalStyles(e, n) : void 0;
75
+ return P(() => {
76
+ y().flushSync();
77
77
  }, [e, n]), t(r);
78
78
  }
79
- var z;
79
+ var L;
80
80
  //#endregion
81
81
  //#region src/react/theme/themeContext.ts
82
82
  (function(e) {
83
83
  function t() {
84
- b().flushSync();
84
+ y().flushSync();
85
85
  }
86
86
  e.flushSync = t;
87
87
  function n() {
88
- b().clear();
88
+ y().clear();
89
89
  }
90
90
  e.clear = n;
91
91
  function r() {
92
- return b().getStyles();
92
+ return y().getStyles();
93
93
  }
94
94
  e.getStyles = r;
95
95
  function i() {
96
- return b().getStyleTag();
96
+ return y().getStyleTag();
97
97
  }
98
98
  e.getStyleTag = i;
99
99
  function a() {
100
- return b().styleElementId;
100
+ return y().styleElementId;
101
101
  }
102
102
  e.styleElementId = a;
103
103
  function o(e) {
104
- b().configure(e);
104
+ y().configure(e);
105
105
  }
106
106
  e.configure = o;
107
- })(z ||= {}), M(c);
108
- var B = c.createContext({
107
+ })(L ||= {}), A(o);
108
+ var R = o.createContext({
109
109
  theme: "",
110
- setTheme: () => {}
110
+ setTheme: () => {},
111
+ setDesign: () => {}
111
112
  });
112
113
  //#endregion
113
114
  //#region src/react/theme/theme.tsx
114
- function V(e) {
115
- let { theme: t, use: n = "local", storageKey: r, globalStyles: i, viewTransition: a, components: c } = e, u = c ? /* @__PURE__ */ O(P, {
116
- value: c,
115
+ function z(e) {
116
+ let { theme: t, use: n = "local", storageKey: r, globalStyles: o, viewTransition: c, components: y, design: k, designStorageKey: A } = e, j = y ? /* @__PURE__ */ D(M, {
117
+ value: y,
117
118
  children: e.children
118
- }) : e.children, p = R(n === "global" ? i : void 0, "html"), [b, j] = h(t ?? v), [M, N] = h(t !== void 0), F = m(null), I = m(b), L = m(null), z = m(void 0), V = l((e) => {
119
- let t = () => {
120
- e === null ? (r && _(r), N(!1)) : (r && D(r, e), j(e), N(!0));
121
- };
122
- if (a) {
123
- let e = T(() => A(t), a === "reveal" ? "reveal" : "fade");
124
- z.current = e.finished, e.finished.then(() => z.current = void 0, () => z.current = void 0);
125
- } else t();
126
- }, [r, a]), H = a === "reveal";
127
- d(() => H ? C() : void 0, [H]);
128
- let [U, W] = h(t);
129
- return t !== U && (W(t), t === void 0 ? N(!1) : (j(t), N(!0))), f(() => {
130
- if (M) return;
131
- let e = r ? w(r) : null, t = e ?? x();
132
- if (t !== I.current && (F.current = t), j(t), e) {
133
- N(!0);
119
+ }) : e.children, N = I(n === "global" ? o : void 0, "html"), [P, F] = p(t ?? _), [L, z] = p(t !== void 0), B = f(null), V = f(P), H = f(null), U = f(null), W = f(void 0), G = s((e) => {
120
+ if (!c) return e();
121
+ let t = w(() => ee(e), c === "reveal" ? "reveal" : "fade");
122
+ W.current = t.finished, t.finished.then(() => W.current = void 0, () => W.current = void 0);
123
+ }, [c]), K = s((e) => G(() => {
124
+ e === null ? (r && g(r), z(!1)) : (r && E(r, e), F(e), z(!0));
125
+ }), [r, G]), [q, J] = p(k), [Y, te] = p(k);
126
+ k !== Y && (te(k), J(k));
127
+ let X = s((e) => G(() => {
128
+ U.current ??= x(), A && (e === null ? g : E)(A, e), J(e ?? k);
129
+ }), [
130
+ k,
131
+ A,
132
+ G
133
+ ]), Z = f(null);
134
+ u(() => {
135
+ let e = A ? C(A) : null;
136
+ e && (Z.current = e, J(e));
137
+ }, [A]), u(() => {
138
+ if (Z.current !== null && Z.current !== q) return;
139
+ Z.current = null;
140
+ let e = n === "global" && q ? v() : null, t = e ? m(e, q) : void 0;
141
+ return U.current?.(W.current), U.current = null, t;
142
+ }, [q, n]);
143
+ let Q = c === "reveal";
144
+ l(() => Q ? S() : void 0, [Q]);
145
+ let [ne, re] = p(t);
146
+ t !== ne && (re(t), t === void 0 ? z(!1) : (F(t), z(!0))), u(() => {
147
+ if (L) return;
148
+ let e = r ? C(r) : null, t = e ?? b();
149
+ if (t !== V.current && (B.current = t), F(t), e) {
150
+ z(!0);
134
151
  return;
135
152
  }
136
- return E(j);
137
- }, [M, r]), o(() => {
138
- b !== I.current && (L.current ??= S());
139
- }, [b]), f(() => {
140
- if (I.current = b, F.current !== null && F.current !== b) return;
141
- F.current = null;
142
- let e = L.current;
143
- L.current = null;
144
- let t = n === "global" ? y() : null, r = t ? g(t, b) : void 0;
145
- return e?.(z.current), r;
146
- }, [b, n]), n === "local" ? /* @__PURE__ */ k(B.Provider, {
147
- value: {
148
- theme: b,
149
- setTheme: V
150
- },
151
- children: [p, /* @__PURE__ */ O(s, {
152
- className: b,
153
- props: { "data-theme": b },
154
- children: u
153
+ return T(F);
154
+ }, [L, r]), i(() => {
155
+ P !== V.current && (H.current ??= x());
156
+ }, [P]), u(() => {
157
+ if (V.current = P, B.current !== null && B.current !== P) return;
158
+ B.current = null;
159
+ let e = H.current;
160
+ H.current = null;
161
+ let t = n === "global" ? v() : null, r = t ? h(t, P) : void 0;
162
+ return e?.(W.current), r;
163
+ }, [P, n]);
164
+ let $ = d(() => ({
165
+ theme: P,
166
+ setTheme: K,
167
+ design: q,
168
+ setDesign: X
169
+ }), [
170
+ P,
171
+ K,
172
+ q,
173
+ X
174
+ ]);
175
+ return n === "local" ? /* @__PURE__ */ O(R.Provider, {
176
+ value: $,
177
+ children: [N, /* @__PURE__ */ D(a, {
178
+ className: P,
179
+ props: {
180
+ "data-theme": P,
181
+ "data-design": q
182
+ },
183
+ children: j
155
184
  })]
156
- }) : /* @__PURE__ */ k(B.Provider, {
157
- value: {
158
- theme: b,
159
- setTheme: V
160
- },
161
- children: [p, u]
185
+ }) : /* @__PURE__ */ O(R.Provider, {
186
+ value: $,
187
+ children: [N, j]
162
188
  });
163
189
  }
164
190
  (function(e) {
165
191
  function t() {
166
- let { theme: e, setTheme: t } = u(B);
192
+ let { theme: e, setTheme: t } = c(R);
167
193
  return [e, t];
168
194
  }
169
195
  e.useTheme = t;
170
- })(V ||= {});
171
- var H = V, U = /* @__PURE__ */ new WeakMap();
172
- function W(e) {
173
- let t = U.get(e);
174
- return t || (t = /* @__PURE__ */ new Map(), U.set(e, t)), t;
196
+ function n() {
197
+ let { design: e, setDesign: t } = c(R);
198
+ return [e, t];
199
+ }
200
+ e.useDesign = n;
201
+ })(z ||= {});
202
+ var B = z, V = /* @__PURE__ */ new WeakMap();
203
+ function H(e) {
204
+ let t = V.get(e);
205
+ return t || (t = /* @__PURE__ */ new Map(), V.set(e, t)), t;
175
206
  }
176
- function G(e = !0) {
177
- let [t] = H.useTheme(), n = p(() => {
207
+ function U(e = !0) {
208
+ let [t] = B.useTheme(), r = d(() => {
178
209
  if (!e) return null;
179
- let t = r();
210
+ let t = n();
180
211
  if (!t) return null;
181
- let n = "box-kite-portal", i = t.getElementById(n);
182
- return i || (i = document.createElement("div"), i.id = n, document.body.appendChild(i)), i;
212
+ let r = "box-kite-portal", i = t.getElementById(r);
213
+ return i || (i = document.createElement("div"), i.id = r, document.body.appendChild(i)), i;
183
214
  }, [e]);
184
- return f(() => {
185
- if (!t || !n) return;
186
- let e = W(n), r = e.get(t) ?? 0;
187
- return e.set(t, r + 1), r === 0 && n.classList.add(t), () => {
188
- let r = (e.get(t) ?? 1) - 1;
189
- r <= 0 ? (e.delete(t), n.classList.remove(t)) : e.set(t, r);
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);
215
+ return u(() => {
216
+ if (!t || !r) return;
217
+ let e = H(r), n = e.get(t) ?? 0;
218
+ return e.set(t, n + 1), n === 0 && r.classList.add(t), () => {
219
+ let n = (e.get(t) ?? 1) - 1;
220
+ n <= 0 ? (e.delete(t), r.classList.remove(t)) : e.set(t, n);
202
221
  };
203
- }, [e, i]), r;
222
+ }, [r, t]), r;
204
223
  }
205
224
  //#endregion
206
- export { L as a, z as i, G as n, F as o, H as r, P as s, q as t };
225
+ 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;