@rufous/ui 0.2.94 → 0.2.95

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/main.cjs CHANGED
@@ -1831,6 +1831,28 @@ var TextField = (0, import_react17.forwardRef)(({
1831
1831
  className
1832
1832
  ].filter(Boolean).join(" ");
1833
1833
  const internalRef = import_react17.default.useRef(null);
1834
+ const handleChange = (e) => {
1835
+ if (type === "number") {
1836
+ const raw = e.target.value;
1837
+ const inputMax = slotProps?.input?.max ?? props.max;
1838
+ const inputMaxLength = slotProps?.input?.maxLength ?? props.maxLength;
1839
+ if (inputMaxLength != null) {
1840
+ const digits = raw.replace(/[^0-9]/g, "");
1841
+ if (digits.length > Number(inputMaxLength)) return;
1842
+ }
1843
+ if (inputMax != null && raw !== "") {
1844
+ if (Number(raw) > Number(inputMax)) return;
1845
+ }
1846
+ const numericValue = raw === "" ? "" : Number(raw);
1847
+ const syntheticEvent = Object.assign({}, e, {
1848
+ target: Object.assign({}, e.target, { value: numericValue }),
1849
+ currentTarget: Object.assign({}, e.currentTarget, { value: numericValue })
1850
+ });
1851
+ onChange?.(syntheticEvent);
1852
+ return;
1853
+ }
1854
+ onChange?.(e);
1855
+ };
1834
1856
  const triggerChange = () => {
1835
1857
  if (internalRef.current) {
1836
1858
  const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
@@ -1894,14 +1916,14 @@ var TextField = (0, import_react17.forwardRef)(({
1894
1916
  name,
1895
1917
  id: inputId,
1896
1918
  value,
1897
- onChange,
1898
1919
  required,
1899
1920
  disabled,
1900
1921
  readOnly,
1901
1922
  step: type === "number" && numberVariant ? STEP_BY_VARIANT[numberVariant] : void 0,
1902
1923
  min: type === "number" && numberVariant ? MIN_BY_VARIANT[numberVariant] : void 0,
1903
1924
  ...slotProps?.input,
1904
- ...props
1925
+ ...props,
1926
+ onChange: handleChange
1905
1927
  }
1906
1928
  ), InputProps?.endAdornment && /* @__PURE__ */ import_react17.default.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, InputProps.endAdornment), type === "number" && !disabled && !readOnly && /* @__PURE__ */ import_react17.default.createElement("div", { className: "rf-text-field__number-controls" }, /* @__PURE__ */ import_react17.default.createElement("button", { type: "button", tabIndex: -1, onClick: handleIncrement, className: "rf-text-field__number-btn" }, /* @__PURE__ */ import_react17.default.createElement("svg", { width: "8", height: "5", viewBox: "0 0 8 5", fill: "currentColor" }, /* @__PURE__ */ import_react17.default.createElement("path", { d: "M4 0L8 5H0L4 0Z" }))), /* @__PURE__ */ import_react17.default.createElement("button", { type: "button", tabIndex: -1, onClick: handleDecrement, className: "rf-text-field__number-btn", style: { marginTop: 2 } }, /* @__PURE__ */ import_react17.default.createElement("svg", { width: "8", height: "5", viewBox: "0 0 8 5", fill: "currentColor" }, /* @__PURE__ */ import_react17.default.createElement("path", { d: "M4 5L0 0H8L4 5Z" })))), hasLabel && /* @__PURE__ */ import_react17.default.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ import_react17.default.createElement("span", { className: "rf-text-field__asterisk" }, "*")), variant === "outlined" && /* @__PURE__ */ import_react17.default.createElement("fieldset", { className: "rf-text-field__notch" }, hasLabel ? /* @__PURE__ */ import_react17.default.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ import_react17.default.createElement("span", null, label, " ", required ? "*" : "")) : /* @__PURE__ */ import_react17.default.createElement("legend", { className: "rf-text-field__legend--empty" }))), helperText && /* @__PURE__ */ import_react17.default.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
1907
1929
  });
package/dist/main.js CHANGED
@@ -1665,6 +1665,28 @@ var TextField = forwardRef3(({
1665
1665
  className
1666
1666
  ].filter(Boolean).join(" ");
1667
1667
  const internalRef = React68.useRef(null);
1668
+ const handleChange = (e) => {
1669
+ if (type === "number") {
1670
+ const raw = e.target.value;
1671
+ const inputMax = slotProps?.input?.max ?? props.max;
1672
+ const inputMaxLength = slotProps?.input?.maxLength ?? props.maxLength;
1673
+ if (inputMaxLength != null) {
1674
+ const digits = raw.replace(/[^0-9]/g, "");
1675
+ if (digits.length > Number(inputMaxLength)) return;
1676
+ }
1677
+ if (inputMax != null && raw !== "") {
1678
+ if (Number(raw) > Number(inputMax)) return;
1679
+ }
1680
+ const numericValue = raw === "" ? "" : Number(raw);
1681
+ const syntheticEvent = Object.assign({}, e, {
1682
+ target: Object.assign({}, e.target, { value: numericValue }),
1683
+ currentTarget: Object.assign({}, e.currentTarget, { value: numericValue })
1684
+ });
1685
+ onChange?.(syntheticEvent);
1686
+ return;
1687
+ }
1688
+ onChange?.(e);
1689
+ };
1668
1690
  const triggerChange = () => {
1669
1691
  if (internalRef.current) {
1670
1692
  const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
@@ -1728,14 +1750,14 @@ var TextField = forwardRef3(({
1728
1750
  name,
1729
1751
  id: inputId,
1730
1752
  value,
1731
- onChange,
1732
1753
  required,
1733
1754
  disabled,
1734
1755
  readOnly,
1735
1756
  step: type === "number" && numberVariant ? STEP_BY_VARIANT[numberVariant] : void 0,
1736
1757
  min: type === "number" && numberVariant ? MIN_BY_VARIANT[numberVariant] : void 0,
1737
1758
  ...slotProps?.input,
1738
- ...props
1759
+ ...props,
1760
+ onChange: handleChange
1739
1761
  }
1740
1762
  ), InputProps?.endAdornment && /* @__PURE__ */ React68.createElement("div", { className: "rf-text-field__adornment rf-text-field__adornment--end" }, InputProps.endAdornment), type === "number" && !disabled && !readOnly && /* @__PURE__ */ React68.createElement("div", { className: "rf-text-field__number-controls" }, /* @__PURE__ */ React68.createElement("button", { type: "button", tabIndex: -1, onClick: handleIncrement, className: "rf-text-field__number-btn" }, /* @__PURE__ */ React68.createElement("svg", { width: "8", height: "5", viewBox: "0 0 8 5", fill: "currentColor" }, /* @__PURE__ */ React68.createElement("path", { d: "M4 0L8 5H0L4 0Z" }))), /* @__PURE__ */ React68.createElement("button", { type: "button", tabIndex: -1, onClick: handleDecrement, className: "rf-text-field__number-btn", style: { marginTop: 2 } }, /* @__PURE__ */ React68.createElement("svg", { width: "8", height: "5", viewBox: "0 0 8 5", fill: "currentColor" }, /* @__PURE__ */ React68.createElement("path", { d: "M4 5L0 0H8L4 5Z" })))), hasLabel && /* @__PURE__ */ React68.createElement("label", { htmlFor: inputId, className: "rf-text-field__label" }, label, " ", required && /* @__PURE__ */ React68.createElement("span", { className: "rf-text-field__asterisk" }, "*")), variant === "outlined" && /* @__PURE__ */ React68.createElement("fieldset", { className: "rf-text-field__notch" }, hasLabel ? /* @__PURE__ */ React68.createElement("legend", { className: "rf-text-field__legend" }, /* @__PURE__ */ React68.createElement("span", null, label, " ", required ? "*" : "")) : /* @__PURE__ */ React68.createElement("legend", { className: "rf-text-field__legend--empty" }))), helperText && /* @__PURE__ */ React68.createElement("div", { className: "rf-text-field__helper-text" }, helperText));
1741
1763
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.2.94",
4
+ "version": "0.2.95",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",