@yourdash/uikit 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,64 +1,78 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright ©2024 Ewsgit<https://ewsgit.uk> and YourDash<https://yourdash.ewsgit.uk> contributors.
|
3
|
-
* YourDash is licensed under the MIT License. (https://mit.ewsgit.uk)
|
4
|
-
*/
|
5
|
-
|
6
|
-
import clippy from "@yourdash/shared/web/helpers/clippy.ts";
|
7
|
-
import Icon from "../icon/icon.tsx";
|
8
|
-
import { UKIconType } from "../icon/iconDictionary.ts";
|
9
|
-
import styles from "./textInput.module.scss";
|
10
|
-
import React, { useEffect, useRef, useState } from "react";
|
11
|
-
|
12
|
-
const TextInputComponent: React.FC<{
|
13
|
-
getValue?: React.Dispatch<React.SetStateAction<string>>;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if (!
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
ref
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
1
|
+
/*
|
2
|
+
* Copyright ©2024 Ewsgit<https://ewsgit.uk> and YourDash<https://yourdash.ewsgit.uk> contributors.
|
3
|
+
* YourDash is licensed under the MIT License. (https://mit.ewsgit.uk)
|
4
|
+
*/
|
5
|
+
|
6
|
+
import clippy from "@yourdash/shared/web/helpers/clippy.ts";
|
7
|
+
import Icon from "../icon/icon.tsx";
|
8
|
+
import { UKIconType } from "../icon/iconDictionary.ts";
|
9
|
+
import styles from "./textInput.module.scss";
|
10
|
+
import React, { useEffect, useRef, useState } from "react";
|
11
|
+
|
12
|
+
const TextInputComponent: React.FC<{
|
13
|
+
getValue?: React.Dispatch<React.SetStateAction<string>>;
|
14
|
+
getLiveValue?: React.Dispatch<React.SetStateAction<string>>;
|
15
|
+
onSubmit?: (value: string) => void;
|
16
|
+
placeholder: string;
|
17
|
+
icon?: UKIconType;
|
18
|
+
defaultValue?: string;
|
19
|
+
value?: string;
|
20
|
+
accessibleName: string;
|
21
|
+
className?: string;
|
22
|
+
type?: string;
|
23
|
+
}> = (props) => {
|
24
|
+
const ref = useRef<HTMLInputElement>(null);
|
25
|
+
|
26
|
+
useEffect(() => {
|
27
|
+
if (!ref.current) return;
|
28
|
+
|
29
|
+
if (props.value) ref.current.value = props.value;
|
30
|
+
}, [props.value]);
|
31
|
+
|
32
|
+
useEffect(() => {
|
33
|
+
if (!ref.current) return;
|
34
|
+
|
35
|
+
ref.current.onchange = () => {
|
36
|
+
if (!ref.current) return;
|
37
|
+
if (!props.getValue) return;
|
38
|
+
|
39
|
+
props.getValue(ref.current.value);
|
40
|
+
};
|
41
|
+
|
42
|
+
ref.current.onkeyup = (event) => {
|
43
|
+
if (!ref.current) return;
|
44
|
+
if (!props.onSubmit) return;
|
45
|
+
|
46
|
+
if (props.getLiveValue) {
|
47
|
+
props.getLiveValue(ref.current.value);
|
48
|
+
}
|
49
|
+
|
50
|
+
if (event.key === "Enter") {
|
51
|
+
props.onSubmit(ref.current.value);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
}, []);
|
55
|
+
|
56
|
+
return (
|
57
|
+
<div className={clippy(styles.component, props.className)}>
|
58
|
+
{props.icon && (
|
59
|
+
<Icon
|
60
|
+
className={styles.icon}
|
61
|
+
icon={props.icon}
|
62
|
+
/>
|
63
|
+
)}
|
64
|
+
<input
|
65
|
+
ref={ref}
|
66
|
+
type={props.type || "text"}
|
67
|
+
aria-label={props.accessibleName}
|
68
|
+
defaultValue={props.defaultValue}
|
69
|
+
className={clippy(styles.input, !props.icon && styles.noIcon)}
|
70
|
+
placeholder={props.placeholder}
|
71
|
+
/>
|
72
|
+
</div>
|
73
|
+
);
|
74
|
+
};
|
75
|
+
|
76
|
+
const TextInput = TextInputComponent;
|
77
|
+
|
78
|
+
export default TextInput;
|