@micromerce/formbuilder-react 1.0.982 → 1.0.984

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
@@ -29,3 +29,73 @@ 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
+ | `accentStrong` | `--fb-color-accent-strong` | the accent | accent 75% mixed with black (`#38709E` for the default) |
78
+ | `accentHover` | `--fb-color-accent-hover` | `#0B5BA6` | accent 60% mixed with black (`#2C5A7E`) |
79
+ | `accentDark` | `--fb-color-accent-dark` | `#255F8E` | the accent hover |
80
+ | `primary` | `--fb-color-primary` | `#4a95d0` | Accent Strong |
81
+ | `label` | `--fb-color-label` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
82
+ | `value` | `--fb-color-value` | `rgba(0,0,0,.54)` | `rgba(0,0,0,.87)` |
83
+ | `fieldText` / `fieldFontWeight` | `--fb-color-field-text` / `--fb-field-font-weight` | `#707070` / `300` | `rgba(0,0,0,.87)` / `400` |
84
+ | `placeholder` | `--fb-color-text-placeholder` | `#999` | `rgba(0,0,0,.54)` |
85
+ | `helper` / `helperFontSize` | `--fb-color-helper` / `--fb-helper-font-size` | `#636569` / `10px` | `rgba(0,0,0,.54)` / `12px` |
86
+ | `border` | `--fb-color-border` | `#ccc` | `rgba(0,0,0,.23)` |
87
+ | `borderHover` / `borderFocus` | `--fb-color-border-hover` / `--fb-color-border-focus` | `rgba(0,0,0,.87)` | `rgba(0,0,0,.87)` |
88
+ | `checkboxOff` | `--fb-color-checkbox-off` | `#D0D0D0` | `#D0D0D0` |
89
+ | `background` / `backgroundReadonly` | `--fb-color-bg` / `--fb-color-bg-readonly` | `#fff` / `#e0e0e033` | `#fff` / `rgba(224,224,224,.2)` |
90
+ | `error` | `--fb-color-error` | `#a94442` | `#D32F2F` |
91
+ | `errorFontSize` / `errorIcon` | `--fb-error-font-size` / `--fb-error-icon` | `14px` / none | `12px` / `"\f06a"` |
92
+ | `alertText` / `alertBackground` | `--fb-color-alert-text` / `--fb-color-alert-bg` | `#b01f14` / `#f4433633` | `#D32F2F` / `rgba(211,47,47,.06)` |
93
+ | `labelWidth` / `labelGap` | `--fb-label-width` / `--fb-label-gap` | `200px` / `10px` | unchanged |
94
+ | `inputHeight` / `inputPadding` / `radius` | `--fb-input-height` / `--fb-input-padding` / `--fb-radius` | `40px` / `6px 12px` / `4px` | unchanged |
95
+ | `buttonHeight` / `buttonPadding` / `buttonRadius` / `buttonTextTransform` | `--fb-button-*` | MUI: `36px` / `6px 16px` / `4px` / `uppercase` | unchanged |
96
+ | `focusRing` | `--fb-focus-ring` | none (checkbox: `2px solid #4A96D2`) | `2px solid` accent |
97
+
98
+ `FORM_BUILDER_TOKENS` lists every key with its property; `styles/theme.module.scss` has the
99
+ preset. Stable class hooks for the rare rule tokens cannot express: `fb-form-group`
100
+ (`--error`), `fb-control-label`, `fb-control-wrapper`, `fb-helper-text`, `fb-error-message`,
101
+ `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;