@react-ui-org/react-ui 0.65.0 → 0.66.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/dist/react-ui.css +10 -10
- package/dist/react-ui.d.ts +35 -27
- package/dist/react-ui.development.css +732 -145
- package/dist/react-ui.development.js +34 -34
- package/dist/react-ui.js +1 -1
- package/package.json +2 -2
- package/src/components/Button/helpers/getRootLabelVisibilityClassName.ts +1 -1
- package/src/components/CheckboxField/CheckboxField.module.scss +7 -3
- package/src/components/CheckboxField/CheckboxField.tsx +3 -3
- package/src/components/CheckboxField/CheckboxField.types.ts +4 -3
- package/src/components/CheckboxField/README.md +25 -3
- package/src/components/FileInputField/FileInputField.module.scss +7 -3
- package/src/components/FileInputField/FileInputField.tsx +3 -3
- package/src/components/FileInputField/FileInputField.types.ts +4 -3
- package/src/components/FileInputField/README.md +20 -3
- package/src/components/FormLayout/FormLayout.module.scss +4 -6
- package/src/components/FormLayout/FormLayoutCustomField.module.scss +7 -3
- package/src/components/FormLayout/FormLayoutCustomField.tsx +3 -3
- package/src/components/FormLayout/FormLayoutCustomField.types.ts +4 -3
- package/src/components/FormLayout/README.md +2 -9
- package/src/components/Grid/_helpers/generateResponsiveCustomProperties.ts +1 -0
- package/src/components/InputGroup/InputGroup.module.scss +7 -3
- package/src/components/InputGroup/InputGroup.tsx +8 -14
- package/src/components/InputGroup/README.md +35 -7
- package/src/components/Modal/_helpers/getPositionClassName.ts +1 -1
- package/src/components/Modal/_helpers/getScrollingClassName.ts +1 -1
- package/src/components/Radio/README.md +40 -3
- package/src/components/Radio/Radio.module.scss +7 -3
- package/src/components/Radio/Radio.tsx +3 -3
- package/src/components/Radio/Radio.types.ts +4 -3
- package/src/components/SelectField/README.md +53 -6
- package/src/components/SelectField/SelectField.module.scss +7 -3
- package/src/components/SelectField/SelectField.tsx +3 -3
- package/src/components/SelectField/SelectField.types.ts +4 -3
- package/src/components/Text/_helpers/getRootClampClassName.ts +1 -1
- package/src/components/Text/_helpers/getRootHyphensClassName.ts +1 -1
- package/src/components/Text/_helpers/getRootWordWrappingClassName.ts +1 -1
- package/src/components/TextArea/README.md +30 -6
- package/src/components/TextArea/TextArea.module.scss +7 -3
- package/src/components/TextArea/TextArea.tsx +3 -3
- package/src/components/TextArea/TextArea.types.ts +4 -3
- package/src/components/TextField/README.md +30 -6
- package/src/components/TextField/TextField.module.scss +7 -3
- package/src/components/TextField/TextField.tsx +3 -3
- package/src/components/TextField/TextField.types.ts +6 -5
- package/src/components/TextLink/README.md +1 -1
- package/src/components/Toggle/README.md +25 -3
- package/src/components/Toggle/Toggle.module.scss +7 -3
- package/src/components/Toggle/Toggle.tsx +3 -3
- package/src/components/Toggle/Toggle.types.ts +4 -3
- package/src/components/_helpers/getRootColorClassName.ts +1 -1
- package/src/components/_helpers/getRootPriorityClassName.ts +1 -1
- package/src/components/_helpers/getRootSizeClassName.ts +1 -1
- package/src/components/_helpers/getRootStateClassName.ts +24 -0
- package/src/index.ts +1 -1
- package/src/styles/settings/_form-fields.scss +2 -1
- package/src/styles/theme/_form-fields.scss +16 -11
- package/src/styles/theme-constants/_colors.scss +21 -0
- package/src/styles/tools/form-fields/_box-field-layout.scss +5 -8
- package/src/styles/tools/form-fields/_inline-field-elements.scss +0 -7
- package/src/styles/tools/form-fields/_inline-field-layout.scss +0 -8
- package/src/styles/tools/form-fields/_variants.scss +7 -7
- package/src/theme.scss +37 -12
- package/src/types/index.ts +1 -1
- package/src/types/states.ts +1 -0
- package/src/components/_helpers/getRootValidationStateClassName.ts +0 -20
- package/src/types/validationStates.ts +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-ui-org/react-ui",
|
|
3
3
|
"description": "React UI is a themeable UI library for React apps.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.66.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"ui",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@babel/preset-react": "^8.0.1",
|
|
95
95
|
"@babel/preset-typescript": "^8.0.1",
|
|
96
96
|
"@happy-dom/jest-environment": "^20.14.5",
|
|
97
|
-
"@playwright/test": "~1.
|
|
97
|
+
"@playwright/test": "~1.64.1",
|
|
98
98
|
"@react-ui-org/eslint-config": "^1.1.0",
|
|
99
99
|
"@react-ui-org/stylelint-config": "^1.0.0",
|
|
100
100
|
"@testing-library/dom": "^10.4.2",
|
|
@@ -35,16 +35,20 @@
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// States
|
|
38
|
+
.isRootStateChanged {
|
|
39
|
+
@include variants.state(changed);
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
.isRootStateInvalid {
|
|
39
|
-
@include variants.
|
|
43
|
+
@include variants.state(invalid);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
.isRootStateValid {
|
|
43
|
-
@include variants.
|
|
47
|
+
@include variants.state(valid);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
.isRootStateWarning {
|
|
47
|
-
@include variants.
|
|
51
|
+
@include variants.state(warning);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
// Invisible label
|
|
@@ -2,7 +2,7 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import { withGlobalProps } from '../../providers/globalProps';
|
|
3
3
|
import { classNames } from '../../helpers/classNames/classNames';
|
|
4
4
|
import { transferProps } from '../../helpers/transferProps';
|
|
5
|
-
import {
|
|
5
|
+
import { getRootStateClassName } from '../_helpers/getRootStateClassName';
|
|
6
6
|
import { FormLayoutContext } from '../FormLayout/FormLayoutContext';
|
|
7
7
|
import styles from './CheckboxField.module.scss';
|
|
8
8
|
import type { CheckboxFieldProps } from './CheckboxField.types';
|
|
@@ -16,7 +16,7 @@ export const CheckboxField = React.forwardRef<HTMLInputElement, CheckboxFieldPro
|
|
|
16
16
|
labelPosition = 'after',
|
|
17
17
|
renderAsRequired = false,
|
|
18
18
|
required = false,
|
|
19
|
-
|
|
19
|
+
state,
|
|
20
20
|
validationText,
|
|
21
21
|
...restProps
|
|
22
22
|
}, ref) => {
|
|
@@ -31,7 +31,7 @@ export const CheckboxField = React.forwardRef<HTMLInputElement, CheckboxFieldPro
|
|
|
31
31
|
labelPosition === 'before' && styles.hasRootLabelBefore,
|
|
32
32
|
disabled && styles.isRootDisabled,
|
|
33
33
|
(renderAsRequired || required) && styles.isRootRequired,
|
|
34
|
-
|
|
34
|
+
getRootStateClassName(styles, state),
|
|
35
35
|
)}
|
|
36
36
|
htmlFor={id}
|
|
37
37
|
id={id && `${id}__label`}
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
} from 'react';
|
|
5
5
|
import type {
|
|
6
6
|
LabelPosition,
|
|
7
|
-
|
|
7
|
+
State,
|
|
8
8
|
} from '../../types';
|
|
9
9
|
|
|
10
10
|
export type CheckboxFieldLabelPosition = LabelPosition;
|
|
@@ -53,9 +53,10 @@ export type CheckboxFieldProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'ty
|
|
|
53
53
|
*/
|
|
54
54
|
required?: boolean;
|
|
55
55
|
/**
|
|
56
|
-
* Alter the field to
|
|
56
|
+
* Alter the field to reflect the state of its data, e.g. a validation result or a change
|
|
57
|
+
* against the saved value.
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
state?: State;
|
|
59
60
|
/**
|
|
60
61
|
* Validation message to be displayed.
|
|
61
62
|
*/
|
|
@@ -146,7 +146,7 @@ React.createElement(() => {
|
|
|
146
146
|
</>
|
|
147
147
|
)}
|
|
148
148
|
onChange={() => setAgree(!agree)}
|
|
149
|
-
|
|
149
|
+
state="valid"
|
|
150
150
|
/>
|
|
151
151
|
<CheckboxField
|
|
152
152
|
checked={agree}
|
|
@@ -158,7 +158,7 @@ React.createElement(() => {
|
|
|
158
158
|
</>
|
|
159
159
|
)}
|
|
160
160
|
onChange={() => setAgree(!agree)}
|
|
161
|
-
|
|
161
|
+
state="warning"
|
|
162
162
|
validationText={(
|
|
163
163
|
<>
|
|
164
164
|
Please wait 10 minutes until we verify your data.
|
|
@@ -178,7 +178,7 @@ React.createElement(() => {
|
|
|
178
178
|
)}
|
|
179
179
|
onChange={() => setAgree(!agree)}
|
|
180
180
|
required
|
|
181
|
-
|
|
181
|
+
state="invalid"
|
|
182
182
|
validationText="You must agree to be able to proceed."
|
|
183
183
|
/>
|
|
184
184
|
</>
|
|
@@ -186,6 +186,28 @@ React.createElement(() => {
|
|
|
186
186
|
});
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
+
### Changed State
|
|
190
|
+
|
|
191
|
+
Changed state highlights fields whose value differs from the saved one, so users
|
|
192
|
+
can review their edits before saving.
|
|
193
|
+
|
|
194
|
+
A field shows one state at a time. When a changed value is also invalid, it's
|
|
195
|
+
up to you to pick the state that matters more to the user.
|
|
196
|
+
|
|
197
|
+
```docoff-react-preview
|
|
198
|
+
React.createElement(() => {
|
|
199
|
+
const [newsletter, setNewsletter] = React.useState(true);
|
|
200
|
+
return (
|
|
201
|
+
<CheckboxField
|
|
202
|
+
checked={newsletter}
|
|
203
|
+
label="Subscribe to newsletter"
|
|
204
|
+
onChange={() => setNewsletter(!newsletter)}
|
|
205
|
+
state="changed"
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
189
211
|
### Required State
|
|
190
212
|
|
|
191
213
|
The required state indicates that the input is mandatory. Required fields
|
|
@@ -100,16 +100,20 @@
|
|
|
100
100
|
cursor: inherit;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
.isRootStateChanged {
|
|
104
|
+
@include variants.state(changed);
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
.isRootStateInvalid {
|
|
104
|
-
@include variants.
|
|
108
|
+
@include variants.state(invalid);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
.isRootStateValid {
|
|
108
|
-
@include variants.
|
|
112
|
+
@include variants.state(valid);
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
.isRootStateWarning {
|
|
112
|
-
@include variants.
|
|
116
|
+
@include variants.state(warning);
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
// Invisible label
|
|
@@ -15,7 +15,7 @@ import { classNames } from '../../helpers/classNames';
|
|
|
15
15
|
import { transferProps } from '../../helpers/transferProps';
|
|
16
16
|
import { TranslationsContext } from '../../providers/translations';
|
|
17
17
|
import { getRootSizeClassName } from '../_helpers/getRootSizeClassName';
|
|
18
|
-
import {
|
|
18
|
+
import { getRootStateClassName } from '../_helpers/getRootStateClassName';
|
|
19
19
|
import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
|
|
20
20
|
import { InputGroupContext } from '../InputGroup/InputGroupContext';
|
|
21
21
|
import { Text } from '../Text';
|
|
@@ -42,7 +42,7 @@ export const FileInputField = React.forwardRef<FileInputFieldRef, FileInputField
|
|
|
42
42
|
onFilesChanged,
|
|
43
43
|
required = false,
|
|
44
44
|
size = 'medium',
|
|
45
|
-
|
|
45
|
+
state,
|
|
46
46
|
validationText,
|
|
47
47
|
...restProps
|
|
48
48
|
}, ref) => {
|
|
@@ -170,7 +170,7 @@ export const FileInputField = React.forwardRef<FileInputFieldRef, FileInputField
|
|
|
170
170
|
styles,
|
|
171
171
|
resolveContextOrProp(inputGroupContext && inputGroupContext.size, size),
|
|
172
172
|
),
|
|
173
|
-
|
|
173
|
+
getRootStateClassName(styles, state),
|
|
174
174
|
)}
|
|
175
175
|
id={`${id}__root`}
|
|
176
176
|
onDragLeave={!disabled ? handleDragLeave : undefined}
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import type {
|
|
8
8
|
Layout,
|
|
9
9
|
Size,
|
|
10
|
-
|
|
10
|
+
State,
|
|
11
11
|
} from '../../types';
|
|
12
12
|
|
|
13
13
|
export type FileInputFieldFilesChangedEvent = ChangeEvent<HTMLInputElement> | DragEvent<HTMLDivElement> | Event | null;
|
|
@@ -87,9 +87,10 @@ export type FileInputFieldProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'i
|
|
|
87
87
|
*/
|
|
88
88
|
size?: Size;
|
|
89
89
|
/**
|
|
90
|
-
* Alter the field to
|
|
90
|
+
* Alter the field to reflect the state of its data, e.g. a validation result or a change
|
|
91
|
+
* against the saved value.
|
|
91
92
|
*/
|
|
92
|
-
|
|
93
|
+
state?: State;
|
|
93
94
|
/**
|
|
94
95
|
* Validation message to be displayed.
|
|
95
96
|
*
|
|
@@ -166,21 +166,21 @@ have.
|
|
|
166
166
|
id="my-file-valid"
|
|
167
167
|
label="Attachment"
|
|
168
168
|
onFilesChanged={() => {}}
|
|
169
|
-
|
|
169
|
+
state="valid"
|
|
170
170
|
validationText="Looks good!"
|
|
171
171
|
/>
|
|
172
172
|
<FileInputField
|
|
173
173
|
id="my-file-invalid"
|
|
174
174
|
label="Attachment"
|
|
175
175
|
onFilesChanged={() => {}}
|
|
176
|
-
|
|
176
|
+
state="invalid"
|
|
177
177
|
validationText="Your file is too big. Please select something smaller."
|
|
178
178
|
/>
|
|
179
179
|
<FileInputField
|
|
180
180
|
id="my-file-warning"
|
|
181
181
|
label="Attachment"
|
|
182
182
|
onFilesChanged={() => {}}
|
|
183
|
-
|
|
183
|
+
state="warning"
|
|
184
184
|
validationText={`
|
|
185
185
|
You selected more than 10 files.
|
|
186
186
|
It may take some time before we process them.
|
|
@@ -188,6 +188,23 @@ have.
|
|
|
188
188
|
/>
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
+
### Changed State
|
|
192
|
+
|
|
193
|
+
Changed state highlights fields whose value differs from the saved one, so users
|
|
194
|
+
can review their edits before saving.
|
|
195
|
+
|
|
196
|
+
A field shows one state at a time. When a changed value is also invalid, it's
|
|
197
|
+
up to you to pick the state that matters more to the user.
|
|
198
|
+
|
|
199
|
+
```docoff-react-preview
|
|
200
|
+
<FileInputField
|
|
201
|
+
id="my-file-changed"
|
|
202
|
+
label="Attachment"
|
|
203
|
+
onFilesChanged={() => {}}
|
|
204
|
+
state="changed"
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
191
208
|
### Disabled State
|
|
192
209
|
|
|
193
210
|
It's possible to disable the whole input.
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
// 1. Form field label width is defined using custom property. FormLayout variants are created just
|
|
2
2
|
// by adjusting this value, either through a particular modification class, or manually through
|
|
3
|
-
// a prop. Form fields then inherit the layout using
|
|
4
|
-
// possible to turn on automatic size of grid column with labels
|
|
3
|
+
// a prop. Form fields then inherit the layout using `subgrid` (or `display: contents` for
|
|
4
|
+
// `<fieldset>`) which makes it possible to turn on automatic size of grid column with labels,
|
|
5
|
+
// see 4.
|
|
5
6
|
//
|
|
6
7
|
// 2. By default, form field label width is set to a configurable global value.
|
|
7
8
|
//
|
|
8
9
|
// 3. Custom label width can be entered individually through a prop for each use of FormLayout.
|
|
9
10
|
//
|
|
10
11
|
// 4. FormLayout can also automatically adjust the width of column with labels according to the
|
|
11
|
-
// longest label
|
|
12
|
-
// supported only in Firefox so a fallback value is necessary for non-supporting browsers
|
|
13
|
-
// (a global default which can be customised per use).
|
|
14
|
-
// https://github.com/react-ui-org/react-ui/issues/232
|
|
12
|
+
// longest label.
|
|
15
13
|
|
|
16
14
|
@use "../../styles/settings/forms";
|
|
17
15
|
@use "../../styles/tools/breakpoint";
|
|
@@ -19,16 +19,20 @@
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// States
|
|
22
|
+
.isRootStateChanged {
|
|
23
|
+
@include variants.state(changed);
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
.isRootStateInvalid {
|
|
23
|
-
@include variants.
|
|
27
|
+
@include variants.state(invalid);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
.isRootStateValid {
|
|
27
|
-
@include variants.
|
|
31
|
+
@include variants.state(valid);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
.isRootStateWarning {
|
|
31
|
-
@include variants.
|
|
35
|
+
@include variants.state(warning);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
// Layouts
|
|
@@ -3,7 +3,7 @@ import { withGlobalProps } from '../../providers/globalProps';
|
|
|
3
3
|
import { classNames } from '../../helpers/classNames/classNames';
|
|
4
4
|
import { transferProps } from '../../helpers/transferProps';
|
|
5
5
|
import { getRootSizeClassName } from '../_helpers/getRootSizeClassName';
|
|
6
|
-
import {
|
|
6
|
+
import { getRootStateClassName } from '../_helpers/getRootStateClassName';
|
|
7
7
|
import { isChildrenEmpty } from '../../helpers/isChildrenEmpty/isChildrenEmpty';
|
|
8
8
|
import { FormLayoutContext } from './FormLayoutContext';
|
|
9
9
|
import { FormLayoutCustomFieldContext } from './FormLayoutCustomFieldContext';
|
|
@@ -46,7 +46,7 @@ export const FormLayoutCustomField: React.FunctionComponent<FormLayoutCustomFiel
|
|
|
46
46
|
label,
|
|
47
47
|
labelForId,
|
|
48
48
|
required = false,
|
|
49
|
-
|
|
49
|
+
state,
|
|
50
50
|
...restProps
|
|
51
51
|
}: FormLayoutCustomFieldProps) => {
|
|
52
52
|
const context = useContext(FormLayoutContext);
|
|
@@ -65,7 +65,7 @@ export const FormLayoutCustomField: React.FunctionComponent<FormLayoutCustomFiel
|
|
|
65
65
|
disabled && styles.isRootDisabled,
|
|
66
66
|
required && styles.isRootRequired,
|
|
67
67
|
getRootSizeClassName(styles, innerFieldSize),
|
|
68
|
-
|
|
68
|
+
getRootStateClassName(styles, state),
|
|
69
69
|
)}
|
|
70
70
|
id={id}
|
|
71
71
|
>
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
} from 'react';
|
|
5
5
|
import type {
|
|
6
6
|
Size,
|
|
7
|
-
|
|
7
|
+
State,
|
|
8
8
|
} from '../../types';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -48,9 +48,10 @@ export type FormLayoutCustomFieldProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
48
48
|
*/
|
|
49
49
|
required?: boolean;
|
|
50
50
|
/**
|
|
51
|
-
* Alter the field to
|
|
51
|
+
* Alter the field to reflect the state of its data, e.g. a validation result or a change
|
|
52
|
+
* against the saved value.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
state?: State;
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -40,11 +40,6 @@ the job: the [CSS grid layout][grid].
|
|
|
40
40
|
Do **not** try to put any custom HTML or React components directly into
|
|
41
41
|
FormLayout without wrapping it with the FormLayoutCustomField first.
|
|
42
42
|
|
|
43
|
-
👉 For usage in auto-width Modal, you may need to turn on the `autoWidth` option
|
|
44
|
-
for your FormLayout. This prevents FormLayout from unexpectedly growing in
|
|
45
|
-
browsers that [don't support][rui-232] [CSS subgrid][subgrid] in cases when
|
|
46
|
-
there are longer validation messages or help texts.
|
|
47
|
-
|
|
48
43
|
## Supported Form Fields
|
|
49
44
|
|
|
50
45
|
The FormLayout supports buttons and all React UI form fields:
|
|
@@ -119,7 +114,7 @@ React.createElement(() => {
|
|
|
119
114
|
<TextField
|
|
120
115
|
inputSize={6}
|
|
121
116
|
label="ZIP"
|
|
122
|
-
|
|
117
|
+
state="invalid"
|
|
123
118
|
validationText="ZIP should be 5 to 6 digits long code."
|
|
124
119
|
/>
|
|
125
120
|
<FormLayoutCustomField label="Country">
|
|
@@ -383,7 +378,7 @@ provide labels with optional feedback style.
|
|
|
383
378
|
<FormLayout fieldLayout="horizontal" labelWidth="auto">
|
|
384
379
|
<FormLayoutCustomField
|
|
385
380
|
label="Custom field label in valid state"
|
|
386
|
-
|
|
381
|
+
state="valid"
|
|
387
382
|
>
|
|
388
383
|
<docoff-placeholder bordered>Custom field content</docoff-placeholder>
|
|
389
384
|
</FormLayoutCustomField>
|
|
@@ -467,6 +462,4 @@ FormLayoutCustomField can be styled using a small subset of
|
|
|
467
462
|
[fragments]: https://reactjs.org/docs/fragments.html
|
|
468
463
|
[grid]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
|
|
469
464
|
[React common props]: https://react.dev/reference/react-dom/components/common#common-props
|
|
470
|
-
[rui-232]: https://github.com/react-ui-org/react-ui/issues/232
|
|
471
465
|
[rui-265]: https://github.com/react-ui-org/react-ui/issues/265
|
|
472
|
-
[subgrid]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Subgrid
|
|
@@ -12,6 +12,7 @@ const prepareValueByType = (value: GridResponsivePropertyValue, type: 'spacing'
|
|
|
12
12
|
return value;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// Returns `null` on purpose: the result is spread into `style`, where `null` is a valid empty value.
|
|
15
16
|
export const generateResponsiveCustomProperties = (
|
|
16
17
|
prop: GridResponsiveValue<GridResponsivePropertyValue> | undefined,
|
|
17
18
|
infix: string,
|
|
@@ -50,16 +50,20 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// States
|
|
53
|
+
.isRootStateChanged {
|
|
54
|
+
@include variants.state(changed);
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
.isRootStateInvalid {
|
|
54
|
-
@include variants.
|
|
58
|
+
@include variants.state(invalid);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
.isRootStateValid {
|
|
58
|
-
@include variants.
|
|
62
|
+
@include variants.state(valid);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
.isRootStateWarning {
|
|
62
|
-
@include variants.
|
|
66
|
+
@include variants.state(warning);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
// Layouts
|
|
@@ -10,16 +10,18 @@ import { withGlobalProps } from '../../providers/globalProps';
|
|
|
10
10
|
import { classNames } from '../../helpers/classNames/classNames';
|
|
11
11
|
import { transferProps } from '../../helpers/transferProps';
|
|
12
12
|
import { getRootSizeClassName } from '../_helpers/getRootSizeClassName';
|
|
13
|
-
import {
|
|
13
|
+
import { getRootStateClassName } from '../_helpers/getRootStateClassName';
|
|
14
14
|
import { isChildrenEmpty } from '../../helpers/isChildrenEmpty/isChildrenEmpty';
|
|
15
15
|
import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
|
|
16
16
|
import { FormLayoutContext } from '../FormLayout/FormLayoutContext';
|
|
17
17
|
import { Text } from '../Text';
|
|
18
|
-
import type {
|
|
18
|
+
import type { State } from '../../types';
|
|
19
19
|
import { InputGroupContext } from './InputGroupContext';
|
|
20
20
|
import styles from './InputGroup.module.scss';
|
|
21
21
|
import type { InputGroupProps } from './InputGroup.types';
|
|
22
22
|
|
|
23
|
+
const statePriority: State[] = ['invalid', 'warning', 'changed', 'valid'];
|
|
24
|
+
|
|
23
25
|
export const InputGroup: React.FunctionComponent<InputGroupProps> = ({
|
|
24
26
|
children,
|
|
25
27
|
disabled = false,
|
|
@@ -44,17 +46,9 @@ export const InputGroup: React.FunctionComponent<InputGroupProps> = ({
|
|
|
44
46
|
return null;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
const
|
|
48
|
-
(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (state === 'invalid' || (state === 'warning' && childValidationState === 'valid')) {
|
|
52
|
-
return state;
|
|
53
|
-
}
|
|
54
|
-
return childValidationState ?? state;
|
|
55
|
-
},
|
|
56
|
-
undefined,
|
|
57
|
-
);
|
|
49
|
+
const childStates = React.Children.toArray(children)
|
|
50
|
+
.map((child) => (child as ReactElement<{ state?: State }>).props.state);
|
|
51
|
+
const state = statePriority.find((priorityState) => childStates.includes(priorityState));
|
|
58
52
|
|
|
59
53
|
return (
|
|
60
54
|
<fieldset
|
|
@@ -68,7 +62,7 @@ export const InputGroup: React.FunctionComponent<InputGroupProps> = ({
|
|
|
68
62
|
disabled && styles.isRootDisabled,
|
|
69
63
|
required && styles.isRootRequired,
|
|
70
64
|
getRootSizeClassName(styles, size),
|
|
71
|
-
|
|
65
|
+
getRootStateClassName(styles, state),
|
|
72
66
|
)}
|
|
73
67
|
disabled={disabled}
|
|
74
68
|
id={id}
|
|
@@ -222,7 +222,7 @@ Disables all fields and buttons inside the group.
|
|
|
222
222
|
### Validation States
|
|
223
223
|
|
|
224
224
|
Validation states visually present the result of validation of the grouped
|
|
225
|
-
inputs. Input group's
|
|
225
|
+
inputs. Input group's state is taken from its child inputs. You
|
|
226
226
|
should always **provide validation messages for states other than valid**
|
|
227
227
|
directly through `validationTexts` prop so users know what happened and what
|
|
228
228
|
action they should take or what options they have.
|
|
@@ -230,7 +230,7 @@ action they should take or what options they have.
|
|
|
230
230
|
These messages are not semantically tied to the `children` elements, the
|
|
231
231
|
connection should be expressed in textual form in the actual message. The
|
|
232
232
|
individual `children` elements must not show any `validationText`, they only
|
|
233
|
-
show their respective `
|
|
233
|
+
show their respective `state`.
|
|
234
234
|
|
|
235
235
|
⚠️ Validation messages passed to input elements' `validationText` prop are
|
|
236
236
|
ignored within InputGroup.
|
|
@@ -252,13 +252,13 @@ for the underlying `<fieldset>` element.
|
|
|
252
252
|
label="First name"
|
|
253
253
|
placeholder="Eg. John"
|
|
254
254
|
required
|
|
255
|
-
|
|
255
|
+
state="invalid"
|
|
256
256
|
/>
|
|
257
257
|
<TextField
|
|
258
258
|
label="Last name"
|
|
259
259
|
placeholder="Eg. Doe"
|
|
260
260
|
required
|
|
261
|
-
|
|
261
|
+
state="invalid"
|
|
262
262
|
/>
|
|
263
263
|
<Button label="Submit" />
|
|
264
264
|
</InputGroup>
|
|
@@ -279,7 +279,7 @@ for the underlying `<fieldset>` element.
|
|
|
279
279
|
label="Last name"
|
|
280
280
|
placeholder="Eg. Doe"
|
|
281
281
|
required
|
|
282
|
-
|
|
282
|
+
state="warning"
|
|
283
283
|
value="123Doe"
|
|
284
284
|
/>
|
|
285
285
|
<Button label="Submit" />
|
|
@@ -292,14 +292,42 @@ for the underlying `<fieldset>` element.
|
|
|
292
292
|
label="First name"
|
|
293
293
|
placeholder="Eg. John"
|
|
294
294
|
required
|
|
295
|
-
|
|
295
|
+
state="valid"
|
|
296
296
|
value="John"
|
|
297
297
|
/>
|
|
298
298
|
<TextField
|
|
299
299
|
label="Last name"
|
|
300
300
|
placeholder="Eg. Doe"
|
|
301
301
|
required
|
|
302
|
-
|
|
302
|
+
state="valid"
|
|
303
|
+
value="Doe"
|
|
304
|
+
/>
|
|
305
|
+
<Button label="Submit" />
|
|
306
|
+
</InputGroup>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Changed State
|
|
310
|
+
|
|
311
|
+
Changed state highlights inputs whose value differs from the saved one, so users
|
|
312
|
+
can review their edits before saving.
|
|
313
|
+
|
|
314
|
+
Input group shows one state at a time. When its inputs have different states,
|
|
315
|
+
the group takes the one that matters most to the user, in this order:
|
|
316
|
+
`invalid`, `warning`, `changed`, `valid`.
|
|
317
|
+
|
|
318
|
+
```docoff-react-preview
|
|
319
|
+
<InputGroup label="First and last name">
|
|
320
|
+
<TextField
|
|
321
|
+
label="First name"
|
|
322
|
+
onChange={() => {}}
|
|
323
|
+
placeholder="Eg. John"
|
|
324
|
+
value="John"
|
|
325
|
+
/>
|
|
326
|
+
<TextField
|
|
327
|
+
label="Last name"
|
|
328
|
+
onChange={() => {}}
|
|
329
|
+
placeholder="Eg. Doe"
|
|
330
|
+
state="changed"
|
|
303
331
|
value="Doe"
|
|
304
332
|
/>
|
|
305
333
|
<Button label="Submit" />
|