@compilorama/compy 0.5.0 → 0.7.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 (48) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/components/banner/banner.css +1 -0
  3. package/dist/cjs/components/banner/banner.js +1 -0
  4. package/dist/cjs/components/banner/banner.md +38 -0
  5. package/dist/cjs/components/banner/tokens.md +56 -0
  6. package/dist/cjs/components/form/form.css +1 -0
  7. package/dist/cjs/components/form/form.js +1 -0
  8. package/dist/cjs/components/form/form.md +36 -0
  9. package/dist/cjs/components/form/tokens.md +9 -0
  10. package/dist/cjs/components/icon/icon.css +1 -0
  11. package/dist/cjs/components/icon/icon.js +1 -0
  12. package/dist/cjs/components/icon/icon.md +39 -0
  13. package/dist/cjs/components/icon/tokens.md +13 -0
  14. package/dist/cjs/docs/CONSUMERS.md +3 -1
  15. package/dist/cjs/docs/components.md +10 -0
  16. package/dist/cjs/docs/tokens.md +39 -0
  17. package/dist/cjs/hooks/use-form/use-form.js +1 -0
  18. package/dist/cjs/hooks/use-form/use-form.md +106 -0
  19. package/dist/cjs/icons/close/icon-close.js +1 -0
  20. package/dist/cjs/icons/close/icon-close.md +24 -0
  21. package/dist/cjs/index.js +1 -1
  22. package/dist/cjs/vars.css +1 -1
  23. package/dist/docs/CONSUMERS.md +3 -1
  24. package/dist/docs/components.md +10 -0
  25. package/dist/docs/tokens.md +39 -0
  26. package/dist/es6/components/banner/banner.css +1 -0
  27. package/dist/es6/components/banner/banner.js +1 -0
  28. package/dist/es6/components/banner/banner.md +38 -0
  29. package/dist/es6/components/banner/tokens.md +56 -0
  30. package/dist/es6/components/form/form.css +1 -0
  31. package/dist/es6/components/form/form.js +1 -0
  32. package/dist/es6/components/form/form.md +36 -0
  33. package/dist/es6/components/form/tokens.md +9 -0
  34. package/dist/es6/components/icon/icon.css +1 -0
  35. package/dist/es6/components/icon/icon.js +1 -0
  36. package/dist/es6/components/icon/icon.md +39 -0
  37. package/dist/es6/components/icon/tokens.md +13 -0
  38. package/dist/es6/docs/CONSUMERS.md +3 -1
  39. package/dist/es6/docs/components.md +10 -0
  40. package/dist/es6/docs/tokens.md +39 -0
  41. package/dist/es6/hooks/use-form/use-form.js +1 -0
  42. package/dist/es6/hooks/use-form/use-form.md +106 -0
  43. package/dist/es6/icons/close/icon-close.js +1 -0
  44. package/dist/es6/icons/close/icon-close.md +24 -0
  45. package/dist/es6/index.js +1 -1
  46. package/dist/es6/vars.css +1 -1
  47. package/dist/index.d.ts +11 -1
  48. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ # [0.7.0](https://github.com/compilorama/compy/compare/v0.6.0...v0.7.0) (2026-11-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * **form:** add Form component ([6d8a318](https://github.com/compilorama/compy/commit/6d8a3187169ccd373ca85f999ee1f5014d9c9f7a))
7
+ * **form:** add submitSuccess prop ([b2a6220](https://github.com/compilorama/compy/commit/b2a622070f8be874d1cb93ae7d30115bfebd1dc8))
8
+ * **form:** replace submitError and submitSuccess with submitFeedback ([ed1007b](https://github.com/compilorama/compy/commit/ed1007be7c282222ae8f70a1fc39e9de8e2bd6bd))
9
+ * **playground:** add Form view and refine useForm tests and docs ([e4d3adf](https://github.com/compilorama/compy/commit/e4d3adf8f44c6ced8e696565e59cf7d6b6afaf20))
10
+ * **use-form:** add setFormSubmitSuccess and clear it on submit ([6e52772](https://github.com/compilorama/compy/commit/6e5277297d04f7221ebb40f27d2e60f5bacd0bbe))
11
+ * **use-form:** add useForm hook and hooks docs tooling ([04f2197](https://github.com/compilorama/compy/commit/04f219703c4465785f83326be0235269f34fe1e4))
12
+ * **use-form:** replace error and success setters with setFormSubmitFeedback ([32c7cdf](https://github.com/compilorama/compy/commit/32c7cdf7202ee8913b1799756acbfd084c03c8c5))
13
+
14
+ # [0.6.0](https://github.com/compilorama/compy/compare/v0.5.0...v0.6.0) (2026-11-23)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **banner:** move close icon stroke width to the banner stylesheet ([6d83ad8](https://github.com/compilorama/compy/commit/6d83ad885c48ef50cae4bacb74860d6c236d1c12))
20
+ * **banner:** set close icon stroke width through the strokeWidth prop ([86e5b45](https://github.com/compilorama/compy/commit/86e5b4555e8dc557e9ceea8e6f483f3cc745fd09))
21
+ * **icon:** set default stroke width to 1px ([a606c3f](https://github.com/compilorama/compy/commit/a606c3f483c1d342f84bf4ee40c5b4eb51ba382c))
22
+
23
+
24
+ ### Features
25
+
26
+ * **banner:** add Banner component and color scales ([db5f324](https://github.com/compilorama/compy/commit/db5f3240383d338bb15339216afc6219196763e8))
27
+ * **icon:** add Icon component and IconClose ([ef3f1be](https://github.com/compilorama/compy/commit/ef3f1be92848e056be3af0fb0bc403d7fde9667a))
28
+
1
29
  # [0.5.0](https://github.com/compilorama/compy/compare/v0.4.0...v0.5.0) (2026-11-22)
2
30
 
3
31
 
@@ -0,0 +1 @@
1
+ .c-banner{--c-banner-background: var(--c-color-blue-95);--c-banner-content: var(--c-color-blue-50);--c-banner-close-icon: var(--c-color-blue-60);--c-banner-close-background-hover: var(--c-color-blue-90);--c-banner-radius: 15px;--c-banner-close-radius: 10px;--c-banner-close-size: 30px;display:block;position:relative;padding:10px 15px;min-height:40px;background:var(--c-banner-background);color:var(--c-banner-content);font-family:var(--c-font-family-primary);font-size:var(--c-font-size-sm);font-weight:400;line-height:20px;border-radius:var(--c-banner-radius);box-sizing:border-box}.c-banner.is-dismissable{padding-right:45px}.c-banner.is-warning{--c-banner-background: var(--c-color-orange-95);--c-banner-content: var(--c-color-orange-50);--c-banner-close-icon: var(--c-color-orange-50);--c-banner-close-background-hover: var(--c-color-orange-90)}.c-banner.is-success{--c-banner-background: var(--c-color-green-95);--c-banner-content: var(--c-color-green-30);--c-banner-close-icon: var(--c-color-green-30);--c-banner-close-background-hover: var(--c-color-green-85)}.c-banner.is-error{--c-banner-background: var(--c-color-red-95);--c-banner-content: var(--c-color-red-60);--c-banner-close-icon: var(--c-color-red-60);--c-banner-close-background-hover: var(--c-color-red-90)}.c-banner button.c-button.is-isometric{--c-button-width: var(--c-banner-close-size);--c-button-height: var(--c-banner-close-size);--c-button-radius: var(--c-banner-close-radius);--c-button-background: transparent;--c-button-background-hover: var(--c-banner-close-background-hover);--c-button-border-color: transparent;--c-button-box-shadow-color: transparent;position:absolute;top:5px;right:5px}.c-banner button.c-button.is-isometric:focus-visible{background:var(--c-banner-close-background-hover)}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _react=require("react"),_button=_interopRequireDefault(require("../button/button.jsx")),_iconClose=_interopRequireDefault(require("../../icons/close/icon-close.jsx"));require("./banner.css");var _jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const Banner=({theme:e,dismissable:r,closeButtonLabel:t,className:s,children:n,...o})=>{const[i,u]=(0,_react.useState)(!0),l=buildBannerClasses({theme:e,dismissable:r,className:s}),a=()=>u(!1);return i?(0,_jsxRuntime.jsxs)("div",{className:l,...o,children:[n,r&&renderCloseButton({closeButtonLabel:t,onClick:a})]}):null};function buildBannerClasses({theme:e,dismissable:r,className:t}){return["c-banner",e&&`is-${e}`,r&&"is-dismissable",t].filter(Boolean).join(" ")}function renderCloseButton({closeButtonLabel:e="Close",onClick:r}){return(0,_jsxRuntime.jsx)(_button.default,{type:"button","aria-label":e,onClick:r,isometric:!0,children:(0,_jsxRuntime.jsx)(_iconClose.default,{size:"20px",strokeWidth:4,strokeColor:"var(--c-banner-close-icon)"})})}var _default=exports.default=Banner;
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Banner
3
+ description: A colored message box with four themes and an optional dismiss button.
4
+ purpose: Show tips and feedback messages with consistent styling, and let users dismiss them.
5
+ ---
6
+
7
+ # Banner
8
+
9
+ A block-level message box with rounded corners. The `children` are rendered inside it, so rich content such as links, buttons, and formatted text is accepted. Without a `theme`, the banner uses the default blue theme.
10
+
11
+ With `dismissable`, a dismiss button (an isometric `Button` with an `IconClose`) is rendered in the top-right corner, and the content never overlaps it. Clicking the button removes the banner from the DOM by itself: the banner is autonomous and has no dismiss callback, and the dismissed state is not persisted.
12
+
13
+ ## Props
14
+
15
+ The Banner API extends the native HTML `div` attributes, which are forwarded to the container.
16
+
17
+ <!-- BEGIN GENERATED PROPS -->
18
+ _Also inherits all props from `HTMLAttributes<HTMLDivElement>`._
19
+
20
+ | Name | Type | Required | Default | Description |
21
+ | --- | --- | --- | --- | --- |
22
+ | children | `ReactNode` | No | `undefined` | Banner content. Accepts any React node, such as links, buttons, and formatted text. |
23
+ | closeButtonLabel | `string` | No | `"Close"` | Accessible name (`aria-label`) of the dismiss button. |
24
+ | dismissable | `boolean` | No | `false` | Renders a dismiss button in the top-right corner. Clicking it removes the banner from the DOM. |
25
+ | theme | `"success" \| "warning" \| "error"` | No | `undefined` | Color theme of the banner. When omitted, the default blue theme is used. |
26
+ <!-- END GENERATED PROPS -->
27
+
28
+ ## When to use
29
+
30
+ - Showing tips, warnings, success feedback, or error messages inside the page flow
31
+ - Messages that the user may want to dismiss
32
+ - Messages with rich content, such as links or buttons
33
+
34
+ ## When NOT to use
35
+
36
+ - **Blocking confirmations** — use a dialog or modal when the user must decide before continuing.
37
+ - **Field-level validation** — use the error message of `FormControl` next to the field.
38
+ - **Transient notifications** — a banner stays in the page until dismissed, so do not use it for toasts that disappear on their own.
@@ -0,0 +1,56 @@
1
+ # Banner tokens
2
+
3
+ Generated from `src/components/banner/banner.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-banner-background` | `var(--c-color-blue-95)` | `var(--c-color-blue-95) → hsl(220 100% 95%)` |
10
+ | `--c-banner-close-background-hover` | `var(--c-color-blue-90)` | `var(--c-color-blue-90) → hsl(220 100% 90%)` |
11
+ | `--c-banner-close-icon` | `var(--c-color-blue-60)` | `var(--c-color-blue-60) → hsl(220 100% 60%)` |
12
+ | `--c-banner-close-radius` | `10px` | `10px` |
13
+ | `--c-banner-close-size` | `30px` | `30px` |
14
+ | `--c-banner-content` | `var(--c-color-blue-50)` | `var(--c-color-blue-50) → hsl(220 100% 50%)` |
15
+ | `--c-banner-radius` | `15px` | `15px` |
16
+
17
+ ## Modifier overrides
18
+
19
+ ### `.c-banner.is-warning`
20
+
21
+ | Token | Declared value | Resolution |
22
+ | --- | --- | --- |
23
+ | `--c-banner-background` | `var(--c-color-orange-95)` | `var(--c-color-orange-95) → hsl(30 100% 95%)` |
24
+ | `--c-banner-close-background-hover` | `var(--c-color-orange-90)` | `var(--c-color-orange-90) → hsl(30 100% 90%)` |
25
+ | `--c-banner-close-icon` | `var(--c-color-orange-50)` | `var(--c-color-orange-50) → hsl(30 100% 50%)` |
26
+ | `--c-banner-content` | `var(--c-color-orange-50)` | `var(--c-color-orange-50) → hsl(30 100% 50%)` |
27
+
28
+ ### `.c-banner.is-success`
29
+
30
+ | Token | Declared value | Resolution |
31
+ | --- | --- | --- |
32
+ | `--c-banner-background` | `var(--c-color-green-95)` | `var(--c-color-green-95) → hsl(145 100% 95%)` |
33
+ | `--c-banner-close-background-hover` | `var(--c-color-green-85)` | `var(--c-color-green-85) → hsl(145 100% 85%)` |
34
+ | `--c-banner-close-icon` | `var(--c-color-green-30)` | `var(--c-color-green-30) → hsl(145 100% 30%)` |
35
+ | `--c-banner-content` | `var(--c-color-green-30)` | `var(--c-color-green-30) → hsl(145 100% 30%)` |
36
+
37
+ ### `.c-banner.is-error`
38
+
39
+ | Token | Declared value | Resolution |
40
+ | --- | --- | --- |
41
+ | `--c-banner-background` | `var(--c-color-red-95)` | `var(--c-color-red-95) → hsl(0 100% 95%)` |
42
+ | `--c-banner-close-background-hover` | `var(--c-color-red-90)` | `var(--c-color-red-90) → hsl(0 100% 90%)` |
43
+ | `--c-banner-close-icon` | `var(--c-color-red-60)` | `var(--c-color-red-60) → hsl(0 100% 60%)` |
44
+ | `--c-banner-content` | `var(--c-color-red-60)` | `var(--c-color-red-60) → hsl(0 100% 60%)` |
45
+
46
+ ### `.c-banner button.c-button.is-isometric`
47
+
48
+ | Token | Declared value | Resolution |
49
+ | --- | --- | --- |
50
+ | `--c-button-background` | `transparent` | `transparent` |
51
+ | `--c-button-background-hover` | `var(--c-banner-close-background-hover)` | `var(--c-banner-close-background-hover) → var(--c-color-blue-90) → hsl(220 100% 90%)` |
52
+ | `--c-button-border-color` | `transparent` | `transparent` |
53
+ | `--c-button-box-shadow-color` | `transparent` | `transparent` |
54
+ | `--c-button-height` | `var(--c-banner-close-size)` | `var(--c-banner-close-size) → 30px` |
55
+ | `--c-button-radius` | `var(--c-banner-close-radius)` | `var(--c-banner-close-radius) → 10px` |
56
+ | `--c-button-width` | `var(--c-banner-close-size)` | `var(--c-banner-close-size) → 30px` |
@@ -0,0 +1 @@
1
+ .c-form{--c-form-gap: 20px;display:flex;flex-direction:column;gap:var(--c-form-gap)}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _banner=_interopRequireDefault(require("../banner/banner.jsx"));require("./form.css");var _jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const Form=({submitFeedback:e,className:r,children:t,...s})=>{const n=["c-form",r].filter(Boolean).join(" ");return(0,_jsxRuntime.jsxs)("form",{className:n,noValidate:!0,...s,children:[e?.message&&(0,_jsxRuntime.jsx)(_banner.default,{theme:e.theme,children:e.message}),t]})};var _default=exports.default=Form;
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: Form
3
+ description: A native form wrapper with browser validation disabled and an optional submission feedback banner.
4
+ purpose: Wrap form controls in a form that never triggers the browser's built-in validation and can show the result of a submission at the top.
5
+ ---
6
+
7
+ # Form
8
+
9
+ A thin wrapper around the native `form` element. It always renders the `noValidate` attribute, so the browser's built-in validation (for example for fields with `required`) never runs. The `className`, `onSubmit` and every other prop are forwarded to the `form` as received.
10
+
11
+ When `submitFeedback` has a `message`, a `Banner` with no dismiss button is rendered before the `children`, with that `message` as its content and the `theme` of the feedback (`error` or `success`). Since there is a single `submitFeedback`, `Form` can never show two banners at once.
12
+
13
+ `Form` is controlled and stateless regarding `submitFeedback`: it renders the banner straight from the prop, with no internal copy of the value. When `Form` is used without a hook, the consumer controls it and must clear it on submit. Pair it with `useForm` to get that behavior for free.
14
+
15
+ ## Props
16
+
17
+ The Form API extends the native HTML `form` attributes, which are forwarded to the element.
18
+
19
+ <!-- BEGIN GENERATED PROPS -->
20
+ _Also inherits all props from `FormHTMLAttributes<HTMLFormElement>`._
21
+
22
+ | Name | Type | Required | Default | Description |
23
+ | --- | --- | --- | --- | --- |
24
+ | children | `ReactNode` | No | `undefined` | Form content, such as form controls and buttons. |
25
+ | submitFeedback | `FormSubmitFeedback` | No | `undefined` | Feedback about the last submission, shown in a banner before the children. The banner uses the `theme` of the feedback. When it is `null`, `undefined` or has no `message`, no banner is rendered. It is fully controlled by the consumer. |
26
+ <!-- END GENERATED PROPS -->
27
+
28
+ ## When to use
29
+
30
+ - Any form whose validation is handled by the application instead of the browser
31
+ - Showing the result of a submission, an error returned by the server or a success confirmation, at the top of the form
32
+
33
+ ## When NOT to use
34
+
35
+ - **Field-level validation messages** — use the error message of `FormControl` next to the field.
36
+ - **Relying on native validation** — `Form` disables it, so use a plain `form` element when you want the browser's built-in validation.
@@ -0,0 +1,9 @@
1
+ # Form tokens
2
+
3
+ Generated from `src/components/form/form.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-form-gap` | `20px` | `20px` |
@@ -0,0 +1 @@
1
+ .c-icon{--c-icon-stroke-color: var(--c-color-gray-10);--c-icon-stroke-width: 1px;--c-icon-shape-color: var(--c-color-gray-10);--c-icon-width: 40px;--c-icon-height: 40px;display:inline-flex;width:var(--c-icon-width);height:var(--c-icon-height)}.c-icon svg{width:100%;height:100%}.c-icon [data-stroke]{fill:none;stroke:var(--c-icon-stroke-color);stroke-width:var(--c-icon-stroke-width);stroke-linecap:round;stroke-linejoin:round}.c-icon [data-shape]{fill:var(--c-icon-shape-color)}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0,require("./icon.css");var _jsxRuntime=require("react/jsx-runtime");const Icon=({name:r,strokeColor:i,strokeWidth:t,size:e,style:o,className:c,children:s,...n})=>{const u=["c-icon",`c-icon-${r}`,c].filter(Boolean).join(" "),d=buildCustomProperties({strokeColor:i,strokeWidth:t,size:e});return(0,_jsxRuntime.jsx)("div",{className:u,style:{...d,...o},"aria-hidden":"true",...n,children:(0,_jsxRuntime.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 40 40",children:s})})};function buildCustomProperties({strokeColor:r,strokeWidth:i,size:t}){return Object.entries({"--c-icon-stroke-color":r,"--c-icon-stroke-width":i,"--c-icon-width":t,"--c-icon-height":t}).filter(([,e])=>e!==void 0).reduce((e,[o,c])=>({...e,[o]:c}),{})}var _default=exports.default=Icon;
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: Icon
3
+ description: A base container that renders inline SVG shapes in a 40×40 viewBox, themeable through design tokens.
4
+ purpose: Build icon components with a consistent size, stroke, and color strategy.
5
+ ---
6
+
7
+ # Icon
8
+
9
+ The base of every icon in the library. It renders a decorative container (`aria-hidden="true"`) with an inline `<svg>` that uses a `0 0 40 40` viewBox, and the `children` are the SVG shapes. Icons ready to use live in `src/icons/` (for example `IconClose`) and are built on top of `Icon`.
10
+
11
+ Shapes must not carry presentational attributes. Mark outlines with `data-stroke` (no fill, round line caps and joins) and filled shapes with `data-shape`. The default color of both is `--c-color-gray-10`: it is never inherited from the parent. Only `strokeColor` (or the `--c-icon-stroke-color` custom property) changes the stroke color. The default stroke width is 1px and the default size is 40px.
12
+
13
+ `strokeColor`, `strokeWidth`, and `size` are applied as `--c-icon-*` custom properties on the container, only when given. Values passed in `style` take precedence over them.
14
+
15
+ ## Props
16
+
17
+ The Icon API extends the native HTML `div` attributes, which are forwarded to the container.
18
+
19
+ <!-- BEGIN GENERATED PROPS -->
20
+ _Also inherits all props from `HTMLAttributes<HTMLDivElement>`._
21
+
22
+ | Name | Type | Required | Default | Description |
23
+ | --- | --- | --- | --- | --- |
24
+ | children | `ReactNode` | No | `undefined` | SVG shapes drawn inside the 40×40 viewBox. Use `data-stroke` for outlines and `data-shape` for filled shapes. |
25
+ | name | `string` | Yes | | Name of the icon. Builds the `c-icon-<name>` css class of the container. |
26
+ | size | `string` | No | `undefined` | Width and height of the icon (for example `20px`), applied as `--c-icon-width` and `--c-icon-height`. |
27
+ | strokeColor | `string` | No | `undefined` | Stroke color of the outlines, applied as `--c-icon-stroke-color`. |
28
+ | strokeWidth | `string \| number` | No | `undefined` | Stroke width of the outlines in viewBox units, applied as `--c-icon-stroke-width`. |
29
+ <!-- END GENERATED PROPS -->
30
+
31
+ ## When to use
32
+
33
+ - Building a new icon component for `src/icons/`
34
+ - Rendering a one-off SVG that must follow the library's stroke, shape, and size tokens
35
+
36
+ ## When NOT to use
37
+
38
+ - **Existing icons** — import the ready-made icon component (for example `IconClose`) instead of drawing its shapes again.
39
+ - **Images and illustrations** — use an `<img>` or an inline SVG for artwork that is not an icon.
@@ -0,0 +1,13 @@
1
+ # Icon tokens
2
+
3
+ Generated from `src/components/icon/icon.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-icon-height` | `40px` | `40px` |
10
+ | `--c-icon-shape-color` | `var(--c-color-gray-10)` | `var(--c-color-gray-10) → hsl(0 0% 10%)` |
11
+ | `--c-icon-stroke-color` | `var(--c-color-gray-10)` | `var(--c-color-gray-10) → hsl(0 0% 10%)` |
12
+ | `--c-icon-stroke-width` | `1px` | `1px` |
13
+ | `--c-icon-width` | `40px` | `40px` |
@@ -10,7 +10,9 @@ From your project root (after `npm install @compilorama/compy`):
10
10
  2. **Global design tokens:** `node_modules/@compilorama/compy/dist/docs/tokens.md`
11
11
  3. **Per-component docs:** under `node_modules/@compilorama/compy/dist/es6/components/<name>/` (or `dist/cjs/...`), for example `button.md` and `tokens.md`
12
12
 
13
- Start with `dist/docs/components.md` to pick a component, then open the linked paths relative to that file.
13
+ 4. **Hook docs:** under `node_modules/@compilorama/compy/dist/es6/hooks/<name>/` (or `dist/cjs/...`), for example `use-form.md`. Hooks are listed under **Hooks** in the component index, and have no `tokens.md`.
14
+
15
+ Start with `dist/docs/components.md` to pick a component or a hook, then open the linked paths relative to that file.
14
16
 
15
17
  ## Customizing tokens
16
18
 
@@ -4,11 +4,21 @@ Generated from component frontmatter. Human usage sections live in each componen
4
4
 
5
5
  | Component | Description | Purpose | Doc path |
6
6
  | --- | --- | --- | --- |
7
+ | Banner | A colored message box with four themes and an optional dismiss button. | Show tips and feedback messages with consistent styling, and let users dismiss them. | [`../components/banner/banner.md`](../components/banner/banner.md) |
7
8
  | Button | A native button element with variant styles driven by design tokens. | Trigger actions and submit forms with consistent visual variants. | [`../components/button/button.md`](../components/button/button.md) |
8
9
  | Checkbox | A native checkbox input with the library look and an optional built-in label. | Let the user turn an option on or off, or pick several options from a list. | [`../components/checkbox/checkbox.md`](../components/checkbox/checkbox.md) |
10
+ | Form | A native form wrapper with browser validation disabled and an optional submission feedback banner. | Wrap form controls in a form that never triggers the browser's built-in validation and can show the result of a submission at the top. | [`../components/form/form.md`](../components/form/form.md) |
9
11
  | FormControl | A wrapper that places a label above a form field and an optional error message below it. | Compose a label, a field, and an error message with consistent spacing, so consumers do not do it by hand. | [`../components/form-control/form-control.md`](../components/form-control/form-control.md) |
12
+ | Icon | A base container that renders inline SVG shapes in a 40×40 viewBox, themeable through design tokens. | Build icon components with a consistent size, stroke, and color strategy. | [`../components/icon/icon.md`](../components/icon/icon.md) |
13
+ | IconClose | A close icon made of two crossing lines, built on top of Icon. | Represent closing, dismissing, or removing something. | [`../icons/close/icon-close.md`](../icons/close/icon-close.md) |
10
14
  | Input | A single-line text field that extends the native HTML input element. | Collect short text values in forms with consistent field styling and error indication. | [`../components/input/input.md`](../components/input/input.md) |
11
15
  | Label | A text label that extends the native HTML label element. | Name a form control with consistent label typography, on its own or next to any control. | [`../components/label/label.md`](../components/label/label.md) |
12
16
  | Radio | A native radio input with the library look and an optional built-in label. | Let the user pick exactly one option from a small group of mutually exclusive options. | [`../components/radio/radio.md`](../components/radio/radio.md) |
13
17
  | Select | Dropdown field that lets the user choose one option from a fixed list. | Let the user choose one option from a fixed list. | [`../components/select/select.md`](../components/select/select.md) |
14
18
  | Textarea | Multi-line text field that collects a longer text value from the user. | Collect a longer text value such as a comment or a message. | [`../components/textarea/textarea.md`](../components/textarea/textarea.md) |
19
+
20
+ ## Hooks
21
+
22
+ | Hook | Description | Purpose | Doc path |
23
+ | --- | --- | --- | --- |
24
+ | useForm | A hook that handles form data, ordered field validation, the submit gate and the submission error. | Validate forms with the leanest API possible and wire everything to Form with a single spread. | [`../hooks/use-form/use-form.md`](../hooks/use-form/use-form.md) |
@@ -17,6 +17,19 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
17
17
  | `--c-color-accented-85` | `var(--c-color-gray-85)` | `var(--c-color-gray-85) → hsl(0 0% 85%)` |
18
18
  | `--c-color-accented-90` | `var(--c-color-gray-90)` | `var(--c-color-gray-90) → hsl(0 0% 90%)` |
19
19
  | `--c-color-accented-95` | `var(--c-color-gray-95)` | `var(--c-color-gray-95) → hsl(0 0% 95%)` |
20
+ | `--c-color-blue-10` | `hsl(220 100% 10%)` | `hsl(220 100% 10%)` |
21
+ | `--c-color-blue-15` | `hsl(220 100% 15%)` | `hsl(220 100% 15%)` |
22
+ | `--c-color-blue-20` | `hsl(220 100% 20%)` | `hsl(220 100% 20%)` |
23
+ | `--c-color-blue-30` | `hsl(220 100% 30%)` | `hsl(220 100% 30%)` |
24
+ | `--c-color-blue-40` | `hsl(220 100% 40%)` | `hsl(220 100% 40%)` |
25
+ | `--c-color-blue-5` | `hsl(220 100% 5%)` | `hsl(220 100% 5%)` |
26
+ | `--c-color-blue-50` | `hsl(220 100% 50%)` | `hsl(220 100% 50%)` |
27
+ | `--c-color-blue-60` | `hsl(220 100% 60%)` | `hsl(220 100% 60%)` |
28
+ | `--c-color-blue-70` | `hsl(220 100% 70%)` | `hsl(220 100% 70%)` |
29
+ | `--c-color-blue-80` | `hsl(220 100% 80%)` | `hsl(220 100% 80%)` |
30
+ | `--c-color-blue-85` | `hsl(220 100% 85%)` | `hsl(220 100% 85%)` |
31
+ | `--c-color-blue-90` | `hsl(220 100% 90%)` | `hsl(220 100% 90%)` |
32
+ | `--c-color-blue-95` | `hsl(220 100% 95%)` | `hsl(220 100% 95%)` |
20
33
  | `--c-color-gray-10` | `hsl(0 0% 10%)` | `hsl(0 0% 10%)` |
21
34
  | `--c-color-gray-15` | `hsl(0 0% 15%)` | `hsl(0 0% 15%)` |
22
35
  | `--c-color-gray-20` | `hsl(0 0% 20%)` | `hsl(0 0% 20%)` |
@@ -30,6 +43,32 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
30
43
  | `--c-color-gray-85` | `hsl(0 0% 85%)` | `hsl(0 0% 85%)` |
31
44
  | `--c-color-gray-90` | `hsl(0 0% 90%)` | `hsl(0 0% 90%)` |
32
45
  | `--c-color-gray-95` | `hsl(0 0% 95%)` | `hsl(0 0% 95%)` |
46
+ | `--c-color-green-10` | `hsl(145 100% 10%)` | `hsl(145 100% 10%)` |
47
+ | `--c-color-green-15` | `hsl(145 100% 15%)` | `hsl(145 100% 15%)` |
48
+ | `--c-color-green-20` | `hsl(145 100% 20%)` | `hsl(145 100% 20%)` |
49
+ | `--c-color-green-30` | `hsl(145 100% 30%)` | `hsl(145 100% 30%)` |
50
+ | `--c-color-green-40` | `hsl(145 100% 40%)` | `hsl(145 100% 40%)` |
51
+ | `--c-color-green-5` | `hsl(145 100% 5%)` | `hsl(145 100% 5%)` |
52
+ | `--c-color-green-50` | `hsl(145 100% 50%)` | `hsl(145 100% 50%)` |
53
+ | `--c-color-green-60` | `hsl(145 100% 60%)` | `hsl(145 100% 60%)` |
54
+ | `--c-color-green-70` | `hsl(145 100% 70%)` | `hsl(145 100% 70%)` |
55
+ | `--c-color-green-80` | `hsl(145 100% 80%)` | `hsl(145 100% 80%)` |
56
+ | `--c-color-green-85` | `hsl(145 100% 85%)` | `hsl(145 100% 85%)` |
57
+ | `--c-color-green-90` | `hsl(145 100% 90%)` | `hsl(145 100% 90%)` |
58
+ | `--c-color-green-95` | `hsl(145 100% 95%)` | `hsl(145 100% 95%)` |
59
+ | `--c-color-orange-10` | `hsl(30 100% 10%)` | `hsl(30 100% 10%)` |
60
+ | `--c-color-orange-15` | `hsl(30 100% 15%)` | `hsl(30 100% 15%)` |
61
+ | `--c-color-orange-20` | `hsl(30 100% 20%)` | `hsl(30 100% 20%)` |
62
+ | `--c-color-orange-30` | `hsl(30 100% 30%)` | `hsl(30 100% 30%)` |
63
+ | `--c-color-orange-40` | `hsl(30 100% 40%)` | `hsl(30 100% 40%)` |
64
+ | `--c-color-orange-5` | `hsl(30 100% 5%)` | `hsl(30 100% 5%)` |
65
+ | `--c-color-orange-50` | `hsl(30 100% 50%)` | `hsl(30 100% 50%)` |
66
+ | `--c-color-orange-60` | `hsl(30 100% 60%)` | `hsl(30 100% 60%)` |
67
+ | `--c-color-orange-70` | `hsl(30 100% 70%)` | `hsl(30 100% 70%)` |
68
+ | `--c-color-orange-80` | `hsl(30 100% 80%)` | `hsl(30 100% 80%)` |
69
+ | `--c-color-orange-85` | `hsl(30 100% 85%)` | `hsl(30 100% 85%)` |
70
+ | `--c-color-orange-90` | `hsl(30 100% 90%)` | `hsl(30 100% 90%)` |
71
+ | `--c-color-orange-95` | `hsl(30 100% 95%)` | `hsl(30 100% 95%)` |
33
72
  | `--c-color-red-10` | `hsl(0 100% 10%)` | `hsl(0 100% 10%)` |
34
73
  | `--c-color-red-15` | `hsl(0 100% 15%)` | `hsl(0 100% 15%)` |
35
74
  | `--c-color-red-20` | `hsl(0 100% 20%)` | `hsl(0 100% 20%)` |
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _react=require("react");const useForm=({initialFormData:t,formValidations:r,onSubmit:u})=>{const[e,a]=(0,_react.useState)(t),[s,n]=(0,_react.useState)(!1),[i,o]=(0,_react.useState)(null),c=useSubmitHandler({formData:e,formValidations:r,onSubmit:u,setHasSubmitted:n,setFormSubmitFeedback:o});return{formData:e,setFormData:a,formValidationErrors:s?validateForm(e,r):{},formProps:{onSubmit:c,submitFeedback:i},setFormSubmitFeedback:o}};function useSubmitHandler({formData:t,formValidations:r,onSubmit:u,setHasSubmitted:e,setFormSubmitFeedback:a}){const s=(0,_react.useRef)(u);return s.current=u,n=>{n.preventDefault(),e(!0),a(null),Object.keys(validateForm(t,r)).length||s.current(t,n)}}function validateForm(t,r){return Object.entries(r).reduce((u,[e,a])=>{const s=validateField(t[e],a);return s?{...u,[e]:s}:u},{})}function validateField(t,r){return r.find(({isValid:e})=>!e(t))?.errorMessage}var _default=exports.default=useForm;
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: useForm
3
+ description: A hook that handles form data, ordered field validation, the submit gate and the submission error.
4
+ purpose: Validate forms with the leanest API possible and wire everything to Form with a single spread.
5
+ ---
6
+
7
+ # useForm
8
+
9
+ A hook that encapsulates the form data, the validation of its fields, the submit gate and the submission error. Wire a form with a single spread: `<Form {...formProps}>`.
10
+
11
+ Validations are declared per field as ordered rules. The first rule whose `isValid` returns `false` defines the error message of the field.
12
+
13
+ `formValidationErrors` is `{}` until the form is submitted for the first time, so it can be forwarded straight to the `errorMessage` of each `FormControl`. After the first submit, it always reflects the current `formData`: errors appear, change and disappear as the user edits the fields.
14
+
15
+ On every submit, the hook prevents the default browser behavior, records that the form was submitted and clears the submission feedback. The consumer's `onSubmit` is called, with `formData` and the event, only when every field is valid. The hook always runs the latest `onSubmit` received, so values captured by the callback are never stale.
16
+
17
+ `setFormSubmitFeedback` is the direct state setter of the submission feedback, an object `{ message, theme }` where `theme` is `error` or `success`. Calling it after a submit, for example after an `await`, shows the banner in `Form`, even when the feedback is identical to the previous one. `null` removes the banner. Since there is a single feedback, the banner is never shown twice. The submission feedback and the field errors are independent: both can be visible at the same time.
18
+
19
+ The hook does not return the `Form` component. Consumers still bind `value` and `onChange` of each input themselves.
20
+
21
+ ## API
22
+
23
+ <!-- BEGIN GENERATED PROPS -->
24
+ ### Arguments
25
+
26
+ | Name | Type | Required | Default | Description |
27
+ | --- | --- | --- | --- | --- |
28
+ | formValidations | `Record<string, UseFormValidation[]>` | Yes | | Ordered validation rules of each field, keyed by field name. The first rule whose `isValid` returns `false` defines the field error message. |
29
+ | initialFormData | `Record<string, any>` | Yes | | Initial form data, keyed by field name. For example, `{ name: '', email: '' }`. |
30
+ | onSubmit | `(formData: Record<string, any>, event: FormEvent<HTMLFormElement>) => void` | Yes | | Submit callback, called with the form data and the submit event only when no field is invalid. The latest callback received is always the one executed. |
31
+
32
+ ### Returned values
33
+
34
+ | Name | Type | Description |
35
+ | --- | --- | --- |
36
+ | formData | `Record<string, any>` | Current form data, initialized with `initialFormData`. |
37
+ | formProps | `{ onSubmit: (event: FormEvent<HTMLFormElement>) => void; submitFeedback: FormSubmitFeedback; }` | Props to be spread into `Form`: the hook submit handler and the current submission feedback. |
38
+ | formValidationErrors | `Record<string, string>` | Error message of each invalid field, keyed by field name. It is empty until the form is submitted for the first time. After that, it always reflects the current form data. |
39
+ | setFormData | `Dispatch<SetStateAction<Record<string, any>>>` | Updates the form data. |
40
+ | setFormSubmitFeedback | `Dispatch<SetStateAction<FormSubmitFeedback>>` | Sets the feedback about the last submission, shown in the `Form` banner. For example, `{ message: 'Something went wrong', theme: 'error' }` or `{ message: 'Profile saved', theme: 'success' }`. `null` removes the banner. Every submit clears it. |
41
+ <!-- END GENERATED PROPS -->
42
+
43
+ ## Usage
44
+
45
+ ```jsx
46
+ import { Button, Form, FormControl, Input, useForm } from '@compilorama/compy';
47
+
48
+ const NAME_FIELD = 'name';
49
+ const EMAIL_FIELD = 'email';
50
+
51
+ const ProfileForm = () => {
52
+ const { formData, setFormData, formValidationErrors, formProps, setFormSubmitFeedback } = useForm({
53
+ initialFormData: { [NAME_FIELD]: '', [EMAIL_FIELD]: '' },
54
+ formValidations: buildFormValidations(),
55
+ onSubmit: async data => {
56
+ try {
57
+ await save(data);
58
+ setFormSubmitFeedback({ message: 'Profile saved', theme: 'success' });
59
+ } catch {
60
+ setFormSubmitFeedback({ message: 'Something went wrong', theme: 'error' });
61
+ }
62
+ }
63
+ });
64
+ const handleFormDataChange = ({ target: { name, value } }) => {
65
+ setFormData(prevState => ({ ...prevState, [name]: value }));
66
+ };
67
+
68
+ return (
69
+ <Form {...formProps}>
70
+ <FormControl label="Name" errorMessage={formValidationErrors[NAME_FIELD]}>
71
+ <Input
72
+ name={NAME_FIELD}
73
+ value={formData[NAME_FIELD]}
74
+ onChange={handleFormDataChange}
75
+ />
76
+ </FormControl>
77
+ <Button type="submit">Save</Button>
78
+ </Form>
79
+ );
80
+ };
81
+
82
+ function buildFormValidations(){
83
+ return {
84
+ [NAME_FIELD]: [
85
+ { isValid: val => !!val, errorMessage: 'Required' },
86
+ { isValid: val => val?.length >= 2, errorMessage: 'Enter at least 2 characters' }
87
+ ],
88
+ [EMAIL_FIELD]: [
89
+ { isValid: val => !!val, errorMessage: 'Required' },
90
+ { isValid: val => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), errorMessage: 'Enter a valid email address' }
91
+ ]
92
+ };
93
+ }
94
+ ```
95
+
96
+ ## When to use
97
+
98
+ - Forms validated by the application, with field errors shown only after the first submit
99
+ - Forms that show an error returned by the server, or a success confirmation, in the `Form` banner
100
+ - Any form where the lean validation model (ordered rules per field) is enough
101
+
102
+ ## When NOT to use
103
+
104
+ - **Asynchronous validation, per-field validation on blur or input masks** — the hook does not support them.
105
+ - **Automatic input wiring** — the hook does not bind `value` and `onChange`; consumers wire each input themselves.
106
+ - **Forms without validation or submission handling** — use `Form` alone with its own `onSubmit`.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _icon=_interopRequireDefault(require("../../components/icon/icon.jsx")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const IconClose=e=>(0,_jsxRuntime.jsxs)(_icon.default,{...e,name:"close",children:[(0,_jsxRuntime.jsx)("path",{"data-stroke":!0,d:"M12,28L28,12"}),(0,_jsxRuntime.jsx)("path",{"data-stroke":!0,d:"M28,28L12,12"})]});var _default=exports.default=IconClose;
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: IconClose
3
+ description: A close icon made of two crossing lines, built on top of Icon.
4
+ purpose: Represent closing, dismissing, or removing something.
5
+ ---
6
+
7
+ # IconClose
8
+
9
+ Two crossing lines drawn through [`Icon`](../../components/icon/icon.md), with the class `c-icon-close`. It accepts and forwards every `Icon` prop (`size`, `strokeColor`, `strokeWidth`, `className`, etc.), except `name` and `children`, which are fixed.
10
+
11
+ ## Props
12
+
13
+ <!-- BEGIN GENERATED PROPS -->
14
+ _Also inherits all props from `Omit<IconProps, 'name' | 'children'>`._
15
+ <!-- END GENERATED PROPS -->
16
+
17
+ ## When to use
18
+
19
+ - Dismiss or close buttons (for example inside an isometric `Button`)
20
+ - Removing an item from a list
21
+
22
+ ## When NOT to use
23
+
24
+ - **Text-only actions** — use a `Button` with a text label when the action needs words to be clear.
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Button",{enumerable:!0,get:function(){return _button.default}}),Object.defineProperty(exports,"Checkbox",{enumerable:!0,get:function(){return _checkbox.default}}),Object.defineProperty(exports,"FormControl",{enumerable:!0,get:function(){return _formControl.default}}),Object.defineProperty(exports,"Input",{enumerable:!0,get:function(){return _input.default}}),Object.defineProperty(exports,"Label",{enumerable:!0,get:function(){return _label.default}}),Object.defineProperty(exports,"Radio",{enumerable:!0,get:function(){return _radio.default}}),Object.defineProperty(exports,"Select",{enumerable:!0,get:function(){return _select.default}}),Object.defineProperty(exports,"Textarea",{enumerable:!0,get:function(){return _textarea.default}}),require("./index.css");var _button=_interopRequireDefault(require("./components/button/button.jsx")),_checkbox=_interopRequireDefault(require("./components/checkbox/checkbox.jsx")),_formControl=_interopRequireDefault(require("./components/form-control/form-control.jsx")),_input=_interopRequireDefault(require("./components/input/input.jsx")),_label=_interopRequireDefault(require("./components/label/label.jsx")),_radio=_interopRequireDefault(require("./components/radio/radio.jsx")),_select=_interopRequireDefault(require("./components/select/select.jsx")),_textarea=_interopRequireDefault(require("./components/textarea/textarea.jsx"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Banner",{enumerable:!0,get:function(){return _banner.default}}),Object.defineProperty(exports,"Button",{enumerable:!0,get:function(){return _button.default}}),Object.defineProperty(exports,"Checkbox",{enumerable:!0,get:function(){return _checkbox.default}}),Object.defineProperty(exports,"Form",{enumerable:!0,get:function(){return _form.default}}),Object.defineProperty(exports,"FormControl",{enumerable:!0,get:function(){return _formControl.default}}),Object.defineProperty(exports,"Icon",{enumerable:!0,get:function(){return _icon.default}}),Object.defineProperty(exports,"IconClose",{enumerable:!0,get:function(){return _iconClose.default}}),Object.defineProperty(exports,"Input",{enumerable:!0,get:function(){return _input.default}}),Object.defineProperty(exports,"Label",{enumerable:!0,get:function(){return _label.default}}),Object.defineProperty(exports,"Radio",{enumerable:!0,get:function(){return _radio.default}}),Object.defineProperty(exports,"Select",{enumerable:!0,get:function(){return _select.default}}),Object.defineProperty(exports,"Textarea",{enumerable:!0,get:function(){return _textarea.default}}),Object.defineProperty(exports,"useForm",{enumerable:!0,get:function(){return _useForm.default}}),require("./index.css");var _banner=_interopRequireDefault(require("./components/banner/banner.jsx")),_button=_interopRequireDefault(require("./components/button/button.jsx")),_checkbox=_interopRequireDefault(require("./components/checkbox/checkbox.jsx")),_form=_interopRequireDefault(require("./components/form/form.jsx")),_formControl=_interopRequireDefault(require("./components/form-control/form-control.jsx")),_icon=_interopRequireDefault(require("./components/icon/icon.jsx")),_iconClose=_interopRequireDefault(require("./icons/close/icon-close.jsx")),_input=_interopRequireDefault(require("./components/input/input.jsx")),_label=_interopRequireDefault(require("./components/label/label.jsx")),_radio=_interopRequireDefault(require("./components/radio/radio.jsx")),_select=_interopRequireDefault(require("./components/select/select.jsx")),_textarea=_interopRequireDefault(require("./components/textarea/textarea.jsx")),_useForm=_interopRequireDefault(require("./hooks/use-form/use-form.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}
package/dist/cjs/vars.css CHANGED
@@ -1 +1 @@
1
- :root{--c-font-family-primary: "Inter", sans-serif;--c-font-size-xxxs: .625rem;--c-font-size-xxs: .75rem;--c-font-size-xs: .875rem;--c-font-size-sm: 1rem;--c-font-size-md: 1.125rem;--c-font-size-lg: 1.25rem;--c-font-size-xl: 1.5rem;--c-font-size-xxl: 2.25rem;--c-font-size-xxxl: 3rem;--c-color-gray-95: hsl(0 0% 95%);--c-color-gray-90: hsl(0 0% 90%);--c-color-gray-85: hsl(0 0% 85%);--c-color-gray-80: hsl(0 0% 80%);--c-color-gray-70: hsl(0 0% 70%);--c-color-gray-60: hsl(0 0% 60%);--c-color-gray-50: hsl(0 0% 50%);--c-color-gray-40: hsl(0 0% 40%);--c-color-gray-30: hsl(0 0% 30%);--c-color-gray-20: hsl(0 0% 20%);--c-color-gray-15: hsl(0 0% 15%);--c-color-gray-10: hsl(0 0% 10%);--c-color-gray-5: hsl(0 0% 5%);--c-color-red-95: hsl(0 100% 95%);--c-color-red-90: hsl(0 100% 90%);--c-color-red-85: hsl(0 100% 85%);--c-color-red-80: hsl(0 100% 80%);--c-color-red-70: hsl(0 100% 70%);--c-color-red-60: hsl(0 100% 60%);--c-color-red-50: hsl(0 100% 50%);--c-color-red-40: hsl(0 100% 40%);--c-color-red-30: hsl(0 100% 30%);--c-color-red-20: hsl(0 100% 20%);--c-color-red-15: hsl(0 100% 15%);--c-color-red-10: hsl(0 100% 10%);--c-color-red-5: hsl(0 100% 5%);--c-color-accented-95: var(--c-color-gray-95);--c-color-accented-90: var(--c-color-gray-90);--c-color-accented-85: var(--c-color-gray-85);--c-color-accented-80: var(--c-color-gray-80);--c-color-accented-70: var(--c-color-gray-70);--c-color-accented-60: var(--c-color-gray-60);--c-color-accented-50: var(--c-color-gray-50);--c-color-accented-40: var(--c-color-gray-40);--c-color-accented-30: var(--c-color-gray-30);--c-color-accented-20: var(--c-color-gray-20);--c-color-accented-15: var(--c-color-gray-15);--c-color-accented-10: var(--c-color-gray-10);--c-color-accented-5: var(--c-color-gray-5)}
1
+ :root{--c-font-family-primary: "Inter", sans-serif;--c-font-size-xxxs: .625rem;--c-font-size-xxs: .75rem;--c-font-size-xs: .875rem;--c-font-size-sm: 1rem;--c-font-size-md: 1.125rem;--c-font-size-lg: 1.25rem;--c-font-size-xl: 1.5rem;--c-font-size-xxl: 2.25rem;--c-font-size-xxxl: 3rem;--c-color-gray-95: hsl(0 0% 95%);--c-color-gray-90: hsl(0 0% 90%);--c-color-gray-85: hsl(0 0% 85%);--c-color-gray-80: hsl(0 0% 80%);--c-color-gray-70: hsl(0 0% 70%);--c-color-gray-60: hsl(0 0% 60%);--c-color-gray-50: hsl(0 0% 50%);--c-color-gray-40: hsl(0 0% 40%);--c-color-gray-30: hsl(0 0% 30%);--c-color-gray-20: hsl(0 0% 20%);--c-color-gray-15: hsl(0 0% 15%);--c-color-gray-10: hsl(0 0% 10%);--c-color-gray-5: hsl(0 0% 5%);--c-color-red-95: hsl(0 100% 95%);--c-color-red-90: hsl(0 100% 90%);--c-color-red-85: hsl(0 100% 85%);--c-color-red-80: hsl(0 100% 80%);--c-color-red-70: hsl(0 100% 70%);--c-color-red-60: hsl(0 100% 60%);--c-color-red-50: hsl(0 100% 50%);--c-color-red-40: hsl(0 100% 40%);--c-color-red-30: hsl(0 100% 30%);--c-color-red-20: hsl(0 100% 20%);--c-color-red-15: hsl(0 100% 15%);--c-color-red-10: hsl(0 100% 10%);--c-color-red-5: hsl(0 100% 5%);--c-color-blue-95: hsl(220 100% 95%);--c-color-blue-90: hsl(220 100% 90%);--c-color-blue-85: hsl(220 100% 85%);--c-color-blue-80: hsl(220 100% 80%);--c-color-blue-70: hsl(220 100% 70%);--c-color-blue-60: hsl(220 100% 60%);--c-color-blue-50: hsl(220 100% 50%);--c-color-blue-40: hsl(220 100% 40%);--c-color-blue-30: hsl(220 100% 30%);--c-color-blue-20: hsl(220 100% 20%);--c-color-blue-15: hsl(220 100% 15%);--c-color-blue-10: hsl(220 100% 10%);--c-color-blue-5: hsl(220 100% 5%);--c-color-orange-95: hsl(30 100% 95%);--c-color-orange-90: hsl(30 100% 90%);--c-color-orange-85: hsl(30 100% 85%);--c-color-orange-80: hsl(30 100% 80%);--c-color-orange-70: hsl(30 100% 70%);--c-color-orange-60: hsl(30 100% 60%);--c-color-orange-50: hsl(30 100% 50%);--c-color-orange-40: hsl(30 100% 40%);--c-color-orange-30: hsl(30 100% 30%);--c-color-orange-20: hsl(30 100% 20%);--c-color-orange-15: hsl(30 100% 15%);--c-color-orange-10: hsl(30 100% 10%);--c-color-orange-5: hsl(30 100% 5%);--c-color-green-95: hsl(145 100% 95%);--c-color-green-90: hsl(145 100% 90%);--c-color-green-85: hsl(145 100% 85%);--c-color-green-80: hsl(145 100% 80%);--c-color-green-70: hsl(145 100% 70%);--c-color-green-60: hsl(145 100% 60%);--c-color-green-50: hsl(145 100% 50%);--c-color-green-40: hsl(145 100% 40%);--c-color-green-30: hsl(145 100% 30%);--c-color-green-20: hsl(145 100% 20%);--c-color-green-15: hsl(145 100% 15%);--c-color-green-10: hsl(145 100% 10%);--c-color-green-5: hsl(145 100% 5%);--c-color-accented-95: var(--c-color-gray-95);--c-color-accented-90: var(--c-color-gray-90);--c-color-accented-85: var(--c-color-gray-85);--c-color-accented-80: var(--c-color-gray-80);--c-color-accented-70: var(--c-color-gray-70);--c-color-accented-60: var(--c-color-gray-60);--c-color-accented-50: var(--c-color-gray-50);--c-color-accented-40: var(--c-color-gray-40);--c-color-accented-30: var(--c-color-gray-30);--c-color-accented-20: var(--c-color-gray-20);--c-color-accented-15: var(--c-color-gray-15);--c-color-accented-10: var(--c-color-gray-10);--c-color-accented-5: var(--c-color-gray-5)}
@@ -10,7 +10,9 @@ From your project root (after `npm install @compilorama/compy`):
10
10
  2. **Global design tokens:** `node_modules/@compilorama/compy/dist/docs/tokens.md`
11
11
  3. **Per-component docs:** under `node_modules/@compilorama/compy/dist/es6/components/<name>/` (or `dist/cjs/...`), for example `button.md` and `tokens.md`
12
12
 
13
- Start with `dist/docs/components.md` to pick a component, then open the linked paths relative to that file.
13
+ 4. **Hook docs:** under `node_modules/@compilorama/compy/dist/es6/hooks/<name>/` (or `dist/cjs/...`), for example `use-form.md`. Hooks are listed under **Hooks** in the component index, and have no `tokens.md`.
14
+
15
+ Start with `dist/docs/components.md` to pick a component or a hook, then open the linked paths relative to that file.
14
16
 
15
17
  ## Customizing tokens
16
18
 
@@ -4,11 +4,21 @@ Generated from component frontmatter. Human usage sections live in each componen
4
4
 
5
5
  | Component | Description | Purpose | Doc path |
6
6
  | --- | --- | --- | --- |
7
+ | Banner | A colored message box with four themes and an optional dismiss button. | Show tips and feedback messages with consistent styling, and let users dismiss them. | [`../components/banner/banner.md`](../components/banner/banner.md) |
7
8
  | Button | A native button element with variant styles driven by design tokens. | Trigger actions and submit forms with consistent visual variants. | [`../components/button/button.md`](../components/button/button.md) |
8
9
  | Checkbox | A native checkbox input with the library look and an optional built-in label. | Let the user turn an option on or off, or pick several options from a list. | [`../components/checkbox/checkbox.md`](../components/checkbox/checkbox.md) |
10
+ | Form | A native form wrapper with browser validation disabled and an optional submission feedback banner. | Wrap form controls in a form that never triggers the browser's built-in validation and can show the result of a submission at the top. | [`../components/form/form.md`](../components/form/form.md) |
9
11
  | FormControl | A wrapper that places a label above a form field and an optional error message below it. | Compose a label, a field, and an error message with consistent spacing, so consumers do not do it by hand. | [`../components/form-control/form-control.md`](../components/form-control/form-control.md) |
12
+ | Icon | A base container that renders inline SVG shapes in a 40×40 viewBox, themeable through design tokens. | Build icon components with a consistent size, stroke, and color strategy. | [`../components/icon/icon.md`](../components/icon/icon.md) |
13
+ | IconClose | A close icon made of two crossing lines, built on top of Icon. | Represent closing, dismissing, or removing something. | [`../icons/close/icon-close.md`](../icons/close/icon-close.md) |
10
14
  | Input | A single-line text field that extends the native HTML input element. | Collect short text values in forms with consistent field styling and error indication. | [`../components/input/input.md`](../components/input/input.md) |
11
15
  | Label | A text label that extends the native HTML label element. | Name a form control with consistent label typography, on its own or next to any control. | [`../components/label/label.md`](../components/label/label.md) |
12
16
  | Radio | A native radio input with the library look and an optional built-in label. | Let the user pick exactly one option from a small group of mutually exclusive options. | [`../components/radio/radio.md`](../components/radio/radio.md) |
13
17
  | Select | Dropdown field that lets the user choose one option from a fixed list. | Let the user choose one option from a fixed list. | [`../components/select/select.md`](../components/select/select.md) |
14
18
  | Textarea | Multi-line text field that collects a longer text value from the user. | Collect a longer text value such as a comment or a message. | [`../components/textarea/textarea.md`](../components/textarea/textarea.md) |
19
+
20
+ ## Hooks
21
+
22
+ | Hook | Description | Purpose | Doc path |
23
+ | --- | --- | --- | --- |
24
+ | useForm | A hook that handles form data, ordered field validation, the submit gate and the submission error. | Validate forms with the leanest API possible and wire everything to Form with a single spread. | [`../hooks/use-form/use-form.md`](../hooks/use-form/use-form.md) |
@@ -17,6 +17,19 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
17
17
  | `--c-color-accented-85` | `var(--c-color-gray-85)` | `var(--c-color-gray-85) → hsl(0 0% 85%)` |
18
18
  | `--c-color-accented-90` | `var(--c-color-gray-90)` | `var(--c-color-gray-90) → hsl(0 0% 90%)` |
19
19
  | `--c-color-accented-95` | `var(--c-color-gray-95)` | `var(--c-color-gray-95) → hsl(0 0% 95%)` |
20
+ | `--c-color-blue-10` | `hsl(220 100% 10%)` | `hsl(220 100% 10%)` |
21
+ | `--c-color-blue-15` | `hsl(220 100% 15%)` | `hsl(220 100% 15%)` |
22
+ | `--c-color-blue-20` | `hsl(220 100% 20%)` | `hsl(220 100% 20%)` |
23
+ | `--c-color-blue-30` | `hsl(220 100% 30%)` | `hsl(220 100% 30%)` |
24
+ | `--c-color-blue-40` | `hsl(220 100% 40%)` | `hsl(220 100% 40%)` |
25
+ | `--c-color-blue-5` | `hsl(220 100% 5%)` | `hsl(220 100% 5%)` |
26
+ | `--c-color-blue-50` | `hsl(220 100% 50%)` | `hsl(220 100% 50%)` |
27
+ | `--c-color-blue-60` | `hsl(220 100% 60%)` | `hsl(220 100% 60%)` |
28
+ | `--c-color-blue-70` | `hsl(220 100% 70%)` | `hsl(220 100% 70%)` |
29
+ | `--c-color-blue-80` | `hsl(220 100% 80%)` | `hsl(220 100% 80%)` |
30
+ | `--c-color-blue-85` | `hsl(220 100% 85%)` | `hsl(220 100% 85%)` |
31
+ | `--c-color-blue-90` | `hsl(220 100% 90%)` | `hsl(220 100% 90%)` |
32
+ | `--c-color-blue-95` | `hsl(220 100% 95%)` | `hsl(220 100% 95%)` |
20
33
  | `--c-color-gray-10` | `hsl(0 0% 10%)` | `hsl(0 0% 10%)` |
21
34
  | `--c-color-gray-15` | `hsl(0 0% 15%)` | `hsl(0 0% 15%)` |
22
35
  | `--c-color-gray-20` | `hsl(0 0% 20%)` | `hsl(0 0% 20%)` |
@@ -30,6 +43,32 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
30
43
  | `--c-color-gray-85` | `hsl(0 0% 85%)` | `hsl(0 0% 85%)` |
31
44
  | `--c-color-gray-90` | `hsl(0 0% 90%)` | `hsl(0 0% 90%)` |
32
45
  | `--c-color-gray-95` | `hsl(0 0% 95%)` | `hsl(0 0% 95%)` |
46
+ | `--c-color-green-10` | `hsl(145 100% 10%)` | `hsl(145 100% 10%)` |
47
+ | `--c-color-green-15` | `hsl(145 100% 15%)` | `hsl(145 100% 15%)` |
48
+ | `--c-color-green-20` | `hsl(145 100% 20%)` | `hsl(145 100% 20%)` |
49
+ | `--c-color-green-30` | `hsl(145 100% 30%)` | `hsl(145 100% 30%)` |
50
+ | `--c-color-green-40` | `hsl(145 100% 40%)` | `hsl(145 100% 40%)` |
51
+ | `--c-color-green-5` | `hsl(145 100% 5%)` | `hsl(145 100% 5%)` |
52
+ | `--c-color-green-50` | `hsl(145 100% 50%)` | `hsl(145 100% 50%)` |
53
+ | `--c-color-green-60` | `hsl(145 100% 60%)` | `hsl(145 100% 60%)` |
54
+ | `--c-color-green-70` | `hsl(145 100% 70%)` | `hsl(145 100% 70%)` |
55
+ | `--c-color-green-80` | `hsl(145 100% 80%)` | `hsl(145 100% 80%)` |
56
+ | `--c-color-green-85` | `hsl(145 100% 85%)` | `hsl(145 100% 85%)` |
57
+ | `--c-color-green-90` | `hsl(145 100% 90%)` | `hsl(145 100% 90%)` |
58
+ | `--c-color-green-95` | `hsl(145 100% 95%)` | `hsl(145 100% 95%)` |
59
+ | `--c-color-orange-10` | `hsl(30 100% 10%)` | `hsl(30 100% 10%)` |
60
+ | `--c-color-orange-15` | `hsl(30 100% 15%)` | `hsl(30 100% 15%)` |
61
+ | `--c-color-orange-20` | `hsl(30 100% 20%)` | `hsl(30 100% 20%)` |
62
+ | `--c-color-orange-30` | `hsl(30 100% 30%)` | `hsl(30 100% 30%)` |
63
+ | `--c-color-orange-40` | `hsl(30 100% 40%)` | `hsl(30 100% 40%)` |
64
+ | `--c-color-orange-5` | `hsl(30 100% 5%)` | `hsl(30 100% 5%)` |
65
+ | `--c-color-orange-50` | `hsl(30 100% 50%)` | `hsl(30 100% 50%)` |
66
+ | `--c-color-orange-60` | `hsl(30 100% 60%)` | `hsl(30 100% 60%)` |
67
+ | `--c-color-orange-70` | `hsl(30 100% 70%)` | `hsl(30 100% 70%)` |
68
+ | `--c-color-orange-80` | `hsl(30 100% 80%)` | `hsl(30 100% 80%)` |
69
+ | `--c-color-orange-85` | `hsl(30 100% 85%)` | `hsl(30 100% 85%)` |
70
+ | `--c-color-orange-90` | `hsl(30 100% 90%)` | `hsl(30 100% 90%)` |
71
+ | `--c-color-orange-95` | `hsl(30 100% 95%)` | `hsl(30 100% 95%)` |
33
72
  | `--c-color-red-10` | `hsl(0 100% 10%)` | `hsl(0 100% 10%)` |
34
73
  | `--c-color-red-15` | `hsl(0 100% 15%)` | `hsl(0 100% 15%)` |
35
74
  | `--c-color-red-20` | `hsl(0 100% 20%)` | `hsl(0 100% 20%)` |
@@ -0,0 +1 @@
1
+ .c-banner{--c-banner-background: var(--c-color-blue-95);--c-banner-content: var(--c-color-blue-50);--c-banner-close-icon: var(--c-color-blue-60);--c-banner-close-background-hover: var(--c-color-blue-90);--c-banner-radius: 15px;--c-banner-close-radius: 10px;--c-banner-close-size: 30px;display:block;position:relative;padding:10px 15px;min-height:40px;background:var(--c-banner-background);color:var(--c-banner-content);font-family:var(--c-font-family-primary);font-size:var(--c-font-size-sm);font-weight:400;line-height:20px;border-radius:var(--c-banner-radius);box-sizing:border-box}.c-banner.is-dismissable{padding-right:45px}.c-banner.is-warning{--c-banner-background: var(--c-color-orange-95);--c-banner-content: var(--c-color-orange-50);--c-banner-close-icon: var(--c-color-orange-50);--c-banner-close-background-hover: var(--c-color-orange-90)}.c-banner.is-success{--c-banner-background: var(--c-color-green-95);--c-banner-content: var(--c-color-green-30);--c-banner-close-icon: var(--c-color-green-30);--c-banner-close-background-hover: var(--c-color-green-85)}.c-banner.is-error{--c-banner-background: var(--c-color-red-95);--c-banner-content: var(--c-color-red-60);--c-banner-close-icon: var(--c-color-red-60);--c-banner-close-background-hover: var(--c-color-red-90)}.c-banner button.c-button.is-isometric{--c-button-width: var(--c-banner-close-size);--c-button-height: var(--c-banner-close-size);--c-button-radius: var(--c-banner-close-radius);--c-button-background: transparent;--c-button-background-hover: var(--c-banner-close-background-hover);--c-button-border-color: transparent;--c-button-box-shadow-color: transparent;position:absolute;top:5px;right:5px}.c-banner button.c-button.is-isometric:focus-visible{background:var(--c-banner-close-background-hover)}
@@ -0,0 +1 @@
1
+ import{useState as f}from"react";import m from"../button/button.js";import d from"../../icons/close/icon-close.js";import"./banner.css";import{jsxs as p,jsx as r}from"react/jsx-runtime";const C=({theme:e,dismissable:s,closeButtonLabel:o,className:n,children:t,...i})=>{const[l,a]=f(!0),c=b({theme:e,dismissable:s,className:n}),u=()=>a(!1);return l?p("div",{className:c,...i,children:[t,s&&x({closeButtonLabel:o,onClick:u})]}):null};function b({theme:e,dismissable:s,className:o}){return["c-banner",e&&`is-${e}`,s&&"is-dismissable",o].filter(Boolean).join(" ")}function x({closeButtonLabel:e="Close",onClick:s}){return r(m,{type:"button","aria-label":e,onClick:s,isometric:!0,children:r(d,{size:"20px",strokeWidth:4,strokeColor:"var(--c-banner-close-icon)"})})}export default C;
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Banner
3
+ description: A colored message box with four themes and an optional dismiss button.
4
+ purpose: Show tips and feedback messages with consistent styling, and let users dismiss them.
5
+ ---
6
+
7
+ # Banner
8
+
9
+ A block-level message box with rounded corners. The `children` are rendered inside it, so rich content such as links, buttons, and formatted text is accepted. Without a `theme`, the banner uses the default blue theme.
10
+
11
+ With `dismissable`, a dismiss button (an isometric `Button` with an `IconClose`) is rendered in the top-right corner, and the content never overlaps it. Clicking the button removes the banner from the DOM by itself: the banner is autonomous and has no dismiss callback, and the dismissed state is not persisted.
12
+
13
+ ## Props
14
+
15
+ The Banner API extends the native HTML `div` attributes, which are forwarded to the container.
16
+
17
+ <!-- BEGIN GENERATED PROPS -->
18
+ _Also inherits all props from `HTMLAttributes<HTMLDivElement>`._
19
+
20
+ | Name | Type | Required | Default | Description |
21
+ | --- | --- | --- | --- | --- |
22
+ | children | `ReactNode` | No | `undefined` | Banner content. Accepts any React node, such as links, buttons, and formatted text. |
23
+ | closeButtonLabel | `string` | No | `"Close"` | Accessible name (`aria-label`) of the dismiss button. |
24
+ | dismissable | `boolean` | No | `false` | Renders a dismiss button in the top-right corner. Clicking it removes the banner from the DOM. |
25
+ | theme | `"success" \| "warning" \| "error"` | No | `undefined` | Color theme of the banner. When omitted, the default blue theme is used. |
26
+ <!-- END GENERATED PROPS -->
27
+
28
+ ## When to use
29
+
30
+ - Showing tips, warnings, success feedback, or error messages inside the page flow
31
+ - Messages that the user may want to dismiss
32
+ - Messages with rich content, such as links or buttons
33
+
34
+ ## When NOT to use
35
+
36
+ - **Blocking confirmations** — use a dialog or modal when the user must decide before continuing.
37
+ - **Field-level validation** — use the error message of `FormControl` next to the field.
38
+ - **Transient notifications** — a banner stays in the page until dismissed, so do not use it for toasts that disappear on their own.
@@ -0,0 +1,56 @@
1
+ # Banner tokens
2
+
3
+ Generated from `src/components/banner/banner.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-banner-background` | `var(--c-color-blue-95)` | `var(--c-color-blue-95) → hsl(220 100% 95%)` |
10
+ | `--c-banner-close-background-hover` | `var(--c-color-blue-90)` | `var(--c-color-blue-90) → hsl(220 100% 90%)` |
11
+ | `--c-banner-close-icon` | `var(--c-color-blue-60)` | `var(--c-color-blue-60) → hsl(220 100% 60%)` |
12
+ | `--c-banner-close-radius` | `10px` | `10px` |
13
+ | `--c-banner-close-size` | `30px` | `30px` |
14
+ | `--c-banner-content` | `var(--c-color-blue-50)` | `var(--c-color-blue-50) → hsl(220 100% 50%)` |
15
+ | `--c-banner-radius` | `15px` | `15px` |
16
+
17
+ ## Modifier overrides
18
+
19
+ ### `.c-banner.is-warning`
20
+
21
+ | Token | Declared value | Resolution |
22
+ | --- | --- | --- |
23
+ | `--c-banner-background` | `var(--c-color-orange-95)` | `var(--c-color-orange-95) → hsl(30 100% 95%)` |
24
+ | `--c-banner-close-background-hover` | `var(--c-color-orange-90)` | `var(--c-color-orange-90) → hsl(30 100% 90%)` |
25
+ | `--c-banner-close-icon` | `var(--c-color-orange-50)` | `var(--c-color-orange-50) → hsl(30 100% 50%)` |
26
+ | `--c-banner-content` | `var(--c-color-orange-50)` | `var(--c-color-orange-50) → hsl(30 100% 50%)` |
27
+
28
+ ### `.c-banner.is-success`
29
+
30
+ | Token | Declared value | Resolution |
31
+ | --- | --- | --- |
32
+ | `--c-banner-background` | `var(--c-color-green-95)` | `var(--c-color-green-95) → hsl(145 100% 95%)` |
33
+ | `--c-banner-close-background-hover` | `var(--c-color-green-85)` | `var(--c-color-green-85) → hsl(145 100% 85%)` |
34
+ | `--c-banner-close-icon` | `var(--c-color-green-30)` | `var(--c-color-green-30) → hsl(145 100% 30%)` |
35
+ | `--c-banner-content` | `var(--c-color-green-30)` | `var(--c-color-green-30) → hsl(145 100% 30%)` |
36
+
37
+ ### `.c-banner.is-error`
38
+
39
+ | Token | Declared value | Resolution |
40
+ | --- | --- | --- |
41
+ | `--c-banner-background` | `var(--c-color-red-95)` | `var(--c-color-red-95) → hsl(0 100% 95%)` |
42
+ | `--c-banner-close-background-hover` | `var(--c-color-red-90)` | `var(--c-color-red-90) → hsl(0 100% 90%)` |
43
+ | `--c-banner-close-icon` | `var(--c-color-red-60)` | `var(--c-color-red-60) → hsl(0 100% 60%)` |
44
+ | `--c-banner-content` | `var(--c-color-red-60)` | `var(--c-color-red-60) → hsl(0 100% 60%)` |
45
+
46
+ ### `.c-banner button.c-button.is-isometric`
47
+
48
+ | Token | Declared value | Resolution |
49
+ | --- | --- | --- |
50
+ | `--c-button-background` | `transparent` | `transparent` |
51
+ | `--c-button-background-hover` | `var(--c-banner-close-background-hover)` | `var(--c-banner-close-background-hover) → var(--c-color-blue-90) → hsl(220 100% 90%)` |
52
+ | `--c-button-border-color` | `transparent` | `transparent` |
53
+ | `--c-button-box-shadow-color` | `transparent` | `transparent` |
54
+ | `--c-button-height` | `var(--c-banner-close-size)` | `var(--c-banner-close-size) → 30px` |
55
+ | `--c-button-radius` | `var(--c-banner-close-radius)` | `var(--c-banner-close-radius) → 10px` |
56
+ | `--c-button-width` | `var(--c-banner-close-size)` | `var(--c-banner-close-size) → 30px` |
@@ -0,0 +1 @@
1
+ .c-form{--c-form-gap: 20px;display:flex;flex-direction:column;gap:var(--c-form-gap)}
@@ -0,0 +1 @@
1
+ import t from"../banner/banner.js";import"./form.css";import{jsx as a,jsxs as n}from"react/jsx-runtime";const l=({submitFeedback:s,className:e,children:r,...o})=>{const m=["c-form",e].filter(Boolean).join(" ");return n("form",{className:m,noValidate:!0,...o,children:[s?.message&&a(t,{theme:s.theme,children:s.message}),r]})};export default l;
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: Form
3
+ description: A native form wrapper with browser validation disabled and an optional submission feedback banner.
4
+ purpose: Wrap form controls in a form that never triggers the browser's built-in validation and can show the result of a submission at the top.
5
+ ---
6
+
7
+ # Form
8
+
9
+ A thin wrapper around the native `form` element. It always renders the `noValidate` attribute, so the browser's built-in validation (for example for fields with `required`) never runs. The `className`, `onSubmit` and every other prop are forwarded to the `form` as received.
10
+
11
+ When `submitFeedback` has a `message`, a `Banner` with no dismiss button is rendered before the `children`, with that `message` as its content and the `theme` of the feedback (`error` or `success`). Since there is a single `submitFeedback`, `Form` can never show two banners at once.
12
+
13
+ `Form` is controlled and stateless regarding `submitFeedback`: it renders the banner straight from the prop, with no internal copy of the value. When `Form` is used without a hook, the consumer controls it and must clear it on submit. Pair it with `useForm` to get that behavior for free.
14
+
15
+ ## Props
16
+
17
+ The Form API extends the native HTML `form` attributes, which are forwarded to the element.
18
+
19
+ <!-- BEGIN GENERATED PROPS -->
20
+ _Also inherits all props from `FormHTMLAttributes<HTMLFormElement>`._
21
+
22
+ | Name | Type | Required | Default | Description |
23
+ | --- | --- | --- | --- | --- |
24
+ | children | `ReactNode` | No | `undefined` | Form content, such as form controls and buttons. |
25
+ | submitFeedback | `FormSubmitFeedback` | No | `undefined` | Feedback about the last submission, shown in a banner before the children. The banner uses the `theme` of the feedback. When it is `null`, `undefined` or has no `message`, no banner is rendered. It is fully controlled by the consumer. |
26
+ <!-- END GENERATED PROPS -->
27
+
28
+ ## When to use
29
+
30
+ - Any form whose validation is handled by the application instead of the browser
31
+ - Showing the result of a submission, an error returned by the server or a success confirmation, at the top of the form
32
+
33
+ ## When NOT to use
34
+
35
+ - **Field-level validation messages** — use the error message of `FormControl` next to the field.
36
+ - **Relying on native validation** — `Form` disables it, so use a plain `form` element when you want the browser's built-in validation.
@@ -0,0 +1,9 @@
1
+ # Form tokens
2
+
3
+ Generated from `src/components/form/form.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-form-gap` | `20px` | `20px` |
@@ -0,0 +1 @@
1
+ .c-icon{--c-icon-stroke-color: var(--c-color-gray-10);--c-icon-stroke-width: 1px;--c-icon-shape-color: var(--c-color-gray-10);--c-icon-width: 40px;--c-icon-height: 40px;display:inline-flex;width:var(--c-icon-width);height:var(--c-icon-height)}.c-icon svg{width:100%;height:100%}.c-icon [data-stroke]{fill:none;stroke:var(--c-icon-stroke-color);stroke-width:var(--c-icon-stroke-width);stroke-linecap:round;stroke-linejoin:round}.c-icon [data-shape]{fill:var(--c-icon-shape-color)}
@@ -0,0 +1 @@
1
+ import"./icon.css";import{jsx as n}from"react/jsx-runtime";const a=({name:t,strokeColor:c,strokeWidth:o,size:e,style:i,className:r,children:s,...d})=>{const l=["c-icon",`c-icon-${t}`,r].filter(Boolean).join(" "),u=h({strokeColor:c,strokeWidth:o,size:e});return n("div",{className:l,style:{...u,...i},"aria-hidden":"true",...d,children:n("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 40 40",children:s})})};function h({strokeColor:t,strokeWidth:c,size:o}){return Object.entries({"--c-icon-stroke-color":t,"--c-icon-stroke-width":c,"--c-icon-width":o,"--c-icon-height":o}).filter(([,e])=>e!==void 0).reduce((e,[i,r])=>({...e,[i]:r}),{})}export default a;
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: Icon
3
+ description: A base container that renders inline SVG shapes in a 40×40 viewBox, themeable through design tokens.
4
+ purpose: Build icon components with a consistent size, stroke, and color strategy.
5
+ ---
6
+
7
+ # Icon
8
+
9
+ The base of every icon in the library. It renders a decorative container (`aria-hidden="true"`) with an inline `<svg>` that uses a `0 0 40 40` viewBox, and the `children` are the SVG shapes. Icons ready to use live in `src/icons/` (for example `IconClose`) and are built on top of `Icon`.
10
+
11
+ Shapes must not carry presentational attributes. Mark outlines with `data-stroke` (no fill, round line caps and joins) and filled shapes with `data-shape`. The default color of both is `--c-color-gray-10`: it is never inherited from the parent. Only `strokeColor` (or the `--c-icon-stroke-color` custom property) changes the stroke color. The default stroke width is 1px and the default size is 40px.
12
+
13
+ `strokeColor`, `strokeWidth`, and `size` are applied as `--c-icon-*` custom properties on the container, only when given. Values passed in `style` take precedence over them.
14
+
15
+ ## Props
16
+
17
+ The Icon API extends the native HTML `div` attributes, which are forwarded to the container.
18
+
19
+ <!-- BEGIN GENERATED PROPS -->
20
+ _Also inherits all props from `HTMLAttributes<HTMLDivElement>`._
21
+
22
+ | Name | Type | Required | Default | Description |
23
+ | --- | --- | --- | --- | --- |
24
+ | children | `ReactNode` | No | `undefined` | SVG shapes drawn inside the 40×40 viewBox. Use `data-stroke` for outlines and `data-shape` for filled shapes. |
25
+ | name | `string` | Yes | | Name of the icon. Builds the `c-icon-<name>` css class of the container. |
26
+ | size | `string` | No | `undefined` | Width and height of the icon (for example `20px`), applied as `--c-icon-width` and `--c-icon-height`. |
27
+ | strokeColor | `string` | No | `undefined` | Stroke color of the outlines, applied as `--c-icon-stroke-color`. |
28
+ | strokeWidth | `string \| number` | No | `undefined` | Stroke width of the outlines in viewBox units, applied as `--c-icon-stroke-width`. |
29
+ <!-- END GENERATED PROPS -->
30
+
31
+ ## When to use
32
+
33
+ - Building a new icon component for `src/icons/`
34
+ - Rendering a one-off SVG that must follow the library's stroke, shape, and size tokens
35
+
36
+ ## When NOT to use
37
+
38
+ - **Existing icons** — import the ready-made icon component (for example `IconClose`) instead of drawing its shapes again.
39
+ - **Images and illustrations** — use an `<img>` or an inline SVG for artwork that is not an icon.
@@ -0,0 +1,13 @@
1
+ # Icon tokens
2
+
3
+ Generated from `src/components/icon/icon.css`.
4
+
5
+ ## Base tokens
6
+
7
+ | Token | Declared value | Resolution |
8
+ | --- | --- | --- |
9
+ | `--c-icon-height` | `40px` | `40px` |
10
+ | `--c-icon-shape-color` | `var(--c-color-gray-10)` | `var(--c-color-gray-10) → hsl(0 0% 10%)` |
11
+ | `--c-icon-stroke-color` | `var(--c-color-gray-10)` | `var(--c-color-gray-10) → hsl(0 0% 10%)` |
12
+ | `--c-icon-stroke-width` | `1px` | `1px` |
13
+ | `--c-icon-width` | `40px` | `40px` |
@@ -10,7 +10,9 @@ From your project root (after `npm install @compilorama/compy`):
10
10
  2. **Global design tokens:** `node_modules/@compilorama/compy/dist/docs/tokens.md`
11
11
  3. **Per-component docs:** under `node_modules/@compilorama/compy/dist/es6/components/<name>/` (or `dist/cjs/...`), for example `button.md` and `tokens.md`
12
12
 
13
- Start with `dist/docs/components.md` to pick a component, then open the linked paths relative to that file.
13
+ 4. **Hook docs:** under `node_modules/@compilorama/compy/dist/es6/hooks/<name>/` (or `dist/cjs/...`), for example `use-form.md`. Hooks are listed under **Hooks** in the component index, and have no `tokens.md`.
14
+
15
+ Start with `dist/docs/components.md` to pick a component or a hook, then open the linked paths relative to that file.
14
16
 
15
17
  ## Customizing tokens
16
18
 
@@ -4,11 +4,21 @@ Generated from component frontmatter. Human usage sections live in each componen
4
4
 
5
5
  | Component | Description | Purpose | Doc path |
6
6
  | --- | --- | --- | --- |
7
+ | Banner | A colored message box with four themes and an optional dismiss button. | Show tips and feedback messages with consistent styling, and let users dismiss them. | [`../components/banner/banner.md`](../components/banner/banner.md) |
7
8
  | Button | A native button element with variant styles driven by design tokens. | Trigger actions and submit forms with consistent visual variants. | [`../components/button/button.md`](../components/button/button.md) |
8
9
  | Checkbox | A native checkbox input with the library look and an optional built-in label. | Let the user turn an option on or off, or pick several options from a list. | [`../components/checkbox/checkbox.md`](../components/checkbox/checkbox.md) |
10
+ | Form | A native form wrapper with browser validation disabled and an optional submission feedback banner. | Wrap form controls in a form that never triggers the browser's built-in validation and can show the result of a submission at the top. | [`../components/form/form.md`](../components/form/form.md) |
9
11
  | FormControl | A wrapper that places a label above a form field and an optional error message below it. | Compose a label, a field, and an error message with consistent spacing, so consumers do not do it by hand. | [`../components/form-control/form-control.md`](../components/form-control/form-control.md) |
12
+ | Icon | A base container that renders inline SVG shapes in a 40×40 viewBox, themeable through design tokens. | Build icon components with a consistent size, stroke, and color strategy. | [`../components/icon/icon.md`](../components/icon/icon.md) |
13
+ | IconClose | A close icon made of two crossing lines, built on top of Icon. | Represent closing, dismissing, or removing something. | [`../icons/close/icon-close.md`](../icons/close/icon-close.md) |
10
14
  | Input | A single-line text field that extends the native HTML input element. | Collect short text values in forms with consistent field styling and error indication. | [`../components/input/input.md`](../components/input/input.md) |
11
15
  | Label | A text label that extends the native HTML label element. | Name a form control with consistent label typography, on its own or next to any control. | [`../components/label/label.md`](../components/label/label.md) |
12
16
  | Radio | A native radio input with the library look and an optional built-in label. | Let the user pick exactly one option from a small group of mutually exclusive options. | [`../components/radio/radio.md`](../components/radio/radio.md) |
13
17
  | Select | Dropdown field that lets the user choose one option from a fixed list. | Let the user choose one option from a fixed list. | [`../components/select/select.md`](../components/select/select.md) |
14
18
  | Textarea | Multi-line text field that collects a longer text value from the user. | Collect a longer text value such as a comment or a message. | [`../components/textarea/textarea.md`](../components/textarea/textarea.md) |
19
+
20
+ ## Hooks
21
+
22
+ | Hook | Description | Purpose | Doc path |
23
+ | --- | --- | --- | --- |
24
+ | useForm | A hook that handles form data, ordered field validation, the submit gate and the submission error. | Validate forms with the leanest API possible and wire everything to Form with a single spread. | [`../hooks/use-form/use-form.md`](../hooks/use-form/use-form.md) |
@@ -17,6 +17,19 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
17
17
  | `--c-color-accented-85` | `var(--c-color-gray-85)` | `var(--c-color-gray-85) → hsl(0 0% 85%)` |
18
18
  | `--c-color-accented-90` | `var(--c-color-gray-90)` | `var(--c-color-gray-90) → hsl(0 0% 90%)` |
19
19
  | `--c-color-accented-95` | `var(--c-color-gray-95)` | `var(--c-color-gray-95) → hsl(0 0% 95%)` |
20
+ | `--c-color-blue-10` | `hsl(220 100% 10%)` | `hsl(220 100% 10%)` |
21
+ | `--c-color-blue-15` | `hsl(220 100% 15%)` | `hsl(220 100% 15%)` |
22
+ | `--c-color-blue-20` | `hsl(220 100% 20%)` | `hsl(220 100% 20%)` |
23
+ | `--c-color-blue-30` | `hsl(220 100% 30%)` | `hsl(220 100% 30%)` |
24
+ | `--c-color-blue-40` | `hsl(220 100% 40%)` | `hsl(220 100% 40%)` |
25
+ | `--c-color-blue-5` | `hsl(220 100% 5%)` | `hsl(220 100% 5%)` |
26
+ | `--c-color-blue-50` | `hsl(220 100% 50%)` | `hsl(220 100% 50%)` |
27
+ | `--c-color-blue-60` | `hsl(220 100% 60%)` | `hsl(220 100% 60%)` |
28
+ | `--c-color-blue-70` | `hsl(220 100% 70%)` | `hsl(220 100% 70%)` |
29
+ | `--c-color-blue-80` | `hsl(220 100% 80%)` | `hsl(220 100% 80%)` |
30
+ | `--c-color-blue-85` | `hsl(220 100% 85%)` | `hsl(220 100% 85%)` |
31
+ | `--c-color-blue-90` | `hsl(220 100% 90%)` | `hsl(220 100% 90%)` |
32
+ | `--c-color-blue-95` | `hsl(220 100% 95%)` | `hsl(220 100% 95%)` |
20
33
  | `--c-color-gray-10` | `hsl(0 0% 10%)` | `hsl(0 0% 10%)` |
21
34
  | `--c-color-gray-15` | `hsl(0 0% 15%)` | `hsl(0 0% 15%)` |
22
35
  | `--c-color-gray-20` | `hsl(0 0% 20%)` | `hsl(0 0% 20%)` |
@@ -30,6 +43,32 @@ Generated from `src/vars.css`. Values show the declared token and the resolved r
30
43
  | `--c-color-gray-85` | `hsl(0 0% 85%)` | `hsl(0 0% 85%)` |
31
44
  | `--c-color-gray-90` | `hsl(0 0% 90%)` | `hsl(0 0% 90%)` |
32
45
  | `--c-color-gray-95` | `hsl(0 0% 95%)` | `hsl(0 0% 95%)` |
46
+ | `--c-color-green-10` | `hsl(145 100% 10%)` | `hsl(145 100% 10%)` |
47
+ | `--c-color-green-15` | `hsl(145 100% 15%)` | `hsl(145 100% 15%)` |
48
+ | `--c-color-green-20` | `hsl(145 100% 20%)` | `hsl(145 100% 20%)` |
49
+ | `--c-color-green-30` | `hsl(145 100% 30%)` | `hsl(145 100% 30%)` |
50
+ | `--c-color-green-40` | `hsl(145 100% 40%)` | `hsl(145 100% 40%)` |
51
+ | `--c-color-green-5` | `hsl(145 100% 5%)` | `hsl(145 100% 5%)` |
52
+ | `--c-color-green-50` | `hsl(145 100% 50%)` | `hsl(145 100% 50%)` |
53
+ | `--c-color-green-60` | `hsl(145 100% 60%)` | `hsl(145 100% 60%)` |
54
+ | `--c-color-green-70` | `hsl(145 100% 70%)` | `hsl(145 100% 70%)` |
55
+ | `--c-color-green-80` | `hsl(145 100% 80%)` | `hsl(145 100% 80%)` |
56
+ | `--c-color-green-85` | `hsl(145 100% 85%)` | `hsl(145 100% 85%)` |
57
+ | `--c-color-green-90` | `hsl(145 100% 90%)` | `hsl(145 100% 90%)` |
58
+ | `--c-color-green-95` | `hsl(145 100% 95%)` | `hsl(145 100% 95%)` |
59
+ | `--c-color-orange-10` | `hsl(30 100% 10%)` | `hsl(30 100% 10%)` |
60
+ | `--c-color-orange-15` | `hsl(30 100% 15%)` | `hsl(30 100% 15%)` |
61
+ | `--c-color-orange-20` | `hsl(30 100% 20%)` | `hsl(30 100% 20%)` |
62
+ | `--c-color-orange-30` | `hsl(30 100% 30%)` | `hsl(30 100% 30%)` |
63
+ | `--c-color-orange-40` | `hsl(30 100% 40%)` | `hsl(30 100% 40%)` |
64
+ | `--c-color-orange-5` | `hsl(30 100% 5%)` | `hsl(30 100% 5%)` |
65
+ | `--c-color-orange-50` | `hsl(30 100% 50%)` | `hsl(30 100% 50%)` |
66
+ | `--c-color-orange-60` | `hsl(30 100% 60%)` | `hsl(30 100% 60%)` |
67
+ | `--c-color-orange-70` | `hsl(30 100% 70%)` | `hsl(30 100% 70%)` |
68
+ | `--c-color-orange-80` | `hsl(30 100% 80%)` | `hsl(30 100% 80%)` |
69
+ | `--c-color-orange-85` | `hsl(30 100% 85%)` | `hsl(30 100% 85%)` |
70
+ | `--c-color-orange-90` | `hsl(30 100% 90%)` | `hsl(30 100% 90%)` |
71
+ | `--c-color-orange-95` | `hsl(30 100% 95%)` | `hsl(30 100% 95%)` |
33
72
  | `--c-color-red-10` | `hsl(0 100% 10%)` | `hsl(0 100% 10%)` |
34
73
  | `--c-color-red-15` | `hsl(0 100% 15%)` | `hsl(0 100% 15%)` |
35
74
  | `--c-color-red-20` | `hsl(0 100% 20%)` | `hsl(0 100% 20%)` |
@@ -0,0 +1 @@
1
+ import{useRef as f,useState as a}from"react";const m=({initialFormData:t,formValidations:r,onSubmit:n})=>{const[e,s]=a(t),[u,o]=a(!1),[l,i]=a(null),d=b({formData:e,formValidations:r,onSubmit:n,setHasSubmitted:o,setFormSubmitFeedback:i});return{formData:e,setFormData:s,formValidationErrors:u?c(e,r):{},formProps:{onSubmit:d,submitFeedback:l},setFormSubmitFeedback:i}};function b({formData:t,formValidations:r,onSubmit:n,setHasSubmitted:e,setFormSubmitFeedback:s}){const u=f(n);return u.current=n,o=>{o.preventDefault(),e(!0),s(null),Object.keys(c(t,r)).length||u.current(t,o)}}function c(t,r){return Object.entries(r).reduce((n,[e,s])=>{const u=F(t[e],s);return u?{...n,[e]:u}:n},{})}function F(t,r){return r.find(({isValid:e})=>!e(t))?.errorMessage}export default m;
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: useForm
3
+ description: A hook that handles form data, ordered field validation, the submit gate and the submission error.
4
+ purpose: Validate forms with the leanest API possible and wire everything to Form with a single spread.
5
+ ---
6
+
7
+ # useForm
8
+
9
+ A hook that encapsulates the form data, the validation of its fields, the submit gate and the submission error. Wire a form with a single spread: `<Form {...formProps}>`.
10
+
11
+ Validations are declared per field as ordered rules. The first rule whose `isValid` returns `false` defines the error message of the field.
12
+
13
+ `formValidationErrors` is `{}` until the form is submitted for the first time, so it can be forwarded straight to the `errorMessage` of each `FormControl`. After the first submit, it always reflects the current `formData`: errors appear, change and disappear as the user edits the fields.
14
+
15
+ On every submit, the hook prevents the default browser behavior, records that the form was submitted and clears the submission feedback. The consumer's `onSubmit` is called, with `formData` and the event, only when every field is valid. The hook always runs the latest `onSubmit` received, so values captured by the callback are never stale.
16
+
17
+ `setFormSubmitFeedback` is the direct state setter of the submission feedback, an object `{ message, theme }` where `theme` is `error` or `success`. Calling it after a submit, for example after an `await`, shows the banner in `Form`, even when the feedback is identical to the previous one. `null` removes the banner. Since there is a single feedback, the banner is never shown twice. The submission feedback and the field errors are independent: both can be visible at the same time.
18
+
19
+ The hook does not return the `Form` component. Consumers still bind `value` and `onChange` of each input themselves.
20
+
21
+ ## API
22
+
23
+ <!-- BEGIN GENERATED PROPS -->
24
+ ### Arguments
25
+
26
+ | Name | Type | Required | Default | Description |
27
+ | --- | --- | --- | --- | --- |
28
+ | formValidations | `Record<string, UseFormValidation[]>` | Yes | | Ordered validation rules of each field, keyed by field name. The first rule whose `isValid` returns `false` defines the field error message. |
29
+ | initialFormData | `Record<string, any>` | Yes | | Initial form data, keyed by field name. For example, `{ name: '', email: '' }`. |
30
+ | onSubmit | `(formData: Record<string, any>, event: FormEvent<HTMLFormElement>) => void` | Yes | | Submit callback, called with the form data and the submit event only when no field is invalid. The latest callback received is always the one executed. |
31
+
32
+ ### Returned values
33
+
34
+ | Name | Type | Description |
35
+ | --- | --- | --- |
36
+ | formData | `Record<string, any>` | Current form data, initialized with `initialFormData`. |
37
+ | formProps | `{ onSubmit: (event: FormEvent<HTMLFormElement>) => void; submitFeedback: FormSubmitFeedback; }` | Props to be spread into `Form`: the hook submit handler and the current submission feedback. |
38
+ | formValidationErrors | `Record<string, string>` | Error message of each invalid field, keyed by field name. It is empty until the form is submitted for the first time. After that, it always reflects the current form data. |
39
+ | setFormData | `Dispatch<SetStateAction<Record<string, any>>>` | Updates the form data. |
40
+ | setFormSubmitFeedback | `Dispatch<SetStateAction<FormSubmitFeedback>>` | Sets the feedback about the last submission, shown in the `Form` banner. For example, `{ message: 'Something went wrong', theme: 'error' }` or `{ message: 'Profile saved', theme: 'success' }`. `null` removes the banner. Every submit clears it. |
41
+ <!-- END GENERATED PROPS -->
42
+
43
+ ## Usage
44
+
45
+ ```jsx
46
+ import { Button, Form, FormControl, Input, useForm } from '@compilorama/compy';
47
+
48
+ const NAME_FIELD = 'name';
49
+ const EMAIL_FIELD = 'email';
50
+
51
+ const ProfileForm = () => {
52
+ const { formData, setFormData, formValidationErrors, formProps, setFormSubmitFeedback } = useForm({
53
+ initialFormData: { [NAME_FIELD]: '', [EMAIL_FIELD]: '' },
54
+ formValidations: buildFormValidations(),
55
+ onSubmit: async data => {
56
+ try {
57
+ await save(data);
58
+ setFormSubmitFeedback({ message: 'Profile saved', theme: 'success' });
59
+ } catch {
60
+ setFormSubmitFeedback({ message: 'Something went wrong', theme: 'error' });
61
+ }
62
+ }
63
+ });
64
+ const handleFormDataChange = ({ target: { name, value } }) => {
65
+ setFormData(prevState => ({ ...prevState, [name]: value }));
66
+ };
67
+
68
+ return (
69
+ <Form {...formProps}>
70
+ <FormControl label="Name" errorMessage={formValidationErrors[NAME_FIELD]}>
71
+ <Input
72
+ name={NAME_FIELD}
73
+ value={formData[NAME_FIELD]}
74
+ onChange={handleFormDataChange}
75
+ />
76
+ </FormControl>
77
+ <Button type="submit">Save</Button>
78
+ </Form>
79
+ );
80
+ };
81
+
82
+ function buildFormValidations(){
83
+ return {
84
+ [NAME_FIELD]: [
85
+ { isValid: val => !!val, errorMessage: 'Required' },
86
+ { isValid: val => val?.length >= 2, errorMessage: 'Enter at least 2 characters' }
87
+ ],
88
+ [EMAIL_FIELD]: [
89
+ { isValid: val => !!val, errorMessage: 'Required' },
90
+ { isValid: val => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), errorMessage: 'Enter a valid email address' }
91
+ ]
92
+ };
93
+ }
94
+ ```
95
+
96
+ ## When to use
97
+
98
+ - Forms validated by the application, with field errors shown only after the first submit
99
+ - Forms that show an error returned by the server, or a success confirmation, in the `Form` banner
100
+ - Any form where the lean validation model (ordered rules per field) is enough
101
+
102
+ ## When NOT to use
103
+
104
+ - **Asynchronous validation, per-field validation on blur or input masks** — the hook does not support them.
105
+ - **Automatic input wiring** — the hook does not bind `value` and `onChange`; consumers wire each input themselves.
106
+ - **Forms without validation or submission handling** — use `Form` alone with its own `onSubmit`.
@@ -0,0 +1 @@
1
+ import o from"../../components/icon/icon.js";import{jsx as t,jsxs as r}from"react/jsx-runtime";const e=s=>r(o,{...s,name:"close",children:[t("path",{"data-stroke":!0,d:"M12,28L28,12"}),t("path",{"data-stroke":!0,d:"M28,28L12,12"})]});export default e;
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: IconClose
3
+ description: A close icon made of two crossing lines, built on top of Icon.
4
+ purpose: Represent closing, dismissing, or removing something.
5
+ ---
6
+
7
+ # IconClose
8
+
9
+ Two crossing lines drawn through [`Icon`](../../components/icon/icon.md), with the class `c-icon-close`. It accepts and forwards every `Icon` prop (`size`, `strokeColor`, `strokeWidth`, `className`, etc.), except `name` and `children`, which are fixed.
10
+
11
+ ## Props
12
+
13
+ <!-- BEGIN GENERATED PROPS -->
14
+ _Also inherits all props from `Omit<IconProps, 'name' | 'children'>`._
15
+ <!-- END GENERATED PROPS -->
16
+
17
+ ## When to use
18
+
19
+ - Dismiss or close buttons (for example inside an isometric `Button`)
20
+ - Removing an item from a list
21
+
22
+ ## When NOT to use
23
+
24
+ - **Text-only actions** — use a `Button` with a text label when the action needs words to be clear.
package/dist/es6/index.js CHANGED
@@ -1 +1 @@
1
- import"./index.css";export{default as Button}from"./components/button/button.js";export{default as Checkbox}from"./components/checkbox/checkbox.js";export{default as FormControl}from"./components/form-control/form-control.js";export{default as Input}from"./components/input/input.js";export{default as Label}from"./components/label/label.js";export{default as Radio}from"./components/radio/radio.js";export{default as Select}from"./components/select/select.js";export{default as Textarea}from"./components/textarea/textarea.js";
1
+ import"./index.css";export{default as Banner}from"./components/banner/banner.js";export{default as Button}from"./components/button/button.js";export{default as Checkbox}from"./components/checkbox/checkbox.js";export{default as Form}from"./components/form/form.js";export{default as FormControl}from"./components/form-control/form-control.js";export{default as Icon}from"./components/icon/icon.js";export{default as IconClose}from"./icons/close/icon-close.js";export{default as Input}from"./components/input/input.js";export{default as Label}from"./components/label/label.js";export{default as Radio}from"./components/radio/radio.js";export{default as Select}from"./components/select/select.js";export{default as Textarea}from"./components/textarea/textarea.js";export{default as useForm}from"./hooks/use-form/use-form.js";
package/dist/es6/vars.css CHANGED
@@ -1 +1 @@
1
- :root{--c-font-family-primary: "Inter", sans-serif;--c-font-size-xxxs: .625rem;--c-font-size-xxs: .75rem;--c-font-size-xs: .875rem;--c-font-size-sm: 1rem;--c-font-size-md: 1.125rem;--c-font-size-lg: 1.25rem;--c-font-size-xl: 1.5rem;--c-font-size-xxl: 2.25rem;--c-font-size-xxxl: 3rem;--c-color-gray-95: hsl(0 0% 95%);--c-color-gray-90: hsl(0 0% 90%);--c-color-gray-85: hsl(0 0% 85%);--c-color-gray-80: hsl(0 0% 80%);--c-color-gray-70: hsl(0 0% 70%);--c-color-gray-60: hsl(0 0% 60%);--c-color-gray-50: hsl(0 0% 50%);--c-color-gray-40: hsl(0 0% 40%);--c-color-gray-30: hsl(0 0% 30%);--c-color-gray-20: hsl(0 0% 20%);--c-color-gray-15: hsl(0 0% 15%);--c-color-gray-10: hsl(0 0% 10%);--c-color-gray-5: hsl(0 0% 5%);--c-color-red-95: hsl(0 100% 95%);--c-color-red-90: hsl(0 100% 90%);--c-color-red-85: hsl(0 100% 85%);--c-color-red-80: hsl(0 100% 80%);--c-color-red-70: hsl(0 100% 70%);--c-color-red-60: hsl(0 100% 60%);--c-color-red-50: hsl(0 100% 50%);--c-color-red-40: hsl(0 100% 40%);--c-color-red-30: hsl(0 100% 30%);--c-color-red-20: hsl(0 100% 20%);--c-color-red-15: hsl(0 100% 15%);--c-color-red-10: hsl(0 100% 10%);--c-color-red-5: hsl(0 100% 5%);--c-color-accented-95: var(--c-color-gray-95);--c-color-accented-90: var(--c-color-gray-90);--c-color-accented-85: var(--c-color-gray-85);--c-color-accented-80: var(--c-color-gray-80);--c-color-accented-70: var(--c-color-gray-70);--c-color-accented-60: var(--c-color-gray-60);--c-color-accented-50: var(--c-color-gray-50);--c-color-accented-40: var(--c-color-gray-40);--c-color-accented-30: var(--c-color-gray-30);--c-color-accented-20: var(--c-color-gray-20);--c-color-accented-15: var(--c-color-gray-15);--c-color-accented-10: var(--c-color-gray-10);--c-color-accented-5: var(--c-color-gray-5)}
1
+ :root{--c-font-family-primary: "Inter", sans-serif;--c-font-size-xxxs: .625rem;--c-font-size-xxs: .75rem;--c-font-size-xs: .875rem;--c-font-size-sm: 1rem;--c-font-size-md: 1.125rem;--c-font-size-lg: 1.25rem;--c-font-size-xl: 1.5rem;--c-font-size-xxl: 2.25rem;--c-font-size-xxxl: 3rem;--c-color-gray-95: hsl(0 0% 95%);--c-color-gray-90: hsl(0 0% 90%);--c-color-gray-85: hsl(0 0% 85%);--c-color-gray-80: hsl(0 0% 80%);--c-color-gray-70: hsl(0 0% 70%);--c-color-gray-60: hsl(0 0% 60%);--c-color-gray-50: hsl(0 0% 50%);--c-color-gray-40: hsl(0 0% 40%);--c-color-gray-30: hsl(0 0% 30%);--c-color-gray-20: hsl(0 0% 20%);--c-color-gray-15: hsl(0 0% 15%);--c-color-gray-10: hsl(0 0% 10%);--c-color-gray-5: hsl(0 0% 5%);--c-color-red-95: hsl(0 100% 95%);--c-color-red-90: hsl(0 100% 90%);--c-color-red-85: hsl(0 100% 85%);--c-color-red-80: hsl(0 100% 80%);--c-color-red-70: hsl(0 100% 70%);--c-color-red-60: hsl(0 100% 60%);--c-color-red-50: hsl(0 100% 50%);--c-color-red-40: hsl(0 100% 40%);--c-color-red-30: hsl(0 100% 30%);--c-color-red-20: hsl(0 100% 20%);--c-color-red-15: hsl(0 100% 15%);--c-color-red-10: hsl(0 100% 10%);--c-color-red-5: hsl(0 100% 5%);--c-color-blue-95: hsl(220 100% 95%);--c-color-blue-90: hsl(220 100% 90%);--c-color-blue-85: hsl(220 100% 85%);--c-color-blue-80: hsl(220 100% 80%);--c-color-blue-70: hsl(220 100% 70%);--c-color-blue-60: hsl(220 100% 60%);--c-color-blue-50: hsl(220 100% 50%);--c-color-blue-40: hsl(220 100% 40%);--c-color-blue-30: hsl(220 100% 30%);--c-color-blue-20: hsl(220 100% 20%);--c-color-blue-15: hsl(220 100% 15%);--c-color-blue-10: hsl(220 100% 10%);--c-color-blue-5: hsl(220 100% 5%);--c-color-orange-95: hsl(30 100% 95%);--c-color-orange-90: hsl(30 100% 90%);--c-color-orange-85: hsl(30 100% 85%);--c-color-orange-80: hsl(30 100% 80%);--c-color-orange-70: hsl(30 100% 70%);--c-color-orange-60: hsl(30 100% 60%);--c-color-orange-50: hsl(30 100% 50%);--c-color-orange-40: hsl(30 100% 40%);--c-color-orange-30: hsl(30 100% 30%);--c-color-orange-20: hsl(30 100% 20%);--c-color-orange-15: hsl(30 100% 15%);--c-color-orange-10: hsl(30 100% 10%);--c-color-orange-5: hsl(30 100% 5%);--c-color-green-95: hsl(145 100% 95%);--c-color-green-90: hsl(145 100% 90%);--c-color-green-85: hsl(145 100% 85%);--c-color-green-80: hsl(145 100% 80%);--c-color-green-70: hsl(145 100% 70%);--c-color-green-60: hsl(145 100% 60%);--c-color-green-50: hsl(145 100% 50%);--c-color-green-40: hsl(145 100% 40%);--c-color-green-30: hsl(145 100% 30%);--c-color-green-20: hsl(145 100% 20%);--c-color-green-15: hsl(145 100% 15%);--c-color-green-10: hsl(145 100% 10%);--c-color-green-5: hsl(145 100% 5%);--c-color-accented-95: var(--c-color-gray-95);--c-color-accented-90: var(--c-color-gray-90);--c-color-accented-85: var(--c-color-gray-85);--c-color-accented-80: var(--c-color-gray-80);--c-color-accented-70: var(--c-color-gray-70);--c-color-accented-60: var(--c-color-gray-60);--c-color-accented-50: var(--c-color-gray-50);--c-color-accented-40: var(--c-color-gray-40);--c-color-accented-30: var(--c-color-gray-30);--c-color-accented-20: var(--c-color-gray-20);--c-color-accented-15: var(--c-color-gray-15);--c-color-accented-10: var(--c-color-gray-10);--c-color-accented-5: var(--c-color-gray-5)}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,17 @@
1
+ export type { BannerProps } from './components/banner/banner.d.ts';
2
+ export { default as Banner } from './components/banner/banner.d.ts';
1
3
  export type { ButtonProps } from './components/button/button.d.ts';
2
4
  export { default as Button } from './components/button/button.d.ts';
3
5
  export type { CheckboxProps } from './components/checkbox/checkbox.d.ts';
4
6
  export { default as Checkbox } from './components/checkbox/checkbox.d.ts';
7
+ export type { FormProps, FormSubmitFeedback } from './components/form/form.d.ts';
8
+ export { default as Form } from './components/form/form.d.ts';
5
9
  export type { FormControlProps } from './components/form-control/form-control.d.ts';
6
10
  export { default as FormControl } from './components/form-control/form-control.d.ts';
11
+ export type { IconProps } from './components/icon/icon.d.ts';
12
+ export { default as Icon } from './components/icon/icon.d.ts';
13
+ export type { IconCloseProps } from './icons/close/icon-close.d.ts';
14
+ export { default as IconClose } from './icons/close/icon-close.d.ts';
7
15
  export type { InputProps } from './components/input/input.d.ts';
8
16
  export { default as Input } from './components/input/input.d.ts';
9
17
  export type { LabelProps } from './components/label/label.d.ts';
@@ -13,4 +21,6 @@ export { default as Radio } from './components/radio/radio.d.ts';
13
21
  export type { SelectProps } from './components/select/select.d.ts';
14
22
  export { default as Select } from './components/select/select.d.ts';
15
23
  export type { TextareaProps } from './components/textarea/textarea.d.ts';
16
- export { default as Textarea } from './components/textarea/textarea.d.ts';
24
+ export { default as Textarea } from './components/textarea/textarea.d.ts';
25
+ export type { UseFormArguments, UseFormReturnedValues, UseFormValidation } from './hooks/use-form/use-form.d.ts';
26
+ export { default as useForm } from './hooks/use-form/use-form.d.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilorama/compy",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "React UI component library",
5
5
  "license": "MIT",
6
6
  "author": "Rafael Camargo <hello@rafaelcamargo.com>",