@epilot/zenith-react 0.1.0 → 0.2.0-next.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.
@@ -1,16 +1,16 @@
1
1
  import { jsxs as k, jsx as s } from "react/jsx-runtime";
2
2
  import * as a from "react";
3
- import { createElement as ae } from "react";
4
- import { SLOT_ATTR as l, mergeClasses as B, shorthands as c } from "@epilot/zenith-runtime/v1";
5
- import { Field as se, FieldLabel as ie, FieldInputGroup as de, FieldGroupAddon as oe, FieldError as pe } from "../field/field.js";
6
- import { Button as ce } from "../button/button.js";
7
- import { Pill as le } from "../pill/pill.js";
8
- import { Popover as ge, PopoverTrigger as ue, PopoverContent as he } from "../popover/popover.js";
9
- import { makeZenithStyles as me } from "../../styles/make-styles.js";
10
- import { gray6 as fe, gray9 as Te, leadingSm as H, textSm as z, grayA8 as Ce, grayA12 as qe, spacingElement1 as ye, spacingGroup1 as Se, spacingElement2 as ke } from "../../tokens/index.js";
11
- import { RangeCalendar as xe } from "./range-calendar.js";
12
- import { formatDateTimeDisplay as i, parseDateTimeInput as b } from "../date-time-picker/date-time-picker-utils.js";
13
- const we = (x) => /* @__PURE__ */ s(
3
+ import { createElement as ie } from "react";
4
+ import { SLOT_ATTR as c, mergeClasses as W, shorthands as p } from "@epilot/zenith-runtime/v1";
5
+ import { Field as oe, FieldLabel as le, FieldInputGroup as pe, FieldGroupAddon as ce, FieldError as ue } from "../field/field.js";
6
+ import { Button as ge } from "../button/button.js";
7
+ import { Pill as he } from "../pill/pill.js";
8
+ import { Popover as me, PopoverTrigger as fe, PopoverContent as Te } from "../popover/popover.js";
9
+ import { makeZenithStyles as ye } from "../../styles/make-styles.js";
10
+ import { gray6 as Ce, gray9 as qe, leadingSm as j, textSm as U, grayA8 as Se, grayA12 as be, spacingElement1 as ke, spacingGroup1 as Ie, spacingElement2 as xe } from "../../tokens/index.js";
11
+ import { RangeCalendar as we } from "./range-calendar.js";
12
+ import { formatDateTimeDisplay as d, parseDateTimeInput as E } from "../date-time-picker/date-time-picker-utils.js";
13
+ const ve = (I) => /* @__PURE__ */ s(
14
14
  "svg",
15
15
  {
16
16
  xmlns: "http://www.w3.org/2000/svg",
@@ -18,10 +18,10 @@ const we = (x) => /* @__PURE__ */ s(
18
18
  viewBox: "0 -960 960 960",
19
19
  width: "18px",
20
20
  fill: "currentColor",
21
- ...x,
21
+ ...I,
22
22
  children: /* @__PURE__ */ s("path", { d: "M200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Zm280 240q-17 0-28.5-11.5T440-440q0-17 11.5-28.5T480-480q17 0 28.5 11.5T520-440q0 17-11.5 28.5T480-400Zm-160 0q-17 0-28.5-11.5T280-440q0-17 11.5-28.5T320-480q17 0 28.5 11.5T360-440q0 17-11.5 28.5T320-400Zm320 0q-17 0-28.5-11.5T600-440q0-17 11.5-28.5T640-480q17 0 28.5 11.5T680-440q0 17-11.5 28.5T640-400ZM480-240q-17 0-28.5-11.5T440-280q0-17 11.5-28.5T480-320q17 0 28.5 11.5T520-280q0 17-11.5 28.5T480-240Zm-160 0q-17 0-28.5-11.5T280-280q0-17 11.5-28.5T320-320q17 0 28.5 11.5T360-280q0 17-11.5 28.5T320-240Zm320 0q-17 0-28.5-11.5T600-280q0-17 11.5-28.5T640-320q17 0 28.5 11.5T680-280q0 17-11.5 28.5T640-240Z" })
23
23
  }
24
- ), Re = "dd/MM/yyyy", _ = me({
24
+ ), Re = "dd/MM/yyyy", J = ye({
25
25
  root: {
26
26
  width: "100%"
27
27
  },
@@ -46,7 +46,7 @@ const we = (x) => /* @__PURE__ */ s(
46
46
  triggerRoot: {
47
47
  display: "flex",
48
48
  alignItems: "center",
49
- ...c.gap(ke),
49
+ ...p.gap(xe),
50
50
  flexGrow: 1,
51
51
  flexShrink: 1,
52
52
  flexBasis: "0%",
@@ -56,101 +56,106 @@ const we = (x) => /* @__PURE__ */ s(
56
56
  input: {
57
57
  width: "5.5rem",
58
58
  outlineStyle: "none",
59
- fontSize: z,
60
- lineHeight: H,
61
- color: qe,
59
+ fontSize: U,
60
+ lineHeight: j,
61
+ color: be,
62
62
  backgroundColor: "transparent",
63
63
  textAlign: "center",
64
- ...c.border("0"),
65
- ...c.padding("0"),
64
+ ...p.border("0"),
65
+ ...p.padding("0"),
66
66
  "::placeholder": {
67
- color: Ce
67
+ color: Se
68
68
  },
69
69
  ":disabled": {
70
70
  cursor: "not-allowed"
71
71
  }
72
72
  },
73
73
  separator: {
74
- fontSize: z,
75
- lineHeight: H,
76
- color: Te,
74
+ fontSize: U,
75
+ lineHeight: j,
76
+ color: qe,
77
77
  flexShrink: 0,
78
78
  userSelect: "none",
79
- ...c.padding("0", "0.125rem")
79
+ ...p.padding("0", "0.125rem")
80
80
  // v1 px-0.5
81
81
  },
82
82
  popoverContent: {
83
- ...c.overflow("hidden")
83
+ ...p.overflow("hidden")
84
84
  },
85
85
  content: {
86
86
  display: "flex",
87
87
  flexDirection: "row",
88
- ...c.gap(Se),
89
- ...c.padding("0.75rem")
88
+ ...p.gap(Ie),
89
+ ...p.padding("0.75rem")
90
90
  // v1 p-3 (0.75rem)
91
91
  },
92
92
  presets: {
93
93
  display: "flex",
94
94
  flexDirection: "column",
95
- ...c.gap(ye),
95
+ ...p.gap(ke),
96
96
  width: "8rem",
97
97
  // v1 w-32
98
98
  borderLeftWidth: "1px",
99
99
  borderLeftStyle: "solid",
100
- borderLeftColor: fe,
100
+ borderLeftColor: Ce,
101
101
  paddingLeft: "0.75rem"
102
102
  // v1 pl-3 (0.75rem)
103
103
  },
104
104
  presetPill: {
105
105
  alignSelf: "flex-start"
106
106
  }
107
- }), be = a.forwardRef((x, t) => {
107
+ }), Ee = a.forwardRef((I, t) => {
108
108
  const {
109
109
  startValue: o,
110
- endValue: d,
111
- startPlaceholder: w,
112
- endPlaceholder: v,
113
- disabled: C,
110
+ endValue: i,
111
+ startPlaceholder: x,
112
+ endPlaceholder: N,
113
+ disabled: g,
114
114
  onStartChange: q,
115
- onEndChange: E,
116
- onStartBlur: I,
115
+ onEndChange: P,
116
+ onStartBlur: V,
117
117
  onEndBlur: n,
118
118
  testId: e,
119
- inputAriaLabel: N,
120
- className: P,
121
- "data-slot": F,
122
- ...V
123
- } = x, u = _();
119
+ inputAriaLabel: Z,
120
+ startId: w,
121
+ endId: v,
122
+ labelId: h,
123
+ className: M,
124
+ "data-slot": H,
125
+ ...A
126
+ } = I, m = J();
124
127
  return /* @__PURE__ */ k(
125
128
  "div",
126
129
  {
127
130
  ref: t,
128
- ...V,
129
- className: B(u.triggerRoot, P),
131
+ ...A,
132
+ className: W(m.triggerRoot, M),
130
133
  "data-slot": "date-range-input",
131
- [l]: "date-range-input",
134
+ [c]: "date-range-input",
132
135
  children: [
133
136
  /* @__PURE__ */ s(
134
137
  "input",
135
138
  {
136
- "aria-label": N || "Start date",
137
- className: u.input,
139
+ "aria-label": Z || "Start date",
140
+ id: w,
141
+ "aria-labelledby": h ? `${h} ${w}` : void 0,
142
+ className: m.input,
138
143
  "data-slot": "date-range-start-input",
139
- [l]: "date-range-start-input",
144
+ [c]: "date-range-start-input",
140
145
  "data-testid": e ? `${e}-start` : void 0,
141
- disabled: C,
142
- onBlur: I,
146
+ disabled: g,
147
+ onBlur: V,
143
148
  onChange: q,
144
- placeholder: w,
149
+ placeholder: x,
145
150
  value: o
146
151
  }
147
152
  ),
148
153
  /* @__PURE__ */ s(
149
154
  "span",
150
155
  {
151
- className: u.separator,
156
+ className: m.separator,
152
157
  "data-slot": "date-range-separator",
153
- [l]: "date-range-separator",
158
+ [c]: "date-range-separator",
154
159
  children: "–"
155
160
  }
156
161
  ),
@@ -158,218 +163,223 @@ const we = (x) => /* @__PURE__ */ s(
158
163
  "input",
159
164
  {
160
165
  "aria-label": "End date",
161
- className: u.input,
166
+ id: v,
167
+ "aria-labelledby": h ? `${h} ${v}` : void 0,
168
+ className: m.input,
162
169
  "data-slot": "date-range-end-input",
163
- [l]: "date-range-end-input",
170
+ [c]: "date-range-end-input",
164
171
  "data-testid": e ? `${e}-end` : void 0,
165
- disabled: C,
172
+ disabled: g,
166
173
  onBlur: n,
167
- onChange: E,
168
- placeholder: v,
169
- value: d
174
+ onChange: P,
175
+ placeholder: N,
176
+ value: i
170
177
  }
171
178
  )
172
179
  ]
173
180
  }
174
181
  );
175
- }), Oe = a.forwardRef(function({
182
+ }), $e = a.forwardRef(function({
176
183
  value: t,
177
184
  onChange: o,
178
- onBlur: d,
179
- disabled: w = !1,
180
- disablePast: v = !1,
181
- label: C,
185
+ onBlur: i,
186
+ disabled: x = !1,
187
+ disablePast: N = !1,
188
+ label: g,
182
189
  error: q,
183
- startPlaceholder: E = "dd/MM/yyyy",
184
- endPlaceholder: I = "dd/MM/yyyy",
190
+ startPlaceholder: P = "dd/MM/yyyy",
191
+ endPlaceholder: V = "dd/MM/yyyy",
185
192
  format: n = Re,
186
193
  locale: e = "de",
187
- className: N,
188
- keyboardIcon: P,
189
- inputAriaLabel: F,
190
- openPickerAriaLabel: V = "Open date picker",
191
- previousMonthLabel: u = "Previous month",
192
- nextMonthLabel: j = "Next month",
193
- testId: $,
194
- currentTimeInTimezone: U,
195
- showWeekNumbers: W = !1,
196
- presets: Z
197
- }, J) {
198
- const p = _(), [M, A] = a.useState(!1), [D, h] = a.useState(
199
- () => t.start ? i(t.start, n, e) : ""
200
- ), [L, m] = a.useState(
201
- () => t.end ? i(t.end, n, e) : ""
202
- ), [R, y] = a.useState(t), f = a.useRef(t), T = a.useRef(
194
+ className: Z,
195
+ keyboardIcon: w,
196
+ inputAriaLabel: v,
197
+ openPickerAriaLabel: h = "Open date picker",
198
+ previousMonthLabel: M = "Previous month",
199
+ nextMonthLabel: H = "Next month",
200
+ testId: A,
201
+ currentTimeInTimezone: m,
202
+ showWeekNumbers: K = !1,
203
+ presets: D
204
+ }, Q) {
205
+ const l = J(), [F, L] = a.useState(!1), [O, f] = a.useState(
206
+ () => t.start ? d(t.start, n, e) : ""
207
+ ), [G, T] = a.useState(
208
+ () => t.end ? d(t.end, n, e) : ""
209
+ ), [R, S] = a.useState(t), y = a.useRef(t), C = a.useRef(
203
210
  void 0
204
211
  );
205
212
  a.useEffect(
206
213
  () => () => {
207
- T.current !== void 0 && clearTimeout(T.current);
214
+ C.current !== void 0 && clearTimeout(C.current);
208
215
  },
209
216
  []
210
217
  ), a.useEffect(() => {
211
- h(
212
- t.start ? i(t.start, n, e) : ""
213
- ), m(
214
- t.end ? i(t.end, n, e) : ""
215
- ), y(t);
218
+ f(
219
+ t.start ? d(t.start, n, e) : ""
220
+ ), T(
221
+ t.end ? d(t.end, n, e) : ""
222
+ ), S(t);
216
223
  }, [t, n, e]), a.useEffect(() => {
217
- M && (f.current = t, y(t));
218
- }, [M, t]);
219
- const K = a.useCallback(
224
+ F && (y.current = t, S(t));
225
+ }, [F, t]);
226
+ const X = a.useCallback(
220
227
  (r) => {
221
- const g = r.target.value;
222
- h(g);
223
- const S = b(g, n, e);
224
- if (S) {
225
- const O = { ...t, start: S };
226
- o(O);
228
+ const u = r.target.value;
229
+ f(u);
230
+ const b = E(u, n, e);
231
+ if (b) {
232
+ const $ = { ...t, start: b };
233
+ o($);
227
234
  }
228
235
  },
229
236
  [o, t, n, e]
230
- ), Q = a.useCallback(
237
+ ), Y = a.useCallback(
231
238
  (r) => {
232
- const g = r.target.value;
233
- m(g);
234
- const S = b(g, n, e);
235
- if (S) {
236
- const O = { ...t, end: S };
237
- o(O);
239
+ const u = r.target.value;
240
+ T(u);
241
+ const b = E(u, n, e);
242
+ if (b) {
243
+ const $ = { ...t, end: b };
244
+ o($);
238
245
  }
239
246
  },
240
247
  [o, t, n, e]
241
- ), X = a.useCallback(() => {
242
- b(D, n, e) || h(
243
- t.start ? i(t.start, n, e) : ""
244
- ), d == null || d();
245
- }, [D, t.start, n, e, d]), Y = a.useCallback(() => {
246
- b(L, n, e) || m(
247
- t.end ? i(t.end, n, e) : ""
248
- ), d == null || d();
249
- }, [L, t.end, n, e, d]), ee = a.useCallback(
248
+ ), ee = a.useCallback(() => {
249
+ E(O, n, e) || f(
250
+ t.start ? d(t.start, n, e) : ""
251
+ ), i == null || i();
252
+ }, [O, t.start, n, e, i]), te = a.useCallback(() => {
253
+ E(G, n, e) || T(
254
+ t.end ? d(t.end, n, e) : ""
255
+ ), i == null || i();
256
+ }, [G, t.end, n, e, i]), ne = a.useCallback(
250
257
  (r) => {
251
- y(r), h(
252
- r.start ? i(r.start, n, e) : ""
253
- ), m(
254
- r.end ? i(r.end, n, e) : ""
258
+ S(r), f(
259
+ r.start ? d(r.start, n, e) : ""
260
+ ), T(
261
+ r.end ? d(r.end, n, e) : ""
255
262
  );
256
263
  },
257
264
  [n, e]
258
- ), G = a.useCallback(
265
+ ), z = a.useCallback(
259
266
  (r) => {
260
- o(r), y(r), h(
261
- r.start ? i(r.start, n, e) : ""
262
- ), m(
263
- r.end ? i(r.end, n, e) : ""
264
- ), T.current !== void 0 && clearTimeout(T.current), T.current = setTimeout(() => {
265
- T.current = void 0, A(!1);
267
+ o(r), S(r), f(
268
+ r.start ? d(r.start, n, e) : ""
269
+ ), T(
270
+ r.end ? d(r.end, n, e) : ""
271
+ ), C.current !== void 0 && clearTimeout(C.current), C.current = setTimeout(() => {
272
+ C.current = void 0, L(!1);
266
273
  }, 150);
267
274
  },
268
275
  [o, n, e]
269
- ), te = a.useCallback(
276
+ ), re = a.useCallback(
270
277
  (r) => {
271
- r || (!R.start || !R.end) && (y(f.current), h(
272
- f.current.start ? i(
273
- f.current.start,
278
+ r || (!R.start || !R.end) && (S(y.current), f(
279
+ y.current.start ? d(
280
+ y.current.start,
274
281
  n,
275
282
  e
276
283
  ) : ""
277
- ), m(
278
- f.current.end ? i(
279
- f.current.end,
284
+ ), T(
285
+ y.current.end ? d(
286
+ y.current.end,
280
287
  n,
281
288
  e
282
289
  ) : ""
283
- )), A(r);
290
+ )), L(r);
284
291
  },
285
292
  [R, n, e]
286
- ), ne = P || /* @__PURE__ */ s(we, {}), re = q ? "destructive" : "highlight";
293
+ ), ae = w || /* @__PURE__ */ s(ve, {}), se = q ? "destructive" : "highlight", B = a.useId(), _ = a.useId(), de = a.useId();
287
294
  return /* @__PURE__ */ k(
288
- se,
295
+ oe,
289
296
  {
290
- className: B(p.root, N),
297
+ className: W(l.root, Z),
291
298
  "data-slot": "daterangepicker",
292
- [l]: "daterangepicker",
293
- ref: J,
294
- variant: re,
299
+ [c]: "daterangepicker",
300
+ ref: Q,
301
+ variant: se,
295
302
  children: [
296
- C && /* @__PURE__ */ s(ie, { children: C }),
297
- /* @__PURE__ */ k(ge, { modal: !0, onOpenChange: te, open: M, children: [
298
- /* @__PURE__ */ k(de, { className: p.inputGroup, children: [
299
- /* @__PURE__ */ s(ue, { asChild: !0, className: p.popoverTrigger, children: /* @__PURE__ */ s(
300
- be,
303
+ g && /* @__PURE__ */ s(le, { id: B, htmlFor: _, children: g }),
304
+ /* @__PURE__ */ k(me, { modal: !0, onOpenChange: re, open: F, children: [
305
+ /* @__PURE__ */ k(pe, { className: l.inputGroup, children: [
306
+ /* @__PURE__ */ s(fe, { asChild: !0, className: l.popoverTrigger, children: /* @__PURE__ */ s(
307
+ Ee,
301
308
  {
302
- disabled: w,
303
- endPlaceholder: I,
304
- endValue: L,
305
- inputAriaLabel: F,
306
- onEndBlur: Y,
307
- onEndChange: Q,
308
- onStartBlur: X,
309
- onStartChange: K,
310
- startPlaceholder: E,
311
- startValue: D,
312
- testId: $
309
+ disabled: x,
310
+ endPlaceholder: V,
311
+ endValue: G,
312
+ inputAriaLabel: v,
313
+ startId: _,
314
+ endId: de,
315
+ labelId: g ? B : void 0,
316
+ onEndBlur: te,
317
+ onEndChange: Y,
318
+ onStartBlur: ee,
319
+ onStartChange: X,
320
+ startPlaceholder: P,
321
+ startValue: O,
322
+ testId: A
313
323
  }
314
324
  ) }),
315
- /* @__PURE__ */ s(oe, { align: "end", children: /* @__PURE__ */ s(
316
- ce,
325
+ /* @__PURE__ */ s(ce, { align: "end", children: /* @__PURE__ */ s(
326
+ ge,
317
327
  {
318
- "aria-label": V,
319
- disabled: w,
320
- onClick: () => A(!0),
321
- className: p.addonButton,
328
+ "aria-label": h,
329
+ disabled: x,
330
+ onClick: () => L(!0),
331
+ className: l.addonButton,
322
332
  size: "icon-sm",
323
333
  variant: "tertiary",
324
- children: ne
334
+ children: ae
325
335
  }
326
336
  ) })
327
337
  ] }),
328
338
  /* @__PURE__ */ s(
329
- he,
339
+ Te,
330
340
  {
331
341
  align: "start",
332
- className: p.popoverContent,
342
+ className: l.popoverContent,
333
343
  flush: !0,
334
344
  side: "bottom",
335
345
  sideOffset: 4,
336
346
  children: /* @__PURE__ */ k(
337
347
  "div",
338
348
  {
339
- className: p.content,
349
+ className: l.content,
340
350
  "data-slot": "daterangepicker-content",
341
- [l]: "daterangepicker-content",
351
+ [c]: "daterangepicker-content",
342
352
  children: [
343
353
  /* @__PURE__ */ s(
344
- xe,
354
+ we,
345
355
  {
346
- currentTimeInTimezone: U,
347
- disablePast: v,
356
+ currentTimeInTimezone: m,
357
+ disablePast: N,
348
358
  locale: e,
349
- nextMonthLabel: j,
350
- onChange: ee,
351
- onRangeComplete: G,
352
- previousMonthLabel: u,
353
- showWeekNumbers: W,
359
+ nextMonthLabel: H,
360
+ onChange: ne,
361
+ onRangeComplete: z,
362
+ previousMonthLabel: M,
363
+ showWeekNumbers: K,
354
364
  value: R
355
365
  }
356
366
  ),
357
- Z && Z.length > 0 && /* @__PURE__ */ s(
367
+ D && D.length > 0 && /* @__PURE__ */ s(
358
368
  "aside",
359
369
  {
360
- className: p.presets,
370
+ className: l.presets,
361
371
  "data-slot": "daterangepicker-presets",
362
- [l]: "daterangepicker-presets",
363
- children: Z.map((r) => /* @__PURE__ */ ae(
364
- le,
372
+ [c]: "daterangepicker-presets",
373
+ children: D.map((r) => /* @__PURE__ */ ie(
374
+ he,
365
375
  {
366
- className: p.presetPill,
376
+ className: l.presetPill,
367
377
  "data-slot": "daterangepicker-preset",
368
- [l]: "daterangepicker-preset",
378
+ [c]: "daterangepicker-preset",
369
379
  key: r.label,
370
380
  onClick: () => {
371
- const g = r.getValue();
372
- G(g);
381
+ const u = r.getValue();
382
+ z(u);
373
383
  },
374
384
  variant: "surface"
375
385
  },
@@ -383,13 +393,13 @@ const we = (x) => /* @__PURE__ */ s(
383
393
  }
384
394
  )
385
395
  ] }),
386
- q && /* @__PURE__ */ s(pe, { children: q })
396
+ q && /* @__PURE__ */ s(ue, { children: q })
387
397
  ]
388
398
  }
389
399
  );
390
400
  });
391
401
  export {
392
- Oe as DateRangePicker,
393
- xe as RangeCalendar
402
+ $e as DateRangePicker,
403
+ we as RangeCalendar
394
404
  };
395
405
  //# sourceMappingURL=date-range-picker.js.map