@sats-group/ui-lib 75.7.0 → 75.9.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.
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-group/ui-lib",
|
|
3
|
-
"version": "75.
|
|
3
|
+
"version": "75.9.0",
|
|
4
4
|
"description": "SATS web user interface library",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^18 || ^20",
|
|
7
7
|
"npm": "^8 || ^9 || ^10"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "run-s clean logos typecheck colour",
|
|
10
|
+
"build": "run-s clean logos typecheck colour components",
|
|
11
11
|
"clean": "node rimraf.mjs",
|
|
12
12
|
"colour": "node codegen/colours.mjs",
|
|
13
|
+
"components": "node codegen/components.mjs",
|
|
13
14
|
"dev": "npm run dev --workspace=site",
|
|
14
15
|
"lint": "eslint",
|
|
15
16
|
"lint:ci": "eslint --max-warnings 0",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const names = [
|
|
2
|
+
'badge',
|
|
3
|
+
'banner',
|
|
4
|
+
'bomb',
|
|
5
|
+
'button',
|
|
6
|
+
'checkbox',
|
|
7
|
+
'chip',
|
|
8
|
+
'chip-selected',
|
|
9
|
+
'collapse',
|
|
10
|
+
'confirmation',
|
|
11
|
+
'context-menu',
|
|
12
|
+
'cropped-image',
|
|
13
|
+
'dropdown-list',
|
|
14
|
+
'expander',
|
|
15
|
+
'filter',
|
|
16
|
+
'filter-wrapper',
|
|
17
|
+
'flag',
|
|
18
|
+
'form-content',
|
|
19
|
+
'hidden-input',
|
|
20
|
+
'link',
|
|
21
|
+
'link-button',
|
|
22
|
+
'link-card',
|
|
23
|
+
'message',
|
|
24
|
+
'message-field',
|
|
25
|
+
'modal',
|
|
26
|
+
'progress-bar',
|
|
27
|
+
'radio',
|
|
28
|
+
'scale-bar',
|
|
29
|
+
'search',
|
|
30
|
+
'select',
|
|
31
|
+
'select-option',
|
|
32
|
+
'tag',
|
|
33
|
+
'text',
|
|
34
|
+
'text-area',
|
|
35
|
+
'text-input',
|
|
36
|
+
'toggle',
|
|
37
|
+
'toolbox',
|
|
38
|
+
'visually-button',
|
|
39
|
+
'visually-hidden',
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
export const selectors = [
|
|
43
|
+
'.badge',
|
|
44
|
+
'.banner',
|
|
45
|
+
'.bomb',
|
|
46
|
+
'.button',
|
|
47
|
+
'.checkbox',
|
|
48
|
+
'.chip',
|
|
49
|
+
'.chip-selected',
|
|
50
|
+
'.collapse',
|
|
51
|
+
'.confirmation',
|
|
52
|
+
'.context-menu',
|
|
53
|
+
'.cropped-image',
|
|
54
|
+
'.dropdown-list',
|
|
55
|
+
'.expander',
|
|
56
|
+
'.filter',
|
|
57
|
+
'.filter-wrapper',
|
|
58
|
+
'.flag',
|
|
59
|
+
'.form-content',
|
|
60
|
+
'.hidden-input',
|
|
61
|
+
'.link',
|
|
62
|
+
'.link-button',
|
|
63
|
+
'.link-card',
|
|
64
|
+
'.message',
|
|
65
|
+
'.message-field',
|
|
66
|
+
'.modal',
|
|
67
|
+
'.progress-bar',
|
|
68
|
+
'.radio',
|
|
69
|
+
'.scale-bar',
|
|
70
|
+
'.search',
|
|
71
|
+
'.select',
|
|
72
|
+
'.select-option',
|
|
73
|
+
'.tag',
|
|
74
|
+
'.text',
|
|
75
|
+
'.text-area',
|
|
76
|
+
'.text-input',
|
|
77
|
+
'.toggle',
|
|
78
|
+
'.toolbox',
|
|
79
|
+
'.visually-button',
|
|
80
|
+
'.visually-hidden',
|
|
81
|
+
];
|
|
@@ -5,6 +5,7 @@ import Text from '../text';
|
|
|
5
5
|
import useInputValidation from '../use-input-validation';
|
|
6
6
|
|
|
7
7
|
import { themes, variants, TextInput as Props } from './text-input.types';
|
|
8
|
+
import { useEffect } from 'react';
|
|
8
9
|
|
|
9
10
|
const RefTextInput = React.forwardRef<HTMLInputElement, Props>(
|
|
10
11
|
(
|
|
@@ -29,8 +30,16 @@ const RefTextInput = React.forwardRef<HTMLInputElement, Props>(
|
|
|
29
30
|
},
|
|
30
31
|
ref,
|
|
31
32
|
) => {
|
|
32
|
-
const [
|
|
33
|
-
|
|
33
|
+
const [isError, setIsError] = React.useState(hasError);
|
|
34
|
+
const [validationOnChange, onInvalid, error] = useInputValidation(
|
|
35
|
+
customErrorMessages,
|
|
36
|
+
customErrorMessages ? customErrorMessages.defaultError : undefined,
|
|
37
|
+
isError,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
setIsError(hasError);
|
|
42
|
+
}, [hasError]);
|
|
34
43
|
|
|
35
44
|
return (
|
|
36
45
|
<label
|
|
@@ -38,7 +47,7 @@ const RefTextInput = React.forwardRef<HTMLInputElement, Props>(
|
|
|
38
47
|
'text-input--theme-dark': theme === themes.dark,
|
|
39
48
|
'text-input--theme-light': theme === themes.light,
|
|
40
49
|
'text-input--disabled': disabled,
|
|
41
|
-
'text-input--error': error ||
|
|
50
|
+
'text-input--error': error || isError,
|
|
42
51
|
'text-input--moving-label': icon ? false : hasMovingLabel,
|
|
43
52
|
'text-input--icon': icon,
|
|
44
53
|
'text-input--variant-small': variant === variants.small,
|
|
@@ -57,6 +66,7 @@ const RefTextInput = React.forwardRef<HTMLInputElement, Props>(
|
|
|
57
66
|
onChange={e => {
|
|
58
67
|
onChange(e);
|
|
59
68
|
validationOnChange(e);
|
|
69
|
+
setIsError(false); // NOTE: We want to reset error state on change to not confuse users.
|
|
60
70
|
}}
|
|
61
71
|
// NOTE: Using " " as placeholder for moving label theme to enable using `:placeholder-shown` to determine when to move the label
|
|
62
72
|
placeholder={
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useState } from 'react';
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Messages } from './use-input-validation.types';
|
|
4
4
|
|
|
@@ -18,14 +18,28 @@ const getCustomMessage = (validity: ValidityState, messages: Messages) => {
|
|
|
18
18
|
if (validity.tooShort) return messages.tooShort;
|
|
19
19
|
if (validity.typeMismatch) return messages.typeMismatch;
|
|
20
20
|
if (validity.valueMissing) return messages.valueMissing;
|
|
21
|
+
return undefined;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export default (
|
|
24
|
+
export default (
|
|
25
|
+
customMessages: Messages = {},
|
|
26
|
+
defaultError?: string,
|
|
27
|
+
isError?: boolean,
|
|
28
|
+
) => {
|
|
24
29
|
const [error, setError] = useState<string | undefined>();
|
|
25
30
|
const validationEnabled = useRef(false);
|
|
26
31
|
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (isError && defaultError) {
|
|
34
|
+
setError(defaultError);
|
|
35
|
+
} else {
|
|
36
|
+
setError(undefined);
|
|
37
|
+
}
|
|
38
|
+
}, [isError, defaultError]);
|
|
39
|
+
|
|
27
40
|
const onInvalid = (e: React.FormEvent<SupportedElement>) => {
|
|
28
41
|
validationEnabled.current = true;
|
|
42
|
+
|
|
29
43
|
const message = getCustomMessage(
|
|
30
44
|
(e.target as HTMLInputElement).validity,
|
|
31
45
|
customMessages,
|
|
@@ -34,7 +48,6 @@ export default (customMessages: Messages = {}) => {
|
|
|
34
48
|
};
|
|
35
49
|
|
|
36
50
|
const onChange = (e: React.ChangeEvent<SupportedElement>) => {
|
|
37
|
-
if (!validationEnabled.current) return;
|
|
38
51
|
const message = getCustomMessage(e.target.validity, customMessages);
|
|
39
52
|
setError(message || e.target?.validationMessage || undefined);
|
|
40
53
|
};
|