@kanda-libs/ks-component-ts 0.2.266 → 0.2.267
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/app/src/App.tsx +26 -11
- package/dist/index.d.ts +9964 -9964
- package/dist/index.esm.js +3 -3
- package/dist/index.esm.js.map +3 -3
- package/package.json +1 -1
- package/src/field/components/RangeInput/RangeInputUncontrolled.tsx +2 -19
- package/src/field/components/RangeInput/useRangeInputProps.ts +8 -32
- package/src/generated/widget/index.tsx +48200 -48199
package/package.json
CHANGED
|
@@ -30,24 +30,8 @@ const RangeInputUncontrolled: FunctionComponent<
|
|
|
30
30
|
name = "",
|
|
31
31
|
...restProps
|
|
32
32
|
}) {
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
inputProps,
|
|
36
|
-
onInput,
|
|
37
|
-
minLabel,
|
|
38
|
-
maxLabel,
|
|
39
|
-
currentLabel,
|
|
40
|
-
classNames,
|
|
41
|
-
} = useRangeInputProps(
|
|
42
|
-
name,
|
|
43
|
-
min,
|
|
44
|
-
max,
|
|
45
|
-
steps,
|
|
46
|
-
formatter,
|
|
47
|
-
prefix,
|
|
48
|
-
suffix,
|
|
49
|
-
error
|
|
50
|
-
);
|
|
33
|
+
const { ref, inputProps, minLabel, maxLabel, currentLabel, classNames } =
|
|
34
|
+
useRangeInputProps(name, min, max, steps, formatter, prefix, suffix, error);
|
|
51
35
|
|
|
52
36
|
return (
|
|
53
37
|
<div className={classNames.container}>
|
|
@@ -69,7 +53,6 @@ const RangeInputUncontrolled: FunctionComponent<
|
|
|
69
53
|
ref={forwardRef}
|
|
70
54
|
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
71
55
|
if (onChange) onChange(e);
|
|
72
|
-
onInput();
|
|
73
56
|
}}
|
|
74
57
|
name={name}
|
|
75
58
|
{...restProps}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { useWatch } from "react-hook-form";
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
|
|
5
5
|
import { BG_COLOR, CLASS_NAMES } from "./constants";
|
|
@@ -25,7 +25,6 @@ interface InputProps {
|
|
|
25
25
|
|
|
26
26
|
export interface Hook {
|
|
27
27
|
ref: React.RefObject<HTMLInputElement> | null;
|
|
28
|
-
onInput: () => void;
|
|
29
28
|
inputProps: InputProps;
|
|
30
29
|
maxLabel: string;
|
|
31
30
|
minLabel: string;
|
|
@@ -43,11 +42,7 @@ export default function useRangeInputProps(
|
|
|
43
42
|
suffix: string,
|
|
44
43
|
error?: string | ErrorMessage
|
|
45
44
|
): Hook {
|
|
46
|
-
const {
|
|
47
|
-
const initialValue = getValues(name);
|
|
48
|
-
const value =
|
|
49
|
-
initialValue || Math.ceil((parseInt(max, 10) - parseInt(min, 10)) / 2);
|
|
50
|
-
const [newValue, setNewValue] = useState<string>(String(initialValue));
|
|
45
|
+
const value = useWatch({ name });
|
|
51
46
|
|
|
52
47
|
const ref = useRef<HTMLInputElement>(null);
|
|
53
48
|
|
|
@@ -61,27 +56,10 @@ export default function useRangeInputProps(
|
|
|
61
56
|
step,
|
|
62
57
|
};
|
|
63
58
|
|
|
64
|
-
const onInput = useCallback(() => {
|
|
65
|
-
if (!ref.current) return;
|
|
66
|
-
const inputArr = Array.from(ref.current.children).filter(
|
|
67
|
-
(element) => element.tagName === "INPUT"
|
|
68
|
-
);
|
|
69
|
-
if (inputArr.length === 0) return;
|
|
70
|
-
const input = inputArr[0] as HTMLInputElement;
|
|
71
|
-
const { value } = input;
|
|
72
|
-
if (!value) return;
|
|
73
|
-
setNewValue(value);
|
|
74
|
-
const pct =
|
|
75
|
-
((parseInt(value, 10) - parseInt(min, 10)) /
|
|
76
|
-
(parseInt(max, 10) - parseInt(min, 10))) *
|
|
77
|
-
100;
|
|
78
|
-
input.style.background = BG_COLOR.replaceAll("$PCT", String(pct));
|
|
79
|
-
}, [min, max]);
|
|
80
|
-
|
|
81
59
|
const currentLabel = useMemo(() => {
|
|
82
|
-
if (!
|
|
83
|
-
return `${prefix}${formatter(
|
|
84
|
-
}, [
|
|
60
|
+
if (!value) return undefined;
|
|
61
|
+
return `${prefix}${formatter(value)}${suffix}`;
|
|
62
|
+
}, [value]);
|
|
85
63
|
|
|
86
64
|
const maxLabel = `${prefix}${formatter(String(max))}${suffix}`;
|
|
87
65
|
const minLabel = `${prefix}${formatter(String(min))}${suffix}`;
|
|
@@ -101,17 +79,15 @@ export default function useRangeInputProps(
|
|
|
101
79
|
);
|
|
102
80
|
if (inputArr.length === 0) return;
|
|
103
81
|
const input = inputArr[0] as HTMLInputElement;
|
|
104
|
-
const initialValue = getValues(name);
|
|
105
82
|
const pct =
|
|
106
|
-
((parseInt(
|
|
83
|
+
((parseInt(value, 10) - parseInt(min, 10)) /
|
|
107
84
|
(parseInt(max, 10) - parseInt(min, 10))) *
|
|
108
85
|
100;
|
|
109
86
|
input.style.background = BG_COLOR.replaceAll("$PCT", String(pct));
|
|
110
|
-
}, [
|
|
87
|
+
}, [value, min, max]);
|
|
111
88
|
|
|
112
89
|
return {
|
|
113
90
|
ref,
|
|
114
|
-
onInput,
|
|
115
91
|
inputProps,
|
|
116
92
|
maxLabel,
|
|
117
93
|
minLabel,
|