@martinsura/ui 0.1.8 → 0.1.10
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.cjs +28 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -532,8 +532,18 @@ var NumberInput = ({
|
|
|
532
532
|
const resolvedErrors = props.errorName ? resolveError(props.errorName) : [];
|
|
533
533
|
const errorDisplay = props.error ?? props.customError ?? (resolvedErrors.length > 0 ? resolvedErrors.join(", ") : void 0);
|
|
534
534
|
const hasError = !!errorDisplay;
|
|
535
|
+
const [internalValue, setInternalValue] = react.useState(
|
|
536
|
+
props.value != null ? String(props.value) : ""
|
|
537
|
+
);
|
|
538
|
+
const isFocused = react.useRef(false);
|
|
539
|
+
react.useEffect(() => {
|
|
540
|
+
if (!isFocused.current) {
|
|
541
|
+
setInternalValue(props.value != null ? String(props.value) : "");
|
|
542
|
+
}
|
|
543
|
+
}, [props.value]);
|
|
535
544
|
const handleChange = (e) => {
|
|
536
545
|
const raw = e.target.value;
|
|
546
|
+
setInternalValue(raw);
|
|
537
547
|
if (raw === "" || raw === "-") {
|
|
538
548
|
props.onChange?.(null);
|
|
539
549
|
return;
|
|
@@ -543,6 +553,13 @@ var NumberInput = ({
|
|
|
543
553
|
props.onChange?.(num);
|
|
544
554
|
}
|
|
545
555
|
};
|
|
556
|
+
const handleFocus = () => {
|
|
557
|
+
isFocused.current = true;
|
|
558
|
+
};
|
|
559
|
+
const handleBlur = () => {
|
|
560
|
+
isFocused.current = false;
|
|
561
|
+
setInternalValue(props.value != null ? String(props.value) : "");
|
|
562
|
+
};
|
|
546
563
|
return /* @__PURE__ */ jsxRuntime.jsxs(InputField, { noMargin: props.noMargin, className: props.className, children: [
|
|
547
564
|
props.label && /* @__PURE__ */ jsxRuntime.jsx(
|
|
548
565
|
InputLabel,
|
|
@@ -558,11 +575,13 @@ var NumberInput = ({
|
|
|
558
575
|
{
|
|
559
576
|
type: "number",
|
|
560
577
|
placeholder: props.placeholder,
|
|
561
|
-
value:
|
|
578
|
+
value: internalValue,
|
|
562
579
|
disabled: props.disabled,
|
|
563
580
|
min: props.min,
|
|
564
581
|
max: props.max,
|
|
565
582
|
onChange: handleChange,
|
|
583
|
+
onFocus: handleFocus,
|
|
584
|
+
onBlur: handleBlur,
|
|
566
585
|
className: tailwindMerge.twMerge(
|
|
567
586
|
numberInputClass,
|
|
568
587
|
inputSizeClasses[size],
|
|
@@ -1660,6 +1679,12 @@ function useGrid(defaults, storageKey) {
|
|
|
1660
1679
|
};
|
|
1661
1680
|
return { ...state, onChange, apiQuery };
|
|
1662
1681
|
}
|
|
1682
|
+
function getNestedValue(obj, path) {
|
|
1683
|
+
return path.split(".").reduce((acc, key) => {
|
|
1684
|
+
if (acc == null || typeof acc !== "object") return void 0;
|
|
1685
|
+
return acc[key];
|
|
1686
|
+
}, obj);
|
|
1687
|
+
}
|
|
1663
1688
|
var columnTypeWidth2 = {
|
|
1664
1689
|
date: 100,
|
|
1665
1690
|
datetime: 130,
|
|
@@ -1872,7 +1897,7 @@ var Grid = (props) => {
|
|
|
1872
1897
|
}
|
|
1873
1898
|
),
|
|
1874
1899
|
props.columns.map((col, colIdx) => {
|
|
1875
|
-
const content = col.render ? col.render(item) : col.dataField ? formatCellValue(item
|
|
1900
|
+
const content = col.render ? col.render(item) : col.dataField ? formatCellValue(getNestedValue(item, col.dataField), col.type) : null;
|
|
1876
1901
|
const centeredContent = col.align === "center";
|
|
1877
1902
|
const rightAlignedContent = col.align === "right";
|
|
1878
1903
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5360,6 +5385,7 @@ exports.TreeSelectInput = TreeSelectInput;
|
|
|
5360
5385
|
exports.UploadInput = UploadInput;
|
|
5361
5386
|
exports.UploadProvider = UploadProvider;
|
|
5362
5387
|
exports.getIcon = getIcon;
|
|
5388
|
+
exports.getNestedValue = getNestedValue;
|
|
5363
5389
|
exports.initUI = initUI;
|
|
5364
5390
|
exports.notification = notification;
|
|
5365
5391
|
exports.registerIcons = registerIcons;
|