@jesusgm/react-components 0.0.0-stage → 0.1.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.
- package/Readme.md +158 -0
- package/dist/components/atoms/avatar/index.d.ts +19 -0
- package/dist/components/atoms/avatar/index.js +44 -0
- package/dist/components/atoms/avatar/index.js.map +1 -0
- package/dist/components/atoms/avatar/styles.css +50 -0
- package/dist/components/atoms/badge/index.d.ts +17 -0
- package/dist/components/atoms/badge/index.js +37 -0
- package/dist/components/atoms/badge/index.js.map +1 -0
- package/dist/components/atoms/badge/styles.css +83 -0
- package/dist/components/atoms/button/index.d.ts +16 -0
- package/dist/components/atoms/button/index.js +22 -0
- package/dist/components/atoms/button/index.js.map +1 -0
- package/dist/components/atoms/button/styles.css +77 -0
- package/dist/components/atoms/checkbox/index.d.ts +13 -0
- package/dist/components/atoms/checkbox/index.js +63 -0
- package/dist/components/atoms/checkbox/index.js.map +1 -0
- package/dist/components/atoms/checkbox/styles.css +87 -0
- package/dist/components/atoms/code-highlighter/index.d.ts +8 -0
- package/dist/components/atoms/code-highlighter/index.js +24 -0
- package/dist/components/atoms/code-highlighter/index.js.map +1 -0
- package/dist/components/atoms/code-highlighter/railscasts.css +1 -0
- package/dist/components/atoms/code-highlighter/styles.css +17 -0
- package/dist/components/atoms/divider/index.d.ts +10 -0
- package/dist/components/atoms/divider/index.js +25 -0
- package/dist/components/atoms/divider/index.js.map +1 -0
- package/dist/components/atoms/divider/styles.css +56 -0
- package/dist/components/atoms/icon/index.d.ts +23 -0
- package/dist/components/atoms/icon/index.js +20 -0
- package/dist/components/atoms/icon/index.js.map +1 -0
- package/dist/components/atoms/icon/styles.css +13 -0
- package/dist/components/atoms/kbd/index.d.ts +7 -0
- package/dist/components/atoms/kbd/index.js +26 -0
- package/dist/components/atoms/kbd/index.js.map +1 -0
- package/dist/components/atoms/kbd/styles.css +29 -0
- package/dist/components/atoms/label/index.d.ts +9 -0
- package/dist/components/atoms/label/index.js +18 -0
- package/dist/components/atoms/label/index.js.map +1 -0
- package/dist/components/atoms/label/styles.css +19 -0
- package/dist/components/atoms/link/index.d.ts +12 -0
- package/dist/components/atoms/link/index.js +32 -0
- package/dist/components/atoms/link/index.js.map +1 -0
- package/dist/components/atoms/link/styles.css +54 -0
- package/dist/components/atoms/progress-bar/index.d.ts +23 -0
- package/dist/components/atoms/progress-bar/index.js +45 -0
- package/dist/components/atoms/progress-bar/index.js.map +1 -0
- package/dist/components/atoms/progress-bar/styles.css +75 -0
- package/dist/components/atoms/radio/context.d.ts +9 -0
- package/dist/components/atoms/radio/context.js +9 -0
- package/dist/components/atoms/radio/context.js.map +1 -0
- package/dist/components/atoms/radio/index.d.ts +15 -0
- package/dist/components/atoms/radio/index.js +44 -0
- package/dist/components/atoms/radio/index.js.map +1 -0
- package/dist/components/atoms/radio/radio-group.d.ts +25 -0
- package/dist/components/atoms/radio/radio-group.js +49 -0
- package/dist/components/atoms/radio/radio-group.js.map +1 -0
- package/dist/components/atoms/radio/styles.css +110 -0
- package/dist/components/atoms/skeleton/index.d.ts +15 -0
- package/dist/components/atoms/skeleton/index.js +38 -0
- package/dist/components/atoms/skeleton/index.js.map +1 -0
- package/dist/components/atoms/skeleton/styles.css +57 -0
- package/dist/components/atoms/spinner/index.d.ts +11 -0
- package/dist/components/atoms/spinner/index.js +22 -0
- package/dist/components/atoms/spinner/index.js.map +1 -0
- package/dist/components/atoms/spinner/styles.css +51 -0
- package/dist/components/atoms/switch/index.d.ts +14 -0
- package/dist/components/atoms/switch/index.js +33 -0
- package/dist/components/atoms/switch/index.js.map +1 -0
- package/dist/components/atoms/switch/styles.css +99 -0
- package/dist/components/atoms/text-input/index.d.ts +20 -0
- package/dist/components/atoms/text-input/index.js +33 -0
- package/dist/components/atoms/text-input/index.js.map +1 -0
- package/dist/components/atoms/text-input/styles.css +80 -0
- package/dist/components/atoms/textarea/index.d.ts +14 -0
- package/dist/components/atoms/textarea/index.js +43 -0
- package/dist/components/atoms/textarea/index.js.map +1 -0
- package/dist/components/atoms/textarea/styles.css +49 -0
- package/dist/components/atoms/typography/index.d.ts +30 -0
- package/dist/components/atoms/typography/index.js +30 -0
- package/dist/components/atoms/typography/index.js.map +1 -0
- package/dist/components/atoms/typography/styles.css +50 -0
- package/dist/components/atoms/video-player/index.d.ts +9 -0
- package/dist/components/atoms/video-player/index.js +17 -0
- package/dist/components/atoms/video-player/index.js.map +1 -0
- package/dist/components/atoms/video-player/styles.css +18 -0
- package/dist/components/atoms/visually-hidden/index.d.ts +7 -0
- package/dist/components/atoms/visually-hidden/index.js +13 -0
- package/dist/components/atoms/visually-hidden/index.js.map +1 -0
- package/dist/components/atoms/visually-hidden/styles.css +12 -0
- package/dist/components/hooks/index.d.ts +3 -0
- package/dist/components/hooks/index.js +4 -0
- package/dist/components/hooks/use-click-outside.d.ts +6 -0
- package/dist/components/hooks/use-click-outside.js +30 -0
- package/dist/components/hooks/use-click-outside.js.map +1 -0
- package/dist/components/hooks/use-controllable-state.d.ts +5 -0
- package/dist/components/hooks/use-controllable-state.js +22 -0
- package/dist/components/hooks/use-controllable-state.js.map +1 -0
- package/dist/components/hooks/use-focus-trap.d.ts +8 -0
- package/dist/components/hooks/use-focus-trap.js +57 -0
- package/dist/components/hooks/use-focus-trap.js.map +1 -0
- package/dist/components/index.d.ts +122 -0
- package/dist/components/index.js +74 -0
- package/dist/components/molecules/accordion/index.d.ts +27 -0
- package/dist/components/molecules/accordion/index.js +98 -0
- package/dist/components/molecules/accordion/index.js.map +1 -0
- package/dist/components/molecules/accordion/styles.css +75 -0
- package/dist/components/molecules/alert/index.d.ts +18 -0
- package/dist/components/molecules/alert/index.js +91 -0
- package/dist/components/molecules/alert/index.js.map +1 -0
- package/dist/components/molecules/alert/styles.css +97 -0
- package/dist/components/molecules/binary-clock/index.d.ts +16 -0
- package/dist/components/molecules/binary-clock/index.js +66 -0
- package/dist/components/molecules/binary-clock/index.js.map +1 -0
- package/dist/components/molecules/binary-clock/styles.css +46 -0
- package/dist/components/molecules/breadcrumb/index.d.ts +23 -0
- package/dist/components/molecules/breadcrumb/index.js +79 -0
- package/dist/components/molecules/breadcrumb/index.js.map +1 -0
- package/dist/components/molecules/breadcrumb/styles.css +61 -0
- package/dist/components/molecules/card/index.d.ts +39 -0
- package/dist/components/molecules/card/index.js +60 -0
- package/dist/components/molecules/card/index.js.map +1 -0
- package/dist/components/molecules/card/styles.css +105 -0
- package/dist/components/molecules/chart/index.d.ts +14 -0
- package/dist/components/molecules/chart/index.js +104 -0
- package/dist/components/molecules/chart/index.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.d.ts +8 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.js +58 -0
- package/dist/components/molecules/conflict-resolver/components/conflictItem.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/components/styles.css +64 -0
- package/dist/components/molecules/conflict-resolver/index.d.ts +10 -0
- package/dist/components/molecules/conflict-resolver/index.js +35 -0
- package/dist/components/molecules/conflict-resolver/index.js.map +1 -0
- package/dist/components/molecules/conflict-resolver/types.d.ts +10 -0
- package/dist/components/molecules/dropable-list/draggable.d.ts +9 -0
- package/dist/components/molecules/dropable-list/draggable.js +18 -0
- package/dist/components/molecules/dropable-list/draggable.js.map +1 -0
- package/dist/components/molecules/dropable-list/index.d.ts +20 -0
- package/dist/components/molecules/dropable-list/index.js +52 -0
- package/dist/components/molecules/dropable-list/index.js.map +1 -0
- package/dist/components/molecules/dropable-list/styles.css +63 -0
- package/dist/components/molecules/dropdown-menu/index.d.ts +43 -0
- package/dist/components/molecules/dropdown-menu/index.js +226 -0
- package/dist/components/molecules/dropdown-menu/index.js.map +1 -0
- package/dist/components/molecules/dropdown-menu/styles.css +94 -0
- package/dist/components/molecules/empty-state/index.d.ts +16 -0
- package/dist/components/molecules/empty-state/index.js +32 -0
- package/dist/components/molecules/empty-state/index.js.map +1 -0
- package/dist/components/molecules/empty-state/styles.css +64 -0
- package/dist/components/molecules/file-input/index.d.ts +39 -0
- package/dist/components/molecules/file-input/index.js +121 -0
- package/dist/components/molecules/file-input/index.js.map +1 -0
- package/dist/components/molecules/file-input/styles.css +86 -0
- package/dist/components/molecules/form-field/index.d.ts +38 -0
- package/dist/components/molecules/form-field/index.js +71 -0
- package/dist/components/molecules/form-field/index.js.map +1 -0
- package/dist/components/molecules/form-field/styles.css +43 -0
- package/dist/components/molecules/list/index.d.ts +25 -0
- package/dist/components/molecules/list/index.js +30 -0
- package/dist/components/molecules/list/index.js.map +1 -0
- package/dist/components/molecules/list/styles.css +28 -0
- package/dist/components/molecules/number-stepper/index.d.ts +31 -0
- package/dist/components/molecules/number-stepper/index.js +163 -0
- package/dist/components/molecules/number-stepper/index.js.map +1 -0
- package/dist/components/molecules/number-stepper/styles.css +69 -0
- package/dist/components/molecules/pagination/index.d.ts +39 -0
- package/dist/components/molecules/pagination/index.js +111 -0
- package/dist/components/molecules/pagination/index.js.map +1 -0
- package/dist/components/molecules/pagination/styles.css +41 -0
- package/dist/components/molecules/popover/index.d.ts +22 -0
- package/dist/components/molecules/popover/index.js +76 -0
- package/dist/components/molecules/popover/index.js.map +1 -0
- package/dist/components/molecules/popover/positioning.d.ts +40 -0
- package/dist/components/molecules/popover/positioning.js +115 -0
- package/dist/components/molecules/popover/positioning.js.map +1 -0
- package/dist/components/molecules/popover/styles.css +36 -0
- package/dist/components/molecules/rating/index.d.ts +33 -0
- package/dist/components/molecules/rating/index.js +117 -0
- package/dist/components/molecules/rating/index.js.map +1 -0
- package/dist/components/molecules/rating/styles.css +94 -0
- package/dist/components/molecules/search-input/index.d.ts +23 -0
- package/dist/components/molecules/search-input/index.js +118 -0
- package/dist/components/molecules/search-input/index.js.map +1 -0
- package/dist/components/molecules/search-input/styles.css +69 -0
- package/dist/components/molecules/segmented-control/button-group.d.ts +10 -0
- package/dist/components/molecules/segmented-control/button-group.js +15 -0
- package/dist/components/molecules/segmented-control/button-group.js.map +1 -0
- package/dist/components/molecules/segmented-control/index.d.ts +38 -0
- package/dist/components/molecules/segmented-control/index.js +80 -0
- package/dist/components/molecules/segmented-control/index.js.map +1 -0
- package/dist/components/molecules/segmented-control/styles.css +130 -0
- package/dist/components/molecules/select/index.d.ts +30 -0
- package/dist/components/molecules/select/index.js +48 -0
- package/dist/components/molecules/select/index.js.map +1 -0
- package/dist/components/molecules/select/styles.css +102 -0
- package/dist/components/molecules/tabs/index.d.ts +31 -0
- package/dist/components/molecules/tabs/index.js +87 -0
- package/dist/components/molecules/tabs/index.js.map +1 -0
- package/dist/components/molecules/tabs/styles.css +87 -0
- package/dist/components/molecules/tag-cloud/index.d.ts +16 -0
- package/dist/components/molecules/tag-cloud/index.js +133 -0
- package/dist/components/molecules/tag-cloud/index.js.map +1 -0
- package/dist/components/molecules/tag-cloud/styles.css +29 -0
- package/dist/components/molecules/tooltip/index.d.ts +22 -0
- package/dist/components/molecules/tooltip/index.js +83 -0
- package/dist/components/molecules/tooltip/index.js.map +1 -0
- package/dist/components/molecules/tooltip/styles.css +30 -0
- package/dist/components/molecules/virtualized-list/index.d.ts +5 -0
- package/dist/components/molecules/virtualized-list/index.js +3 -0
- package/dist/components/molecules/virtualized-list/lista/index.d.ts +11 -0
- package/dist/components/molecules/virtualized-list/lista/index.js +30 -0
- package/dist/components/molecules/virtualized-list/lista/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/lista/styles.css +27 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.d.ts +10 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.js +17 -0
- package/dist/components/molecules/virtualized-list/lista-slow/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/row/index.d.ts +9 -0
- package/dist/components/molecules/virtualized-list/row/index.js +30 -0
- package/dist/components/molecules/virtualized-list/row/index.js.map +1 -0
- package/dist/components/molecules/virtualized-list/types.d.ts +4 -0
- package/dist/components/organisms/combobox/index.d.ts +82 -0
- package/dist/components/organisms/combobox/index.js +386 -0
- package/dist/components/organisms/combobox/index.js.map +1 -0
- package/dist/components/organisms/combobox/styles.css +269 -0
- package/dist/components/organisms/command-palette/index.d.ts +49 -0
- package/dist/components/organisms/command-palette/index.js +239 -0
- package/dist/components/organisms/command-palette/index.js.map +1 -0
- package/dist/components/organisms/command-palette/score.d.ts +12 -0
- package/dist/components/organisms/command-palette/score.js +43 -0
- package/dist/components/organisms/command-palette/score.js.map +1 -0
- package/dist/components/organisms/command-palette/styles.css +212 -0
- package/dist/components/organisms/date-picker/calendar.d.ts +29 -0
- package/dist/components/organisms/date-picker/calendar.js +178 -0
- package/dist/components/organisms/date-picker/calendar.js.map +1 -0
- package/dist/components/organisms/date-picker/date-utils.d.ts +52 -0
- package/dist/components/organisms/date-picker/date-utils.js +139 -0
- package/dist/components/organisms/date-picker/date-utils.js.map +1 -0
- package/dist/components/organisms/date-picker/index.d.ts +54 -0
- package/dist/components/organisms/date-picker/index.js +173 -0
- package/dist/components/organisms/date-picker/index.js.map +1 -0
- package/dist/components/organisms/date-picker/styles.css +179 -0
- package/dist/components/organisms/drawer/index.d.ts +16 -0
- package/dist/components/organisms/drawer/index.js +15 -0
- package/dist/components/organisms/drawer/index.js.map +1 -0
- package/dist/components/organisms/drawer/styles.css +163 -0
- package/dist/components/organisms/editor/index.d.ts +13 -0
- package/dist/components/organisms/editor/index.js +56 -0
- package/dist/components/organisms/editor/index.js.map +1 -0
- package/dist/components/organisms/editor/styles.css +61 -0
- package/dist/components/organisms/form/context.d.ts +7 -0
- package/dist/components/organisms/form/context.js +11 -0
- package/dist/components/organisms/form/context.js.map +1 -0
- package/dist/components/organisms/form/field.d.ts +18 -0
- package/dist/components/organisms/form/field.js +98 -0
- package/dist/components/organisms/form/field.js.map +1 -0
- package/dist/components/organisms/form/form-actions.d.ts +8 -0
- package/dist/components/organisms/form/form-actions.js +13 -0
- package/dist/components/organisms/form/form-actions.js.map +1 -0
- package/dist/components/organisms/form/index.d.ts +24 -0
- package/dist/components/organisms/form/index.js +215 -0
- package/dist/components/organisms/form/index.js.map +1 -0
- package/dist/components/organisms/form/styles.css +29 -0
- package/dist/components/organisms/form/types.d.ts +95 -0
- package/dist/components/organisms/form/validation.d.ts +5 -0
- package/dist/components/organisms/form/validation.js +35 -0
- package/dist/components/organisms/form/validation.js.map +1 -0
- package/dist/components/organisms/header/index.d.ts +40 -0
- package/dist/components/organisms/header/index.js +186 -0
- package/dist/components/organisms/header/index.js.map +1 -0
- package/dist/components/organisms/header/styles.css +126 -0
- package/dist/components/organisms/modal/dialog-base.d.ts +31 -0
- package/dist/components/organisms/modal/dialog-base.js +123 -0
- package/dist/components/organisms/modal/dialog-base.js.map +1 -0
- package/dist/components/organisms/modal/index.d.ts +13 -0
- package/dist/components/organisms/modal/index.js +15 -0
- package/dist/components/organisms/modal/index.js.map +1 -0
- package/dist/components/organisms/modal/styles.css +143 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.d.ts +13 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.js +16 -0
- package/dist/components/organisms/presenter/components/slides/simple/index.js.map +1 -0
- package/dist/components/organisms/presenter/components/slides/simple/styles.css +6 -0
- package/dist/components/organisms/presenter/index.d.ts +17 -0
- package/dist/components/organisms/presenter/index.js +63 -0
- package/dist/components/organisms/presenter/index.js.map +1 -0
- package/dist/components/organisms/presenter/styles.css +75 -0
- package/dist/components/organisms/sidebar/index.d.ts +50 -0
- package/dist/components/organisms/sidebar/index.js +157 -0
- package/dist/components/organisms/sidebar/index.js.map +1 -0
- package/dist/components/organisms/sidebar/styles.css +197 -0
- package/dist/components/organisms/slider/index.d.ts +47 -0
- package/dist/components/organisms/slider/index.js +214 -0
- package/dist/components/organisms/slider/index.js.map +1 -0
- package/dist/components/organisms/slider/styles.css +110 -0
- package/dist/components/organisms/table/components/cell/index.d.ts +8 -0
- package/dist/components/organisms/table/components/cell/index.js +11 -0
- package/dist/components/organisms/table/components/cell/index.js.map +1 -0
- package/dist/components/organisms/table/index.d.ts +29 -0
- package/dist/components/organisms/table/index.js +105 -0
- package/dist/components/organisms/table/index.js.map +1 -0
- package/dist/components/organisms/table/styles.css +66 -0
- package/dist/components/organisms/terminal/index.d.ts +15 -0
- package/dist/components/organisms/terminal/index.js +111 -0
- package/dist/components/organisms/terminal/index.js.map +1 -0
- package/dist/components/organisms/terminal/styles.css +123 -0
- package/dist/components/organisms/toast/index.d.ts +66 -0
- package/dist/components/organisms/toast/index.js +142 -0
- package/dist/components/organisms/toast/index.js.map +1 -0
- package/dist/components/organisms/toast/styles.css +138 -0
- package/dist/components/organisms/wizard/index.d.ts +44 -0
- package/dist/components/organisms/wizard/index.js +171 -0
- package/dist/components/organisms/wizard/index.js.map +1 -0
- package/dist/components/organisms/wizard/styles.css +160 -0
- package/dist/components/utils/cx.d.ts +2 -0
- package/dist/components/utils/cx.js +8 -0
- package/dist/components/utils/cx.js.map +1 -0
- package/dist/components/utils/portal/index.d.ts +9 -0
- package/dist/components/utils/portal/index.js +13 -0
- package/dist/components/utils/portal/index.js.map +1 -0
- package/dist/components/utils/theme-provider/index.d.ts +22 -0
- package/dist/components/utils/theme-provider/index.js +36 -0
- package/dist/components/utils/theme-provider/index.js.map +1 -0
- package/dist/styles.css +743 -0
- package/dist/tokens.css +299 -0
- package/package.json +390 -4
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CKEditor } from "@ckeditor/ckeditor5-react";
|
|
2
|
+
import { BlockQuote, Bold, ClassicEditor, Essentials, Heading, Italic, Link, List, Paragraph, Undo } from "ckeditor5";
|
|
3
|
+
import "ckeditor5/ckeditor5.css";
|
|
4
|
+
import './styles.css';/* empty css */
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/organisms/editor/index.tsx
|
|
7
|
+
var config = {
|
|
8
|
+
licenseKey: "GPL",
|
|
9
|
+
plugins: [
|
|
10
|
+
Essentials,
|
|
11
|
+
Paragraph,
|
|
12
|
+
Heading,
|
|
13
|
+
Bold,
|
|
14
|
+
Italic,
|
|
15
|
+
Link,
|
|
16
|
+
List,
|
|
17
|
+
BlockQuote,
|
|
18
|
+
Undo
|
|
19
|
+
],
|
|
20
|
+
toolbar: [
|
|
21
|
+
"undo",
|
|
22
|
+
"redo",
|
|
23
|
+
"|",
|
|
24
|
+
"heading",
|
|
25
|
+
"|",
|
|
26
|
+
"bold",
|
|
27
|
+
"italic",
|
|
28
|
+
"link",
|
|
29
|
+
"|",
|
|
30
|
+
"bulletedList",
|
|
31
|
+
"numberedList",
|
|
32
|
+
"blockQuote"
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
function Editor({ onChange, onBlur, onFocus, value = "" }) {
|
|
36
|
+
return /* @__PURE__ */ jsx("div", {
|
|
37
|
+
className: "ds-editor",
|
|
38
|
+
children: /* @__PURE__ */ jsx(CKEditor, {
|
|
39
|
+
editor: ClassicEditor,
|
|
40
|
+
config,
|
|
41
|
+
data: value,
|
|
42
|
+
onChange: (_event, editor) => {
|
|
43
|
+
if (onChange) onChange(editor.getData());
|
|
44
|
+
},
|
|
45
|
+
onBlur: (_event, editor) => {
|
|
46
|
+
if (onBlur) onBlur(editor);
|
|
47
|
+
},
|
|
48
|
+
onFocus: (_event, editor) => {
|
|
49
|
+
if (onFocus) onFocus(editor);
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export { Editor as default };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_jsx"],"sources":["../../../../src/components/organisms/editor/index.tsx"],"sourcesContent":["import { CKEditor } from \"@ckeditor/ckeditor5-react\";\nimport {\n ClassicEditor,\n Essentials,\n Paragraph,\n Heading,\n Bold,\n Italic,\n Link,\n List,\n BlockQuote,\n Undo,\n type EditorConfig,\n} from \"ckeditor5\";\nimport \"ckeditor5/ckeditor5.css\";\n\nimport \"./styles.css\";\n\nexport interface EditorProps {\n /** Value of editor content (HTML) */\n value?: string;\n /** Called with the editor HTML on each change */\n onChange?: (data: string) => void;\n /** Called when the editor loses focus */\n onBlur?: (editor: ClassicEditor) => void;\n /** Called when the editor gets focus */\n onFocus?: (editor: ClassicEditor) => void;\n}\n\nconst config: EditorConfig = {\n licenseKey: \"GPL\",\n plugins: [Essentials, Paragraph, Heading, Bold, Italic, Link, List, BlockQuote, Undo],\n toolbar: [\n \"undo\",\n \"redo\",\n \"|\",\n \"heading\",\n \"|\",\n \"bold\",\n \"italic\",\n \"link\",\n \"|\",\n \"bulletedList\",\n \"numberedList\",\n \"blockQuote\",\n ],\n};\n\nfunction Editor({ onChange, onBlur, onFocus, value = \"\" }: EditorProps) {\n return (\n <div className=\"ds-editor\">\n <CKEditor\n editor={ClassicEditor}\n config={config}\n data={value}\n onChange={(_event, editor) => {\n if (onChange) onChange(editor.getData());\n }}\n onBlur={(_event, editor) => {\n if (onBlur) onBlur(editor);\n }}\n onFocus={(_event, editor) => {\n if (onFocus) onFocus(editor);\n }}\n />\n </div>\n );\n}\n\nexport default Editor;\n"],"mappings":";;;;;;AA6BA,IAAM,SAAuB;CAC3B,YAAY;CACZ,SAAS;EAAC;EAAY;EAAW;EAAS;EAAM;EAAQ;EAAM;EAAM;EAAY;CAAI;CACpF,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAEA,SAAS,OAAO,EAAE,UAAU,QAAQ,SAAS,QAAQ,MAAmB;CACtE,OACEA,oBAAC,OAAD;EAAK,WAAU;EACb,UAAAA,oBAAC,UAAD;GACE,QAAQ;GACA;GACR,MAAM;GACN,WAAW,QAAQ,WAAW;IAC5B,IAAI,UAAU,SAAS,OAAO,QAAQ,CAAC;GACzC;GACA,SAAS,QAAQ,WAAW;IAC1B,IAAI,QAAQ,OAAO,MAAM;GAC3B;GACA,UAAU,QAAQ,WAAW;IAC3B,IAAI,SAAS,QAAQ,MAAM;GAC7B;EACD,CAAA;CACE,CAAA;AAET"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* CKEditor 5 is themed through its own CSS variables, mapped here to design tokens.
|
|
3
|
+
* They are set on :root because CKEditor renders panels (dropdowns, balloons) outside the editor.
|
|
4
|
+
* This file is imported after ckeditor5.css so these values win.
|
|
5
|
+
*/
|
|
6
|
+
:root {
|
|
7
|
+
--ck-font-face: var(--font-sans);
|
|
8
|
+
--ck-font-size-base: var(--font-size-sm);
|
|
9
|
+
--ck-border-radius: var(--radius-md);
|
|
10
|
+
|
|
11
|
+
--ck-color-base-foreground: var(--color-bg-subtle);
|
|
12
|
+
--ck-color-base-background: var(--color-surface);
|
|
13
|
+
--ck-color-base-border: var(--color-border-strong);
|
|
14
|
+
--ck-color-base-action: var(--color-success);
|
|
15
|
+
--ck-color-base-focus: var(--color-focus-ring);
|
|
16
|
+
--ck-color-base-text: var(--color-text);
|
|
17
|
+
--ck-color-base-active: var(--color-primary);
|
|
18
|
+
--ck-color-base-active-focus: var(--color-primary-hover);
|
|
19
|
+
--ck-color-base-error: var(--color-danger);
|
|
20
|
+
--ck-color-text: var(--color-text);
|
|
21
|
+
--ck-color-shadow-drop: rgb(0 0 0 / 0.15);
|
|
22
|
+
--ck-color-focus-border: var(--color-focus-ring);
|
|
23
|
+
|
|
24
|
+
--ck-color-toolbar-background: var(--color-bg-subtle);
|
|
25
|
+
--ck-color-toolbar-border: var(--color-border-strong);
|
|
26
|
+
--ck-color-panel-background: var(--color-surface-raised);
|
|
27
|
+
--ck-color-panel-border: var(--color-border);
|
|
28
|
+
--ck-color-dropdown-panel-background: var(--color-surface-raised);
|
|
29
|
+
--ck-color-dropdown-panel-border: var(--color-border);
|
|
30
|
+
--ck-color-input-background: var(--color-surface);
|
|
31
|
+
--ck-color-input-border: var(--color-border-strong);
|
|
32
|
+
--ck-color-input-text: var(--color-text);
|
|
33
|
+
--ck-color-labeled-field-label-background: var(--color-surface-raised);
|
|
34
|
+
--ck-color-list-background: var(--color-surface-raised);
|
|
35
|
+
--ck-color-list-button-hover-background: var(--color-neutral);
|
|
36
|
+
--ck-color-list-button-on-background: var(--color-primary);
|
|
37
|
+
--ck-color-list-button-on-text: var(--color-text-on-primary);
|
|
38
|
+
|
|
39
|
+
--ck-color-button-default-background: transparent;
|
|
40
|
+
--ck-color-button-default-hover-background: var(--color-neutral);
|
|
41
|
+
--ck-color-button-default-active-background: var(--color-neutral-hover);
|
|
42
|
+
--ck-color-button-on-background: var(--color-primary-subtle);
|
|
43
|
+
--ck-color-button-on-hover-background: var(--color-neutral-hover);
|
|
44
|
+
--ck-color-button-on-color: var(--color-primary-text);
|
|
45
|
+
--ck-color-button-action-background: var(--color-primary);
|
|
46
|
+
--ck-color-button-action-hover-background: var(--color-primary-hover);
|
|
47
|
+
--ck-color-button-action-text: var(--color-text-on-primary);
|
|
48
|
+
|
|
49
|
+
--ck-color-link-default: var(--color-primary-text);
|
|
50
|
+
--ck-color-tooltip-background: var(--color-text);
|
|
51
|
+
--ck-color-tooltip-text: var(--color-text-inverse);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.ds-editor .ck.ck-editor__main > .ck-editor__editable {
|
|
55
|
+
min-height: 300px;
|
|
56
|
+
padding: 0 var(--space-4);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.ds-editor .ck.ck-editor__main > .ck-editor__editable:not(.ck-focused) {
|
|
60
|
+
border-color: var(--color-border-strong);
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FieldRegistration, FormApi, FormValidateOn, FormValues } from "./types";
|
|
2
|
+
export interface FormContextValue extends FormApi<FormValues> {
|
|
3
|
+
validateOn: FormValidateOn;
|
|
4
|
+
registerField: (name: string, registration: FieldRegistration) => () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const FormContext: import("react").Context<FormContextValue | null>;
|
|
7
|
+
export declare function useFormContext(component: string): FormContextValue;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
// src/components/organisms/form/context.ts
|
|
3
|
+
var FormContext = createContext(null);
|
|
4
|
+
function useFormContext(component) {
|
|
5
|
+
const context = useContext(FormContext);
|
|
6
|
+
if (!context) throw new Error(`${component} must be used inside <Form>`);
|
|
7
|
+
return context;
|
|
8
|
+
}
|
|
9
|
+
export { FormContext, useFormContext };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../../../src/components/organisms/form/context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { FieldRegistration, FormApi, FormValidateOn, FormValues } from \"./types\";\n\nexport interface FormContextValue extends FormApi<FormValues> {\n validateOn: FormValidateOn;\n registerField: (name: string, registration: FieldRegistration) => () => void;\n}\n\nexport const FormContext = createContext<FormContextValue | null>(null);\n\nexport function useFormContext(component: string): FormContextValue {\n const context = useContext(FormContext);\n if (!context) throw new Error(`${component} must be used inside <Form>`);\n return context;\n}\n"],"mappings":";;AAQA,IAAa,cAAc,cAAuC,IAAI;AAEtE,SAAgB,eAAe,WAAqC;CAClE,MAAM,UAAU,WAAW,WAAW;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,GAAG,UAAU,4BAA4B;CACvE,OAAO;AACT"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { FormFieldProps } from "../../molecules/form-field";
|
|
3
|
+
import type { FieldRenderProps, FieldRules } from "./types";
|
|
4
|
+
export interface FieldProps extends Omit<FormFieldProps, "children" | "error" | "htmlFor"> {
|
|
5
|
+
/** Key of the value in the form's `values` */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Validation rules. `required` on the field implies `rules.required` */
|
|
8
|
+
rules?: FieldRules;
|
|
9
|
+
/** Id of the control. Generated when omitted (or taken from the child's `id`) */
|
|
10
|
+
id?: string;
|
|
11
|
+
/**
|
|
12
|
+
* A single control element, wired automatically with `name`, `value` (or `checked` for checkboxes
|
|
13
|
+
* and switches), `onChange`, `onBlur` and the FormField props; or a render prop `(field) => ReactNode`.
|
|
14
|
+
*/
|
|
15
|
+
children: ReactElement | ((field: FieldRenderProps) => ReactNode);
|
|
16
|
+
}
|
|
17
|
+
/** A form control bound to a value of the enclosing `<Form>`, rendered inside a FormField. */
|
|
18
|
+
export declare function Field({ name, rules, required, id: idProp, children, ...formFieldProps }: FieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { cloneElement, isValidElement, useEffect, useId, useRef } from "react";
|
|
2
|
+
import Checkbox from "../../atoms/checkbox/index.js";
|
|
3
|
+
import Switch from "../../atoms/switch/index.js";
|
|
4
|
+
import FormField from "../../molecules/form-field/index.js";
|
|
5
|
+
import { useFormContext } from "./context.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/organisms/form/field.tsx
|
|
8
|
+
/** Reads a value from a change event, or returns the argument as is (for controls that emit values). */
|
|
9
|
+
function extractValue(eventOrValue) {
|
|
10
|
+
if (eventOrValue && typeof eventOrValue === "object" && "target" in eventOrValue) {
|
|
11
|
+
const target = eventOrValue.target;
|
|
12
|
+
if (target && typeof target === "object" && "value" in target) {
|
|
13
|
+
const el = target;
|
|
14
|
+
if (el.type === "checkbox") return el.checked;
|
|
15
|
+
if (el.type === "select-multiple") return Array.from(target.selectedOptions, (option) => option.value);
|
|
16
|
+
return el.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return eventOrValue;
|
|
20
|
+
}
|
|
21
|
+
var chain = (theirs, ours) => (arg) => {
|
|
22
|
+
if (typeof theirs === "function") theirs(arg);
|
|
23
|
+
ours(arg);
|
|
24
|
+
};
|
|
25
|
+
/** A form control bound to a value of the enclosing `<Form>`, rendered inside a FormField. */
|
|
26
|
+
function Field({ name, rules, required = false, id: idProp, children, ...formFieldProps }) {
|
|
27
|
+
const form = useFormContext("Field");
|
|
28
|
+
const autoId = useId();
|
|
29
|
+
const element = isValidElement(children) ? children : null;
|
|
30
|
+
const childId = element && typeof element.props.id === "string" ? element.props.id : void 0;
|
|
31
|
+
const id = idProp ?? childId ?? `ds-form-field-${autoId}`;
|
|
32
|
+
const latest = useRef({
|
|
33
|
+
rules,
|
|
34
|
+
required,
|
|
35
|
+
id
|
|
36
|
+
});
|
|
37
|
+
latest.current = {
|
|
38
|
+
rules,
|
|
39
|
+
required,
|
|
40
|
+
id
|
|
41
|
+
};
|
|
42
|
+
const { registerField } = form;
|
|
43
|
+
useEffect(() => registerField(name, {
|
|
44
|
+
getRules: () => {
|
|
45
|
+
const { rules: current, required: isRequired } = latest.current;
|
|
46
|
+
return isRequired && !current?.required ? {
|
|
47
|
+
...current,
|
|
48
|
+
required: true
|
|
49
|
+
} : current;
|
|
50
|
+
},
|
|
51
|
+
getElement: () => document.getElementById(latest.current.id)
|
|
52
|
+
}), [name, registerField]);
|
|
53
|
+
const value = form.values[name];
|
|
54
|
+
const touched = Boolean(form.touched[name]);
|
|
55
|
+
const error = touched ? form.errors[name] : void 0;
|
|
56
|
+
const setValue = (next) => form.setValue(name, next);
|
|
57
|
+
const handleChange = (eventOrValue) => {
|
|
58
|
+
if (form.validateOn === "change") form.setFieldTouched(name, true, false);
|
|
59
|
+
setValue(extractValue(eventOrValue));
|
|
60
|
+
};
|
|
61
|
+
const handleBlur = () => form.setFieldTouched(name, true);
|
|
62
|
+
const isRequired = required || Boolean(rules?.required);
|
|
63
|
+
let control;
|
|
64
|
+
if (element) {
|
|
65
|
+
const isCheckbox = element.type === Checkbox || element.type === Switch || element.props.type === "checkbox";
|
|
66
|
+
control = cloneElement(element, {
|
|
67
|
+
name,
|
|
68
|
+
...isCheckbox ? { checked: Boolean(value) } : { value: value === void 0 ? "" : value },
|
|
69
|
+
onChange: chain(element.props.onChange, handleChange),
|
|
70
|
+
onBlur: chain(element.props.onBlur, handleBlur)
|
|
71
|
+
});
|
|
72
|
+
} else if (typeof children === "function") control = ({ invalid, ...fieldProps }) => children({
|
|
73
|
+
field: {
|
|
74
|
+
...fieldProps,
|
|
75
|
+
name,
|
|
76
|
+
value,
|
|
77
|
+
checked: Boolean(value),
|
|
78
|
+
onChange: handleChange,
|
|
79
|
+
onBlur: handleBlur
|
|
80
|
+
},
|
|
81
|
+
meta: {
|
|
82
|
+
error,
|
|
83
|
+
touched,
|
|
84
|
+
invalid: Boolean(invalid)
|
|
85
|
+
},
|
|
86
|
+
setValue
|
|
87
|
+
});
|
|
88
|
+
return /* @__PURE__ */ jsx(FormField, {
|
|
89
|
+
...formFieldProps,
|
|
90
|
+
htmlFor: id,
|
|
91
|
+
required: isRequired,
|
|
92
|
+
error,
|
|
93
|
+
children: control
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export { Field };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","names":["_jsx"],"sources":["../../../../src/components/organisms/form/field.tsx"],"sourcesContent":["import { cloneElement, isValidElement, useEffect, useId, useRef } from \"react\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport Checkbox from \"../../atoms/checkbox\";\nimport Switch from \"../../atoms/switch\";\nimport FormField from \"../../molecules/form-field\";\nimport type { FormFieldProps } from \"../../molecules/form-field\";\nimport { useFormContext } from \"./context\";\nimport type { FieldRenderProps, FieldRules } from \"./types\";\n\nexport interface FieldProps extends Omit<FormFieldProps, \"children\" | \"error\" | \"htmlFor\"> {\n /** Key of the value in the form's `values` */\n name: string;\n /** Validation rules. `required` on the field implies `rules.required` */\n rules?: FieldRules;\n /** Id of the control. Generated when omitted (or taken from the child's `id`) */\n id?: string;\n /**\n * A single control element, wired automatically with `name`, `value` (or `checked` for checkboxes\n * and switches), `onChange`, `onBlur` and the FormField props; or a render prop `(field) => ReactNode`.\n */\n children: ReactElement | ((field: FieldRenderProps) => ReactNode);\n}\n\ntype AnyProps = Record<string, unknown>;\n\n/** Reads a value from a change event, or returns the argument as is (for controls that emit values). */\nfunction extractValue(eventOrValue: unknown): unknown {\n if (eventOrValue && typeof eventOrValue === \"object\" && \"target\" in eventOrValue) {\n const target = (eventOrValue as { target: unknown }).target;\n if (target && typeof target === \"object\" && \"value\" in target) {\n const el = target as HTMLInputElement;\n if (el.type === \"checkbox\") return el.checked;\n if (el.type === \"select-multiple\") {\n return Array.from((target as HTMLSelectElement).selectedOptions, (option) => option.value);\n }\n return el.value;\n }\n }\n return eventOrValue;\n}\n\nconst chain =\n (theirs: unknown, ours: (arg: unknown) => void) =>\n (arg: unknown) => {\n if (typeof theirs === \"function\") theirs(arg);\n ours(arg);\n };\n\n/** A form control bound to a value of the enclosing `<Form>`, rendered inside a FormField. */\nexport function Field({ name, rules, required = false, id: idProp, children, ...formFieldProps }: FieldProps) {\n const form = useFormContext(\"Field\");\n const autoId = useId();\n const element = isValidElement(children) ? (children as ReactElement<AnyProps>) : null;\n const childId = element && typeof element.props.id === \"string\" ? element.props.id : undefined;\n const id = idProp ?? childId ?? `ds-form-field-${autoId}`;\n\n const latest = useRef({ rules, required, id });\n latest.current = { rules, required, id };\n const { registerField } = form;\n\n useEffect(\n () =>\n registerField(name, {\n getRules: () => {\n const { rules: current, required: isRequired } = latest.current;\n return isRequired && !current?.required ? { ...current, required: true } : current;\n },\n getElement: () => document.getElementById(latest.current.id),\n }),\n [name, registerField]\n );\n\n const value = form.values[name];\n const touched = Boolean(form.touched[name]);\n const error = touched ? form.errors[name] : undefined;\n\n const setValue = (next: unknown) => form.setValue(name, next);\n const handleChange = (eventOrValue: unknown) => {\n if (form.validateOn === \"change\") form.setFieldTouched(name, true, false);\n setValue(extractValue(eventOrValue));\n };\n const handleBlur = () => form.setFieldTouched(name, true);\n\n const isRequired = required || Boolean(rules?.required);\n\n let control: FormFieldProps[\"children\"];\n if (element) {\n const isCheckbox = element.type === Checkbox || element.type === Switch || element.props.type === \"checkbox\";\n control = cloneElement(element, {\n name,\n ...(isCheckbox ? { checked: Boolean(value) } : { value: value === undefined ? \"\" : value }),\n onChange: chain(element.props.onChange, handleChange),\n onBlur: chain(element.props.onBlur, handleBlur),\n });\n } else if (typeof children === \"function\") {\n control = ({ invalid, ...fieldProps }) =>\n children({\n field: {\n ...fieldProps,\n name,\n value,\n checked: Boolean(value),\n onChange: handleChange,\n onBlur: handleBlur,\n },\n meta: { error, touched, invalid: Boolean(invalid) },\n setValue,\n });\n }\n\n return (\n <FormField {...formFieldProps} htmlFor={id} required={isRequired} error={error}>\n {control}\n </FormField>\n );\n}\n"],"mappings":";;;;;;;;AA0BA,SAAS,aAAa,cAAgC;CACpD,IAAI,gBAAgB,OAAO,iBAAiB,YAAY,YAAY,cAAc;EAChF,MAAM,SAAU,aAAqC;EACrD,IAAI,UAAU,OAAO,WAAW,YAAY,WAAW,QAAQ;GAC7D,MAAM,KAAK;GACX,IAAI,GAAG,SAAS,YAAY,OAAO,GAAG;GACtC,IAAI,GAAG,SAAS,mBACd,OAAO,MAAM,KAAM,OAA6B,kBAAkB,WAAW,OAAO,KAAK;GAE3F,OAAO,GAAG;EACZ;CACF;CACA,OAAO;AACT;AAEA,IAAM,SACH,QAAiB,UACjB,QAAiB;CAChB,IAAI,OAAO,WAAW,YAAY,OAAO,GAAG;CAC5C,KAAK,GAAG;AACV;;AAGF,SAAgB,MAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI,QAAQ,UAAU,GAAG,kBAA8B;CAC5G,MAAM,OAAO,eAAe,OAAO;CACnC,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,eAAe,QAAQ,IAAK,WAAsC;CAClF,MAAM,UAAU,WAAW,OAAO,QAAQ,MAAM,OAAO,WAAW,QAAQ,MAAM,KAAK,KAAA;CACrF,MAAM,KAAK,UAAU,WAAW,iBAAiB;CAEjD,MAAM,SAAS,OAAO;EAAE;EAAO;EAAU;CAAG,CAAC;CAC7C,OAAO,UAAU;EAAE;EAAO;EAAU;CAAG;CACvC,MAAM,EAAE,kBAAkB;CAE1B,gBAEI,cAA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AI;EAAgB,SAAS;EAAI,UAAU;EAAmB;EACtE,UAAA;CACQ,CAAA;AAEf"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export type FormActionsAlign = "start" | "end" | "between" | "stretch";
|
|
3
|
+
export interface FormActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** How the buttons are distributed. Default "end" */
|
|
5
|
+
align?: FormActionsAlign;
|
|
6
|
+
}
|
|
7
|
+
/** Footer slot for the form buttons (submit, cancel, reset). */
|
|
8
|
+
export declare function FormActions({ align, className, ...rest }: FormActionsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cx } from "../../utils/cx.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/components/organisms/form/form-actions.tsx
|
|
4
|
+
/** Footer slot for the form buttons (submit, cancel, reset). */
|
|
5
|
+
function FormActions({ align = "end", className, ...rest }) {
|
|
6
|
+
return /* @__PURE__ */ jsx("div", {
|
|
7
|
+
className: cx("ds-form__actions", `ds-form__actions--${align}`, className),
|
|
8
|
+
...rest
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export { FormActions };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=form-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-actions.js","names":["_jsx"],"sources":["../../../../src/components/organisms/form/form-actions.tsx"],"sourcesContent":["import type { HTMLAttributes } from \"react\";\nimport { cx } from \"../../utils/cx\";\n\nexport type FormActionsAlign = \"start\" | \"end\" | \"between\" | \"stretch\";\n\nexport interface FormActionsProps extends HTMLAttributes<HTMLDivElement> {\n /** How the buttons are distributed. Default \"end\" */\n align?: FormActionsAlign;\n}\n\n/** Footer slot for the form buttons (submit, cancel, reset). */\nexport function FormActions({ align = \"end\", className, ...rest }: FormActionsProps) {\n return <div className={cx(\"ds-form__actions\", `ds-form__actions--${align}`, className)} {...rest} />;\n}\n"],"mappings":";;;;AAWA,SAAgB,YAAY,EAAE,QAAQ,OAAO,WAAW,GAAG,QAA0B;CACnF,OAAOA,oBAAC,OAAD;EAAK,WAAW,GAAG,oBAAoB,qBAAqB,SAAS,SAAS;EAAG,GAAI;CAAO,CAAA;AACrG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FormHTMLAttributes } from "react";
|
|
2
|
+
import type { FormApi, FormChildren, FormErrors, FormSubmitHelpers, FormValidateOn, FormValues } from "./types";
|
|
3
|
+
export { Field } from "./field";
|
|
4
|
+
export type { FieldProps } from "./field";
|
|
5
|
+
export { FormActions } from "./form-actions";
|
|
6
|
+
export type { FormActionsProps, FormActionsAlign } from "./form-actions";
|
|
7
|
+
export type { FieldLengthRule, FieldRenderProps, FieldRules, FormApi, FormErrors, FormSubmitHelpers, FormTouched, FormValidateOn, FormValues, } from "./types";
|
|
8
|
+
export interface FormProps<V extends FormValues = FormValues> extends Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "children"> {
|
|
9
|
+
/** Starting values, keyed by field name. Give every field a value (e.g. `""`, `false`, `0`, or `null` for a NumberStepper) */
|
|
10
|
+
initialValues: V;
|
|
11
|
+
/** Form-level validation. Return (or resolve) an error message per field name */
|
|
12
|
+
validate?: (values: V) => FormErrors | Promise<FormErrors>;
|
|
13
|
+
/** Called with the values when the form is submitted and valid. May return a promise */
|
|
14
|
+
onSubmit?: (values: V, helpers: FormSubmitHelpers<V>) => void | Promise<unknown>;
|
|
15
|
+
/** When errors are computed and shown. Default "blur". After the first submit, changes always re-validate */
|
|
16
|
+
validateOn?: FormValidateOn;
|
|
17
|
+
/** Content, or a function receiving the form API */
|
|
18
|
+
children?: FormChildren<V>;
|
|
19
|
+
}
|
|
20
|
+
/** Access the state and actions of the enclosing `<Form>`. */
|
|
21
|
+
export declare function useForm<V extends FormValues = FormValues>(): FormApi<V>;
|
|
22
|
+
/** Lightweight, dependency-free form state, validation and submit orchestration. */
|
|
23
|
+
declare function Form<V extends FormValues = FormValues>({ initialValues, validate, onSubmit, validateOn, className, children, onReset, ...rest }: FormProps<V>): import("react").JSX.Element;
|
|
24
|
+
export default Form;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
import { getFocusable } from "../../hooks/use-focus-trap.js";
|
|
3
|
+
import { cx } from "../../utils/cx.js";
|
|
4
|
+
import { FormContext, useFormContext } from "./context.js";
|
|
5
|
+
import { validateRules } from "./validation.js";
|
|
6
|
+
import './styles.css';/* empty css */
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Field } from "./field.js";
|
|
9
|
+
import { FormActions } from "./form-actions.js";
|
|
10
|
+
// src/components/organisms/form/index.tsx
|
|
11
|
+
var isPromise = (value) => value != null && typeof value.then === "function";
|
|
12
|
+
var clean = (errors) => {
|
|
13
|
+
const out = {};
|
|
14
|
+
if (errors) {
|
|
15
|
+
for (const [name, message] of Object.entries(errors)) if (message) out[name] = message;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
};
|
|
19
|
+
var escapeName = (name) => name.replace(/["\\]/g, "\\$&");
|
|
20
|
+
/** Access the state and actions of the enclosing `<Form>`. */
|
|
21
|
+
function useForm() {
|
|
22
|
+
return useFormContext("useForm");
|
|
23
|
+
}
|
|
24
|
+
/** Lightweight, dependency-free form state, validation and submit orchestration. */
|
|
25
|
+
function Form({ initialValues, validate, onSubmit, validateOn = "blur", className, children, onReset, ...rest }) {
|
|
26
|
+
const [values, setValuesState] = useState(initialValues);
|
|
27
|
+
const [errors, setErrorsState] = useState({});
|
|
28
|
+
const [touched, setTouchedState] = useState({});
|
|
29
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
30
|
+
const [submitCount, setSubmitCountState] = useState(0);
|
|
31
|
+
const valuesRef = useRef(values);
|
|
32
|
+
const errorsRef = useRef(errors);
|
|
33
|
+
const touchedRef = useRef(touched);
|
|
34
|
+
const submitCountRef = useRef(0);
|
|
35
|
+
const submittingRef = useRef(false);
|
|
36
|
+
const runRef = useRef(0);
|
|
37
|
+
const fieldsRef = useRef(/* @__PURE__ */ new Map());
|
|
38
|
+
const formRef = useRef(null);
|
|
39
|
+
const propsRef = useRef({
|
|
40
|
+
initialValues,
|
|
41
|
+
validate,
|
|
42
|
+
onSubmit,
|
|
43
|
+
validateOn
|
|
44
|
+
});
|
|
45
|
+
propsRef.current = {
|
|
46
|
+
initialValues,
|
|
47
|
+
validate,
|
|
48
|
+
onSubmit,
|
|
49
|
+
validateOn
|
|
50
|
+
};
|
|
51
|
+
const setValuesSync = (next) => {
|
|
52
|
+
valuesRef.current = next;
|
|
53
|
+
setValuesState(next);
|
|
54
|
+
};
|
|
55
|
+
const setErrors = useCallback((next) => {
|
|
56
|
+
errorsRef.current = clean(next);
|
|
57
|
+
setErrorsState(errorsRef.current);
|
|
58
|
+
}, []);
|
|
59
|
+
const setTouched = (next) => {
|
|
60
|
+
touchedRef.current = next;
|
|
61
|
+
setTouchedState(next);
|
|
62
|
+
};
|
|
63
|
+
const setSubmitCount = (next) => {
|
|
64
|
+
submitCountRef.current = next;
|
|
65
|
+
setSubmitCountState(next);
|
|
66
|
+
};
|
|
67
|
+
/** Field rules + form-level validate. Synchronous unless `validate` returns a promise. */
|
|
68
|
+
const runValidation = (vals) => {
|
|
69
|
+
const fieldErrors = {};
|
|
70
|
+
fieldsRef.current.forEach((registration, name) => {
|
|
71
|
+
const message = validateRules(vals[name], vals, registration.getRules());
|
|
72
|
+
if (message) fieldErrors[name] = message;
|
|
73
|
+
});
|
|
74
|
+
const formResult = propsRef.current.validate?.(vals);
|
|
75
|
+
if (isPromise(formResult)) return formResult.then((formErrors) => ({
|
|
76
|
+
...clean(formErrors),
|
|
77
|
+
...fieldErrors
|
|
78
|
+
}));
|
|
79
|
+
return {
|
|
80
|
+
...clean(formResult),
|
|
81
|
+
...fieldErrors
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** Validates and stores the errors, ignoring results of outdated async runs. */
|
|
85
|
+
const applyValidation = (vals) => {
|
|
86
|
+
const run = ++runRef.current;
|
|
87
|
+
const result = runValidation(vals);
|
|
88
|
+
if (isPromise(result)) result.then((next) => {
|
|
89
|
+
if (run === runRef.current) setErrors(next);
|
|
90
|
+
}, () => void 0);
|
|
91
|
+
else setErrors(result);
|
|
92
|
+
};
|
|
93
|
+
const setValue = (name, value) => {
|
|
94
|
+
const next = {
|
|
95
|
+
...valuesRef.current,
|
|
96
|
+
[name]: value
|
|
97
|
+
};
|
|
98
|
+
setValuesSync(next);
|
|
99
|
+
if (propsRef.current.validateOn === "change" || submitCountRef.current > 0 || errorsRef.current[name]) applyValidation(next);
|
|
100
|
+
};
|
|
101
|
+
const setFieldTouched = (name, isTouched = true, shouldValidate) => {
|
|
102
|
+
setTouched({
|
|
103
|
+
...touchedRef.current,
|
|
104
|
+
[name]: isTouched
|
|
105
|
+
});
|
|
106
|
+
if (shouldValidate ?? (propsRef.current.validateOn !== "submit" || submitCountRef.current > 0)) applyValidation(valuesRef.current);
|
|
107
|
+
};
|
|
108
|
+
const setFieldError = (name, error) => {
|
|
109
|
+
setErrors({
|
|
110
|
+
...errorsRef.current,
|
|
111
|
+
[name]: error
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const reset = (next) => {
|
|
115
|
+
runRef.current++;
|
|
116
|
+
setValuesSync(next ?? propsRef.current.initialValues);
|
|
117
|
+
setErrors({});
|
|
118
|
+
setTouched({});
|
|
119
|
+
setSubmitCount(0);
|
|
120
|
+
};
|
|
121
|
+
const focusFirstInvalid = (errs) => {
|
|
122
|
+
const form = formRef.current;
|
|
123
|
+
Object.keys(errs).map((name) => {
|
|
124
|
+
const element = fieldsRef.current.get(name)?.getElement() ?? form?.querySelector(`[name="${escapeName(name)}"]`) ?? null;
|
|
125
|
+
if (!element) return null;
|
|
126
|
+
return /^(INPUT|SELECT|TEXTAREA|BUTTON)$/.test(element.tagName) || element.tabIndex >= 0 ? element : getFocusable(element)[0] ?? null;
|
|
127
|
+
}).filter((el) => el != null).sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1)[0]?.focus();
|
|
128
|
+
};
|
|
129
|
+
const submit = async () => {
|
|
130
|
+
if (submittingRef.current) return;
|
|
131
|
+
const vals = valuesRef.current;
|
|
132
|
+
const allTouched = { ...touchedRef.current };
|
|
133
|
+
for (const name of [...Object.keys(vals), ...fieldsRef.current.keys()]) allTouched[name] = true;
|
|
134
|
+
setTouched(allTouched);
|
|
135
|
+
setSubmitCount(submitCountRef.current + 1);
|
|
136
|
+
const run = ++runRef.current;
|
|
137
|
+
submittingRef.current = true;
|
|
138
|
+
try {
|
|
139
|
+
let result = runValidation(vals);
|
|
140
|
+
if (isPromise(result)) {
|
|
141
|
+
setIsSubmitting(true);
|
|
142
|
+
result = await result;
|
|
143
|
+
}
|
|
144
|
+
if (run === runRef.current) setErrors(result);
|
|
145
|
+
if (Object.keys(result).length > 0) {
|
|
146
|
+
focusFirstInvalid(result);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const handler = propsRef.current.onSubmit;
|
|
150
|
+
if (handler) {
|
|
151
|
+
const pending = handler(vals, {
|
|
152
|
+
reset,
|
|
153
|
+
setErrors,
|
|
154
|
+
setFieldError
|
|
155
|
+
});
|
|
156
|
+
if (isPromise(pending)) {
|
|
157
|
+
setIsSubmitting(true);
|
|
158
|
+
await pending;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
submittingRef.current = false;
|
|
163
|
+
setIsSubmitting(false);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const registerField = useCallback((name, registration) => {
|
|
167
|
+
fieldsRef.current.set(name, registration);
|
|
168
|
+
return () => {
|
|
169
|
+
if (fieldsRef.current.get(name) === registration) fieldsRef.current.delete(name);
|
|
170
|
+
};
|
|
171
|
+
}, []);
|
|
172
|
+
const api = {
|
|
173
|
+
values,
|
|
174
|
+
errors,
|
|
175
|
+
touched,
|
|
176
|
+
isSubmitting,
|
|
177
|
+
isValid: Object.keys(errors).length === 0,
|
|
178
|
+
submitCount,
|
|
179
|
+
setValue,
|
|
180
|
+
setFieldTouched,
|
|
181
|
+
setFieldError,
|
|
182
|
+
setErrors,
|
|
183
|
+
reset,
|
|
184
|
+
submit,
|
|
185
|
+
validateOn,
|
|
186
|
+
registerField
|
|
187
|
+
};
|
|
188
|
+
const handleSubmit = (event) => {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
submit().catch((error) => {
|
|
191
|
+
console.error(error);
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const handleReset = (event) => {
|
|
195
|
+
onReset?.(event);
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
reset();
|
|
198
|
+
};
|
|
199
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, {
|
|
200
|
+
value: api,
|
|
201
|
+
children: /* @__PURE__ */ jsx("form", {
|
|
202
|
+
ref: formRef,
|
|
203
|
+
noValidate: true,
|
|
204
|
+
className: cx("ds-form", className),
|
|
205
|
+
"aria-busy": isSubmitting || void 0,
|
|
206
|
+
onSubmit: handleSubmit,
|
|
207
|
+
onReset: handleReset,
|
|
208
|
+
...rest,
|
|
209
|
+
children: typeof children === "function" ? children(api) : children
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export { Field, FormActions, Form as default, useForm };
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_jsx"],"sources":["../../../../src/components/organisms/form/index.tsx"],"sourcesContent":["import { useCallback, useRef, useState } from \"react\";\nimport type { FormEvent, FormHTMLAttributes } from \"react\";\nimport { getFocusable } from \"../../hooks\";\nimport { cx } from \"../../utils/cx\";\nimport { FormContext, useFormContext } from \"./context\";\nimport type { FormContextValue } from \"./context\";\nimport type {\n FieldRegistration,\n FormApi,\n FormChildren,\n FormErrors,\n FormSubmitHelpers,\n FormTouched,\n FormValidateOn,\n FormValues,\n} from \"./types\";\nimport { validateRules } from \"./validation\";\nimport \"./styles.css\";\n\nexport { Field } from \"./field\";\nexport type { FieldProps } from \"./field\";\nexport { FormActions } from \"./form-actions\";\nexport type { FormActionsProps, FormActionsAlign } from \"./form-actions\";\nexport type {\n FieldLengthRule,\n FieldRenderProps,\n FieldRules,\n FormApi,\n FormErrors,\n FormSubmitHelpers,\n FormTouched,\n FormValidateOn,\n FormValues,\n} from \"./types\";\n\nexport interface FormProps<V extends FormValues = FormValues>\n extends Omit<FormHTMLAttributes<HTMLFormElement>, \"onSubmit\" | \"children\"> {\n /** Starting values, keyed by field name. Give every field a value (e.g. `\"\"`, `false`, `0`, or `null` for a NumberStepper) */\n initialValues: V;\n /** Form-level validation. Return (or resolve) an error message per field name */\n validate?: (values: V) => FormErrors | Promise<FormErrors>;\n /** Called with the values when the form is submitted and valid. May return a promise */\n onSubmit?: (values: V, helpers: FormSubmitHelpers<V>) => void | Promise<unknown>;\n /** When errors are computed and shown. Default \"blur\". After the first submit, changes always re-validate */\n validateOn?: FormValidateOn;\n /** Content, or a function receiving the form API */\n children?: FormChildren<V>;\n}\n\ntype Result = FormErrors | Promise<FormErrors>;\n\nconst isPromise = (value: unknown): value is Promise<FormErrors> =>\n value != null && typeof (value as Promise<unknown>).then === \"function\";\n\nconst clean = (errors: FormErrors | undefined | void): FormErrors => {\n const out: FormErrors = {};\n if (errors) for (const [name, message] of Object.entries(errors)) if (message) out[name] = message;\n return out;\n};\n\nconst escapeName = (name: string) => name.replace(/[\"\\\\]/g, \"\\\\$&\");\n\n/** Access the state and actions of the enclosing `<Form>`. */\nexport function useForm<V extends FormValues = FormValues>(): FormApi<V> {\n return useFormContext(\"useForm\") as unknown as FormApi<V>;\n}\n\n/** Lightweight, dependency-free form state, validation and submit orchestration. */\nfunction Form<V extends FormValues = FormValues>({\n initialValues,\n validate,\n onSubmit,\n validateOn = \"blur\",\n className,\n children,\n onReset,\n ...rest\n}: FormProps<V>) {\n const [values, setValuesState] = useState<V>(initialValues);\n const [errors, setErrorsState] = useState<FormErrors>({});\n const [touched, setTouchedState] = useState<FormTouched>({});\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [submitCount, setSubmitCountState] = useState(0);\n\n // Refs mirror the state so callbacks always read the latest values.\n const valuesRef = useRef(values);\n const errorsRef = useRef(errors);\n const touchedRef = useRef(touched);\n const submitCountRef = useRef(0);\n const submittingRef = useRef(false);\n const runRef = useRef(0);\n const fieldsRef = useRef(new Map<string, FieldRegistration>());\n const formRef = useRef<HTMLFormElement>(null);\n const propsRef = useRef({ initialValues, validate, onSubmit, validateOn });\n propsRef.current = { initialValues, validate, onSubmit, validateOn };\n\n const setValuesSync = (next: V) => {\n valuesRef.current = next;\n setValuesState(next);\n };\n const setErrors = useCallback((next: FormErrors) => {\n errorsRef.current = clean(next);\n setErrorsState(errorsRef.current);\n }, []);\n const setTouched = (next: FormTouched) => {\n touchedRef.current = next;\n setTouchedState(next);\n };\n const setSubmitCount = (next: number) => {\n submitCountRef.current = next;\n setSubmitCountState(next);\n };\n\n /** Field rules + form-level validate. Synchronous unless `validate` returns a promise. */\n const runValidation = (vals: V): Result => {\n const fieldErrors: FormErrors = {};\n fieldsRef.current.forEach((registration, name) => {\n const message = validateRules(vals[name], vals, registration.getRules());\n if (message) fieldErrors[name] = message;\n });\n const formResult = propsRef.current.validate?.(vals);\n if (isPromise(formResult)) return formResult.then((formErrors) => ({ ...clean(formErrors), ...fieldErrors }));\n return { ...clean(formResult), ...fieldErrors };\n };\n\n /** Validates and stores the errors, ignoring results of outdated async runs. */\n const applyValidation = (vals: V) => {\n const run = ++runRef.current;\n const result = runValidation(vals);\n if (isPromise(result)) {\n result.then(\n (next) => {\n if (run === runRef.current) setErrors(next);\n },\n () => undefined\n );\n } else {\n setErrors(result);\n }\n };\n\n const setValue = (name: string, value: unknown) => {\n const next = { ...valuesRef.current, [name]: value } as V;\n setValuesSync(next);\n if (propsRef.current.validateOn === \"change\" || submitCountRef.current > 0 || errorsRef.current[name]) {\n applyValidation(next);\n }\n };\n\n const setFieldTouched = (name: string, isTouched = true, shouldValidate?: boolean) => {\n setTouched({ ...touchedRef.current, [name]: isTouched });\n const validateNow = shouldValidate ?? (propsRef.current.validateOn !== \"submit\" || submitCountRef.current > 0);\n if (validateNow) applyValidation(valuesRef.current);\n };\n\n const setFieldError = (name: string, error: string | undefined) => {\n setErrors({ ...errorsRef.current, [name]: error });\n };\n\n const reset = (next?: V) => {\n runRef.current++;\n setValuesSync(next ?? propsRef.current.initialValues);\n setErrors({});\n setTouched({});\n setSubmitCount(0);\n };\n\n const focusFirstInvalid = (errs: FormErrors) => {\n const form = formRef.current;\n const targets = Object.keys(errs)\n .map((name) => {\n const element =\n fieldsRef.current.get(name)?.getElement() ?? form?.querySelector<HTMLElement>(`[name=\"${escapeName(name)}\"]`) ?? null;\n if (!element) return null;\n const isNativeControl = /^(INPUT|SELECT|TEXTAREA|BUTTON)$/.test(element.tagName);\n return isNativeControl || element.tabIndex >= 0 ? element : (getFocusable(element)[0] ?? null);\n })\n .filter((el): el is HTMLElement => el != null)\n .sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));\n targets[0]?.focus();\n };\n\n const submit = async () => {\n if (submittingRef.current) return;\n const vals = valuesRef.current;\n const allTouched: FormTouched = { ...touchedRef.current };\n for (const name of [...Object.keys(vals), ...fieldsRef.current.keys()]) allTouched[name] = true;\n setTouched(allTouched);\n setSubmitCount(submitCountRef.current + 1);\n\n const run = ++runRef.current;\n submittingRef.current = true;\n try {\n let result = runValidation(vals);\n if (isPromise(result)) {\n setIsSubmitting(true);\n result = await result;\n }\n if (run === runRef.current) setErrors(result);\n if (Object.keys(result).length > 0) {\n focusFirstInvalid(result);\n return;\n }\n const handler = propsRef.current.onSubmit;\n if (handler) {\n const pending = handler(vals, { reset, setErrors, setFieldError });\n if (isPromise(pending)) {\n setIsSubmitting(true);\n await pending;\n }\n }\n } finally {\n submittingRef.current = false;\n setIsSubmitting(false);\n }\n };\n\n const registerField = useCallback((name: string, registration: FieldRegistration) => {\n fieldsRef.current.set(name, registration);\n return () => {\n if (fieldsRef.current.get(name) === registration) fieldsRef.current.delete(name);\n };\n }, []);\n\n const api: FormContextValue = {\n values,\n errors,\n touched,\n isSubmitting,\n isValid: Object.keys(errors).length === 0,\n submitCount,\n setValue,\n setFieldTouched,\n setFieldError,\n setErrors,\n reset: reset as (values?: FormValues) => void,\n submit,\n validateOn,\n registerField,\n };\n\n const handleSubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n submit().catch((error: unknown) => {\n // Surface errors thrown by onSubmit without leaving an unhandled rejection.\n console.error(error);\n });\n };\n\n const handleReset = (event: FormEvent<HTMLFormElement>) => {\n onReset?.(event);\n event.preventDefault();\n reset();\n };\n\n return (\n <FormContext.Provider value={api}>\n <form\n ref={formRef}\n noValidate\n className={cx(\"ds-form\", className)}\n aria-busy={isSubmitting || undefined}\n onSubmit={handleSubmit}\n onReset={handleReset}\n {...rest}\n >\n {typeof children === \"function\" ? children(api as unknown as FormApi<V>) : children}\n </form>\n </FormContext.Provider>\n );\n}\n\nexport default Form;\n"],"mappings":";;;;;;;;;;AAmDA,IAAM,aAAa,UACjB,SAAS,QAAQ,OAAQ,MAA2B,SAAS;AAE/D,IAAM,SAAS,WAAsD;CACnE,MAAM,MAAkB,CAAC;CACzB,IAAI,QAAa;OAAA,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,MAAM,GAAG,IAAI,SAAS,IAAI,QAAQ;CAAA;CAC3F,OAAO;AACT;AAEA,IAAM,cAAc,SAAiB,KAAK,QAAQ,UAAU,MAAM;;AAGlE,SAAgB,UAAyD;CACvE,OAAO,eAAe,SAAS;AACjC;;AAGA,SAAS,KAAwC,EAC/C,eACA,UACA,UACA,aAAa,QACb,WACA,UACA,SACA,GAA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AAO,IAAI;EACjF;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,MAAwB;EAC5B;EACA;EACA;EACA;EACA,SAAS,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW;EACxC;EACA;EACA;EACA;EACA;EACO;EACP;EACA;EACA;CACF;CAEA,MAAM,gBAAgB,UAAsC;EAC1D,MAAM,eAAe;EACrB,OAAO,CAAC,CAAC,OAAO,UAAmB;GAEjC,QAAQ,MAAM,KAAK;EACrB,CAAC;CACH;CAEA,MAAM,eAAe,UAAsC;EACzD,UAAU,KAAK;EACf,MAAM,eAAe;EACrB,MAAM;CACR;CAEA,OACEA,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC3B,UAAAA,oBAAC,QAAD;GACE,KAAK;GACL,YAAA;GACA,WAAW,GAAG,WAAW,SAAS;GAClC,aAAW,gBAAgB,KAAA;GAC3B,UAAU;GACV,SAAS;GACT,GAAI;GAEH,UAAA,OAAO,aAAa,aAAa,SAAS,GAA4B,IAAI;EACvE,CAAA;CACc,CAAA;AAE1B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.ds-form {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--space-4);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.ds-form__actions {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: var(--space-2);
|
|
12
|
+
padding-top: var(--space-2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.ds-form__actions--start {
|
|
16
|
+
justify-content: flex-start;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ds-form__actions--end {
|
|
20
|
+
justify-content: flex-end;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ds-form__actions--between {
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ds-form__actions--stretch > * {
|
|
28
|
+
flex: 1 1 0;
|
|
29
|
+
}
|