dry-ux 1.81.0 → 1.83.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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { InputHTMLAttributes } from "react";
|
|
3
|
+
import { IEnhancedProps } from "./interface";
|
|
4
|
+
interface CurrencyInputProps extends InputHTMLAttributes<HTMLInputElement>, IEnhancedProps {
|
|
5
|
+
/** Show decimal places (default: true) */
|
|
6
|
+
decimal_places?: boolean;
|
|
7
|
+
/** Currency symbol (default: "$") */
|
|
8
|
+
currency?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const CurrencyInput: React.ForwardRefExoticComponent<CurrencyInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CurrencyInput = void 0;
|
|
15
|
+
const React = require("react");
|
|
16
|
+
const HTMLInputs_1 = require("./HTMLInputs");
|
|
17
|
+
const utilities_1 = require("../helpers/utilities");
|
|
18
|
+
const toRaw = (value) => {
|
|
19
|
+
if (value == null || value === "")
|
|
20
|
+
return "";
|
|
21
|
+
return String(value).replace(/[^0-9.\-]/g, "");
|
|
22
|
+
};
|
|
23
|
+
const formatDisplay = (raw, currency, decimal_places) => {
|
|
24
|
+
if (raw === "" || raw === "-")
|
|
25
|
+
return raw;
|
|
26
|
+
const num = parseFloat(raw);
|
|
27
|
+
if (isNaN(num))
|
|
28
|
+
return raw;
|
|
29
|
+
return currency + (0, utilities_1.formatDollar)(num, decimal_places);
|
|
30
|
+
};
|
|
31
|
+
exports.CurrencyInput = React.forwardRef((_a, ref) => {
|
|
32
|
+
var _b;
|
|
33
|
+
var { decimal_places = true, currency = "$", name, value, defaultValue, onChange, onFocus, onBlur } = _a, rest = __rest(_a, ["decimal_places", "currency", "name", "value", "defaultValue", "onChange", "onFocus", "onBlur"]);
|
|
34
|
+
const initialRaw = toRaw((_b = value !== null && value !== void 0 ? value : defaultValue) !== null && _b !== void 0 ? _b : "");
|
|
35
|
+
const [rawValue, setRawValue] = React.useState(initialRaw);
|
|
36
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
37
|
+
const isControlled = value !== undefined;
|
|
38
|
+
// Sync rawValue when controlled value changes
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
if (isControlled) {
|
|
41
|
+
setRawValue(toRaw(value));
|
|
42
|
+
}
|
|
43
|
+
}, [value]);
|
|
44
|
+
const displayValue = isFocused ? rawValue : formatDisplay(rawValue, currency, decimal_places);
|
|
45
|
+
const handleFocus = (e) => {
|
|
46
|
+
setIsFocused(true);
|
|
47
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
48
|
+
};
|
|
49
|
+
const handleBlur = (e) => {
|
|
50
|
+
setIsFocused(false);
|
|
51
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
52
|
+
};
|
|
53
|
+
const handleChange = (e) => {
|
|
54
|
+
const raw = toRaw(e.target.value);
|
|
55
|
+
setRawValue(raw);
|
|
56
|
+
if (onChange) {
|
|
57
|
+
// Provide the raw numeric value to the parent's onChange
|
|
58
|
+
const syntheticEvent = Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value: raw, name }) });
|
|
59
|
+
onChange(syntheticEvent);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return (React.createElement(React.Fragment, null,
|
|
63
|
+
React.createElement(HTMLInputs_1.Input, Object.assign({ ref: ref }, rest, { type: "text", value: displayValue, onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange })),
|
|
64
|
+
React.createElement("input", { type: "hidden", name: name, value: rawValue })));
|
|
65
|
+
});
|
|
@@ -92,7 +92,7 @@ export declare class Element {
|
|
|
92
92
|
* @param once Whether the event should only fire once.
|
|
93
93
|
* @returns A function to remove the event listener, or undefined if the element is not suitable for events.
|
|
94
94
|
*/
|
|
95
|
-
addEventListener(type: string, handler: (e:
|
|
95
|
+
addEventListener(type: string, handler: (e: any) => void, once?: boolean): () => void | undefined;
|
|
96
96
|
/**
|
|
97
97
|
* Adds a change event listener to the element.
|
|
98
98
|
* @param handler The event handler function.
|
|
@@ -106,21 +106,21 @@ export declare class Element {
|
|
|
106
106
|
* @param once Whether the event should only fire once.
|
|
107
107
|
* @returns A function to remove the event listener.
|
|
108
108
|
*/
|
|
109
|
-
click(handler: (e:
|
|
109
|
+
click(handler: (e: MouseEvent) => void, once?: boolean): () => void | undefined;
|
|
110
110
|
/**
|
|
111
111
|
* Adds a focus event listener to the element.
|
|
112
112
|
* @param handler The event handler function.
|
|
113
113
|
* @param once Whether the event should only fire once.
|
|
114
114
|
* @returns A function to remove the event listener.
|
|
115
115
|
*/
|
|
116
|
-
focus(handler: (e:
|
|
116
|
+
focus(handler: (e: FocusEvent) => void, once?: boolean): () => void | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* Adds a blur event listener to the element.
|
|
119
119
|
* @param handler The event handler function.
|
|
120
120
|
* @param once Whether the event should only fire once.
|
|
121
121
|
* @returns A function to remove the event listener.
|
|
122
122
|
*/
|
|
123
|
-
blur(handler: (e:
|
|
123
|
+
blur(handler: (e: FocusEvent) => void, once?: boolean): () => void | undefined;
|
|
124
124
|
/**
|
|
125
125
|
* Adds a keydown event listener to the element.
|
|
126
126
|
* @param handler The keyboard event handler function.
|
|
@@ -124,14 +124,11 @@ class Element {
|
|
|
124
124
|
* @returns A function to remove the event listener, or undefined if the element is not suitable for events.
|
|
125
125
|
*/
|
|
126
126
|
addEventListener(type, handler, once) {
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.nativeInput.addEventListener("change", handler, { once, signal: abortController.signal });
|
|
133
|
-
return abortController.abort;
|
|
134
|
-
}
|
|
127
|
+
if (!type)
|
|
128
|
+
return;
|
|
129
|
+
const abortController = new AbortController();
|
|
130
|
+
this.native.addEventListener(type, handler, { once, signal: abortController.signal });
|
|
131
|
+
return () => abortController.abort();
|
|
135
132
|
}
|
|
136
133
|
/**
|
|
137
134
|
* Adds a change event listener to the element.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export { Viewport } from "./ui-utils/ViewportDetect";
|
|
|
19
19
|
export * from "./enhanced-inputs/HTMLInputs";
|
|
20
20
|
export * from "./enhanced-inputs/interface";
|
|
21
21
|
export { Element, InputElement } from "./enhanced-inputs/Element";
|
|
22
|
+
export { CurrencyInput } from "./enhanced-inputs/CurrencyInput";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Element = exports.Viewport = exports.Validation = exports.RenderWhenVisible = exports.Spinner = exports.Loader = exports.ErrorScreen = exports.ErrorBoundary = exports.DajaxiceProxy = exports.unflatten = exports.flatten = exports.classSet = exports.DryUXProvider = exports.Money = exports.DryUXRenderer = exports.DryUXContext = exports.useDryUxContext = void 0;
|
|
17
|
+
exports.CurrencyInput = exports.Element = exports.Viewport = exports.Validation = exports.RenderWhenVisible = exports.Spinner = exports.Loader = exports.ErrorScreen = exports.ErrorBoundary = exports.DajaxiceProxy = exports.unflatten = exports.flatten = exports.classSet = exports.DryUXProvider = exports.Money = exports.DryUXRenderer = exports.DryUXContext = exports.useDryUxContext = void 0;
|
|
18
18
|
var UIUtilProvider_1 = require("./ui-utils/UIUtilProvider");
|
|
19
19
|
Object.defineProperty(exports, "useDryUxContext", { enumerable: true, get: function () { return UIUtilProvider_1.useUIUtilContext; } });
|
|
20
20
|
Object.defineProperty(exports, "DryUXContext", { enumerable: true, get: function () { return UIUtilProvider_1.UIUtilContext; } });
|
|
@@ -52,3 +52,5 @@ __exportStar(require("./enhanced-inputs/HTMLInputs"), exports);
|
|
|
52
52
|
__exportStar(require("./enhanced-inputs/interface"), exports);
|
|
53
53
|
var Element_1 = require("./enhanced-inputs/Element");
|
|
54
54
|
Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return Element_1.Element; } });
|
|
55
|
+
var CurrencyInput_1 = require("./enhanced-inputs/CurrencyInput");
|
|
56
|
+
Object.defineProperty(exports, "CurrencyInput", { enumerable: true, get: function () { return CurrencyInput_1.CurrencyInput; } });
|