@ioca/react 1.4.74 → 1.4.76
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/lib/cjs/components/button/toggle.js +11 -18
- package/lib/cjs/components/button/toggle.js.map +1 -1
- package/lib/cjs/components/checkbox/checkbox.js +5 -8
- package/lib/cjs/components/checkbox/checkbox.js.map +1 -1
- package/lib/cjs/components/checkbox/item.js +15 -16
- package/lib/cjs/components/checkbox/item.js.map +1 -1
- package/lib/cjs/components/collapse/collapse.js +11 -13
- package/lib/cjs/components/collapse/collapse.js.map +1 -1
- package/lib/cjs/components/form/field.js +16 -20
- package/lib/cjs/components/form/field.js.map +1 -1
- package/lib/cjs/components/input/input.js +21 -18
- package/lib/cjs/components/input/input.js.map +1 -1
- package/lib/cjs/components/input/number.js +65 -19
- package/lib/cjs/components/input/number.js.map +1 -1
- package/lib/cjs/components/input/range.js +10 -13
- package/lib/cjs/components/input/range.js.map +1 -1
- package/lib/cjs/components/input/textarea.js +4 -7
- package/lib/cjs/components/input/textarea.js.map +1 -1
- package/lib/cjs/components/picker/colors/footer.js +7 -10
- package/lib/cjs/components/picker/colors/footer.js.map +1 -1
- package/lib/cjs/components/picker/colors/index.js +23 -21
- package/lib/cjs/components/picker/colors/index.js.map +1 -1
- package/lib/cjs/components/picker/dates/index.js +9 -12
- package/lib/cjs/components/picker/dates/index.js.map +1 -1
- package/lib/cjs/components/picker/dates/panel.js +29 -35
- package/lib/cjs/components/picker/dates/panel.js.map +1 -1
- package/lib/cjs/components/picker/time/index.js +8 -12
- package/lib/cjs/components/picker/time/index.js.map +1 -1
- package/lib/cjs/components/picker/time/panel.js +38 -21
- package/lib/cjs/components/picker/time/panel.js.map +1 -1
- package/lib/cjs/components/popconfirm/popconfirm.js +1 -1
- package/lib/cjs/components/popconfirm/popconfirm.js.map +1 -1
- package/lib/cjs/components/popup/content.js +5 -9
- package/lib/cjs/components/popup/content.js.map +1 -1
- package/lib/cjs/components/popup/popup.js +388 -157
- package/lib/cjs/components/popup/popup.js.map +1 -1
- package/lib/cjs/components/radio/radio.js +4 -7
- package/lib/cjs/components/radio/radio.js.map +1 -1
- package/lib/cjs/components/select/select.js +19 -24
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/cjs/components/tabs/tabs.js +61 -54
- package/lib/cjs/components/tabs/tabs.js.map +1 -1
- package/lib/cjs/components/tree/tree.js +24 -26
- package/lib/cjs/components/tree/tree.js.map +1 -1
- package/lib/cjs/components/upload/upload.js +26 -33
- package/lib/cjs/components/upload/upload.js.map +1 -1
- package/lib/cjs/js/hooks.js +0 -4
- package/lib/cjs/js/hooks.js.map +1 -1
- package/lib/css/index.css +1 -1
- package/lib/css/index.css.map +1 -1
- package/lib/es/components/button/toggle.js +12 -19
- package/lib/es/components/button/toggle.js.map +1 -1
- package/lib/es/components/checkbox/checkbox.js +6 -9
- package/lib/es/components/checkbox/checkbox.js.map +1 -1
- package/lib/es/components/checkbox/item.js +16 -17
- package/lib/es/components/checkbox/item.js.map +1 -1
- package/lib/es/components/collapse/collapse.js +12 -14
- package/lib/es/components/collapse/collapse.js.map +1 -1
- package/lib/es/components/form/field.js +17 -21
- package/lib/es/components/form/field.js.map +1 -1
- package/lib/es/components/input/input.js +22 -19
- package/lib/es/components/input/input.js.map +1 -1
- package/lib/es/components/input/number.js +67 -21
- package/lib/es/components/input/number.js.map +1 -1
- package/lib/es/components/input/range.js +11 -14
- package/lib/es/components/input/range.js.map +1 -1
- package/lib/es/components/input/textarea.js +5 -8
- package/lib/es/components/input/textarea.js.map +1 -1
- package/lib/es/components/picker/colors/footer.js +8 -11
- package/lib/es/components/picker/colors/footer.js.map +1 -1
- package/lib/es/components/picker/colors/index.js +24 -22
- package/lib/es/components/picker/colors/index.js.map +1 -1
- package/lib/es/components/picker/dates/index.js +9 -12
- package/lib/es/components/picker/dates/index.js.map +1 -1
- package/lib/es/components/picker/dates/panel.js +30 -36
- package/lib/es/components/picker/dates/panel.js.map +1 -1
- package/lib/es/components/picker/time/index.js +8 -12
- package/lib/es/components/picker/time/index.js.map +1 -1
- package/lib/es/components/picker/time/panel.js +39 -22
- package/lib/es/components/picker/time/panel.js.map +1 -1
- package/lib/es/components/popconfirm/popconfirm.js +1 -1
- package/lib/es/components/popconfirm/popconfirm.js.map +1 -1
- package/lib/es/components/popup/content.js +6 -10
- package/lib/es/components/popup/content.js.map +1 -1
- package/lib/es/components/popup/popup.js +390 -159
- package/lib/es/components/popup/popup.js.map +1 -1
- package/lib/es/components/radio/radio.js +5 -8
- package/lib/es/components/radio/radio.js.map +1 -1
- package/lib/es/components/select/select.js +19 -24
- package/lib/es/components/select/select.js.map +1 -1
- package/lib/es/components/tabs/tabs.js +63 -56
- package/lib/es/components/tabs/tabs.js.map +1 -1
- package/lib/es/components/tree/tree.js +25 -27
- package/lib/es/components/tree/tree.js.map +1 -1
- package/lib/es/components/upload/upload.js +27 -34
- package/lib/es/components/upload/upload.js.map +1 -1
- package/lib/es/js/hooks.js +2 -5
- package/lib/es/js/hooks.js.map +1 -1
- package/lib/index.js +803 -541
- package/lib/types/components/popup/type.d.ts +0 -4
- package/package.json +100 -99
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var material = require('@ricons/material');
|
|
7
|
-
var hooks = require('../../js/hooks.js');
|
|
8
7
|
var classNames = require('classnames');
|
|
9
8
|
var react = require('react');
|
|
10
9
|
var utils = require('../../js/utils.js');
|
|
@@ -17,11 +16,33 @@ var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);
|
|
|
17
16
|
|
|
18
17
|
const Number = (props) => {
|
|
19
18
|
const { ref, label, name, value = "", labelInline, step = 1, min = -Infinity, max = Infinity, thousand, precision, type, className, width, status = "normal", append, border, prepend, disabled, message, tip, hideControl, showMax, style, onChange, onEnter, onInput, onBlur, ...restProps } = props;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const [inputValue, setInputValue] = react.useState(value === undefined || value === null ? "" : String(value));
|
|
20
|
+
const formatOut = (num) => {
|
|
21
|
+
const v = utils.clamp(num, min, max);
|
|
22
|
+
if (precision !== undefined)
|
|
23
|
+
return utils.formatNumber(v, { precision, thousand });
|
|
24
|
+
const s = String(v);
|
|
25
|
+
if (!thousand)
|
|
26
|
+
return s;
|
|
27
|
+
const negative = s.startsWith("-");
|
|
28
|
+
const body = negative ? s.slice(1) : s;
|
|
29
|
+
const [integer, decimal] = body.split(".");
|
|
30
|
+
const withThousand = integer.replace(/\B(?=(\d{3})+(?!\d))/g, thousand);
|
|
31
|
+
return decimal
|
|
32
|
+
? `${negative ? "-" : ""}${withThousand}.${decimal}`
|
|
33
|
+
: `${negative ? "-" : ""}${withThousand}`;
|
|
34
|
+
};
|
|
35
|
+
const sanitizeNumberInput = (raw) => {
|
|
36
|
+
const hasMinus = raw.startsWith("-");
|
|
37
|
+
let v = raw.replace(/[^\d.]/g, "");
|
|
38
|
+
if (hasMinus)
|
|
39
|
+
v = `-${v}`;
|
|
40
|
+
const parts = v.split(".");
|
|
41
|
+
if (parts.length > 1) {
|
|
42
|
+
v = `${parts.shift()}.${parts.join("")}`;
|
|
43
|
+
}
|
|
44
|
+
return v;
|
|
45
|
+
};
|
|
25
46
|
const formatInputValue = (v) => {
|
|
26
47
|
if (!v)
|
|
27
48
|
return "";
|
|
@@ -33,32 +54,57 @@ const Number = (props) => {
|
|
|
33
54
|
};
|
|
34
55
|
const handleChange = (e) => {
|
|
35
56
|
const { value } = e.target;
|
|
36
|
-
const v = formatInputValue(value
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
const v = sanitizeNumberInput(formatInputValue(value));
|
|
58
|
+
const isIntermediate = v === "" || v === "-" || v === "." || v === "-." || v.endsWith(".");
|
|
59
|
+
setInputValue(v);
|
|
60
|
+
if (isIntermediate)
|
|
61
|
+
return;
|
|
62
|
+
const num = parseFloat(v);
|
|
63
|
+
if (globalThis.Number.isNaN(num))
|
|
64
|
+
return;
|
|
65
|
+
onChange?.(utils.clamp(num, min, max), e);
|
|
66
|
+
if (precision !== undefined)
|
|
67
|
+
setInputValue(formatOut(num));
|
|
40
68
|
};
|
|
41
69
|
const handleOperate = (param) => {
|
|
42
|
-
const value = parseFloat(formatInputValue(
|
|
43
|
-
const result =
|
|
44
|
-
|
|
45
|
-
onChange?.(result);
|
|
70
|
+
const value = parseFloat(formatInputValue(inputValue)) || 0; // 确保值为数字,默认值为 0
|
|
71
|
+
const result = value + param;
|
|
72
|
+
setInputValue(formatOut(result));
|
|
73
|
+
onChange?.(utils.clamp(result, min, max));
|
|
46
74
|
};
|
|
47
75
|
const handleMax = () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
setInputValue(formatOut(max));
|
|
77
|
+
onChange?.(utils.clamp(max, min, max));
|
|
78
|
+
};
|
|
79
|
+
const handleBlur = (e) => {
|
|
80
|
+
onBlur?.(e);
|
|
81
|
+
const v = sanitizeNumberInput(formatInputValue(inputValue));
|
|
82
|
+
if (!v || v === "-" || v === "." || v === "-.") {
|
|
83
|
+
setInputValue("");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const num = parseFloat(v);
|
|
87
|
+
if (globalThis.Number.isNaN(num))
|
|
88
|
+
return;
|
|
89
|
+
const numValue = utils.clamp(num, min, max);
|
|
90
|
+
setInputValue(formatOut(numValue));
|
|
91
|
+
onChange?.(numValue, e);
|
|
51
92
|
};
|
|
52
93
|
react.useEffect(() => {
|
|
53
|
-
|
|
94
|
+
setInputValue(value === undefined || value === null ? "" : String(value));
|
|
54
95
|
}, [value]);
|
|
55
96
|
const inputProps = {
|
|
56
97
|
ref,
|
|
57
98
|
name,
|
|
58
99
|
disabled,
|
|
59
|
-
value:
|
|
100
|
+
value: inputValue,
|
|
60
101
|
className: "i-input i-input-number",
|
|
61
102
|
onChange: handleChange,
|
|
103
|
+
onKeyDown: (e) => {
|
|
104
|
+
e.code === "Enter" && onEnter?.(e);
|
|
105
|
+
},
|
|
106
|
+
onInput,
|
|
107
|
+
onBlur: handleBlur,
|
|
62
108
|
...restProps,
|
|
63
109
|
};
|
|
64
110
|
return (jsxRuntime.jsx(container.default, { label: label, labelInline: labelInline, className: className, style: { width, ...style }, tip: message ?? tip, status: status, children: jsxRuntime.jsxs("div", { className: classNames__default("i-input-item", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sources":["../../../../packages/components/input/number.tsx"],"sourcesContent":["import {\n\tKeyboardDoubleArrowUpRound,\n\tMinusRound,\n\tPlusRound,\n} from \"@ricons/material\";\nimport { useReactive } from \"@p/js/hooks\";\nimport classNames from \"classnames\";\nimport { ChangeEvent, useEffect } from \"react\";\nimport \"../../css/input.css\";\nimport { clamp, formatNumber } from \"../../js/utils\";\nimport Helpericon from \"../utils/helpericon\";\nimport InputContainer from \"./container\";\nimport type { IInputNumber } from \"./type\";\n\nconst Number = (props: IInputNumber) => {\n\tconst {\n\t\tref,\n\t\tlabel,\n\t\tname,\n\t\tvalue = \"\",\n\t\tlabelInline,\n\t\tstep = 1,\n\t\tmin = -Infinity,\n\t\tmax = Infinity,\n\t\tthousand,\n\t\tprecision,\n\t\ttype,\n\t\tclassName,\n\t\twidth,\n\t\tstatus = \"normal\",\n\t\tappend,\n\t\tborder,\n\t\tprepend,\n\t\tdisabled,\n\t\tmessage,\n\t\ttip,\n\t\thideControl,\n\t\tshowMax,\n\t\tstyle,\n\t\tonChange,\n\t\tonEnter,\n\t\tonInput,\n\t\tonBlur,\n\t\t...restProps\n\t} = props;\n\n\tconst state = useReactive({\n\t\tvalue,\n\t});\n\n\tconst getRangeNumber = (v: number) => clamp(v, min, max);\n\n\tconst getFormatNumber = (v: number) =>\n\t\tformatNumber(v, { precision, thousand });\n\n\tconst formatInputValue = (v?: string | number) => {\n\t\tif (!v) return \"\";\n\t\tif (typeof v === \"number\") return v.toString();\n\t\tif (!thousand) return v;\n\n\t\treturn v.split(thousand).join(\"\");\n\t};\n\n\tconst handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n\t\tconst { value } = e.target;\n\t\tconst v = formatInputValue(value.replace(/[^\\d\\.-]/g, \"\")); // 保留负号和小数点\n\t\tconst numValue = clamp(+v, min, max); // 确保值在范围内\n\n\t\tstate.value = getFormatNumber(numValue); // 修复 thousand 格式化\n\t\tonChange?.(numValue, e);\n\t};\n\n\tconst handleOperate = (param: number) => {\n\t\tconst value = parseFloat(formatInputValue(state.value)) || 0; // 确保值为数字,默认值为 0\n\t\tconst result = getRangeNumber(value + param);\n\n\t\tstate.value = getFormatNumber(result);\n\n\t\tonChange?.(result);\n\t};\n\n\tconst handleMax = () => {\n\t\tconst result = getRangeNumber(max);\n\t\tstate.value = getFormatNumber(result);\n\t\tonChange?.(result);\n\t};\n\n\tuseEffect(() => {\n\t\tstate.value = value;\n\t}, [value]);\n\n\tconst inputProps = {\n\t\tref,\n\t\tname,\n\t\tdisabled,\n\t\tvalue: state.value,\n\t\tclassName: \"i-input i-input-number\",\n\t\tonChange: handleChange,\n\t\t...restProps,\n\t};\n\n\treturn (\n\t\t<InputContainer\n\t\t\tlabel={label}\n\t\t\tlabelInline={labelInline}\n\t\t\tclassName={className}\n\t\t\tstyle={{ width, ...style }}\n\t\t\ttip={message ?? tip}\n\t\t\tstatus={status}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-input-item\", {\n\t\t\t\t\t[`i-input-${status}`]: status !== \"normal\",\n\t\t\t\t\t\"i-input-borderless\": !border,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{prepend && <div className='i-input-prepend'>{prepend}</div>}\n\n\t\t\t\t{!hideControl && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<MinusRound />}\n\t\t\t\t\t\tonClick={() => handleOperate(-step)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t<input {...inputProps} />\n\n\t\t\t\t{!hideControl && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<PlusRound />}\n\t\t\t\t\t\tonClick={() => handleOperate(step)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t{showMax && max && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<KeyboardDoubleArrowUpRound />}\n\t\t\t\t\t\tonClick={handleMax}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t{append && <div className='i-input-append'>{append}</div>}\n\t\t\t</div>\n\t\t</InputContainer>\n\t);\n};\n\nexport default Number;\n"],"names":["useReactive","clamp","formatNumber","useEffect","_jsx","InputContainer","_jsxs","classNames","Helpericon","MinusRound","PlusRound","KeyboardDoubleArrowUpRound"],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,MAAM,GAAG,CAAC,KAAmB,KAAI;AACtC,IAAA,MAAM,EACL,GAAG,EACH,KAAK,EACL,IAAI,EACJ,KAAK,GAAG,EAAE,EACV,WAAW,EACX,IAAI,GAAG,CAAC,EACR,GAAG,GAAG,CAAC,QAAQ,EACf,GAAG,GAAG,QAAQ,EACd,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,GAAG,QAAQ,EACjB,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,EACH,WAAW,EACX,OAAO,EACP,KAAK,EACL,QAAQ,EACR,OAAO,EACP,OAAO,EACP,MAAM,EACN,GAAG,SAAS,EACZ,GAAG,KAAK;IAET,MAAM,KAAK,GAAGA,iBAAW,CAAC;QACzB,KAAK;AACL,KAAA,CAAC;AAEF,IAAA,MAAM,cAAc,GAAG,CAAC,CAAS,KAAKC,WAAK,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;AAExD,IAAA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,EAEDL,cAAA,CAAA,OAAA,EAAA,EAAA,GAAW,UAAU,EAAA,CAAI,EAExB,CAAC,WAAW,IAAI,CAAC,QAAQ,KACzBA,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACM,kBAAS,EAAA,EAAA,CAAG,EACnB,OAAO,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAAA,CACjC,CACF,EAEA,OAAO,IAAI,GAAG,IAAI,CAAC,QAAQ,KAC3BN,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACO,mCAA0B,EAAA,EAAA,CAAG,EACpC,OAAO,EAAE,SAAS,EAAA,CACjB,CACF,EAEA,MAAM,IAAIP,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,gBAAgB,EAAA,QAAA,EAAE,MAAM,EAAA,CAAO,CAAA,EAAA,CACpD,EAAA,CACU;AAEnB;;;;"}
|
|
1
|
+
{"version":3,"file":"number.js","sources":["../../../../packages/components/input/number.tsx"],"sourcesContent":["import {\n\tKeyboardDoubleArrowUpRound,\n\tMinusRound,\n\tPlusRound,\n} from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport {\n\tChangeEvent,\n\tuseEffect,\n\tuseState,\n\ttype FocusEvent,\n\ttype KeyboardEvent,\n} from \"react\";\nimport \"../../css/input.css\";\nimport { clamp, formatNumber } from \"../../js/utils\";\nimport Helpericon from \"../utils/helpericon\";\nimport InputContainer from \"./container\";\nimport type { IInputNumber } from \"./type\";\n\nconst Number = (props: IInputNumber) => {\n\tconst {\n\t\tref,\n\t\tlabel,\n\t\tname,\n\t\tvalue = \"\",\n\t\tlabelInline,\n\t\tstep = 1,\n\t\tmin = -Infinity,\n\t\tmax = Infinity,\n\t\tthousand,\n\t\tprecision,\n\t\ttype,\n\t\tclassName,\n\t\twidth,\n\t\tstatus = \"normal\",\n\t\tappend,\n\t\tborder,\n\t\tprepend,\n\t\tdisabled,\n\t\tmessage,\n\t\ttip,\n\t\thideControl,\n\t\tshowMax,\n\t\tstyle,\n\t\tonChange,\n\t\tonEnter,\n\t\tonInput,\n\t\tonBlur,\n\t\t...restProps\n\t} = props;\n\n\tconst [inputValue, setInputValue] = useState<string>(\n\t\tvalue === undefined || value === null ? \"\" : String(value),\n\t);\n\n\tconst formatOut = (num: number) => {\n\t\tconst v = clamp(num, min, max);\n\t\tif (precision !== undefined)\n\t\t\treturn formatNumber(v, { precision, thousand });\n\t\tconst s = String(v);\n\t\tif (!thousand) return s;\n\t\tconst negative = s.startsWith(\"-\");\n\t\tconst body = negative ? s.slice(1) : s;\n\t\tconst [integer, decimal] = body.split(\".\");\n\t\tconst withThousand = integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousand);\n\t\treturn decimal\n\t\t\t? `${negative ? \"-\" : \"\"}${withThousand}.${decimal}`\n\t\t\t: `${negative ? \"-\" : \"\"}${withThousand}`;\n\t};\n\n\tconst sanitizeNumberInput = (raw: string) => {\n\t\tconst hasMinus = raw.startsWith(\"-\");\n\t\tlet v = raw.replace(/[^\\d.]/g, \"\");\n\t\tif (hasMinus) v = `-${v}`;\n\n\t\tconst parts = v.split(\".\");\n\t\tif (parts.length > 1) {\n\t\t\tv = `${parts.shift()}.${parts.join(\"\")}`;\n\t\t}\n\n\t\treturn v;\n\t};\n\n\tconst formatInputValue = (v?: string | number) => {\n\t\tif (!v) return \"\";\n\t\tif (typeof v === \"number\") return v.toString();\n\t\tif (!thousand) return v;\n\n\t\treturn v.split(thousand).join(\"\");\n\t};\n\n\tconst handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n\t\tconst { value } = e.target;\n\t\tconst v = sanitizeNumberInput(formatInputValue(value));\n\t\tconst isIntermediate =\n\t\t\tv === \"\" || v === \"-\" || v === \".\" || v === \"-.\" || v.endsWith(\".\");\n\n\t\tsetInputValue(v);\n\t\tif (isIntermediate) return;\n\n\t\tconst num = parseFloat(v);\n\t\tif (globalThis.Number.isNaN(num)) return;\n\n\t\tonChange?.(clamp(num, min, max), e);\n\t\tif (precision !== undefined) setInputValue(formatOut(num));\n\t};\n\n\tconst handleOperate = (param: number) => {\n\t\tconst value = parseFloat(formatInputValue(inputValue)) || 0; // 确保值为数字,默认值为 0\n\t\tconst result = value + param;\n\t\tsetInputValue(formatOut(result));\n\t\tonChange?.(clamp(result, min, max));\n\t};\n\n\tconst handleMax = () => {\n\t\tsetInputValue(formatOut(max));\n\t\tonChange?.(clamp(max, min, max));\n\t};\n\n\tconst handleBlur = (e: FocusEvent<HTMLInputElement>) => {\n\t\tonBlur?.(e);\n\n\t\tconst v = sanitizeNumberInput(formatInputValue(inputValue));\n\t\tif (!v || v === \"-\" || v === \".\" || v === \"-.\") {\n\t\t\tsetInputValue(\"\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst num = parseFloat(v);\n\t\tif (globalThis.Number.isNaN(num)) return;\n\n\t\tconst numValue = clamp(num, min, max);\n\t\tsetInputValue(formatOut(numValue));\n\t\tonChange?.(numValue, e);\n\t};\n\n\tuseEffect(() => {\n\t\tsetInputValue(\n\t\t\tvalue === undefined || value === null ? \"\" : String(value),\n\t\t);\n\t}, [value]);\n\n\tconst inputProps = {\n\t\tref,\n\t\tname,\n\t\tdisabled,\n\t\tvalue: inputValue,\n\t\tclassName: \"i-input i-input-number\",\n\t\tonChange: handleChange,\n\t\tonKeyDown: (e: KeyboardEvent<HTMLInputElement>) => {\n\t\t\te.code === \"Enter\" && onEnter?.(e);\n\t\t},\n\t\tonInput,\n\t\tonBlur: handleBlur,\n\t\t...restProps,\n\t};\n\n\treturn (\n\t\t<InputContainer\n\t\t\tlabel={label}\n\t\t\tlabelInline={labelInline}\n\t\t\tclassName={className}\n\t\t\tstyle={{ width, ...style }}\n\t\t\ttip={message ?? tip}\n\t\t\tstatus={status}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-input-item\", {\n\t\t\t\t\t[`i-input-${status}`]: status !== \"normal\",\n\t\t\t\t\t\"i-input-borderless\": !border,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{prepend && <div className='i-input-prepend'>{prepend}</div>}\n\n\t\t\t\t{!hideControl && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<MinusRound />}\n\t\t\t\t\t\tonClick={() => handleOperate(-step)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t<input {...inputProps} />\n\n\t\t\t\t{!hideControl && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<PlusRound />}\n\t\t\t\t\t\tonClick={() => handleOperate(step)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t{showMax && max && !disabled && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<KeyboardDoubleArrowUpRound />}\n\t\t\t\t\t\tonClick={handleMax}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t{append && <div className='i-input-append'>{append}</div>}\n\t\t\t</div>\n\t\t</InputContainer>\n\t);\n};\n\nexport default Number;\n"],"names":["useState","clamp","formatNumber","useEffect","_jsx","InputContainer","_jsxs","classNames","Helpericon","MinusRound","PlusRound","KeyboardDoubleArrowUpRound"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAM,MAAM,GAAG,CAAC,KAAmB,KAAI;AACtC,IAAA,MAAM,EACL,GAAG,EACH,KAAK,EACL,IAAI,EACJ,KAAK,GAAG,EAAE,EACV,WAAW,EACX,IAAI,GAAG,CAAC,EACR,GAAG,GAAG,CAAC,QAAQ,EACf,GAAG,GAAG,QAAQ,EACd,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,GAAG,QAAQ,EACjB,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,EACH,WAAW,EACX,O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AA,EAAE,OAAO,EAAA,CAAO,EAE3D,CAAC,WAAW,IAAI,CAAC,QAAQ,KACzBA,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACK,mBAAU,KAAG,EACpB,OAAO,EAAE,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,EAAA,CAClC,CACF,EAEDL,cAAA,CAAA,OAAA,EAAA,EAAA,GAAW,UAAU,EAAA,CAAI,EAExB,CAAC,WAAW,IAAI,CAAC,QAAQ,KACzBA,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACM,kBAAS,EAAA,EAAA,CAAG,EACnB,OAAO,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAAA,CACjC,CACF,EAEA,OAAO,IAAI,GAAG,IAAI,CAAC,QAAQ,KAC3BN,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACO,mCAA0B,EAAA,EAAA,CAAG,EACpC,OAAO,EAAE,SAAS,EAAA,CACjB,CACF,EAEA,MAAM,IAAIP,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,gBAAgB,EAAA,QAAA,EAAE,MAAM,EAAA,CAAO,CAAA,EAAA,CACpD,EAAA,CACU;AAEnB;;;;"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var material = require('@ricons/material');
|
|
7
|
-
var hooks = require('../../js/hooks.js');
|
|
8
7
|
var classNames = require('classnames');
|
|
9
8
|
var react = require('react');
|
|
10
9
|
var utils = require('../../js/utils.js');
|
|
@@ -17,9 +16,7 @@ var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);
|
|
|
17
16
|
|
|
18
17
|
const Range = (props) => {
|
|
19
18
|
const { label, name, value, labelInline, min = -Infinity, max = Infinity, type, className, status = "normal", message, tip, append, prepend, step = 1, width, thousand, precision, hideControl, placeholder, border, autoSwitch, onChange, onBlur, style, ...restProps } = props;
|
|
20
|
-
const
|
|
21
|
-
value,
|
|
22
|
-
});
|
|
19
|
+
const [rangeValue, setRangeValue] = react.useState(value);
|
|
23
20
|
const getRangeNumber = (v) => utils.clamp(v, min, max);
|
|
24
21
|
const getFormatNumber = (v) => utils.formatNumber(v, { precision, thousand });
|
|
25
22
|
const formatInputValue = (v) => {
|
|
@@ -32,31 +29,31 @@ const Range = (props) => {
|
|
|
32
29
|
const handleChange = (e, i) => {
|
|
33
30
|
const { value } = e.target;
|
|
34
31
|
const v = formatInputValue(value.replace(/[^\d\.-]/g, ""));
|
|
35
|
-
const range = Array.isArray(
|
|
32
|
+
const range = Array.isArray(rangeValue) ? [...rangeValue] : [];
|
|
36
33
|
range[i] = v;
|
|
37
|
-
|
|
34
|
+
setRangeValue(range);
|
|
38
35
|
onChange?.(range, e);
|
|
39
36
|
};
|
|
40
37
|
const handleOperate = (e, param, i) => {
|
|
41
38
|
e.preventDefault();
|
|
42
39
|
e.stopPropagation();
|
|
43
|
-
const range = Array.isArray(
|
|
40
|
+
const range = Array.isArray(rangeValue) ? [...rangeValue] : [];
|
|
44
41
|
const value = formatInputValue(range[i]) ?? 0;
|
|
45
42
|
const result = getRangeNumber(+value + param);
|
|
46
43
|
range[i] = getFormatNumber(result);
|
|
47
|
-
|
|
44
|
+
setRangeValue(range);
|
|
48
45
|
onChange?.(range, e);
|
|
49
46
|
};
|
|
50
47
|
const handleSwitch = (e) => {
|
|
51
48
|
e?.preventDefault();
|
|
52
49
|
e?.stopPropagation();
|
|
53
|
-
const range =
|
|
50
|
+
const range = Array.isArray(rangeValue) ? [...rangeValue] : [];
|
|
54
51
|
[range[0], range[1]] = [range[1], range[0]];
|
|
55
|
-
|
|
52
|
+
setRangeValue(range);
|
|
56
53
|
onChange?.(range);
|
|
57
54
|
};
|
|
58
55
|
react.useEffect(() => {
|
|
59
|
-
|
|
56
|
+
setRangeValue(value);
|
|
60
57
|
}, [value]);
|
|
61
58
|
const inputProps = {
|
|
62
59
|
name,
|
|
@@ -66,7 +63,7 @@ const Range = (props) => {
|
|
|
66
63
|
const handleBlur = () => {
|
|
67
64
|
if (!autoSwitch)
|
|
68
65
|
return;
|
|
69
|
-
const range = Array.isArray(
|
|
66
|
+
const range = Array.isArray(rangeValue) ? rangeValue : [];
|
|
70
67
|
if (range.length < 2)
|
|
71
68
|
return;
|
|
72
69
|
const [left, right] = range.map(Number);
|
|
@@ -77,7 +74,7 @@ const Range = (props) => {
|
|
|
77
74
|
return (jsxRuntime.jsx(container.default, { label: label, labelInline: labelInline, className: className, style: { width, ...style }, tip: message ?? tip, status: status, children: jsxRuntime.jsxs("div", { className: classNames__default("i-input-item", {
|
|
78
75
|
[`i-input-${status}`]: status !== "normal",
|
|
79
76
|
"i-input-borderless": !border,
|
|
80
|
-
}), children: [prepend && jsxRuntime.jsx("div", { className: 'i-input-prepend', children: prepend }), !hideControl && (jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.MinusRound, {}), onClick: (e) => handleOperate(e, -step, 0) })), jsxRuntime.jsx("input", { value:
|
|
77
|
+
}), children: [prepend && jsxRuntime.jsx("div", { className: 'i-input-prepend', children: prepend }), !hideControl && (jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.MinusRound, {}), onClick: (e) => handleOperate(e, -step, 0) })), jsxRuntime.jsx("input", { value: rangeValue?.[0] || "", placeholder: placeholder?.[0], ...inputProps, onBlur: handleBlur, onChange: (e) => handleChange(e, 0) }), !hideControl && (jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.PlusRound, {}), onClick: (e) => handleOperate(e, step, 0) })), jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.SyncAltRound, {}), style: { margin: 0 }, onClick: handleSwitch }), !hideControl && (jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.MinusRound, {}), onClick: (e) => handleOperate(e, -step, 1) })), jsxRuntime.jsx("input", { value: rangeValue?.[1] || "", placeholder: placeholder?.[1], ...inputProps, onBlur: handleBlur, onChange: (e) => handleChange(e, 1) }), !hideControl && (jsxRuntime.jsx(helpericon.default, { active: true, icon: jsxRuntime.jsx(material.PlusRound, {}), onClick: (e) => handleOperate(e, step, 1) })), append && jsxRuntime.jsx("div", { className: 'i-input-append', children: append })] }) }));
|
|
81
78
|
};
|
|
82
79
|
|
|
83
80
|
exports.default = Range;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","sources":["../../../../packages/components/input/range.tsx"],"sourcesContent":["import { MinusRound, PlusRound, SyncAltRound } from \"@ricons/material\";\nimport
|
|
1
|
+
{"version":3,"file":"range.js","sources":["../../../../packages/components/input/range.tsx"],"sourcesContent":["import { MinusRound, PlusRound, SyncAltRound } from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport { ChangeEvent, MouseEvent, useEffect, useState } from \"react\";\nimport \"../../css/input.css\";\nimport { clamp, formatNumber } from \"../../js/utils\";\nimport Helpericon from \"../utils/helpericon\";\nimport InputContainer from \"./container\";\nimport type { IInputRange } from \"./type\";\n\nconst Range = (props: IInputRange) => {\n\tconst {\n\t\tlabel,\n\t\tname,\n\t\tvalue,\n\t\tlabelInline,\n\t\tmin = -Infinity,\n\t\tmax = Infinity,\n\t\ttype,\n\t\tclassName,\n\t\tstatus = \"normal\",\n\t\tmessage,\n\t\ttip,\n\t\tappend,\n\t\tprepend,\n\t\tstep = 1,\n\t\twidth,\n\t\tthousand,\n\t\tprecision,\n\t\thideControl,\n\t\tplaceholder,\n\t\tborder,\n\t\tautoSwitch,\n\t\tonChange,\n\t\tonBlur,\n\t\tstyle,\n\t\t...restProps\n\t} = props;\n\n\tconst [rangeValue, setRangeValue] = useState(value);\n\n\tconst getRangeNumber = (v: number) => clamp(v, min, max);\n\n\tconst getFormatNumber = (v: number) =>\n\t\tformatNumber(v, { precision, thousand });\n\n\tconst formatInputValue = (v?: string | number) => {\n\t\tif (!v) return \"\";\n\t\tif (typeof v === \"number\" || !thousand) return v;\n\n\t\treturn v.replaceAll(thousand, \"\");\n\t};\n\n\tconst handleChange = (e: ChangeEvent<HTMLInputElement>, i: number) => {\n\t\tconst { value } = e.target;\n\t\tconst v = formatInputValue(value.replace(/[^\\d\\.-]/g, \"\"));\n\t\tconst range = Array.isArray(rangeValue) ? [...rangeValue] : [];\n\n\t\trange[i] = v;\n\t\tsetRangeValue(range);\n\t\tonChange?.(range, e);\n\t};\n\n\tconst handleOperate = (\n\t\te: MouseEvent<Element>,\n\t\tparam: number,\n\t\ti: number\n\t) => {\n\t\te.preventDefault();\n\t\te.stopPropagation();\n\n\t\tconst range = Array.isArray(rangeValue) ? [...rangeValue] : [];\n\t\tconst value = formatInputValue(range[i]) ?? 0;\n\t\tconst result = getRangeNumber(+value + param);\n\n\t\trange[i] = getFormatNumber(result);\n\n\t\tsetRangeValue(range);\n\t\tonChange?.(range, e);\n\t};\n\n\tconst handleSwitch = (e?: MouseEvent) => {\n\t\te?.preventDefault();\n\t\te?.stopPropagation();\n\t\tconst range = Array.isArray(rangeValue) ? [...rangeValue] : [];\n\t\t[range[0], range[1]] = [range[1], range[0]];\n\n\t\tsetRangeValue(range);\n\t\tonChange?.(range);\n\t};\n\n\tuseEffect(() => {\n\t\tsetRangeValue(value);\n\t}, [value]);\n\n\tconst inputProps = {\n\t\tname,\n\t\tclassName: \"i-input i-input-number\",\n\t\t...restProps,\n\t};\n\n\tconst handleBlur = () => {\n\t\tif (!autoSwitch) return;\n\t\tconst range = Array.isArray(rangeValue) ? rangeValue : [];\n\n\t\tif (range.length < 2) return;\n\n\t\tconst [left, right] = range.map(Number);\n\t\tif (left > right) {\n\t\t\thandleSwitch();\n\t\t}\n\t};\n\n\treturn (\n\t\t<InputContainer\n\t\t\tlabel={label}\n\t\t\tlabelInline={labelInline}\n\t\t\tclassName={className}\n\t\t\tstyle={{ width, ...style }}\n\t\t\ttip={message ?? tip}\n\t\t\tstatus={status}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-input-item\", {\n\t\t\t\t\t[`i-input-${status}`]: status !== \"normal\",\n\t\t\t\t\t\"i-input-borderless\": !border,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{prepend && <div className='i-input-prepend'>{prepend}</div>}\n\n\t\t\t\t{!hideControl && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<MinusRound />}\n\t\t\t\t\t\tonClick={(e) => handleOperate(e, -step, 0)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t<input\n\t\t\t\t\tvalue={rangeValue?.[0] || \"\"}\n\t\t\t\t\tplaceholder={placeholder?.[0]}\n\t\t\t\t\t{...inputProps}\n\t\t\t\t\tonBlur={handleBlur}\n\t\t\t\t\tonChange={(e) => handleChange(e, 0)}\n\t\t\t\t/>\n\n\t\t\t\t{!hideControl && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<PlusRound />}\n\t\t\t\t\t\tonClick={(e) => handleOperate(e, step, 0)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t\t<Helpericon\n\t\t\t\t\tactive\n\t\t\t\t\ticon={<SyncAltRound />}\n\t\t\t\t\tstyle={{ margin: 0 }}\n\t\t\t\t\tonClick={handleSwitch}\n\t\t\t\t/>\n\t\t\t\t{!hideControl && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<MinusRound />}\n\t\t\t\t\t\tonClick={(e) => handleOperate(e, -step, 1)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t<input\n\t\t\t\t\tvalue={rangeValue?.[1] || \"\"}\n\t\t\t\t\tplaceholder={placeholder?.[1]}\n\t\t\t\t\t{...inputProps}\n\t\t\t\t\tonBlur={handleBlur}\n\t\t\t\t\tonChange={(e) => handleChange(e, 1)}\n\t\t\t\t/>\n\n\t\t\t\t{!hideControl && (\n\t\t\t\t\t<Helpericon\n\t\t\t\t\t\tactive\n\t\t\t\t\t\ticon={<PlusRound />}\n\t\t\t\t\t\tonClick={(e) => handleOperate(e, step, 1)}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\n\t\t\t\t{append && <div className='i-input-append'>{append}</div>}\n\t\t\t</div>\n\t\t</InputContainer>\n\t);\n};\n\nexport default Range;\n"],"names":["useState","clamp","formatNumber","useEffect","_jsx","InputContainer","_jsxs","classNames","Helpericon","MinusRound","PlusRound","SyncAltRound"],"mappings":";;;;;;;;;;;;;;;;AASA,MAAM,KAAK,GAAG,CAAC,KAAkB,KAAI;AACpC,IAAA,MAAM,EACL,KAAK,EACL,IAAI,EACJ,KAAK,EACL,WAAW,EACX,GAAG,GAAG,CAAC,QAAQ,EACf,GAAG,GAAG,QAAQ,EACd,IAAI,EACJ,SAAS,EACT,MAAM,GAAG,QAAQ,EACjB,OAAO,EACP,GAAG,EACH,MAAM,EACN,OAAO,EACP,IAAI,GAAG,CAAC,EACR,KAAK,EACL,QAAQ,EACR,SAAS,EACT,WAAW,EACX,WAAW,EACX,MAAM,EACN,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,GAAG,SAAS,EACZ,GAAG,KAAK;IAET,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AAEnD,IAAA,MAAM,cAAc,GAAG,CAAC,CAAS,KAAKC,WAAK,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;AAExD,IAAA,MAAM,eAAe,GAAG,CAAC,CAAS,KACjCC,kBAAY,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAEzC,IAAA,MAAM,gBAAgB,GAAG,CAAC,CAAmB,KAAI;AAChD,QAAA,IAAI,CAAC,CAAC;AAAE,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CAAC,WAAW,KACZP,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACK,mBAAU,EAAA,EAAA,CAAG,EACpB,OAAO,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,EAAA,CACzC,CACF,EAEDL,cAAA,CAAA,OAAA,EAAA,EACC,KAAK,EAAE,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,EAC5B,WAAW,EAAE,WAAW,GAAG,CAAC,CAAC,EAAA,GACzB,UAAU,EACd,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAAA,CAClC,EAED,CAAC,WAAW,KACZA,cAAA,CAACI,kBAAU,EAAA,EACV,MAAM,EAAA,IAAA,EACN,IAAI,EAAEJ,cAAA,CAACM,kBAAS,EAAA,EAAA,CAAG,EACnB,OAAO,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAA,CACxC,CACF,EAEA,MAAM,IAAIN,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,gBAAgB,EAAA,QAAA,EAAE,MAAM,EAAA,CAAO,CAAA,EAAA,CACpD,EAAA,CACU;AAEnB;;;;"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var hooks = require('../../js/hooks.js');
|
|
7
6
|
var classNames = require('classnames');
|
|
8
7
|
var react = require('react');
|
|
9
8
|
var container = require('./container.js');
|
|
@@ -14,13 +13,11 @@ var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);
|
|
|
14
13
|
|
|
15
14
|
const Textarea = (props) => {
|
|
16
15
|
const { ref, label, name, value = "", labelInline, className, status = "normal", message, tip, autoSize, border, width, style, onChange, onEnter, ...restProps } = props;
|
|
17
|
-
const
|
|
18
|
-
value,
|
|
19
|
-
});
|
|
16
|
+
const [textareaValue, setTextareaValue] = react.useState(value);
|
|
20
17
|
const refTextarea = react.useRef(null);
|
|
21
18
|
const handleChange = (e) => {
|
|
22
19
|
const v = e.target.value;
|
|
23
|
-
|
|
20
|
+
setTextareaValue(v);
|
|
24
21
|
const ta = refTextarea.current;
|
|
25
22
|
if (autoSize && ta) {
|
|
26
23
|
ta.style.height = `${ta.scrollHeight}px`;
|
|
@@ -34,7 +31,7 @@ const Textarea = (props) => {
|
|
|
34
31
|
onEnter?.(e);
|
|
35
32
|
};
|
|
36
33
|
react.useEffect(() => {
|
|
37
|
-
|
|
34
|
+
setTextareaValue(value);
|
|
38
35
|
}, [value]);
|
|
39
36
|
react.useImperativeHandle(ref, () => {
|
|
40
37
|
return {
|
|
@@ -44,7 +41,7 @@ const Textarea = (props) => {
|
|
|
44
41
|
const inputProps = {
|
|
45
42
|
ref: refTextarea,
|
|
46
43
|
name,
|
|
47
|
-
value:
|
|
44
|
+
value: textareaValue,
|
|
48
45
|
className: "i-input i-textarea",
|
|
49
46
|
onChange: handleChange,
|
|
50
47
|
onKeyDown: handleKeydown,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.js","sources":["../../../../packages/components/input/textarea.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"textarea.js","sources":["../../../../packages/components/input/textarea.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport {\n\tChangeEvent,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n\tuseState,\n\ttype KeyboardEvent,\n} from \"react\";\nimport \"../../css/input.css\";\nimport InputContainer from \"./container\";\nimport type { ITextarea } from \"./type\";\n\nconst Textarea = (props: ITextarea) => {\n\tconst {\n\t\tref,\n\t\tlabel,\n\t\tname,\n\t\tvalue = \"\",\n\t\tlabelInline,\n\t\tclassName,\n\t\tstatus = \"normal\",\n\t\tmessage,\n\t\ttip,\n\t\tautoSize,\n\t\tborder,\n\t\twidth,\n\t\tstyle,\n\t\tonChange,\n\t\tonEnter,\n\t\t...restProps\n\t} = props;\n\n\tconst [textareaValue, setTextareaValue] = useState(value);\n\tconst refTextarea = useRef<HTMLTextAreaElement>(null);\n\n\tconst handleChange = (\n\t\te: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,\n\t) => {\n\t\tconst v = e.target.value;\n\n\t\tsetTextareaValue(v);\n\n\t\tconst ta = refTextarea.current as HTMLElement;\n\t\tif (autoSize && ta) {\n\t\t\tta.style.height = `${ta.scrollHeight}px`;\n\t\t}\n\n\t\tonChange?.(v, e);\n\t};\n\n\tconst handleKeydown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n\t\tif (e.code !== \"Enter\") return;\n\n\t\te.stopPropagation();\n\t\tonEnter?.(e);\n\t};\n\n\tuseEffect(() => {\n\t\tsetTextareaValue(value);\n\t}, [value]);\n\n\tuseImperativeHandle(ref, () => {\n\t\treturn {\n\t\t\tinput: refTextarea.current,\n\t\t};\n\t});\n\n\tconst inputProps = {\n\t\tref: refTextarea,\n\t\tname,\n\t\tvalue: textareaValue,\n\t\tclassName: \"i-input i-textarea\",\n\t\tonChange: handleChange,\n\t\tonKeyDown: handleKeydown,\n\t\t...restProps,\n\t};\n\n\treturn (\n\t\t<InputContainer\n\t\t\tlabel={label}\n\t\t\tlabelInline={labelInline}\n\t\t\tclassName={className}\n\t\t\tstyle={{ width, ...style }}\n\t\t\ttip={message ?? tip}\n\t\t\tstatus={status}\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-input-item\", {\n\t\t\t\t\t[`i-input-${status}`]: status !== \"normal\",\n\t\t\t\t\t\"i-input-borderless\": !border,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t<textarea {...inputProps} />\n\t\t\t</div>\n\t\t</InputContainer>\n\t);\n};\n\nexport default Textarea;\n"],"names":["useState","useRef","useEff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AAE,WAAW,CAAC,OAAO;SAC1B;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,MAAM,UAAU,GAAG;AAClB,QAAA,GAAG,EAAE,WAAW;QAChB,IAAI;AACJ,QAAA,KAAK,EAAE,aAAa;AACpB,QAAA,SAAS,EAAE,oBAAoB;AAC/B,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,SAAS,EAAE,aAAa;AACxB,QAAA,GAAG,SAAS;KACZ;AAED,IAAA,QACCC,cAAA,CAACC,iBAAc,IACd,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAC1B,GAAG,EAAE,OAAO,IAAI,GAAG,EACnB,MAAM,EAAE,MAAM,YAEdD,cAAA,CAAA,KAAA,EAAA,EACC,SAAS,EAAEE,mBAAU,CAAC,cAAc,EAAE;AACrC,gBAAA,CAAC,WAAW,MAAM,CAAA,CAAE,GAAG,MAAM,KAAK,QAAQ;gBAC1C,oBAAoB,EAAE,CAAC,MAAM;AAC7B,aAAA,CAAC,YAEFF,cAAA,CAAA,UAAA,EAAA,EAAA,GAAc,UAAU,GAAI,EAAA,CACvB,EAAA,CACU;AAEnB;;;;"}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var material = require('@ricons/material');
|
|
7
7
|
var react = require('react');
|
|
8
|
-
var hooks = require('../../../js/hooks.js');
|
|
9
8
|
var button = require('../../button/button.js');
|
|
10
9
|
var icon = require('../../icon/icon.js');
|
|
11
10
|
var input = require('../../input/input.js');
|
|
@@ -18,23 +17,21 @@ const ColorMethods = {
|
|
|
18
17
|
};
|
|
19
18
|
function Footer(props) {
|
|
20
19
|
const { value, type, onTypeChange, onChange, onOk } = props;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
type,
|
|
24
|
-
});
|
|
20
|
+
const [inputValue, setInputValue] = react.useState(value);
|
|
21
|
+
const [colorType, setColorType] = react.useState(type);
|
|
25
22
|
const handleChange = (v) => {
|
|
26
|
-
|
|
23
|
+
setInputValue(v);
|
|
27
24
|
onChange(v);
|
|
28
25
|
};
|
|
29
26
|
const handleTypeChange = (t) => {
|
|
30
|
-
|
|
27
|
+
setColorType(t);
|
|
31
28
|
onTypeChange(t);
|
|
32
29
|
};
|
|
33
30
|
react.useEffect(() => {
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
setInputValue(value);
|
|
32
|
+
setColorType(type);
|
|
36
33
|
}, [value, type]);
|
|
37
|
-
return (jsxRuntime.jsxs("div", { className: 'i-colorpicker-footer', children: [jsxRuntime.jsx(select.default, { readOnly: true, hideClear: true, hideArrow: true, style: { width: "5.6em" }, options: ["RGB", "HEX", "HSB"], value:
|
|
34
|
+
return (jsxRuntime.jsxs("div", { className: 'i-colorpicker-footer', children: [jsxRuntime.jsx(select.default, { readOnly: true, hideClear: true, hideArrow: true, style: { width: "5.6em" }, options: ["RGB", "HEX", "HSB"], value: colorType, onChange: handleTypeChange }), jsxRuntime.jsx(input.default, { placeholder: 'color', value: inputValue, onChange: handleChange }), jsxRuntime.jsx(button.default, { square: true, onClick: onOk, children: jsxRuntime.jsx(icon.default, { icon: jsxRuntime.jsx(material.CheckRound, {}) }) })] }));
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
exports.ColorMethods = ColorMethods;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.js","sources":["../../../../../packages/components/picker/colors/footer.tsx"],"sourcesContent":["import { CheckRound } from \"@ricons/material\";\nimport { useEffect } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"footer.js","sources":["../../../../../packages/components/picker/colors/footer.tsx"],"sourcesContent":["import { CheckRound } from \"@ricons/material\";\nimport { useEffect, useState } from \"react\";\nimport Button from \"../../button\";\nimport Icon from \"../../icon\";\nimport Input from \"../../input\";\nimport Select from \"../../select\";\n\nexport const ColorMethods = {\n\tHEX: \"toHexString\",\n\tRGB: \"toRgbString\",\n\tHSB: \"toHsbString\",\n};\n\nexport default function Footer(props) {\n\tconst { value, type, onTypeChange, onChange, onOk } = props;\n\tconst [inputValue, setInputValue] = useState(value);\n\tconst [colorType, setColorType] = useState(type);\n\n\tconst handleChange = (v) => {\n\t\tsetInputValue(v);\n\t\tonChange(v);\n\t};\n\n\tconst handleTypeChange = (t) => {\n\t\tsetColorType(t);\n\t\tonTypeChange(t);\n\t};\n\n\tuseEffect(() => {\n\t\tsetInputValue(value);\n\t\tsetColorType(type);\n\t}, [value, type]);\n\n\treturn (\n\t\t<div className='i-colorpicker-footer'>\n\t\t\t<Select\n\t\t\t\treadOnly\n\t\t\t\thideClear\n\t\t\t\thideArrow\n\t\t\t\tstyle={{ width: \"5.6em\" }}\n\t\t\t\toptions={[\"RGB\", \"HEX\", \"HSB\"]}\n\t\t\t\tvalue={colorType}\n\t\t\t\tonChange={handleTypeChange}\n\t\t\t/>\n\t\t\t<Input\n\t\t\t\tplaceholder='color'\n\t\t\t\tvalue={inputValue}\n\t\t\t\tonChange={handleChange}\n\t\t\t/>\n\t\t\t<Button square onClick={onOk}>\n\t\t\t\t<Icon icon={<CheckRound />} />\n\t\t\t</Button>\n\t\t</div>\n\t);\n}\n"],"names":["useState","useEffect","_jsxs","_jsx","Select","Input","Button","Icon","CheckRound"],"mappings":";;;;;;;;;;;;AAOO,MAAM,YAAY,GAAG;AAC3B,IAAA,GAAG,EAAE,aAAa;AAClB,IAAA,GAAG,EAAE,aAAa;AAClB,IAAA,GAAG,EAAE,aAAa;;AAGL,SAAU,MAAM,CAAC,KAAK,EAAA;AACnC,IAAA,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,KAAK;IAC3D,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;IACnD,MA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anel = require('@rc-component/color-picker');
|
|
7
7
|
var react = require('react');
|
|
8
|
-
var hooks = require('../../../js/hooks.js');
|
|
9
8
|
var popup = require('../../popup/popup.js');
|
|
10
9
|
var footer = require('./footer.js');
|
|
11
10
|
var handle = require('./handle.js');
|
|
@@ -16,48 +15,51 @@ var ColorsPanel__default = /*#__PURE__*/_interopDefaultCompat(ColorsPanel);
|
|
|
16
15
|
|
|
17
16
|
function ColorPicker(props) {
|
|
18
17
|
const { value, type = "HEX", disabledAlpha, children, usePanel, handle: handle$1 = "both", placeholder = "Colors", popupProps, onChange, } = props;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
visible: popupProps?.visible,
|
|
24
|
-
});
|
|
18
|
+
const [colorType, setColorType] = react.useState(type);
|
|
19
|
+
const [colorValue, setColorValue] = react.useState(value);
|
|
20
|
+
const [syncValue, setSyncValue] = react.useState(value);
|
|
21
|
+
const [visible, setVisible] = react.useState(popupProps?.visible);
|
|
25
22
|
const handleChange = (target) => {
|
|
26
|
-
|
|
23
|
+
setSyncValue(target);
|
|
27
24
|
};
|
|
28
25
|
const handleComplete = (target) => {
|
|
29
|
-
const method = footer.ColorMethods[
|
|
26
|
+
const method = footer.ColorMethods[colorType];
|
|
30
27
|
if (target.a !== 1) {
|
|
31
28
|
target.a = parseFloat(target.a.toFixed(3));
|
|
32
29
|
}
|
|
33
|
-
|
|
30
|
+
setColorValue(target[method]?.());
|
|
34
31
|
};
|
|
35
32
|
const handleVisibleChange = (v) => {
|
|
36
|
-
|
|
33
|
+
setVisible(v);
|
|
37
34
|
popupProps?.onVisibleChange?.(v);
|
|
38
35
|
};
|
|
39
36
|
const handleTypeChange = (t) => {
|
|
40
37
|
const method = footer.ColorMethods[t];
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
setColorType(t);
|
|
39
|
+
setColorValue(syncValue?.[method]?.());
|
|
43
40
|
};
|
|
44
41
|
const handleValueChange = (v) => {
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
setColorValue(v);
|
|
43
|
+
setSyncValue(v);
|
|
47
44
|
};
|
|
48
45
|
const handleOk = () => {
|
|
49
|
-
onChange?.(
|
|
50
|
-
|
|
46
|
+
onChange?.(colorValue);
|
|
47
|
+
setVisible(false);
|
|
51
48
|
};
|
|
52
49
|
react.useEffect(() => {
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
setSyncValue(value);
|
|
51
|
+
setColorValue(value);
|
|
55
52
|
}, [value]);
|
|
53
|
+
react.useEffect(() => {
|
|
54
|
+
if (popupProps?.visible !== undefined) {
|
|
55
|
+
setVisible(popupProps.visible);
|
|
56
|
+
}
|
|
57
|
+
}, [popupProps?.visible]);
|
|
56
58
|
if (usePanel) {
|
|
57
59
|
return jsxRuntime.jsx(ColorsPanel__default, { ...props });
|
|
58
60
|
}
|
|
59
|
-
return (jsxRuntime.jsx(popup.default, { trigger: 'click', touchable: true, position: 'bottom', ...popupProps, visible:
|
|
60
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [panel, jsxRuntime.jsx(footer.default, { value:
|
|
61
|
+
return (jsxRuntime.jsx(popup.default, { trigger: 'click', touchable: true, position: 'bottom', ...popupProps, visible: visible, content: jsxRuntime.jsx(ColorsPanel__default, { value: syncValue, disabledAlpha: disabledAlpha, panelRender: (panel) => {
|
|
62
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [panel, jsxRuntime.jsx(footer.default, { value: colorValue, type: colorType, onTypeChange: handleTypeChange, onChange: handleValueChange, onOk: handleOk })] }));
|
|
61
63
|
}, onChange: handleChange, onChangeComplete: handleComplete }), onVisibleChange: handleVisibleChange, children: children ?? (jsxRuntime.jsx(handle.default, { color: value, handle: handle$1, placeholder: placeholder })) }));
|
|
62
64
|
}
|
|
63
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/colors/index.tsx"],"sourcesContent":["import ColorsPanel from \"@rc-component/color-picker\";\nimport { useEffect } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/colors/index.tsx"],"sourcesContent":["import ColorsPanel from \"@rc-component/color-picker\";\nimport { useEffect, useState } from \"react\";\nimport Popup from \"../../popup\";\nimport { IColorPicker } from \"../type\";\nimport Footer, { ColorMethods } from \"./footer\";\nimport Handle from \"./handle\";\nimport \"./index.css\";\n\nexport default function ColorPicker(props: IColorPicker) {\n\tconst {\n\t\tvalue,\n\t\ttype = \"HEX\",\n\t\tdisabledAlpha,\n\t\tchildren,\n\t\tusePanel,\n\t\thandle = \"both\",\n\t\tplaceholder = \"Colors\",\n\t\tpopupProps,\n\t\tonChange,\n\t} = props;\n\n\tconst [colorType, setColorType] = useState(type);\n\tconst [colorValue, setColorValue] = useState(value);\n\tconst [syncValue, setSyncValue] = useState(value);\n\tconst [visible, setVisible] = useState<boolean | undefined>(popupProps?.visible);\n\n\tconst handleChange = (target) => {\n\t\tsetSyncValue(target);\n\t};\n\n\tconst handleComplete = (target) => {\n\t\tconst method = ColorMethods[colorType];\n\n\t\tif (target.a !== 1) {\n\t\t\ttarget.a = parseFloat(target.a.toFixed(3));\n\t\t}\n\n\t\tsetColorValue(target[method]?.());\n\t};\n\n\tconst handleVisibleChange = (v: boolean) => {\n\t\tsetVisible(v);\n\t\tpopupProps?.onVisibleChange?.(v);\n\t};\n\n\tconst handleTypeChange = (t) => {\n\t\tconst method = ColorMethods[t];\n\n\t\tsetColorType(t);\n\t\tsetColorValue(syncValue?.[method]?.());\n\t};\n\n\tconst handleValueChange = (v) => {\n\t\tsetColorValue(v);\n\t\tsetSyncValue(v);\n\t};\n\n\tconst handleOk = () => {\n\t\tonChange?.(colorValue);\n\t\tsetVisible(false);\n\t};\n\n\tuseEffect(() => {\n\t\tsetSyncValue(value);\n\t\tsetColorValue(value);\n\t}, [value]);\n\n\tuseEffect(() => {\n\t\tif (popupProps?.visible !== undefined) {\n\t\t\tsetVisible(popupProps.visible);\n\t\t}\n\t}, [popupProps?.visible]);\n\n\tif (usePanel) {\n\t\treturn <ColorsPanel {...props} />;\n\t}\n\n\treturn (\n\t\t<Popup\n\t\t\ttrigger='click'\n\t\t\ttouchable\n\t\t\tposition='bottom'\n\t\t\t{...popupProps}\n\t\t\tvisible={visible}\n\t\t\tcontent={\n\t\t\t\t<ColorsPanel\n\t\t\t\t\tvalue={syncValue}\n\t\t\t\t\tdisabledAlpha={disabledAlpha}\n\t\t\t\t\tpanelRender={(panel) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t{panel}\n\t\t\t\t\t\t\t\t<Footer\n\t\t\t\t\t\t\t\t\tvalue={colorValue}\n\t\t\t\t\t\t\t\t\ttype={colorType}\n\t\t\t\t\t\t\t\t\tonTypeChange={handleTypeChange}\n\t\t\t\t\t\t\t\t\tonChange={handleValueChange}\n\t\t\t\t\t\t\t\t\tonOk={handleOk}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t);\n\t\t\t\t\t}}\n\t\t\t\t\tonChange={handleChange}\n\t\t\t\t\tonChangeComplete={handleComplete}\n\t\t\t\t/>\n\t\t\t}\n\t\t\tonVisibleChange={handleVisibleChange}\n\t\t>\n\t\t\t{children ?? (\n\t\t\t\t<Handle\n\t\t\t\t\tcolor={value}\n\t\t\t\t\thandle={handle}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</Popup>\n\t);\n}\n"],"names":["handle","useState","ColorMethods","useEffect","_jsx","ColorsPanel","Popup","_jsxs","_Fragment","Footer","Handle"],"mappings":";;;;;;;;;;;;;;;AAQc,SAAU,WAAW,CAAC,KAAmB,EAAA;IACtD,MAAM,EACL,KAAK,EACL,IAAI,GAAG,KAAK,EACZ,aAAa,EACb,QAAQ,EACR,QAAQ,UACRA,QAAM,GAAG,MAAM,EACf,WAAW,GAAG,QAAQ,EACtB,UAAU,EACV,Q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,QAAQ,KACRL,cAAA,CAACM,cAAM,IACN,KAAK,EAAE,KAAK,EACZ,MAAM,EAAEV,QAAM,EACd,WAAW,EAAE,WAAW,EAAA,CACvB,CACF,EAAA,CACM;AAEV;;;;"}
|
|
@@ -8,7 +8,6 @@ var classNames = require('classnames');
|
|
|
8
8
|
var dayjs = require('dayjs');
|
|
9
9
|
var customParseFormat = require('dayjs/plugin/customParseFormat.js');
|
|
10
10
|
var react = require('react');
|
|
11
|
-
var hooks = require('../../../js/hooks.js');
|
|
12
11
|
var icon = require('../../icon/icon.js');
|
|
13
12
|
var input = require('../../input/input.js');
|
|
14
13
|
var popup = require('../../popup/popup.js');
|
|
@@ -25,29 +24,27 @@ const FORMATTYPES = ["YYYY-MM-DD", "YYYY-M-D", "YYYY/MM/DD", "YYYY/M/D"];
|
|
|
25
24
|
const FORMAT = "YYYY-MM-DD";
|
|
26
25
|
const Datepicker = (props) => {
|
|
27
26
|
const { name, value, weeks, format = FORMAT, placeholder = props.format ?? FORMAT, className, renderDate, renderMonth, renderYear, popupProps, disabledDate, onDateClick, onChange, onBlur, ...restProps } = props;
|
|
28
|
-
const
|
|
29
|
-
value,
|
|
30
|
-
});
|
|
27
|
+
const [inputValue, setInputValue] = react.useState(value);
|
|
31
28
|
const [active, setActive] = react.useState(false);
|
|
32
29
|
const dayJsValue = react.useMemo(() => {
|
|
33
|
-
if (!
|
|
30
|
+
if (!inputValue)
|
|
34
31
|
return null;
|
|
35
|
-
const date = dayjs__default(
|
|
32
|
+
const date = dayjs__default(inputValue, format, true);
|
|
36
33
|
if (date.isValid())
|
|
37
34
|
return date;
|
|
38
35
|
return null;
|
|
39
|
-
}, [
|
|
36
|
+
}, [inputValue, format]);
|
|
40
37
|
const handleDateClick = (date) => {
|
|
41
38
|
handleChange(date.format(format));
|
|
42
39
|
};
|
|
43
40
|
const handleChange = (v) => {
|
|
44
|
-
|
|
41
|
+
setInputValue(v);
|
|
45
42
|
onChange?.(v);
|
|
46
43
|
};
|
|
47
44
|
const handleSetDate = () => {
|
|
48
|
-
if (!
|
|
45
|
+
if (!inputValue)
|
|
49
46
|
return;
|
|
50
|
-
const date = dayjs__default(
|
|
47
|
+
const date = dayjs__default(inputValue, FORMATTYPES, true);
|
|
51
48
|
if (date.isValid()) {
|
|
52
49
|
handleChange(date.format(format));
|
|
53
50
|
return;
|
|
@@ -63,9 +60,9 @@ const Datepicker = (props) => {
|
|
|
63
60
|
setActive(v);
|
|
64
61
|
};
|
|
65
62
|
react.useEffect(() => {
|
|
66
|
-
|
|
63
|
+
setInputValue(value);
|
|
67
64
|
}, [value]);
|
|
68
|
-
return (jsxRuntime.jsx(popup.default, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange,
|
|
65
|
+
return (jsxRuntime.jsx(popup.default, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange, content: jsxRuntime.jsx(panel.default, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, children: jsxRuntime.jsx(input.default, { value: inputValue, append: jsxRuntime.jsx(icon.default, { icon: jsxRuntime.jsx(material.CalendarMonthTwotone, {}), className: 'i-datepicker-icon', size: '1em' }), placeholder: placeholder, onChange: handleChange, onBlur: handleBlur, onEnter: handleSetDate, className: classNames__default("i-datepicker-label", className), ...restProps }) }));
|
|
69
66
|
};
|
|
70
67
|
|
|
71
68
|
exports.default = Datepicker;
|