@react-ui-org/react-ui 0.65.0 → 0.67.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.
Files changed (67) hide show
  1. package/dist/react-ui.css +11 -11
  2. package/dist/react-ui.d.ts +36 -28
  3. package/dist/react-ui.development.css +742 -165
  4. package/dist/react-ui.development.js +56 -266
  5. package/dist/react-ui.js +1 -1
  6. package/package.json +35 -37
  7. package/src/components/Button/helpers/getRootLabelVisibilityClassName.ts +1 -1
  8. package/src/components/CheckboxField/CheckboxField.module.scss +7 -3
  9. package/src/components/CheckboxField/CheckboxField.tsx +3 -3
  10. package/src/components/CheckboxField/CheckboxField.types.ts +4 -3
  11. package/src/components/CheckboxField/README.md +25 -3
  12. package/src/components/FileInputField/FileInputField.module.scss +7 -3
  13. package/src/components/FileInputField/FileInputField.tsx +3 -3
  14. package/src/components/FileInputField/FileInputField.types.ts +4 -3
  15. package/src/components/FileInputField/README.md +20 -3
  16. package/src/components/FormLayout/FormLayout.module.scss +4 -6
  17. package/src/components/FormLayout/FormLayoutCustomField.module.scss +7 -3
  18. package/src/components/FormLayout/FormLayoutCustomField.tsx +3 -3
  19. package/src/components/FormLayout/FormLayoutCustomField.types.ts +4 -3
  20. package/src/components/FormLayout/README.md +2 -9
  21. package/src/components/Grid/_helpers/generateResponsiveCustomProperties.ts +1 -0
  22. package/src/components/InputGroup/InputGroup.module.scss +7 -3
  23. package/src/components/InputGroup/InputGroup.tsx +8 -14
  24. package/src/components/InputGroup/README.md +35 -7
  25. package/src/components/Modal/_helpers/getPositionClassName.ts +1 -1
  26. package/src/components/Modal/_helpers/getScrollingClassName.ts +1 -1
  27. package/src/components/Radio/README.md +40 -3
  28. package/src/components/Radio/Radio.module.scss +7 -3
  29. package/src/components/Radio/Radio.tsx +3 -3
  30. package/src/components/Radio/Radio.types.ts +4 -3
  31. package/src/components/SelectField/README.md +53 -6
  32. package/src/components/SelectField/SelectField.module.scss +7 -3
  33. package/src/components/SelectField/SelectField.tsx +3 -3
  34. package/src/components/SelectField/SelectField.types.ts +4 -3
  35. package/src/components/Text/_helpers/getRootClampClassName.ts +1 -1
  36. package/src/components/Text/_helpers/getRootHyphensClassName.ts +1 -1
  37. package/src/components/Text/_helpers/getRootWordWrappingClassName.ts +1 -1
  38. package/src/components/TextArea/README.md +30 -6
  39. package/src/components/TextArea/TextArea.module.scss +7 -3
  40. package/src/components/TextArea/TextArea.tsx +3 -3
  41. package/src/components/TextArea/TextArea.types.ts +4 -3
  42. package/src/components/TextField/README.md +30 -6
  43. package/src/components/TextField/TextField.module.scss +7 -3
  44. package/src/components/TextField/TextField.tsx +3 -3
  45. package/src/components/TextField/TextField.types.ts +6 -5
  46. package/src/components/TextLink/README.md +1 -1
  47. package/src/components/Toggle/README.md +25 -3
  48. package/src/components/Toggle/Toggle.module.scss +7 -3
  49. package/src/components/Toggle/Toggle.tsx +3 -3
  50. package/src/components/Toggle/Toggle.types.ts +4 -3
  51. package/src/components/_helpers/getRootColorClassName.ts +1 -1
  52. package/src/components/_helpers/getRootPriorityClassName.ts +1 -1
  53. package/src/components/_helpers/getRootSizeClassName.ts +1 -1
  54. package/src/components/_helpers/getRootStateClassName.ts +24 -0
  55. package/src/index.ts +1 -1
  56. package/src/styles/settings/_form-fields.scss +2 -1
  57. package/src/styles/theme/_form-fields.scss +16 -11
  58. package/src/styles/theme-constants/_colors.scss +21 -0
  59. package/src/styles/tools/form-fields/_box-field-layout.scss +5 -8
  60. package/src/styles/tools/form-fields/_inline-field-elements.scss +0 -7
  61. package/src/styles/tools/form-fields/_inline-field-layout.scss +0 -8
  62. package/src/styles/tools/form-fields/_variants.scss +7 -7
  63. package/src/theme.scss +37 -12
  64. package/src/types/index.ts +1 -1
  65. package/src/types/states.ts +1 -0
  66. package/src/components/_helpers/getRootValidationStateClassName.ts +0 -20
  67. 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.65.0",
4
+ "version": "0.67.0",
5
5
  "keywords": [
6
6
  "react",
7
7
  "ui",
@@ -44,42 +44,40 @@
44
44
  "url": "https://github.com/react-ui-org/react-ui"
45
45
  },
46
46
  "engines": {
47
- "node": ">=22.11.0"
47
+ "node": "^24.22.3 || >=26.13.1"
48
48
  },
49
49
  "devEngines": {
50
50
  "runtime": {
51
51
  "name": "node",
52
- "version": "^22.23.0 || ^24.17.0",
52
+ "version": "^24.22.3 || ^26.13.1",
53
53
  "onFail": "error"
54
54
  },
55
55
  "packageManager": {
56
56
  "name": "npm",
57
- "version": "^11.13.0",
57
+ "version": "^11.19.1",
58
58
  "onFail": "error"
59
59
  }
60
60
  },
61
61
  "scripts": {
62
62
  "build": "webpack --mode=production && webpack --mode=development",
63
- "build:types": "node node_modules/@typescript/native/bin/tsc -p tsconfig.build.json && dts-bundle-generator --project tsconfig.build.json --no-check -o dist/react-ui.d.ts dist/types/index.d.ts",
63
+ "build:types": "node node_modules/@typescript/native/bin/tsc -p tsconfig.build.json && dts-bundle-generator --project tsconfig.build.json --no-check --export-referenced-types -o dist/react-ui.d.ts dist/types/index.d.ts",
64
64
  "copy": "npm run copy:css && npm run copy:js",
65
65
  "copy:css": "cp src/docs/_assets/generated/react-ui.css dist && cp src/docs/_assets/generated/react-ui.development.css dist",
66
66
  "copy:js": "cp src/docs/_assets/generated/react-ui.js dist && cp src/docs/_assets/generated/react-ui.development.js dist",
67
- "eslint": "eslint src tests",
68
- "lint": "npm run eslint && npm run markdownlint && npm run stylelint && npm run typecheck",
69
- "markdownlint": "markdownlint-cli2 \"README.md\" \"src/**/*.md\"",
67
+ "lint": "npm run lint:stylelint && npm run lint:eslint && npm run lint:types && npm run lint:markdownlint",
68
+ "lint:eslint": "eslint",
69
+ "lint:markdownlint": "markdownlint-cli2 \"README.md\" \"src/**/*.md\"",
70
+ "lint:stylelint": "stylelint \"src/**/*.{css,scss}\" \"!src/docs/_assets/generated/**\" --config stylelint.config.mjs",
71
+ "lint:types": "node node_modules/@typescript/native/bin/tsc --noEmit",
70
72
  "postbuild": "npm run copy && npm run build:types",
71
73
  "postinstall": "sh scripts/write-lockfile-hash.sh",
72
74
  "precopy": "rm -rf dist && mkdir dist",
73
75
  "prepublishOnly": "npm run build",
74
76
  "start": "webpack --watch --mode=development",
75
77
  "start:chrome": "sh scripts/mcps/chrome-host/start-host-chrome.sh",
76
- "stylelint": "stylelint \"src/**/*.{css,scss}\" \"!src/docs/_assets/generated/**\" --config stylelint.config.mjs",
77
- "test": "npm run test:jest",
78
78
  "test:jest": "jest --coverage",
79
- "test:playwright-ct:all": "playwright test -c playwright-ct.config.ts",
80
- "test:playwright-ct:all-with-update": "playwright test -c playwright-ct.config.ts --update-snapshots",
81
- "test:playwright-ct:show-report": "playwright show-report --host=0.0.0.0 --port=9323",
82
- "typecheck": "node node_modules/@typescript/native/bin/tsc --noEmit"
79
+ "test:playwright": "playwright test -c playwright-ct.config.ts",
80
+ "test:playwright:report": "playwright show-report --host=0.0.0.0"
83
81
  },
84
82
  "dependencies": {
85
83
  "normalize.css": "^8.0.1"
@@ -89,49 +87,49 @@
89
87
  "react-dom": "^18.2.0"
90
88
  },
91
89
  "devDependencies": {
92
- "@babel/core": "^8.0.5",
93
- "@babel/preset-env": "^8.0.5",
90
+ "@babel/core": "^8.1.2",
91
+ "@babel/preset-env": "^8.0.7",
94
92
  "@babel/preset-react": "^8.0.1",
95
- "@babel/preset-typescript": "^8.0.1",
96
- "@happy-dom/jest-environment": "^20.14.5",
97
- "@playwright/test": "~1.63.0",
98
- "@react-ui-org/eslint-config": "^1.1.0",
99
- "@react-ui-org/stylelint-config": "^1.0.0",
93
+ "@babel/preset-typescript": "^8.0.7",
94
+ "@happy-dom/jest-environment": "^21.0.4",
95
+ "@playwright/test": "~1.65.1",
96
+ "@react-ui-org/eslint-config": "^2.0.0",
97
+ "@react-ui-org/stylelint-config": "^2.0.0",
100
98
  "@testing-library/dom": "^10.4.2",
101
99
  "@testing-library/jest-dom": "^7.0.1",
102
100
  "@testing-library/react": "^16.3.3",
103
- "@testing-library/user-event": "^14.6.7",
101
+ "@testing-library/user-event": "^14.6.12",
104
102
  "@types/jest": "^30.0.0",
105
- "@types/node": "^26.5.1",
103
+ "@types/node": "^26.6.6",
106
104
  "@types/react": "^19.3.0",
107
105
  "@types/react-dom": "^19.3.0",
108
106
  "@typescript/native": "npm:typescript@^7.0.2",
109
- "autoprefixer": "^10.6.0",
110
- "babel-jest": "^30.5.1",
107
+ "autoprefixer": "^10.6.2",
108
+ "babel-jest": "^30.5.2",
111
109
  "babel-loader": "^10.1.1",
112
110
  "babel-plugin-polyfill-corejs3": "^1.0.0",
113
- "core-js": "^3.50.0",
111
+ "core-js": "^3.51.0",
114
112
  "css-loader": "^7.1.5",
115
- "dotenv": "^17.4.2",
116
- "dts-bundle-generator": "^9.5.1",
113
+ "dotenv": "^18.0.10",
114
+ "dts-bundle-generator": "^10.0.0",
117
115
  "eslint": "^9.39.5",
118
116
  "identity-obj-proxy": "^3.0.0",
119
- "jest": "^30.5.1",
120
- "markdownlint-cli2": "^0.23.3",
117
+ "jest": "^30.5.2",
118
+ "markdownlint-cli2": "^0.24.1",
121
119
  "mini-css-extract-plugin": "^2.10.2",
122
- "postcss": "^8.5.28",
120
+ "postcss": "^8.5.33",
123
121
  "postcss-loader": "^8.2.1",
124
122
  "react": "^18.3.1",
125
123
  "react-dom": "^18.3.1",
126
- "sass": "^1.104.1",
127
- "sass-loader": "^17.0.1",
128
- "stylelint": "^17.15.0",
124
+ "sass": "^1.108.2",
125
+ "sass-loader": "^17.1.0",
126
+ "stylelint": "^17.16.0",
129
127
  "stylelint-webpack-plugin": "^5.1.0",
130
128
  "terser-webpack-plugin": "^5.6.1",
131
129
  "typescript": "npm:@typescript/typescript6@^6.0.2",
132
- "webpack": "^5.111.0",
133
- "webpack-cli": "^7.2.3",
134
- "webpack-dev-server": "^6.0.0",
130
+ "webpack": "^5.112.2",
131
+ "webpack-cli": "^7.3.1",
132
+ "webpack-dev-server": "^6.1.0",
135
133
  "webpack-visualizer-plugin2": "^2.0.0"
136
134
  },
137
135
  "overrides": {
@@ -32,5 +32,5 @@ export default (styles: CssModuleClasses, labelVisibility?: ButtonLabelVisibilit
32
32
  return styles.hasLabelHidden;
33
33
  }
34
34
 
35
- return null;
35
+ return undefined;
36
36
  };
@@ -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.validation(invalid);
43
+ @include variants.state(invalid);
40
44
  }
41
45
 
42
46
  .isRootStateValid {
43
- @include variants.validation(valid);
47
+ @include variants.state(valid);
44
48
  }
45
49
 
46
50
  .isRootStateWarning {
47
- @include variants.validation(warning);
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 { getRootValidationStateClassName } from '../_helpers/getRootValidationStateClassName';
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
- validationState,
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
- getRootValidationStateClassName(styles, validationState),
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
- ValidationState,
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 provide feedback based on validation result.
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
- validationState?: ValidationState;
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
- validationState="valid"
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
- validationState="warning"
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
- validationState="invalid"
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.validation(invalid);
108
+ @include variants.state(invalid);
105
109
  }
106
110
 
107
111
  .isRootStateValid {
108
- @include variants.validation(valid);
112
+ @include variants.state(valid);
109
113
  }
110
114
 
111
115
  .isRootStateWarning {
112
- @include variants.validation(warning);
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 { getRootValidationStateClassName } from '../_helpers/getRootValidationStateClassName';
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
- validationState,
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
- getRootValidationStateClassName(styles, validationState),
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
- ValidationState,
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 provide feedback based on validation result.
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
- validationState?: ValidationState;
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
- validationState="valid"
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
- validationState="invalid"
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
- validationState="warning"
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 the `subgrid` feature which makes it
4
- // possible to turn on automatic size of grid column with labels (in supporting browsers, see 4).
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 (which is possible only with `subgrid`). However, this feature is currently
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.validation(invalid);
27
+ @include variants.state(invalid);
24
28
  }
25
29
 
26
30
  .isRootStateValid {
27
- @include variants.validation(valid);
31
+ @include variants.state(valid);
28
32
  }
29
33
 
30
34
  .isRootStateWarning {
31
- @include variants.validation(warning);
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 { getRootValidationStateClassName } from '../_helpers/getRootValidationStateClassName';
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
- validationState,
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
- getRootValidationStateClassName(styles, validationState),
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
- ValidationState,
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 provide feedback based on validation result.
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
- validationState?: ValidationState;
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
- validationState="invalid"
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
- validationState="valid"
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.validation(invalid);
58
+ @include variants.state(invalid);
55
59
  }
56
60
 
57
61
  .isRootStateValid {
58
- @include variants.validation(valid);
62
+ @include variants.state(valid);
59
63
  }
60
64
 
61
65
  .isRootStateWarning {
62
- @include variants.validation(warning);
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 { getRootValidationStateClassName } from '../_helpers/getRootValidationStateClassName';
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 { ValidationState } from '../../types';
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 validationState = React.Children.toArray(children).reduce<ValidationState | undefined>(
48
- (state, child) => {
49
- const childValidationState = (child as ReactElement<{ validationState?: ValidationState }>).props.validationState;
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
- getRootValidationStateClassName(styles, validationState),
65
+ getRootStateClassName(styles, state),
72
66
  )}
73
67
  disabled={disabled}
74
68
  id={id}