@micromerce/formbuilder-react 1.0.981 → 1.0.983
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 +69 -0
- package/dist/components/FormBuilder/FormBuilder.d.ts +4 -1
- package/dist/formbuilder.js +73 -73
- package/dist/formbuilder.js.map +1 -1
- package/dist/hooks/useDependent/toScriptLiteral.d.ts +10 -0
- package/dist/hooks/useDependent/useDependent.d.ts +3 -1
- package/dist/index.d.ts +5 -1
- package/dist/theme/FormBuilderThemeProvider.d.ts +17 -0
- package/dist/theme/index.d.ts +4 -0
- package/dist/theme/tokens.d.ts +72 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,3 +29,72 @@ instead of
|
|
|
29
29
|
Then run `npm rum watch` to start the formbuilder-react (and changes are automatically applied).<br>
|
|
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
|
+
|
|
33
|
+
## Styling from outside
|
|
34
|
+
|
|
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).
|
|
39
|
+
|
|
40
|
+
### In React
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { FormBuilder, FormBuilderThemeProvider } from "@micromerce/formbuilder-react";
|
|
44
|
+
|
|
45
|
+
// the webclient design system (micromerce/webclient DESIGN.md) for one form
|
|
46
|
+
<FormBuilder config={config} themePreset="design" />
|
|
47
|
+
|
|
48
|
+
// a preset plus single tokens, for everything inside the provider
|
|
49
|
+
<FormBuilderThemeProvider preset="design" theme={{ accent: "#058AD7", labelWidth: 160 }}>
|
|
50
|
+
<FormBuilder config={config} />
|
|
51
|
+
</FormBuilderThemeProvider>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- `theme` is typed (`FormBuilderTheme`); numbers for lengths are taken as px. Single tokens win
|
|
55
|
+
over the preset; nested providers override the outer one.
|
|
56
|
+
- `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 and menus into a portal under `<body>`; they only see tokens set on
|
|
60
|
+
`<body>` / `:root` (or on a provider around the portal target).
|
|
61
|
+
|
|
62
|
+
### In CSS
|
|
63
|
+
|
|
64
|
+
```css
|
|
65
|
+
.my-form { --fb-color-accent: var(--primary-color); --fb-label-width: 160px; }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
or the whole design system with a class on any ancestor: `<body class="fb-theme-design">`.
|
|
69
|
+
|
|
70
|
+
The default declarations use `:where(:root)` (no specificity), so a host rule always wins.
|
|
71
|
+
|
|
72
|
+
### Tokens
|
|
73
|
+
|
|
74
|
+
| `theme` key | Custom property | Default (unchanged) | `design` preset |
|
|
75
|
+
|---|---|---|---|
|
|
76
|
+
| `accent` | `--fb-color-accent` | `#4A96D2` | `var(--primary-color, #4A96D2)` |
|
|
77
|
+
| `accentHover` | `--fb-color-accent-hover` | `#0B5BA6` | `#0B5BA6` |
|
|
78
|
+
| `accentDark` | `--fb-color-accent-dark` | `#255F8E` | `#255F8E` |
|
|
79
|
+
| `primary` | `--fb-color-primary` | `#4a95d0` | the accent |
|
|
80
|
+
| `label` | `--fb-color-label` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
|
|
81
|
+
| `value` | `--fb-color-value` | `rgba(0,0,0,.54)` | `rgba(0,0,0,.87)` |
|
|
82
|
+
| `fieldText` / `fieldFontWeight` | `--fb-color-field-text` / `--fb-field-font-weight` | `#707070` / `300` | `rgba(0,0,0,.87)` / `400` |
|
|
83
|
+
| `placeholder` | `--fb-color-text-placeholder` | `#999` | `rgba(0,0,0,.54)` |
|
|
84
|
+
| `helper` / `helperFontSize` | `--fb-color-helper` / `--fb-helper-font-size` | `#636569` / `10px` | `rgba(0,0,0,.54)` / `12px` |
|
|
85
|
+
| `border` | `--fb-color-border` | `#ccc` | `rgba(0,0,0,.23)` |
|
|
86
|
+
| `borderHover` / `borderFocus` | `--fb-color-border-hover` / `--fb-color-border-focus` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
|
|
87
|
+
| `checkboxOff` | `--fb-color-checkbox-off` | `#D0D0D0` | `#D0D0D0` |
|
|
88
|
+
| `background` / `backgroundReadonly` | `--fb-color-bg` / `--fb-color-bg-readonly` | `#fff` / `#e0e0e033` | `#fff` / `rgba(224,224,224,.2)` |
|
|
89
|
+
| `error` | `--fb-color-error` | `#a94442` | `#D32F2F` |
|
|
90
|
+
| `errorFontSize` / `errorIcon` | `--fb-error-font-size` / `--fb-error-icon` | `14px` / none | `12px` / `"\f06a"` |
|
|
91
|
+
| `alertText` / `alertBackground` | `--fb-color-alert-text` / `--fb-color-alert-bg` | `#b01f14` / `#f4433633` | `#D32F2F` / `rgba(211,47,47,.06)` |
|
|
92
|
+
| `labelWidth` / `labelGap` | `--fb-label-width` / `--fb-label-gap` | `200px` / `10px` | unchanged |
|
|
93
|
+
| `inputHeight` / `inputPadding` / `radius` | `--fb-input-height` / `--fb-input-padding` / `--fb-radius` | `40px` / `6px 12px` / `4px` | unchanged |
|
|
94
|
+
| `buttonHeight` / `buttonPadding` / `buttonRadius` / `buttonTextTransform` | `--fb-button-*` | MUI: `36px` / `6px 16px` / `4px` / `uppercase` | unchanged |
|
|
95
|
+
| `focusRing` | `--fb-focus-ring` | none (checkbox: `2px solid #4A96D2`) | `2px solid` accent |
|
|
96
|
+
|
|
97
|
+
`FORM_BUILDER_TOKENS` lists every key with its property; `styles/theme.module.scss` has the
|
|
98
|
+
preset. Stable class hooks for the rare rule tokens cannot express: `fb-form-group`
|
|
99
|
+
(`--error`), `fb-control-label`, `fb-control-wrapper`, `fb-helper-text`, `fb-error-message`,
|
|
100
|
+
`fb-form-footer`, `fb-submit-button`, `fb-tooltip`. Prefer them over `data-testid` selectors.
|
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import type { PostMessageProps, PostMessageResponse } from "../../types";
|
|
3
3
|
import { FileUploaderConfig, FormBuilderConfig, resolveUrl } from "../../types";
|
|
4
4
|
import type { controlProps } from "../../types/controlProps";
|
|
5
|
+
import type { FormBuilderTheme, FormBuilderThemePreset } from "../../theme";
|
|
5
6
|
import type { queryControl } from "../QueryControl/data/defaultControls";
|
|
6
7
|
import "../../styles/theme.module.scss";
|
|
7
8
|
import { IFormState } from "./utils/extractFormControlValues";
|
|
@@ -18,8 +19,10 @@ export interface IProps {
|
|
|
18
19
|
onValidationFail?: () => void;
|
|
19
20
|
postGenAiMessage?: ({ message, profile, }: PostMessageProps) => Promise<PostMessageResponse>;
|
|
20
21
|
onChange?: (fieldId: string, value: string | string[]) => void;
|
|
22
|
+
themePreset?: FormBuilderThemePreset;
|
|
23
|
+
theme?: FormBuilderTheme;
|
|
21
24
|
}
|
|
22
|
-
declare const FormBuilder: ({ config, controlProps, customControls, fileUploaderConfig, iconType, state, resolveUrl, onSubmit, onValidationFail, postGenAiMessage, onChange, }: IProps) => React.JSX.Element | undefined;
|
|
25
|
+
declare const FormBuilder: ({ config, controlProps, customControls, fileUploaderConfig, iconType, state, resolveUrl, onSubmit, onValidationFail, postGenAiMessage, onChange, themePreset, theme, }: IProps) => React.JSX.Element | undefined;
|
|
23
26
|
interface FormProps {
|
|
24
27
|
method: string;
|
|
25
28
|
formSubmitted: boolean;
|