@kalyx/react 1.0.0-rc.10 → 1.0.0-rc.11

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { createContext, forwardRef, useState, useRef, useCallback, useContext, useId, useMemo, useEffect } from 'react';
2
+ import { createContext, forwardRef, useState, useRef, useEffect, useCallback, useContext, useId, useMemo } from 'react';
3
3
  import { parseInputValue, formatTimeString, parseTimeString, getTimeInTimezone, getTime, DateFnsAdapter, DEFAULT_DATEPICKER_LABELS, civilMidnightFromUtcDay, getMonthName, getWeekdayNames, getCalendarDays, formatMonthYear, isDateDisabled, getISOWeekNumber, DEFAULT_RANGEPICKER_LABELS, DEFAULT_TIMEPICKER_LABELS, setTimeInTimezone, setTime, to12Hour, to24Hour, generateMinutes, generateHours, formatFullDate } from '@kalyx/core';
4
4
  export { DEFAULT_DATEPICKER_LABELS, DEFAULT_DATETIMEPICKER_LABELS, DEFAULT_RANGEPICKER_LABELS, DEFAULT_TIMEPICKER_LABELS, DateFnsAdapter } from '@kalyx/core';
5
5
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
@@ -156,6 +156,10 @@ var DatePickerInput = forwardRef(
156
156
  const displayFormat = formatProp ?? ctx.displayFormat;
157
157
  const [inputText, setInputText] = useState(null);
158
158
  const isComposingRef = useRef(false);
159
+ useEffect(() => {
160
+ if (isComposingRef.current) return;
161
+ setInputText(null);
162
+ }, [ctx.value]);
159
163
  let formattedValue = "";
160
164
  if (ctx.value) {
161
165
  try {
@@ -1098,6 +1102,17 @@ function useRangePickerContext(componentName) {
1098
1102
  return context;
1099
1103
  }
1100
1104
  var EMPTY_RANGE = { start: null, end: null };
1105
+ var SR_ONLY = {
1106
+ position: "absolute",
1107
+ width: 1,
1108
+ height: 1,
1109
+ padding: 0,
1110
+ margin: -1,
1111
+ overflow: "hidden",
1112
+ clip: "rect(0, 0, 0, 0)",
1113
+ whiteSpace: "nowrap",
1114
+ border: 0
1115
+ };
1101
1116
  function RangePickerRoot({
1102
1117
  value: controlledValue,
1103
1118
  defaultValue,
@@ -1124,6 +1139,8 @@ function RangePickerRoot({
1124
1139
  const [isOpen, setIsOpen] = useState(false);
1125
1140
  const [selectingTarget, setSelectingTarget] = useState("start");
1126
1141
  const [hoverDate, setHoverDate] = useState(null);
1142
+ const [announcement, setAnnouncement] = useState("");
1143
+ const announce = useCallback((message) => setAnnouncement(message), []);
1127
1144
  const [viewMonth, setViewMonth] = useState(
1128
1145
  () => currentValue.start ?? adapter.today(displayTimezone)
1129
1146
  );
@@ -1226,7 +1243,8 @@ function RangePickerRoot({
1226
1243
  isDisabled,
1227
1244
  isReadOnly: readOnly,
1228
1245
  pickerId,
1229
- labels: mergedLabels
1246
+ labels: mergedLabels,
1247
+ announce
1230
1248
  }),
1231
1249
  [
1232
1250
  currentValue,
@@ -1249,10 +1267,14 @@ function RangePickerRoot({
1249
1267
  isDisabled,
1250
1268
  readOnly,
1251
1269
  pickerId,
1252
- mergedLabels
1270
+ mergedLabels,
1271
+ announce
1253
1272
  ]
1254
1273
  );
1255
- return /* @__PURE__ */ jsx(RangePickerContext.Provider, { value: contextValue, children });
1274
+ return /* @__PURE__ */ jsxs(RangePickerContext.Provider, { value: contextValue, children: [
1275
+ children,
1276
+ /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", style: SR_ONLY, children: announcement })
1277
+ ] });
1256
1278
  }
1257
1279
  var RangePickerInput = forwardRef(
1258
1280
  function RangePickerInput2({ part, format: formatProp, onClick, onKeyDown, ...props }, ref) {
@@ -1352,17 +1374,6 @@ function safeFormatFullDate2(iso, locale) {
1352
1374
  return iso;
1353
1375
  }
1354
1376
  }
1355
- var srOnly2 = {
1356
- position: "absolute",
1357
- width: "1px",
1358
- height: "1px",
1359
- padding: 0,
1360
- margin: "-1px",
1361
- overflow: "hidden",
1362
- clip: "rect(0, 0, 0, 0)",
1363
- whiteSpace: "nowrap",
1364
- border: 0
1365
- };
1366
1377
  function RangePickerCalendar({
1367
1378
  classNames,
1368
1379
  selectionMode = "range",
@@ -1372,7 +1383,6 @@ function RangePickerCalendar({
1372
1383
  }) {
1373
1384
  const ctx = useRangePickerContext("RangePicker.Calendar");
1374
1385
  const gridRef = useRef(null);
1375
- const [announcement, setAnnouncement] = useState("");
1376
1386
  const {
1377
1387
  adapter,
1378
1388
  viewMonth,
@@ -1424,7 +1434,7 @@ function RangePickerCalendar({
1424
1434
  ctx.setFocusedDate(adapter.startOfMonth(newMonth));
1425
1435
  const y = adapter.getYear(newMonth);
1426
1436
  const m = adapter.getMonth(newMonth);
1427
- setAnnouncement(formatMonthYear(y, m, locale));
1437
+ ctx.announce(formatMonthYear(y, m, locale));
1428
1438
  },
1429
1439
  [adapter, viewMonth, ctx, locale]
1430
1440
  );
@@ -1436,15 +1446,27 @@ function RangePickerCalendar({
1436
1446
  const range = { start: weekStart, end: weekEnd };
1437
1447
  ctx.setRange(range);
1438
1448
  ctx.close();
1439
- setAnnouncement(
1440
- `${safeFormatFullDate2(weekStart, locale)} \u2013 ${safeFormatFullDate2(weekEnd, locale)}`
1449
+ ctx.announce(
1450
+ `${ctx.labels.rangeSelected}: ${safeFormatFullDate2(weekStart, locale)} \u2013 ${safeFormatFullDate2(weekEnd, locale)}`
1441
1451
  );
1442
1452
  } else {
1453
+ const wasPickingStart = selectingTarget === "start";
1454
+ const previousStart = value.start;
1443
1455
  ctx.selectDate(iso);
1444
- setAnnouncement(safeFormatFullDate2(iso, locale));
1456
+ const formatted = safeFormatFullDate2(iso, locale);
1457
+ if (wasPickingStart) {
1458
+ ctx.announce(`${formatted}. ${ctx.labels.selectingEnd}`);
1459
+ } else if (previousStart) {
1460
+ const [start, end] = adapter.isBefore(iso, previousStart) ? [iso, previousStart] : [previousStart, iso];
1461
+ ctx.announce(
1462
+ `${ctx.labels.rangeSelected}: ${safeFormatFullDate2(start, locale)} \u2013 ${safeFormatFullDate2(end, locale)}`
1463
+ );
1464
+ } else {
1465
+ ctx.announce(formatted);
1466
+ }
1445
1467
  }
1446
1468
  },
1447
- [selectionMode, adapter, weekStartsOn, ctx, locale]
1469
+ [selectionMode, adapter, weekStartsOn, ctx, locale, selectingTarget, value.start]
1448
1470
  );
1449
1471
  const handleDayClick = useCallback(
1450
1472
  (day) => {
@@ -1653,8 +1675,7 @@ function RangePickerCalendar({
1653
1675
  )) })
1654
1676
  ]
1655
1677
  }
1656
- ),
1657
- /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", style: srOnly2, children: announcement })
1678
+ )
1658
1679
  ] });
1659
1680
  }
1660
1681
  function RangePickerPresets({ classNames, children, ...props }) {
@@ -1847,6 +1868,9 @@ var TimePickerInput = forwardRef(
1847
1868
  function TimePickerInput2({ onBlur, onKeyDown, ...props }, ref) {
1848
1869
  const ctx = useTimePickerContext("TimePicker.Input");
1849
1870
  const [inputText, setInputText] = useState(null);
1871
+ useEffect(() => {
1872
+ setInputText(null);
1873
+ }, [ctx.value]);
1850
1874
  const displayValue = inputText !== null ? inputText : formatTimeString(ctx.currentTime, ctx.withSeconds);
1851
1875
  const commitInput = useCallback(() => {
1852
1876
  if (inputText === null) return;