@orianatech/pire 1.5.0 → 1.6.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
@@ -584,6 +584,7 @@ var enMessages = {
584
584
  chartEmpty: "No data for this period",
585
585
  numPadClear: "Clear",
586
586
  numPadBackspace: "Remove last digit",
587
+ numPadDecimal: "Decimal separator",
587
588
  viewSwitcherName: "Saved views: {view}",
588
589
  viewSwitcherNameModified: "Saved views: {view}, modified",
589
590
  viewSwitcherModifiedMark: "\xB7 modified",
@@ -668,6 +669,7 @@ var esMessages = {
668
669
  chartEmpty: "Sin datos para este per\xEDodo",
669
670
  numPadClear: "Limpiar",
670
671
  numPadBackspace: "Borrar \xFAltimo d\xEDgito",
672
+ numPadDecimal: "Separador decimal",
671
673
  viewSwitcherName: "Vistas guardadas: {view}",
672
674
  viewSwitcherNameModified: "Vistas guardadas: {view}, modificada",
673
675
  viewSwitcherModifiedMark: "\xB7 modificada",
@@ -1700,10 +1702,14 @@ import {
1700
1702
  useLocale,
1701
1703
  NumberFieldStateContext
1702
1704
  } from "react-aria-components";
1703
- import { jsx as jsx26, jsxs as jsxs19 } from "react/jsx-runtime";
1705
+
1706
+ // src/components/utils/decimalSeparator.ts
1704
1707
  function decimalSeparatorFor(locale) {
1705
1708
  return new Intl.NumberFormat(locale).formatToParts(1.1).find((part) => part.type === "decimal")?.value ?? ".";
1706
1709
  }
1710
+
1711
+ // src/components/forms/NumberField.tsx
1712
+ import { jsx as jsx26, jsxs as jsxs19 } from "react/jsx-runtime";
1707
1713
  function typeIntoInput(el, text) {
1708
1714
  const start = el.selectionStart ?? el.value.length;
1709
1715
  const end = el.selectionEnd ?? start;
@@ -5031,6 +5037,7 @@ function EmptyState({
5031
5037
 
5032
5038
  // src/components/patterns/NumPad.tsx
5033
5039
  import * as React30 from "react";
5040
+ import { useLocale as useLocale2 } from "react-aria-components";
5034
5041
  import { jsx as jsx71, jsxs as jsxs61 } from "react/jsx-runtime";
5035
5042
  var BASE_KEYS = [
5036
5043
  { value: "7" },
@@ -5047,6 +5054,12 @@ var BASE_KEYS = [
5047
5054
  { value: "0" }
5048
5055
  ];
5049
5056
  var isInsertable = (value) => /^[0-9]+$/.test(value);
5057
+ function fittingDigits(digits, buffer, separator, maxFractionDigits) {
5058
+ const separatorAt = buffer.indexOf(separator);
5059
+ if (separatorAt === -1) return digits;
5060
+ const room = maxFractionDigits - (buffer.length - separatorAt - 1);
5061
+ return room <= 0 ? "" : digits.slice(0, room);
5062
+ }
5050
5063
  function useNumPadKeyboard(onKey, isDisabled, containerRef) {
5051
5064
  const handler = React30.useRef(onKey);
5052
5065
  handler.current = onKey;
@@ -5074,6 +5087,10 @@ function useNumPadKeyboard(onKey, isDisabled, containerRef) {
5074
5087
  handler.current("clear");
5075
5088
  return;
5076
5089
  }
5090
+ if (event.key === "," || event.key === ".") {
5091
+ handler.current("decimal");
5092
+ return;
5093
+ }
5077
5094
  };
5078
5095
  document.addEventListener("keydown", onKeyDown);
5079
5096
  return () => document.removeEventListener("keydown", onKeyDown);
@@ -5086,6 +5103,7 @@ function NumPad({
5086
5103
  onChange,
5087
5104
  extraKeys = [],
5088
5105
  onAction,
5106
+ maxFractionDigits,
5089
5107
  isDisabled,
5090
5108
  size = "md",
5091
5109
  className,
@@ -5093,6 +5111,9 @@ function NumPad({
5093
5111
  }) {
5094
5112
  const msg = usePireMessages();
5095
5113
  const containerRef = React30.useRef(null);
5114
+ const { locale } = useLocale2();
5115
+ const separator = decimalSeparatorFor(locale);
5116
+ const allowsDecimal = maxFractionDigits !== void 0 && maxFractionDigits > 0;
5096
5117
  const applyKey = React30.useCallback(
5097
5118
  (key) => {
5098
5119
  if (isDisabled) return;
@@ -5104,16 +5125,27 @@ function NumPad({
5104
5125
  onChange("");
5105
5126
  return;
5106
5127
  }
5128
+ if (key.value === "decimal") {
5129
+ if (!allowsDecimal || value.includes(separator)) return;
5130
+ onChange((value === "" ? "0" : value) + separator);
5131
+ return;
5132
+ }
5107
5133
  if (isInsertable(key.value)) {
5108
- onChange(value + key.value);
5134
+ onChange(
5135
+ value + (allowsDecimal ? fittingDigits(key.value, value, separator, maxFractionDigits) : key.value)
5136
+ );
5109
5137
  return;
5110
5138
  }
5111
5139
  onAction?.(key.value);
5112
5140
  },
5113
- [isDisabled, value, onChange, onAction]
5141
+ [isDisabled, value, onChange, onAction, allowsDecimal, separator, maxFractionDigits]
5114
5142
  );
5115
5143
  useNumPadKeyboard((keyValue) => applyKey({ value: keyValue }), isDisabled, containerRef);
5116
- const keys = [...BASE_KEYS, ...extraKeys];
5144
+ const keys = [
5145
+ ...BASE_KEYS,
5146
+ ...allowsDecimal ? [{ value: "decimal", label: separator }] : [],
5147
+ ...extraKeys
5148
+ ];
5117
5149
  return /* @__PURE__ */ jsxs61(
5118
5150
  "div",
5119
5151
  {
@@ -5125,7 +5157,7 @@ function NumPad({
5125
5157
  children: [
5126
5158
  target !== void 0 ? /* @__PURE__ */ jsx71("div", { className: "pire-numpad-target", role: "status", "aria-live": "polite", children: target }) : null,
5127
5159
  /* @__PURE__ */ jsx71("div", { className: "pire-numpad-grid", role: "group", "aria-label": ariaLabel, children: keys.map((key) => {
5128
- const accessibleLabel = key.value === "backspace" ? msg.numPadBackspace : key.value === "clear" ? msg.numPadClear : void 0;
5160
+ const accessibleLabel = key.value === "backspace" ? msg.numPadBackspace : key.value === "clear" ? msg.numPadClear : key.value === "decimal" ? msg.numPadDecimal : void 0;
5129
5161
  return /* @__PURE__ */ jsx71(
5130
5162
  Button,
5131
5163
  {
@@ -5134,6 +5166,7 @@ function NumPad({
5134
5166
  fullWidth: true,
5135
5167
  className: "pire-numpad-key",
5136
5168
  "data-span": key.span === 2 ? "2" : void 0,
5169
+ "data-key": key.value === "decimal" ? "decimal" : void 0,
5137
5170
  isDisabled,
5138
5171
  "aria-label": accessibleLabel,
5139
5172
  onPress: () => applyKey(key),