@orianatech/pire 0.21.0 → 0.22.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.
package/dist/index.js CHANGED
@@ -1447,6 +1447,15 @@ function typeIntoInput(el, text) {
1447
1447
  const caret = start + text.length;
1448
1448
  el.setSelectionRange(caret, caret);
1449
1449
  }
1450
+ function toAriaNumber(value) {
1451
+ if (value === void 0) {
1452
+ return void 0;
1453
+ }
1454
+ if (value === null || value === "") {
1455
+ return NaN;
1456
+ }
1457
+ return typeof value === "number" ? value : Number(value);
1458
+ }
1450
1459
  function NumberField({
1451
1460
  label,
1452
1461
  suffix,
@@ -1457,10 +1466,16 @@ function NumberField({
1457
1466
  fullWidth = true,
1458
1467
  className,
1459
1468
  style,
1469
+ value,
1470
+ defaultValue,
1471
+ onChange,
1472
+ emptyValue,
1460
1473
  ...rest
1461
1474
  }) {
1462
1475
  const msg = usePireMessages();
1463
1476
  const { locale } = useLocale();
1477
+ const empty = emptyValue === void 0 ? NaN : emptyValue;
1478
+ const handleChange = onChange && ((next) => onChange(Number.isNaN(next) ? empty : next));
1464
1479
  const handleDecimalKey = (event) => {
1465
1480
  if (event.key !== "." || event.ctrlKey || event.metaKey || event.altKey) {
1466
1481
  return;
@@ -1479,32 +1494,44 @@ function NumberField({
1479
1494
  event.preventDefault();
1480
1495
  typeIntoInput(event.currentTarget, separator);
1481
1496
  };
1482
- return /* @__PURE__ */ jsxs18(AriaNumberField, { className: cx("pire-field", className), style, validationBehavior: "aria", ...rest, children: [
1483
- label ? /* @__PURE__ */ jsxs18(Label7, { className: "pire-field-label", children: [
1484
- label,
1485
- rest.isRequired ? /* @__PURE__ */ jsx25("span", { className: "pire-field-req", "aria-hidden": "true", children: "*" }) : null
1486
- ] }) : null,
1487
- /* @__PURE__ */ jsxs18(
1488
- Group5,
1489
- {
1490
- className: "pire-control",
1491
- "data-size": size,
1492
- "data-full-width": String(fullWidth),
1493
- "data-invalid": rest.isInvalid ? "true" : void 0,
1494
- "data-readonly": rest.isReadOnly ? "true" : void 0,
1495
- children: [
1496
- /* @__PURE__ */ jsx25(AriaInput4, { className: "pire-input", "data-numeric": "true", onKeyDown: handleDecimalKey }),
1497
- suffix ? /* @__PURE__ */ jsx25("span", { className: "pire-affix", children: suffix }) : null,
1498
- hideStepper ? null : /* @__PURE__ */ jsxs18("span", { className: "pire-stepper", children: [
1499
- /* @__PURE__ */ jsx25(AriaButton8, { slot: "increment", className: "pire-stepper-btn", "aria-label": msg.numberFieldIncrease, children: /* @__PURE__ */ jsx25(Icon, { name: "plus", size: 10 }) }),
1500
- /* @__PURE__ */ jsx25(AriaButton8, { slot: "decrement", className: "pire-stepper-btn", "aria-label": msg.numberFieldDecrease, children: /* @__PURE__ */ jsx25(Icon, { name: "minus", size: 10 }) })
1501
- ] })
1502
- ]
1503
- }
1504
- ),
1505
- description ? /* @__PURE__ */ jsx25(Text9, { slot: "description", className: "pire-field-hint", children: description }) : null,
1506
- /* @__PURE__ */ jsx25(FieldError7, { className: "pire-field-error", children: errorMessage })
1507
- ] });
1497
+ return /* @__PURE__ */ jsxs18(
1498
+ AriaNumberField,
1499
+ {
1500
+ className: cx("pire-field", className),
1501
+ style,
1502
+ validationBehavior: "aria",
1503
+ value: toAriaNumber(value),
1504
+ defaultValue: toAriaNumber(defaultValue),
1505
+ onChange: handleChange,
1506
+ ...rest,
1507
+ children: [
1508
+ label ? /* @__PURE__ */ jsxs18(Label7, { className: "pire-field-label", children: [
1509
+ label,
1510
+ rest.isRequired ? /* @__PURE__ */ jsx25("span", { className: "pire-field-req", "aria-hidden": "true", children: "*" }) : null
1511
+ ] }) : null,
1512
+ /* @__PURE__ */ jsxs18(
1513
+ Group5,
1514
+ {
1515
+ className: "pire-control",
1516
+ "data-size": size,
1517
+ "data-full-width": String(fullWidth),
1518
+ "data-invalid": rest.isInvalid ? "true" : void 0,
1519
+ "data-readonly": rest.isReadOnly ? "true" : void 0,
1520
+ children: [
1521
+ /* @__PURE__ */ jsx25(AriaInput4, { className: "pire-input", "data-numeric": "true", onKeyDown: handleDecimalKey }),
1522
+ suffix ? /* @__PURE__ */ jsx25("span", { className: "pire-affix", children: suffix }) : null,
1523
+ hideStepper ? null : /* @__PURE__ */ jsxs18("span", { className: "pire-stepper", children: [
1524
+ /* @__PURE__ */ jsx25(AriaButton8, { slot: "increment", className: "pire-stepper-btn", "aria-label": msg.numberFieldIncrease, children: /* @__PURE__ */ jsx25(Icon, { name: "plus", size: 10 }) }),
1525
+ /* @__PURE__ */ jsx25(AriaButton8, { slot: "decrement", className: "pire-stepper-btn", "aria-label": msg.numberFieldDecrease, children: /* @__PURE__ */ jsx25(Icon, { name: "minus", size: 10 }) })
1526
+ ] })
1527
+ ]
1528
+ }
1529
+ ),
1530
+ description ? /* @__PURE__ */ jsx25(Text9, { slot: "description", className: "pire-field-hint", children: description }) : null,
1531
+ /* @__PURE__ */ jsx25(FieldError7, { className: "pire-field-error", children: errorMessage })
1532
+ ]
1533
+ }
1534
+ );
1508
1535
  }
1509
1536
 
1510
1537
  // src/components/forms/DatePicker.tsx
@@ -1527,7 +1554,29 @@ import {
1527
1554
  Text as Text10,
1528
1555
  FieldError as FieldError8
1529
1556
  } from "react-aria-components";
1557
+ import { parseDate } from "@internationalized/date";
1530
1558
  import { jsx as jsx26, jsxs as jsxs19 } from "react/jsx-runtime";
1559
+ var ISO_DATE = /^(\d{4}-\d{2}-\d{2})(?:[T ].*)?$/;
1560
+ function coerceDateValue(value) {
1561
+ if (value === void 0) {
1562
+ return void 0;
1563
+ }
1564
+ if (value === null || value === "") {
1565
+ return null;
1566
+ }
1567
+ if (typeof value !== "string") {
1568
+ return value;
1569
+ }
1570
+ const match = ISO_DATE.exec(value);
1571
+ if (!match) {
1572
+ return null;
1573
+ }
1574
+ try {
1575
+ return parseDate(match[1]);
1576
+ } catch {
1577
+ return null;
1578
+ }
1579
+ }
1531
1580
  function DatePicker({
1532
1581
  label,
1533
1582
  description,
@@ -1536,42 +1585,61 @@ function DatePicker({
1536
1585
  fullWidth = true,
1537
1586
  className,
1538
1587
  style,
1588
+ value,
1589
+ defaultValue,
1590
+ onChange,
1591
+ valueFormat,
1539
1592
  ...rest
1540
1593
  }) {
1541
1594
  const msg = usePireMessages();
1542
- return /* @__PURE__ */ jsxs19(AriaDatePicker, { className: cx("pire-field", className), style, validationBehavior: "aria", ...rest, children: [
1543
- label ? /* @__PURE__ */ jsxs19(Label8, { className: "pire-field-label", children: [
1544
- label,
1545
- rest.isRequired ? /* @__PURE__ */ jsx26("span", { className: "pire-field-req", "aria-hidden": "true", children: "*" }) : null
1546
- ] }) : null,
1547
- /* @__PURE__ */ jsxs19(
1548
- Group6,
1549
- {
1550
- className: "pire-control",
1551
- "data-size": size,
1552
- "data-full-width": String(fullWidth),
1553
- "data-invalid": rest.isInvalid ? "true" : void 0,
1554
- "data-readonly": rest.isReadOnly ? "true" : void 0,
1555
- children: [
1556
- /* @__PURE__ */ jsx26(DateInput, { className: "pire-datefield", children: (segment) => /* @__PURE__ */ jsx26(DateSegment, { segment, className: "pire-datesegment" }) }),
1557
- /* @__PURE__ */ jsx26(AriaButton9, { className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerOpenCalendar, style: { width: 24, height: 24 }, children: /* @__PURE__ */ jsx26(Icon, { name: "calendar", size: 16 }) })
1558
- ]
1559
- }
1560
- ),
1561
- description ? /* @__PURE__ */ jsx26(Text10, { slot: "description", className: "pire-field-hint", children: description }) : null,
1562
- /* @__PURE__ */ jsx26(FieldError8, { className: "pire-field-error", children: errorMessage }),
1563
- /* @__PURE__ */ jsx26(Popover4, { className: "pire-popover", children: /* @__PURE__ */ jsx26(AriaDialog, { children: /* @__PURE__ */ jsxs19(Calendar, { className: "pire-calendar", children: [
1564
- /* @__PURE__ */ jsxs19("header", { className: "pire-calendar-head", children: [
1565
- /* @__PURE__ */ jsx26(AriaButton9, { slot: "previous", className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerPreviousMonth, children: /* @__PURE__ */ jsx26(Icon, { name: "chevron-left", size: 16 }) }),
1566
- /* @__PURE__ */ jsx26(Heading2, { className: "pire-calendar-title" }),
1567
- /* @__PURE__ */ jsx26(AriaButton9, { slot: "next", className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerNextMonth, children: /* @__PURE__ */ jsx26(Icon, { name: "chevron-right", size: 16 }) })
1568
- ] }),
1569
- /* @__PURE__ */ jsxs19(CalendarGrid, { className: "pire-calendar-grid", children: [
1570
- /* @__PURE__ */ jsx26(CalendarGridHeader, { children: (day) => /* @__PURE__ */ jsx26(CalendarHeaderCell, { children: day }) }),
1571
- /* @__PURE__ */ jsx26(CalendarGridBody, { children: (date) => /* @__PURE__ */ jsx26(CalendarCell, { date, className: "pire-calendar-cell" }) })
1572
- ] })
1573
- ] }) }) })
1574
- ] });
1595
+ const handleChange = onChange && ((next) => onChange(
1596
+ valueFormat === "iso" && next ? next.toString() : next
1597
+ ));
1598
+ return /* @__PURE__ */ jsxs19(
1599
+ AriaDatePicker,
1600
+ {
1601
+ className: cx("pire-field", className),
1602
+ style,
1603
+ validationBehavior: "aria",
1604
+ value: coerceDateValue(value),
1605
+ defaultValue: coerceDateValue(defaultValue),
1606
+ onChange: handleChange,
1607
+ ...rest,
1608
+ children: [
1609
+ label ? /* @__PURE__ */ jsxs19(Label8, { className: "pire-field-label", children: [
1610
+ label,
1611
+ rest.isRequired ? /* @__PURE__ */ jsx26("span", { className: "pire-field-req", "aria-hidden": "true", children: "*" }) : null
1612
+ ] }) : null,
1613
+ /* @__PURE__ */ jsxs19(
1614
+ Group6,
1615
+ {
1616
+ className: "pire-control",
1617
+ "data-size": size,
1618
+ "data-full-width": String(fullWidth),
1619
+ "data-invalid": rest.isInvalid ? "true" : void 0,
1620
+ "data-readonly": rest.isReadOnly ? "true" : void 0,
1621
+ children: [
1622
+ /* @__PURE__ */ jsx26(DateInput, { className: "pire-datefield", children: (segment) => /* @__PURE__ */ jsx26(DateSegment, { segment, className: "pire-datesegment" }) }),
1623
+ /* @__PURE__ */ jsx26(AriaButton9, { className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerOpenCalendar, style: { width: 24, height: 24 }, children: /* @__PURE__ */ jsx26(Icon, { name: "calendar", size: 16 }) })
1624
+ ]
1625
+ }
1626
+ ),
1627
+ description ? /* @__PURE__ */ jsx26(Text10, { slot: "description", className: "pire-field-hint", children: description }) : null,
1628
+ /* @__PURE__ */ jsx26(FieldError8, { className: "pire-field-error", children: errorMessage }),
1629
+ /* @__PURE__ */ jsx26(Popover4, { className: "pire-popover", children: /* @__PURE__ */ jsx26(AriaDialog, { children: /* @__PURE__ */ jsxs19(Calendar, { className: "pire-calendar", children: [
1630
+ /* @__PURE__ */ jsxs19("header", { className: "pire-calendar-head", children: [
1631
+ /* @__PURE__ */ jsx26(AriaButton9, { slot: "previous", className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerPreviousMonth, children: /* @__PURE__ */ jsx26(Icon, { name: "chevron-left", size: 16 }) }),
1632
+ /* @__PURE__ */ jsx26(Heading2, { className: "pire-calendar-title" }),
1633
+ /* @__PURE__ */ jsx26(AriaButton9, { slot: "next", className: "pire-iconbtn", "data-size": "sm", "aria-label": msg.datePickerNextMonth, children: /* @__PURE__ */ jsx26(Icon, { name: "chevron-right", size: 16 }) })
1634
+ ] }),
1635
+ /* @__PURE__ */ jsxs19(CalendarGrid, { className: "pire-calendar-grid", children: [
1636
+ /* @__PURE__ */ jsx26(CalendarGridHeader, { children: (day) => /* @__PURE__ */ jsx26(CalendarHeaderCell, { children: day }) }),
1637
+ /* @__PURE__ */ jsx26(CalendarGridBody, { children: (date) => /* @__PURE__ */ jsx26(CalendarCell, { date, className: "pire-calendar-cell" }) })
1638
+ ] })
1639
+ ] }) }) })
1640
+ ]
1641
+ }
1642
+ );
1575
1643
  }
1576
1644
 
1577
1645
  // src/components/forms/DateRangePicker.tsx