@ballistix.digital/react-components 9.10.1 → 9.11.1-rc-413.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
@@ -12,6 +12,7 @@ var $iA2ta$fortawesomereactfontawesome = require("@fortawesome/react-fontawesome
12
12
  var $iA2ta$floatinguireact = require("@floating-ui/react");
13
13
  var $iA2ta$headlessuireact = require("@headlessui/react");
14
14
  var $iA2ta$reactinputmask = require("@react-input/mask");
15
+ var $iA2ta$reactnumberformat = require("react-number-format");
15
16
  var $iA2ta$tanstackreacttable = require("@tanstack/react-table");
16
17
  var $iA2ta$reacttailwindcssselect = require("react-tailwindcss-select");
17
18
  var $iA2ta$xlsx = require("xlsx");
@@ -1361,6 +1362,7 @@ var $ccdca29d489f3200$export$2e2bcd8739ae039 = $ccdca29d489f3200$var$ProgressTra
1361
1362
 
1362
1363
 
1363
1364
 
1365
+
1364
1366
  const $3369f7d596d23d58$var$base = {
1365
1367
  foot: '',
1366
1368
  hint: 'text-gray-400 text-xs mt-1',
@@ -1650,7 +1652,7 @@ var $47f4a9343fdccb9b$export$2e2bcd8739ae039 = $47f4a9343fdccb9b$var$styles;
1650
1652
 
1651
1653
 
1652
1654
  const $c474e734ef48f77c$var$InputGroup = (props)=>{
1653
- const { name: name, htmlType: htmlType = 'text', label: label, hint: hint, description: description, placeholder: placeholder, leading: leading, trailing: trailing, required: required, value: value, mask: mask, min: min, max: max, step: step, maxLength: maxLength, rows: rows, error: error, type: type = 'normal', isDisabled: isDisabled, isRequired: isRequired = false, isTouched: isTouched = false, isSolo: isSolo = false, isOptionalLabelHidden: isOptionalLabelHidden = false, onChange: onChange, onClear: onClear, onBlur: onBlur, onClick: onClick, onKeyDown: onKeyDown, setRefOnLoad: setRefOnLoad, styles: stylesOverrides } = props;
1655
+ const { name: name, htmlType: htmlType = 'text', label: label, hint: hint, description: description, placeholder: placeholder, leading: leading, trailing: trailing, required: required, value: value, mask: mask, min: min, max: max, step: step, maxLength: maxLength, rows: rows, error: error, precision: precision, thousandSeparator: thousandSeparator, decimalSeparator: decimalSeparator, currency: currency, type: type = 'normal', isDisabled: isDisabled, isRequired: isRequired = false, isTouched: isTouched = false, isSolo: isSolo = false, isOptionalLabelHidden: isOptionalLabelHidden = false, onChange: onChange, onClear: onClear, onBlur: onBlur, onClick: onClick, onKeyDown: onKeyDown, setRefOnLoad: setRefOnLoad, styles: stylesOverrides } = props;
1654
1656
  const isValid = error === undefined;
1655
1657
  const maskRef = (0, $iA2ta$reactinputmask.useMask)({
1656
1658
  mask: mask?.mask,
@@ -1660,6 +1662,74 @@ const $c474e734ef48f77c$var$InputGroup = (props)=>{
1660
1662
  });
1661
1663
  const defaultRef = (0, $iA2ta$react.useRef)(null);
1662
1664
  const ref = mask ? maskRef : defaultRef;
1665
+ const isNumeric = htmlType === 'number' || htmlType === 'percent' || htmlType === 'currency';
1666
+ const numericValueRef = (0, $iA2ta$react.useRef)(null);
1667
+ const numericFormatProps = (0, $iA2ta$react.useMemo)(()=>{
1668
+ if (htmlType === 'percent') return {
1669
+ decimalScale: precision,
1670
+ suffix: '%'
1671
+ };
1672
+ if (htmlType === 'currency') {
1673
+ const resolvedDecimalSeparator = decimalSeparator ?? ',';
1674
+ return {
1675
+ decimalScale: precision ?? 2,
1676
+ fixedDecimalScale: true,
1677
+ thousandSeparator: thousandSeparator ?? '.',
1678
+ decimalSeparator: resolvedDecimalSeparator,
1679
+ // Numpad decimal keys are typically ".", regardless of locale. A literal "." can never be a
1680
+ // manually-typed thousand separator (grouping is auto-inserted), so it's safe to also accept
1681
+ // it as a decimal keystroke even when the configured decimal separator is something else.
1682
+ allowedDecimalSeparators: Array.from(new Set([
1683
+ resolvedDecimalSeparator,
1684
+ '.'
1685
+ ])),
1686
+ prefix: `${currency ?? "\u20AC"} `
1687
+ };
1688
+ }
1689
+ // htmlType === 'number'
1690
+ return {
1691
+ decimalScale: precision,
1692
+ thousandSeparator: thousandSeparator,
1693
+ allowNegative: min === undefined || Number(min) < 0
1694
+ };
1695
+ }, [
1696
+ htmlType,
1697
+ precision,
1698
+ thousandSeparator,
1699
+ decimalSeparator,
1700
+ currency,
1701
+ min
1702
+ ]);
1703
+ const handleNumericValueChange = (values, sourceInfo)=>{
1704
+ numericValueRef.current = values.floatValue ?? null;
1705
+ if (sourceInfo.source !== 'event') return;
1706
+ onChange(values.floatValue ?? null, values.formattedValue);
1707
+ };
1708
+ const handleNumericBlur = (e)=>{
1709
+ if (htmlType === 'number' && numericValueRef.current !== null) {
1710
+ let clamped = numericValueRef.current;
1711
+ if (min !== undefined) clamped = Math.max(Number(min), clamped);
1712
+ if (max !== undefined) clamped = Math.min(Number(max), clamped);
1713
+ if (clamped !== numericValueRef.current) {
1714
+ numericValueRef.current = clamped;
1715
+ onChange(clamped, String(clamped));
1716
+ }
1717
+ }
1718
+ onBlur(e);
1719
+ };
1720
+ const handleNumericKeyDown = (e)=>{
1721
+ if (htmlType === 'number' && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
1722
+ e.preventDefault();
1723
+ const stepValue = step !== undefined && step !== 'any' ? Number(step) : 1;
1724
+ const delta = stepValue * (e.key === 'ArrowUp' ? 1 : -1);
1725
+ let next = (numericValueRef.current ?? 0) + delta;
1726
+ if (min !== undefined) next = Math.max(Number(min), next);
1727
+ if (max !== undefined) next = Math.min(Number(max), next);
1728
+ numericValueRef.current = next;
1729
+ onChange(next, String(next));
1730
+ }
1731
+ onKeyDown?.(e);
1732
+ };
1663
1733
  const handleGenerateStyle = ()=>{
1664
1734
  const result = (0, $f0c671820c340322$export$e2d2075c69d9100d)((0, $47f4a9343fdccb9b$export$2e2bcd8739ae039).base);
1665
1735
  const keys = (0, $iA2ta$lodash.concat)((0, $27f90b0cff19565d$export$be5d6ab3c5b84767)((0, $47f4a9343fdccb9b$export$2e2bcd8739ae039).base), (0, $27f90b0cff19565d$export$be5d6ab3c5b84767)((0, $3369f7d596d23d58$export$2e2bcd8739ae039).base), (0, $27f90b0cff19565d$export$be5d6ab3c5b84767)((0, $65bb4d593718fcda$export$2e2bcd8739ae039).base));
@@ -1704,7 +1774,7 @@ const $c474e734ef48f77c$var$InputGroup = (props)=>{
1704
1774
  className: styles.leading,
1705
1775
  children: leading
1706
1776
  }),
1707
- !htmlType || htmlType !== 'area' && (0, $iA2ta$reactjsxruntime.jsxs)("div", {
1777
+ !htmlType || htmlType !== 'area' && !isNumeric && (0, $iA2ta$reactjsxruntime.jsxs)("div", {
1708
1778
  className: "flex items-center",
1709
1779
  children: [
1710
1780
  (0, $iA2ta$reactjsxruntime.jsx)("input", {
@@ -1745,6 +1815,27 @@ const $c474e734ef48f77c$var$InputGroup = (props)=>{
1745
1815
  })
1746
1816
  ]
1747
1817
  }),
1818
+ isNumeric && (0, $iA2ta$reactjsxruntime.jsx)("div", {
1819
+ className: "flex items-center",
1820
+ children: (0, $iA2ta$reactjsxruntime.jsx)((0, $iA2ta$reactnumberformat.NumericFormat), {
1821
+ getInputRef: ref,
1822
+ name: name,
1823
+ id: name,
1824
+ "data-cy": inputDataCy,
1825
+ className: styles.input,
1826
+ placeholder: placeholder,
1827
+ defaultValue: isSolo ? value : undefined,
1828
+ value: isSolo ? undefined : value,
1829
+ valueIsNumericString: true,
1830
+ inputMode: "decimal",
1831
+ disabled: isDisabled,
1832
+ onValueChange: handleNumericValueChange,
1833
+ onBlur: handleNumericBlur,
1834
+ onClick: onClick,
1835
+ onKeyDown: handleNumericKeyDown,
1836
+ ...numericFormatProps
1837
+ })
1838
+ }),
1748
1839
  htmlType === 'area' && (0, $iA2ta$reactjsxruntime.jsx)("textarea", {
1749
1840
  rows: rows,
1750
1841
  name: name,