@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 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). Every
36
- component reads them with its former value as fallback, so **nothing changes unless a host sets
37
- them** — existing forms look exactly as before (checked story by story against the previous
38
- release).
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 webclient design system (micromerce/webclient DESIGN.md) for one form
46
- <FormBuilder config={config} themePreset="design" />
51
+ // the look before the design system, for one form
52
+ <FormBuilder config={config} themePreset="legacy" />
47
53
 
48
- // a preset plus single tokens, for everything inside the provider
49
- <FormBuilderThemeProvider preset="design" theme={{ accent: "#058AD7", labelWidth: 160 }}>
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
- - `toCssVars(theme)` returns the custom properties for a `style` prop, for a host that applies
58
- the theme to an element of its own (e.g. `<body>`).
59
- - MUI renders tooltips, menus and the option lists of Select / MultiSelect into a portal under
60
- `<body>`; they only see tokens set on `<body>` / `:root` (or on a provider around the portal
61
- target).
62
- - The preset derives Accent Strong, the hover and the tints where its class sits. Set
63
- `accent` on the same element (a provider with `preset` and `theme` does that), or set the
64
- derived tokens too when a deeper element changes the accent.
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 whole design system with a class on any ancestor: `<body class="fb-theme-design">`.
73
-
74
- The default declarations use `:where(:root)` (no specificity), so a host rule always wins.
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 (unchanged) | `design` preset |
84
+ | `theme` key | Custom property | Default (design) | `legacy` preset |
79
85
  |---|---|---|---|
80
- | `accent` | `--fb-color-accent` | `#4A96D2` | `var(--primary-color, #4A96D2)` |
81
- | `accentStrong` | `--fb-color-accent-strong` | the accent | the accent (DESIGN.md, The Entity Accent Rule); 75% mixed with black is the accessible alternative |
82
- | `accentHover` | `--fb-color-accent-hover` | `#0B5BA6` | accent 75% mixed with black (`#38709E` for the default) |
83
- | `accentDark` | `--fb-color-accent-dark` | `#255F8E` | the accent hover |
84
- | `onAccent` | `--fb-color-on-accent` | `white` (calendar: 85% white) | `#fff` |
85
- | `primary` | `--fb-color-primary` | `#4a95d0` | Accent Strong (the accent) |
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,.54)` | `rgba(0,0,0,.87)` |
88
- | `fieldText` / `fieldFontWeight` | `--fb-color-field-text` / `--fb-field-font-weight` | `#707070` / `300` | `rgba(0,0,0,.87)` / `400` |
89
- | `placeholder` | `--fb-color-text-placeholder` | `#999` | `rgba(0,0,0,.54)` |
90
- | `helper` / `helperFontSize` | `--fb-color-helper` / `--fb-helper-font-size` | `#636569` / `10px` | `rgba(0,0,0,.54)` / `12px` |
91
- | `border` | `--fb-color-border` | `#ccc` | `rgba(0,0,0,.23)` |
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 | `inset 0 0 0 1px rgba(0,0,0,.87)` (focus 2px, hover 1px) |
94
- | `checkboxOff` / `switchOff` | `--fb-color-checkbox-off` / `--fb-color-switch-off` | `#D0D0D0` / `rgba(0,0,0,.38)` | `rgba(0,0,0,.54)` (4.6:1, WCAG 1.4.11) |
95
- | `optionSelected` / `optionSelectedFocus` | `--fb-color-option-selected` / `--fb-color-option-selected-focus` | MUI blue at 8% / 12% | accent 8% / 16% tint |
96
- | `background` / `backgroundReadonly` | `--fb-color-bg` / `--fb-color-bg-readonly` | `#fff` / `#e0e0e033` | `#fff` / `rgba(224,224,224,.2)` |
97
- | `error` | `--fb-color-error` | `#a94442` | `#D32F2F` |
98
- | `errorFontSize` / `errorIcon` | `--fb-error-font-size` / `--fb-error-icon` | `14px` / none | `12px` / `"\f06a"` |
99
- | `alertText` / `alertBackground` | `--fb-color-alert-text` / `--fb-color-alert-bg` | `#b01f14` / `#f4433633` | `#D32F2F` / `rgba(211,47,47,.06)` |
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`) | `2px solid` accent |
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 the
106
- preset. Stable class hooks for the rare rule tokens cannot express: `fb-form-group`
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;