@micromerce/formbuilder-react 1.0.986 → 1.0.990
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/README.md +48 -42
- package/dist/components/FormBuilder/FormBuilder.d.ts +3 -1
- package/dist/formbuilder.js +71 -71
- package/dist/formbuilder.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/theme/FormBuilderThemeProvider.d.ts +76 -4
- package/dist/theme/index.d.ts +3 -3
- package/dist/theme/tokens.d.ts +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,38 +30,44 @@ Then run `npm rum watch` to start the formbuilder-react (and changes are automat
|
|
|
30
30
|
The other service should now have access to the local lib.<br>
|
|
31
31
|
Warning `...is not a module.` will be displayed, but can be ignored.
|
|
32
32
|
|
|
33
|
+
## Validation
|
|
34
|
+
|
|
35
|
+
The form checks itself on submit and shows the error below every invalid field. The browser's
|
|
36
|
+
own check (its "Please fill out this field" bubble) is off (`noValidate`); turn it on with
|
|
37
|
+
`<FormBuilder config={config} browserValidation />`.
|
|
38
|
+
|
|
33
39
|
## Styling from outside
|
|
34
40
|
|
|
35
|
-
The formbuilder is styled through CSS custom properties (`--fb-*`, "fb" for formbuilder).
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
The formbuilder is styled through CSS custom properties (`--fb-*`, "fb" for formbuilder). Their
|
|
42
|
+
default is the webclient design system (micromerce/webclient `DESIGN.md`), declared on `:root`:
|
|
43
|
+
a host needs no class and no theme for it, and the tenant accent comes from `--primary-color`.
|
|
44
|
+
The look before the design system is the `legacy` preset.
|
|
39
45
|
|
|
40
46
|
### In React
|
|
41
47
|
|
|
42
48
|
```tsx
|
|
43
49
|
import { FormBuilder, FormBuilderThemeProvider } from "@micromerce/formbuilder-react";
|
|
44
50
|
|
|
45
|
-
// the
|
|
46
|
-
<FormBuilder config={config} themePreset="
|
|
51
|
+
// the look before the design system, for one form
|
|
52
|
+
<FormBuilder config={config} themePreset="legacy" />
|
|
47
53
|
|
|
48
|
-
//
|
|
49
|
-
<FormBuilderThemeProvider
|
|
54
|
+
// single tokens on top of the default, for everything inside the provider
|
|
55
|
+
<FormBuilderThemeProvider theme={{ accent: "#058AD7", labelWidth: 160 }}>
|
|
50
56
|
<FormBuilder config={config} />
|
|
51
57
|
</FormBuilderThemeProvider>
|
|
52
58
|
```
|
|
53
59
|
|
|
54
60
|
- `theme` is typed (`FormBuilderTheme`); numbers for lengths are taken as px. Single tokens win
|
|
55
|
-
over the preset; nested providers override the outer one.
|
|
61
|
+
over the preset; nested providers override the outer one (the inner preset wins).
|
|
56
62
|
- `FormBuilder` only wraps itself in an element when `theme` or `themePreset` is given.
|
|
57
|
-
-
|
|
58
|
-
the theme
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
`
|
|
64
|
-
|
|
63
|
+
- Tooltips, menus and the option lists of Select / MultiSelect, which MUI renders into a portal
|
|
64
|
+
under `<body>`, get the theme of the FormBuilder (or of the provider around it) as well.
|
|
65
|
+
Controls used on their own, outside a FormBuilder, only see the tokens of `:root` there.
|
|
66
|
+
- `toCssVars(theme)` returns the custom properties for a `style` prop, `LEGACY_CSS_VARS` the
|
|
67
|
+
legacy preset, for a host that applies a theme to an element of its own.
|
|
68
|
+
- Accent Strong, the hover and the tints are derived from the accent on `:root` (from the
|
|
69
|
+
tenant's `--primary-color`). A deeper element that changes `accent` sets the derived tokens
|
|
70
|
+
too.
|
|
65
71
|
|
|
66
72
|
### In CSS
|
|
67
73
|
|
|
@@ -69,40 +75,40 @@ import { FormBuilder, FormBuilderThemeProvider } from "@micromerce/formbuilder-r
|
|
|
69
75
|
.my-form { --fb-color-accent: var(--primary-color); --fb-label-width: 160px; }
|
|
70
76
|
```
|
|
71
77
|
|
|
72
|
-
or the
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
or the legacy look with the class `fb-theme-legacy` on any ancestor. The default declarations
|
|
79
|
+
use `:where(:root)` (no specificity), so a host rule always wins. The class `fb-theme-design`
|
|
80
|
+
still works: it brings the default back inside a legacy theme.
|
|
75
81
|
|
|
76
82
|
### Tokens
|
|
77
83
|
|
|
78
|
-
| `theme` key | Custom property | Default (
|
|
84
|
+
| `theme` key | Custom property | Default (design) | `legacy` preset |
|
|
79
85
|
|---|---|---|---|
|
|
80
|
-
| `accent` | `--fb-color-accent` |
|
|
81
|
-
| `accentStrong` | `--fb-color-accent-strong` | the accent
|
|
82
|
-
| `accentHover` | `--fb-color-accent-hover` |
|
|
83
|
-
| `accentDark` | `--fb-color-accent-dark` |
|
|
84
|
-
| `onAccent` | `--fb-color-on-accent` | `white` (calendar: 85% white) |
|
|
85
|
-
| `primary` | `--fb-color-primary` |
|
|
86
|
+
| `accent` | `--fb-color-accent` | `var(--primary-color, #4A96D2)` | `#4A96D2` |
|
|
87
|
+
| `accentStrong` | `--fb-color-accent-strong` | the accent (DESIGN.md, The Entity Accent Rule); 75% mixed with black is the accessible alternative | the accent |
|
|
88
|
+
| `accentHover` | `--fb-color-accent-hover` | accent 75% mixed with black (`#38709E` for the default) | `#0B5BA6` |
|
|
89
|
+
| `accentDark` | `--fb-color-accent-dark` | the accent hover | `#255F8E` |
|
|
90
|
+
| `onAccent` | `--fb-color-on-accent` | `#fff` | `white` (calendar: 85% white) |
|
|
91
|
+
| `primary` | `--fb-color-primary` | Accent Strong (the accent) | `#4a95d0` |
|
|
86
92
|
| `label` | `--fb-color-label` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
|
|
87
|
-
| `value` | `--fb-color-value` | `rgba(0,0,0,.
|
|
88
|
-
| `fieldText` / `fieldFontWeight` | `--fb-color-field-text` / `--fb-field-font-weight` |
|
|
89
|
-
| `placeholder` | `--fb-color-text-placeholder` |
|
|
90
|
-
| `helper` / `helperFontSize` | `--fb-color-helper` / `--fb-helper-font-size` |
|
|
91
|
-
| `border` | `--fb-color-border` |
|
|
93
|
+
| `value` | `--fb-color-value` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.54)` |
|
|
94
|
+
| `fieldText` / `fieldFontWeight` | `--fb-color-field-text` / `--fb-field-font-weight` | `rgba(0,0,0,.87)` / `400` | `#707070` / `300` |
|
|
95
|
+
| `placeholder` | `--fb-color-text-placeholder` | `rgba(0,0,0,.54)` | `#999` |
|
|
96
|
+
| `helper` / `helperFontSize` | `--fb-color-helper` / `--fb-helper-font-size` | `rgba(0,0,0,.54)` / `12px` | `#636569` / `10px` |
|
|
97
|
+
| `border` | `--fb-color-border` | `rgba(0,0,0,.23)` | `#ccc` |
|
|
92
98
|
| `borderHover` / `borderFocus` | `--fb-color-border-hover` / `--fb-color-border-focus` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
|
|
93
|
-
| `fieldFocusShadow` | `--fb-field-focus-shadow` | none
|
|
94
|
-
| `checkboxOff` / `switchOff` | `--fb-color-checkbox-off` / `--fb-color-switch-off` |
|
|
95
|
-
| `optionSelected` / `optionSelectedFocus` | `--fb-color-option-selected` / `--fb-color-option-selected-focus` |
|
|
96
|
-
| `background` / `backgroundReadonly` | `--fb-color-bg` / `--fb-color-bg-readonly` | `#fff` /
|
|
97
|
-
| `error` | `--fb-color-error` | `#
|
|
98
|
-
| `errorFontSize` / `errorIcon` | `--fb-error-font-size` / `--fb-error-icon` | `
|
|
99
|
-
| `alertText` / `alertBackground` | `--fb-color-alert-text` / `--fb-color-alert-bg` | `#
|
|
99
|
+
| `fieldFocusShadow` | `--fb-field-focus-shadow` | none (focus looks like hover) | none |
|
|
100
|
+
| `checkboxOff` / `switchOff` | `--fb-color-checkbox-off` / `--fb-color-switch-off` | `rgba(0,0,0,.54)` (4.6:1, WCAG 1.4.11) | `#D0D0D0` / `rgba(0,0,0,.38)` |
|
|
101
|
+
| `optionSelected` / `optionSelectedFocus` | `--fb-color-option-selected` / `--fb-color-option-selected-focus` | accent 8% / 16% tint | MUI blue at 8% / 12% |
|
|
102
|
+
| `background` / `backgroundReadonly` | `--fb-color-bg` / `--fb-color-bg-readonly` | `#fff` / `rgba(224,224,224,.2)` | `#fff` / `#e0e0e033` |
|
|
103
|
+
| `error` | `--fb-color-error` | `#D32F2F` | `#a94442` |
|
|
104
|
+
| `errorFontSize` / `errorIcon` | `--fb-error-font-size` / `--fb-error-icon` | `12px` / `"\f06a"` | `14px` / none |
|
|
105
|
+
| `alertText` / `alertBackground` | `--fb-color-alert-text` / `--fb-color-alert-bg` | `#D32F2F` / `rgba(211,47,47,.06)` | `#b01f14` / `#f4433633` |
|
|
100
106
|
| `labelWidth` / `labelGap` | `--fb-label-width` / `--fb-label-gap` | `200px` / `10px` | unchanged |
|
|
101
107
|
| `inputHeight` / `inputPadding` / `radius` | `--fb-input-height` / `--fb-input-padding` / `--fb-radius` | `40px` / `6px 12px` / `4px` | unchanged |
|
|
102
108
|
| `buttonHeight` / `buttonPadding` / `buttonRadius` / `buttonTextTransform` | `--fb-button-*` | MUI: `36px` / `6px 16px` / `4px` / `uppercase` | unchanged |
|
|
103
|
-
| `focusRing` | `--fb-focus-ring` | none (checkbox: `2px solid #4A96D2`) |
|
|
109
|
+
| `focusRing` | `--fb-focus-ring` | `2px solid` accent | none (checkbox: `2px solid #4A96D2`) |
|
|
104
110
|
|
|
105
|
-
`FORM_BUILDER_TOKENS` lists every key with its property; `styles/theme.module.scss` has
|
|
106
|
-
|
|
111
|
+
`FORM_BUILDER_TOKENS` lists every key with its property; `styles/theme.module.scss` has both
|
|
112
|
+
token sets. Stable class hooks for the rare rule tokens cannot express: `fb-form-group`
|
|
107
113
|
(`--error`), `fb-control-label`, `fb-control-wrapper`, `fb-helper-text`, `fb-error-message`,
|
|
108
114
|
`fb-form-footer`, `fb-submit-button`, `fb-tooltip`. Prefer them over `data-testid` selectors.
|
|
@@ -21,10 +21,12 @@ export interface IProps {
|
|
|
21
21
|
onChange?: (fieldId: string, value: string | string[]) => void;
|
|
22
22
|
themePreset?: FormBuilderThemePreset;
|
|
23
23
|
theme?: FormBuilderTheme;
|
|
24
|
+
browserValidation?: boolean;
|
|
24
25
|
}
|
|
25
|
-
declare const FormBuilder: ({ config, controlProps, customControls, fileUploaderConfig, iconType, state, resolveUrl, onSubmit, onValidationFail, postGenAiMessage, onChange, themePreset, theme, }: IProps) => React.JSX.Element | undefined;
|
|
26
|
+
declare const FormBuilder: ({ config, controlProps, customControls, fileUploaderConfig, iconType, state, resolveUrl, onSubmit, onValidationFail, postGenAiMessage, onChange, themePreset, theme, browserValidation, }: IProps) => React.JSX.Element | undefined;
|
|
26
27
|
interface FormProps {
|
|
27
28
|
method: string;
|
|
29
|
+
browserValidation?: boolean;
|
|
28
30
|
formSubmitted: boolean;
|
|
29
31
|
state?: FormState | "";
|
|
30
32
|
error?: string;
|