design-zystem 1.0.420 → 1.0.421

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/ui/index.js CHANGED
@@ -8376,6 +8376,7 @@ var import_locale2 = require("date-fns/locale");
8376
8376
  var RadixPopover6 = __toESM(require("@radix-ui/react-popover"));
8377
8377
  var import_jsx_runtime96 = require("react/jsx-runtime");
8378
8378
  var formatMonthCaption = (month) => (0, import_date_fns.format)(month, "MMM yyyy", { locale: import_locale2.fr });
8379
+ var isSameCalendarDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
8379
8380
  var RANGE_PRESETS = [
8380
8381
  {
8381
8382
  label: "Mois pr\xE9c\xE9dent",
@@ -8437,8 +8438,21 @@ var DatePicker = ({
8437
8438
  }) => {
8438
8439
  const isRange = mode === "range";
8439
8440
  const [open, setOpen] = (0, import_react59.useState)(false);
8440
- const [activePreset, setActivePreset] = (0, import_react59.useState)(null);
8441
8441
  const resolvedPresets = presets != null ? presets : isRange ? RANGE_PRESETS : SINGLE_PRESETS;
8442
+ const activePreset = (0, import_react59.useMemo)(() => {
8443
+ var _a;
8444
+ const match = resolvedPresets.find((preset) => {
8445
+ const result = preset.getValue();
8446
+ if (isRange) {
8447
+ if (!startDate || !endDate) return false;
8448
+ const [start, end] = result;
8449
+ return isSameCalendarDay(start, startDate) && isSameCalendarDay(end, endDate);
8450
+ }
8451
+ if (!value) return false;
8452
+ return isSameCalendarDay(result, value);
8453
+ });
8454
+ return (_a = match == null ? void 0 : match.label) != null ? _a : null;
8455
+ }, [isRange, resolvedPresets, startDate, endDate, value]);
8442
8456
  const displayText = isRange ? startDate && endDate ? `${(0, import_date_fns.format)(startDate, "dd/MM/yyyy")} \u2014 ${(0, import_date_fns.format)(endDate, "dd/MM/yyyy")}` : placeholder != null ? placeholder : "S\xE9lectionner une p\xE9riode" : value ? (0, import_date_fns.format)(value, "dd/MM/yyyy") : placeholder != null ? placeholder : "S\xE9lectionner une date";
8443
8457
  const hasValue = isRange ? Boolean(startDate && endDate) : Boolean(value);
8444
8458
  const dayPickerDisabled = [
@@ -8453,13 +8467,11 @@ var DatePicker = ({
8453
8467
  } else {
8454
8468
  onChange == null ? void 0 : onChange(result);
8455
8469
  }
8456
- setActivePreset(preset.label);
8457
8470
  setOpen(false);
8458
8471
  };
8459
8472
  const handleReset = () => {
8460
8473
  if (isRange) onRangeChange == null ? void 0 : onRangeChange(null, null);
8461
8474
  else onChange == null ? void 0 : onChange(null);
8462
- setActivePreset(null);
8463
8475
  };
8464
8476
  const calendar = /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(RadixPopover6.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
8465
8477
  RadixPopover6.Content,
@@ -8482,7 +8494,6 @@ var DatePicker = ({
8482
8494
  onSelect: (range) => {
8483
8495
  var _a, _b;
8484
8496
  onRangeChange == null ? void 0 : onRangeChange((_a = range == null ? void 0 : range.from) != null ? _a : null, (_b = range == null ? void 0 : range.to) != null ? _b : null);
8485
- setActivePreset(null);
8486
8497
  },
8487
8498
  locale: import_locale.fr,
8488
8499
  disabled: dayPickerDisabled,
@@ -8497,7 +8508,6 @@ var DatePicker = ({
8497
8508
  selected: value != null ? value : void 0,
8498
8509
  onSelect: (date) => {
8499
8510
  onChange == null ? void 0 : onChange(date != null ? date : null);
8500
- setActivePreset(null);
8501
8511
  setOpen(false);
8502
8512
  },
8503
8513
  locale: import_locale.fr,
@@ -8537,10 +8547,12 @@ var DatePicker = ({
8537
8547
  {
8538
8548
  type: "button",
8539
8549
  "aria-label": "Ouvrir le calendrier",
8550
+ "aria-pressed": hasValue && !activePreset,
8540
8551
  disabled,
8541
8552
  className: cn(
8542
- "flex h-9 w-9 items-center justify-center rounded-[6px] border border-grey-300 bg-white text-neutral-800 transition-colors",
8543
- "hover:border-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
8553
+ "flex h-9 w-9 items-center justify-center rounded-[6px] border transition-colors",
8554
+ hasValue && !activePreset ? "border-blue-700 bg-blue-50 text-blue-700" : "border-grey-300 bg-white text-neutral-800 hover:border-blue-700",
8555
+ "disabled:cursor-not-allowed disabled:opacity-60"
8544
8556
  ),
8545
8557
  children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(FaIcon, { name: "calendar", size: 16 })
8546
8558
  }
@@ -8552,6 +8564,7 @@ var DatePicker = ({
8552
8564
  {
8553
8565
  type: "button",
8554
8566
  "aria-label": preset.label,
8567
+ "aria-pressed": active,
8555
8568
  disabled,
8556
8569
  onClick: () => applyPreset(preset),
8557
8570
  className: cn(
package/dist/ui/index.mjs CHANGED
@@ -8194,7 +8194,7 @@ var Stepper = ({
8194
8194
  );
8195
8195
 
8196
8196
  // src/ui/components/ui/DatePicker.tsx
8197
- import { useState as useState18 } from "react";
8197
+ import { useState as useState18, useMemo as useMemo3 } from "react";
8198
8198
  import { DayPicker } from "react-day-picker";
8199
8199
  import { fr } from "react-day-picker/locale";
8200
8200
  import "react-day-picker/style.css";
@@ -8213,6 +8213,7 @@ import { fr as dateFnsFr } from "date-fns/locale";
8213
8213
  import * as RadixPopover6 from "@radix-ui/react-popover";
8214
8214
  import { jsx as jsx96, jsxs as jsxs58 } from "react/jsx-runtime";
8215
8215
  var formatMonthCaption = (month) => format(month, "MMM yyyy", { locale: dateFnsFr });
8216
+ var isSameCalendarDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
8216
8217
  var RANGE_PRESETS = [
8217
8218
  {
8218
8219
  label: "Mois pr\xE9c\xE9dent",
@@ -8274,8 +8275,21 @@ var DatePicker = ({
8274
8275
  }) => {
8275
8276
  const isRange = mode === "range";
8276
8277
  const [open, setOpen] = useState18(false);
8277
- const [activePreset, setActivePreset] = useState18(null);
8278
8278
  const resolvedPresets = presets != null ? presets : isRange ? RANGE_PRESETS : SINGLE_PRESETS;
8279
+ const activePreset = useMemo3(() => {
8280
+ var _a;
8281
+ const match = resolvedPresets.find((preset) => {
8282
+ const result = preset.getValue();
8283
+ if (isRange) {
8284
+ if (!startDate || !endDate) return false;
8285
+ const [start, end] = result;
8286
+ return isSameCalendarDay(start, startDate) && isSameCalendarDay(end, endDate);
8287
+ }
8288
+ if (!value) return false;
8289
+ return isSameCalendarDay(result, value);
8290
+ });
8291
+ return (_a = match == null ? void 0 : match.label) != null ? _a : null;
8292
+ }, [isRange, resolvedPresets, startDate, endDate, value]);
8279
8293
  const displayText = isRange ? startDate && endDate ? `${format(startDate, "dd/MM/yyyy")} \u2014 ${format(endDate, "dd/MM/yyyy")}` : placeholder != null ? placeholder : "S\xE9lectionner une p\xE9riode" : value ? format(value, "dd/MM/yyyy") : placeholder != null ? placeholder : "S\xE9lectionner une date";
8280
8294
  const hasValue = isRange ? Boolean(startDate && endDate) : Boolean(value);
8281
8295
  const dayPickerDisabled = [
@@ -8290,13 +8304,11 @@ var DatePicker = ({
8290
8304
  } else {
8291
8305
  onChange == null ? void 0 : onChange(result);
8292
8306
  }
8293
- setActivePreset(preset.label);
8294
8307
  setOpen(false);
8295
8308
  };
8296
8309
  const handleReset = () => {
8297
8310
  if (isRange) onRangeChange == null ? void 0 : onRangeChange(null, null);
8298
8311
  else onChange == null ? void 0 : onChange(null);
8299
- setActivePreset(null);
8300
8312
  };
8301
8313
  const calendar = /* @__PURE__ */ jsx96(RadixPopover6.Portal, { children: /* @__PURE__ */ jsx96(
8302
8314
  RadixPopover6.Content,
@@ -8319,7 +8331,6 @@ var DatePicker = ({
8319
8331
  onSelect: (range) => {
8320
8332
  var _a, _b;
8321
8333
  onRangeChange == null ? void 0 : onRangeChange((_a = range == null ? void 0 : range.from) != null ? _a : null, (_b = range == null ? void 0 : range.to) != null ? _b : null);
8322
- setActivePreset(null);
8323
8334
  },
8324
8335
  locale: fr,
8325
8336
  disabled: dayPickerDisabled,
@@ -8334,7 +8345,6 @@ var DatePicker = ({
8334
8345
  selected: value != null ? value : void 0,
8335
8346
  onSelect: (date) => {
8336
8347
  onChange == null ? void 0 : onChange(date != null ? date : null);
8337
- setActivePreset(null);
8338
8348
  setOpen(false);
8339
8349
  },
8340
8350
  locale: fr,
@@ -8374,10 +8384,12 @@ var DatePicker = ({
8374
8384
  {
8375
8385
  type: "button",
8376
8386
  "aria-label": "Ouvrir le calendrier",
8387
+ "aria-pressed": hasValue && !activePreset,
8377
8388
  disabled,
8378
8389
  className: cn(
8379
- "flex h-9 w-9 items-center justify-center rounded-[6px] border border-grey-300 bg-white text-neutral-800 transition-colors",
8380
- "hover:border-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
8390
+ "flex h-9 w-9 items-center justify-center rounded-[6px] border transition-colors",
8391
+ hasValue && !activePreset ? "border-blue-700 bg-blue-50 text-blue-700" : "border-grey-300 bg-white text-neutral-800 hover:border-blue-700",
8392
+ "disabled:cursor-not-allowed disabled:opacity-60"
8381
8393
  ),
8382
8394
  children: /* @__PURE__ */ jsx96(FaIcon, { name: "calendar", size: 16 })
8383
8395
  }
@@ -8389,6 +8401,7 @@ var DatePicker = ({
8389
8401
  {
8390
8402
  type: "button",
8391
8403
  "aria-label": preset.label,
8404
+ "aria-pressed": active,
8392
8405
  disabled,
8393
8406
  onClick: () => applyPreset(preset),
8394
8407
  className: cn(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "design-zystem",
3
- "version": "1.0.420",
3
+ "version": "1.0.421",
4
4
  "description": "A React design system of importable components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",