@yourdash/uikit 1.0.8 → 1.0.9

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.
@@ -19,6 +19,8 @@
19
19
 
20
20
  &.disableMargin {
21
21
  height: 100%;
22
+ margin-top: 0;
23
+ margin-bottom: 0;
22
24
  }
23
25
  }
24
26
 
@@ -29,5 +31,7 @@
29
31
 
30
32
  &.disableMargin {
31
33
  width: 100%;
34
+ margin-left: 0;
35
+ margin-right: 0;
32
36
  }
33
37
  }
@@ -1,84 +1,82 @@
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 { UKIcon } from "../icon/iconDictionary.ts";
9
- import styles from "./textInput.module.scss";
10
- import React, { useEffect, useRef, useState } from "react";
11
-
12
- // TODO: maybe remove onEnter for onSubmit
13
-
14
- const TextInputComponent: React.ForwardRefExoticComponent<{
15
- onChange?: (value: string) => void;
16
- onSubmit?: (value: string) => void;
17
- placeholder: string;
18
- icon?: UKIcon;
19
- onEnter?: (value: string) => void;
20
- defaultValue?: string;
21
- value?: string;
22
- accessibleName: string;
23
- className?: string;
24
- type?: string;
25
- }> = (props, fwrdRef) => {
26
- const ref = useRef<HTMLInputElement>(null);
27
-
28
- React.useImperativeHandle(fwrdRef, () => ref.current);
29
-
30
- const [value, setValue] = useState(props.defaultValue || "");
31
-
32
- useEffect(() => {
33
- if (props.value) setValue(props.value);
34
- }, [props.value]);
35
-
36
- useEffect(() => {
37
- if (!ref.current) return;
38
-
39
- ref.current.value = value;
40
- }, [value]);
41
-
42
- useEffect(() => {
43
- setTimeout(() => {
44
- if (ref.current?.value !== props.defaultValue) {
45
- ref.current?.onkeyup?.({ currentTarget: ref.current } as unknown as KeyboardEvent);
46
- ref.current?.onchange?.({ currentTarget: ref.current } as unknown as Event);
47
- }
48
- }, 500);
49
- }, []);
50
-
51
- return (
52
- <div className={clippy(styles.component, props.className)}>
53
- {props.icon && (
54
- <Icon
55
- className={styles.icon}
56
- icon={props.icon}
57
- />
58
- )}
59
- <input
60
- ref={ref}
61
- type={props.type || "text"}
62
- aria-label={props.accessibleName}
63
- className={clippy(styles.input, !props.icon && styles.noIcon)}
64
- placeholder={props.placeholder}
65
- onKeyUp={(e) => {
66
- setValue(e.currentTarget.value);
67
- props.onChange?.(e.currentTarget.value);
68
- }}
69
- onChange={(e) => props.onSubmit?.(e.currentTarget.value)}
70
- onKeyDown={(e) => {
71
- if (e.key === "Enter") {
72
- e.preventDefault();
73
-
74
- props.onEnter?.(e.currentTarget.value);
75
- }
76
- }}
77
- />
78
- </div>
79
- );
80
- };
81
-
82
- const TextInput = React.forwardRef(TextInputComponent);
83
-
84
- export default TextInput;
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 { UKIcon } from "../icon/iconDictionary.ts";
9
+ import styles from "./textInput.module.scss";
10
+ import React, { useEffect, useRef, useState } from "react";
11
+
12
+ // TODO: maybe remove onEnter for onSubmit
13
+
14
+ const TextInputComponent: React.FC<{
15
+ onChange?: (value: string) => void;
16
+ onSubmit?: (value: string) => void;
17
+ placeholder: string;
18
+ icon?: UKIcon;
19
+ onEnter?: (value: string) => void;
20
+ defaultValue?: string;
21
+ value?: string;
22
+ accessibleName: string;
23
+ className?: string;
24
+ type?: string;
25
+ }> = (props) => {
26
+ const ref = useRef<HTMLInputElement>(null);
27
+
28
+ const [value, setValue] = useState(props.defaultValue || "");
29
+
30
+ useEffect(() => {
31
+ if (props.value) setValue(props.value);
32
+ }, [props.value]);
33
+
34
+ useEffect(() => {
35
+ if (!ref.current) return;
36
+
37
+ ref.current.value = value;
38
+ }, [value]);
39
+
40
+ useEffect(() => {
41
+ setTimeout(() => {
42
+ if (ref.current?.value !== props.defaultValue) {
43
+ ref.current?.onkeyup?.({ currentTarget: ref.current } as unknown as KeyboardEvent);
44
+ ref.current?.onchange?.({ currentTarget: ref.current } as unknown as Event);
45
+ }
46
+ }, 200);
47
+ }, []);
48
+
49
+ return (
50
+ <div className={clippy(styles.component, props.className)}>
51
+ {props.icon && (
52
+ <Icon
53
+ className={styles.icon}
54
+ icon={props.icon}
55
+ />
56
+ )}
57
+ <input
58
+ ref={ref}
59
+ type={props.type || "text"}
60
+ aria-label={props.accessibleName}
61
+ className={clippy(styles.input, !props.icon && styles.noIcon)}
62
+ placeholder={props.placeholder}
63
+ onKeyUp={(e) => {
64
+ setValue(e.currentTarget.value);
65
+ props.onChange?.(e.currentTarget.value);
66
+ }}
67
+ onChange={(e) => props.onSubmit?.(e.currentTarget.value)}
68
+ onKeyDown={(e) => {
69
+ if (e.key === "Enter") {
70
+ e.preventDefault();
71
+
72
+ props.onEnter?.(e.currentTarget.value);
73
+ }
74
+ }}
75
+ />
76
+ </div>
77
+ );
78
+ };
79
+
80
+ const TextInput = TextInputComponent;
81
+
82
+ export default TextInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourdash/uikit",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {