shelving 1.199.2 → 1.200.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/index.js +1 -0
- package/package.json +10 -5
- package/ui/app/App.d.ts +11 -0
- package/ui/app/App.js +21 -0
- package/ui/app/App.module.css +168 -0
- package/ui/app/App.tsx +26 -0
- package/ui/app/index.d.ts +1 -0
- package/ui/app/index.js +1 -0
- package/ui/app/index.ts +1 -0
- package/ui/block/Address.d.ts +20 -0
- package/ui/block/Address.js +17 -0
- package/ui/block/Address.module.css +20 -0
- package/ui/block/Address.tsx +47 -0
- package/ui/block/Blockquote.d.ts +5 -0
- package/ui/block/Blockquote.js +5 -0
- package/ui/block/Blockquote.module.css +21 -0
- package/ui/block/Blockquote.tsx +10 -0
- package/ui/block/Card.d.ts +10 -0
- package/ui/block/Card.js +7 -0
- package/ui/block/Card.module.css +32 -0
- package/ui/block/Card.tsx +18 -0
- package/ui/block/Divider.d.ts +6 -0
- package/ui/block/Divider.js +5 -0
- package/ui/block/Divider.module.css +19 -0
- package/ui/block/Divider.tsx +11 -0
- package/ui/block/Element.d.ts +9 -0
- package/ui/block/Element.js +7 -0
- package/ui/block/Element.module.css +12 -0
- package/ui/block/Element.tsx +14 -0
- package/ui/block/Elements.d.ts +27 -0
- package/ui/block/Elements.js +10 -0
- package/ui/block/Elements.module.css +70 -0
- package/ui/block/Elements.tsx +44 -0
- package/ui/block/Figure.d.ts +6 -0
- package/ui/block/Figure.js +5 -0
- package/ui/block/Figure.module.css +27 -0
- package/ui/block/Figure.tsx +16 -0
- package/ui/block/Heading.d.ts +6 -0
- package/ui/block/Heading.js +7 -0
- package/ui/block/Heading.module.css +23 -0
- package/ui/block/Heading.tsx +13 -0
- package/ui/block/Image.d.ts +6 -0
- package/ui/block/Image.js +5 -0
- package/ui/block/Image.module.css +20 -0
- package/ui/block/Image.tsx +11 -0
- package/ui/block/List.d.ts +6 -0
- package/ui/block/List.js +6 -0
- package/ui/block/List.module.css +30 -0
- package/ui/block/List.tsx +12 -0
- package/ui/block/Paragraph.d.ts +15 -0
- package/ui/block/Paragraph.js +7 -0
- package/ui/block/Paragraph.module.css +36 -0
- package/ui/block/Paragraph.tsx +21 -0
- package/ui/block/Preformatted.d.ts +5 -0
- package/ui/block/Preformatted.js +5 -0
- package/ui/block/Preformatted.module.css +23 -0
- package/ui/block/Preformatted.tsx +10 -0
- package/ui/block/Prose.d.ts +6 -0
- package/ui/block/Prose.js +28 -0
- package/ui/block/Prose.module.css +15 -0
- package/ui/block/Prose.tsx +56 -0
- package/ui/block/Section.d.ts +28 -0
- package/ui/block/Section.js +26 -0
- package/ui/block/Section.module.css +28 -0
- package/ui/block/Section.tsx +53 -0
- package/ui/block/Subheading.d.ts +3 -0
- package/ui/block/Subheading.js +7 -0
- package/ui/block/Subheading.module.css +23 -0
- package/ui/block/Subheading.tsx +10 -0
- package/ui/block/Table.d.ts +5 -0
- package/ui/block/Table.js +5 -0
- package/ui/block/Table.module.css +85 -0
- package/ui/block/Table.tsx +14 -0
- package/ui/block/Video.d.ts +36 -0
- package/ui/block/Video.js +43 -0
- package/ui/block/Video.module.css +103 -0
- package/ui/block/Video.tsx +91 -0
- package/ui/block/index.d.ts +17 -0
- package/ui/block/index.js +17 -0
- package/ui/block/index.ts +17 -0
- package/ui/dialog/Dialog.d.ts +13 -0
- package/ui/dialog/Dialog.js +28 -0
- package/ui/dialog/Dialog.module.css +29 -0
- package/ui/dialog/Dialog.tsx +57 -0
- package/ui/dialog/Dialogs.d.ts +23 -0
- package/ui/dialog/Dialogs.js +43 -0
- package/ui/dialog/Dialogs.tsx +64 -0
- package/ui/dialog/Modal.d.ts +5 -0
- package/ui/dialog/Modal.js +5 -0
- package/ui/dialog/Modal.module.css +11 -0
- package/ui/dialog/Modal.tsx +10 -0
- package/ui/dialog/index.d.ts +3 -0
- package/ui/dialog/index.js +3 -0
- package/ui/dialog/index.ts +3 -0
- package/ui/form/ArrayInput.d.ts +13 -0
- package/ui/form/ArrayInput.js +23 -0
- package/ui/form/ArrayInput.tsx +90 -0
- package/ui/form/ArrayRadioInputs.d.ts +15 -0
- package/ui/form/ArrayRadioInputs.js +16 -0
- package/ui/form/ArrayRadioInputs.tsx +53 -0
- package/ui/form/Button.d.ts +24 -0
- package/ui/form/Button.js +21 -0
- package/ui/form/Button.module.css +83 -0
- package/ui/form/Button.tsx +48 -0
- package/ui/form/ButtonInput.d.ts +7 -0
- package/ui/form/ButtonInput.js +19 -0
- package/ui/form/ButtonInput.tsx +33 -0
- package/ui/form/ButtonInputPopover.d.ts +16 -0
- package/ui/form/ButtonInputPopover.js +17 -0
- package/ui/form/ButtonInputPopover.tsx +32 -0
- package/ui/form/ButtonPopover.d.ts +16 -0
- package/ui/form/ButtonPopover.js +17 -0
- package/ui/form/ButtonPopover.tsx +31 -0
- package/ui/form/CheckboxInput.d.ts +7 -0
- package/ui/form/CheckboxInput.js +8 -0
- package/ui/form/CheckboxInput.tsx +37 -0
- package/ui/form/ChoiceRadioInputs.d.ts +17 -0
- package/ui/form/ChoiceRadioInputs.js +13 -0
- package/ui/form/ChoiceRadioInputs.tsx +60 -0
- package/ui/form/Clickable.d.ts +27 -0
- package/ui/form/Clickable.js +29 -0
- package/ui/form/Clickable.tsx +87 -0
- package/ui/form/DataInput.d.ts +9 -0
- package/ui/form/DataInput.js +17 -0
- package/ui/form/DataInput.tsx +43 -0
- package/ui/form/DateInput.d.ts +12 -0
- package/ui/form/DateInput.js +17 -0
- package/ui/form/DateInput.tsx +58 -0
- package/ui/form/DictionaryInput.d.ts +13 -0
- package/ui/form/DictionaryInput.js +32 -0
- package/ui/form/DictionaryInput.tsx +106 -0
- package/ui/form/Field.d.ts +10 -0
- package/ui/form/Field.js +7 -0
- package/ui/form/Field.module.css +45 -0
- package/ui/form/Field.test.tsx +26 -0
- package/ui/form/Field.tsx +32 -0
- package/ui/form/FileInput.d.ts +7 -0
- package/ui/form/FileInput.js +13 -0
- package/ui/form/FileInput.tsx +41 -0
- package/ui/form/Form.d.ts +38 -0
- package/ui/form/Form.js +61 -0
- package/ui/form/Form.module.css +9 -0
- package/ui/form/Form.tsx +130 -0
- package/ui/form/FormContext.d.ts +13 -0
- package/ui/form/FormContext.js +22 -0
- package/ui/form/FormContext.tsx +33 -0
- package/ui/form/FormFields.d.ts +6 -0
- package/ui/form/FormFields.js +16 -0
- package/ui/form/FormFields.tsx +30 -0
- package/ui/form/FormFooter.d.ts +11 -0
- package/ui/form/FormFooter.js +13 -0
- package/ui/form/FormFooter.tsx +27 -0
- package/ui/form/FormInput.d.ts +8 -0
- package/ui/form/FormInput.js +12 -0
- package/ui/form/FormInput.tsx +23 -0
- package/ui/form/FormMessage.d.ts +4 -0
- package/ui/form/FormMessage.js +11 -0
- package/ui/form/FormMessage.tsx +16 -0
- package/ui/form/FormNotice.d.ts +4 -0
- package/ui/form/FormNotice.js +11 -0
- package/ui/form/FormNotice.tsx +16 -0
- package/ui/form/FormNotify.d.ts +2 -0
- package/ui/form/FormNotify.js +11 -0
- package/ui/form/FormNotify.tsx +13 -0
- package/ui/form/FormStore.d.ts +39 -0
- package/ui/form/FormStore.js +95 -0
- package/ui/form/FormStore.tsx +107 -0
- package/ui/form/Input.d.ts +47 -0
- package/ui/form/Input.js +43 -0
- package/ui/form/Input.module.css +190 -0
- package/ui/form/Input.tsx +81 -0
- package/ui/form/NumberInput.d.ts +12 -0
- package/ui/form/NumberInput.js +18 -0
- package/ui/form/NumberInput.tsx +54 -0
- package/ui/form/Popover.d.ts +31 -0
- package/ui/form/Popover.js +20 -0
- package/ui/form/Popover.module.css +25 -0
- package/ui/form/Popover.tsx +61 -0
- package/ui/form/Progress.d.ts +9 -0
- package/ui/form/Progress.js +8 -0
- package/ui/form/Progress.module.css +30 -0
- package/ui/form/Progress.tsx +21 -0
- package/ui/form/QueryInput.d.ts +32 -0
- package/ui/form/QueryInput.js +37 -0
- package/ui/form/QueryInput.tsx +94 -0
- package/ui/form/RadioInput.d.ts +7 -0
- package/ui/form/RadioInput.js +8 -0
- package/ui/form/RadioInput.tsx +37 -0
- package/ui/form/SchemaInput.d.ts +59 -0
- package/ui/form/SchemaInput.js +102 -0
- package/ui/form/SchemaInput.tsx +154 -0
- package/ui/form/SegmentedProgress.d.ts +10 -0
- package/ui/form/SegmentedProgress.js +16 -0
- package/ui/form/SegmentedProgress.module.css +31 -0
- package/ui/form/SegmentedProgress.tsx +34 -0
- package/ui/form/SelectInput.d.ts +8 -0
- package/ui/form/SelectInput.js +6 -0
- package/ui/form/SelectInput.tsx +45 -0
- package/ui/form/SubmitButton.d.ts +7 -0
- package/ui/form/SubmitButton.js +15 -0
- package/ui/form/SubmitButton.tsx +38 -0
- package/ui/form/TextInput.d.ts +16 -0
- package/ui/form/TextInput.js +31 -0
- package/ui/form/TextInput.tsx +97 -0
- package/ui/form/index.d.ts +34 -0
- package/ui/form/index.js +34 -0
- package/ui/form/index.ts +34 -0
- package/ui/index.d.ts +12 -0
- package/ui/index.js +12 -0
- package/ui/index.ts +12 -0
- package/ui/inline/Code.d.ts +17 -0
- package/ui/inline/Code.js +14 -0
- package/ui/inline/Code.module.css +14 -0
- package/ui/inline/Code.tsx +34 -0
- package/ui/inline/Deleted.d.ts +5 -0
- package/ui/inline/Deleted.js +5 -0
- package/ui/inline/Deleted.module.css +9 -0
- package/ui/inline/Deleted.tsx +10 -0
- package/ui/inline/Emphasis.d.ts +5 -0
- package/ui/inline/Emphasis.js +5 -0
- package/ui/inline/Emphasis.module.css +5 -0
- package/ui/inline/Emphasis.tsx +10 -0
- package/ui/inline/Inserted.d.ts +5 -0
- package/ui/inline/Inserted.js +5 -0
- package/ui/inline/Inserted.module.css +9 -0
- package/ui/inline/Inserted.tsx +10 -0
- package/ui/inline/Link.d.ts +5 -0
- package/ui/inline/Link.js +5 -0
- package/ui/inline/Link.module.css +19 -0
- package/ui/inline/Link.tsx +9 -0
- package/ui/inline/Mark.d.ts +5 -0
- package/ui/inline/Mark.js +5 -0
- package/ui/inline/Mark.module.css +15 -0
- package/ui/inline/Mark.tsx +10 -0
- package/ui/inline/Small.d.ts +5 -0
- package/ui/inline/Small.js +5 -0
- package/ui/inline/Small.module.css +9 -0
- package/ui/inline/Small.tsx +10 -0
- package/ui/inline/Strong.d.ts +5 -0
- package/ui/inline/Strong.js +5 -0
- package/ui/inline/Strong.module.css +5 -0
- package/ui/inline/Strong.tsx +10 -0
- package/ui/inline/Subscript.d.ts +5 -0
- package/ui/inline/Subscript.js +5 -0
- package/ui/inline/Subscript.module.css +9 -0
- package/ui/inline/Subscript.tsx +10 -0
- package/ui/inline/Superscript.d.ts +5 -0
- package/ui/inline/Superscript.js +5 -0
- package/ui/inline/Superscript.module.css +9 -0
- package/ui/inline/Superscript.tsx +10 -0
- package/ui/inline/When.d.ts +18 -0
- package/ui/inline/When.js +24 -0
- package/ui/inline/When.tsx +49 -0
- package/ui/inline/index.d.ts +11 -0
- package/ui/inline/index.js +11 -0
- package/ui/inline/index.ts +11 -0
- package/ui/layout/CenteredLayout.d.ts +10 -0
- package/ui/layout/CenteredLayout.js +11 -0
- package/ui/layout/CenteredLayout.module.css +13 -0
- package/ui/layout/CenteredLayout.tsx +23 -0
- package/ui/layout/Layout.d.ts +9 -0
- package/ui/layout/Layout.js +25 -0
- package/ui/layout/Layout.module.css +64 -0
- package/ui/layout/Layout.ts +26 -0
- package/ui/layout/index.d.ts +2 -0
- package/ui/layout/index.js +2 -0
- package/ui/layout/index.tsx +2 -0
- package/ui/misc/Catcher.d.ts +45 -0
- package/ui/misc/Catcher.js +57 -0
- package/ui/misc/Catcher.tsx +114 -0
- package/ui/misc/Loading.d.ts +8 -0
- package/ui/misc/Loading.js +6 -0
- package/ui/misc/Loading.module.css +19 -0
- package/ui/misc/Loading.tsx +31 -0
- package/ui/misc/Meta.d.ts +9 -0
- package/ui/misc/Meta.js +14 -0
- package/ui/misc/Meta.tsx +20 -0
- package/ui/misc/index.d.ts +3 -0
- package/ui/misc/index.js +3 -0
- package/ui/misc/index.tsx +3 -0
- package/ui/notice/Message.d.ts +11 -0
- package/ui/notice/Message.js +12 -0
- package/ui/notice/Message.module.css +8 -0
- package/ui/notice/Message.tsx +30 -0
- package/ui/notice/Notice.d.ts +15 -0
- package/ui/notice/Notice.js +13 -0
- package/ui/notice/Notice.module.css +15 -0
- package/ui/notice/Notice.tsx +42 -0
- package/ui/notice/NoticeStore.d.ts +21 -0
- package/ui/notice/NoticeStore.js +44 -0
- package/ui/notice/NoticeStore.ts +60 -0
- package/ui/notice/Notices.d.ts +7 -0
- package/ui/notice/Notices.js +22 -0
- package/ui/notice/Notices.module.css +10 -0
- package/ui/notice/Notices.tsx +28 -0
- package/ui/notice/NoticesStore.d.ts +11 -0
- package/ui/notice/NoticesStore.js +16 -0
- package/ui/notice/NoticesStore.ts +23 -0
- package/ui/notice/README.md +40 -0
- package/ui/notice/Status.d.ts +29 -0
- package/ui/notice/Status.js +6 -0
- package/ui/notice/Status.module.css +79 -0
- package/ui/notice/Status.tsx +36 -0
- package/ui/notice/StatusIcon.d.ts +12 -0
- package/ui/notice/StatusIcon.js +19 -0
- package/ui/notice/StatusIcon.module.css +28 -0
- package/ui/notice/StatusIcon.tsx +33 -0
- package/ui/notice/index.d.ts +7 -0
- package/ui/notice/index.js +7 -0
- package/ui/notice/index.ts +7 -0
- package/ui/page/Head.d.ts +8 -0
- package/ui/page/Head.js +32 -0
- package/ui/page/Head.tsx +49 -0
- package/ui/page/Page.d.ts +10 -0
- package/ui/page/Page.js +10 -0
- package/ui/page/Page.tsx +21 -0
- package/ui/page/index.d.ts +2 -0
- package/ui/page/index.js +2 -0
- package/ui/page/index.ts +2 -0
- package/ui/router/Router.d.ts +31 -0
- package/ui/router/Router.js +59 -0
- package/ui/router/Router.tsx +88 -0
- package/ui/router/RouterContext.d.ts +5 -0
- package/ui/router/RouterContext.js +9 -0
- package/ui/router/RouterContext.tsx +12 -0
- package/ui/router/RouterStore.d.ts +13 -0
- package/ui/router/RouterStore.js +23 -0
- package/ui/router/RouterStore.test.tsx +43 -0
- package/ui/router/RouterStore.tsx +29 -0
- package/ui/router/Routes.d.ts +39 -0
- package/ui/router/Routes.js +35 -0
- package/ui/router/Routes.tsx +62 -0
- package/ui/router/index.d.ts +4 -0
- package/ui/router/index.js +4 -0
- package/ui/router/index.ts +4 -0
- package/ui/transition/CollapseTransition.css +3 -0
- package/ui/transition/CollapseTransition.d.ts +6 -0
- package/ui/transition/CollapseTransition.js +6 -0
- package/ui/transition/CollapseTransition.tsx +9 -0
- package/ui/transition/FadeTransition.css +25 -0
- package/ui/transition/FadeTransition.d.ts +5 -0
- package/ui/transition/FadeTransition.js +5 -0
- package/ui/transition/FadeTransition.tsx +8 -0
- package/ui/transition/HorizontalTransition.css +66 -0
- package/ui/transition/HorizontalTransition.d.ts +6 -0
- package/ui/transition/HorizontalTransition.js +6 -0
- package/ui/transition/HorizontalTransition.tsx +9 -0
- package/ui/transition/Transition.css +3 -0
- package/ui/transition/Transition.d.ts +18 -0
- package/ui/transition/Transition.js +21 -0
- package/ui/transition/Transition.tsx +35 -0
- package/ui/transition/VerticalTransition.css +66 -0
- package/ui/transition/VerticalTransition.d.ts +6 -0
- package/ui/transition/VerticalTransition.js +6 -0
- package/ui/transition/VerticalTransition.tsx +9 -0
- package/ui/transition/index.d.ts +6 -0
- package/ui/transition/index.js +6 -0
- package/ui/transition/index.tsx +6 -0
- package/ui/transition/util.d.ts +17 -0
- package/ui/transition/util.js +6 -0
- package/ui/transition/util.tsx +24 -0
- package/ui/types.d.ts +9 -0
- package/ui/util/context.d.ts +6 -0
- package/ui/util/context.js +10 -0
- package/ui/util/context.ts +15 -0
- package/ui/util/css.d.ts +37 -0
- package/ui/util/css.js +63 -0
- package/ui/util/css.ts +80 -0
- package/ui/util/event.d.ts +2 -0
- package/ui/util/event.js +4 -0
- package/ui/util/event.ts +4 -0
- package/ui/util/focus.d.ts +16 -0
- package/ui/util/focus.js +21 -0
- package/ui/util/focus.ts +23 -0
- package/ui/util/index.d.ts +8 -0
- package/ui/util/index.js +8 -0
- package/ui/util/index.ts +8 -0
- package/ui/util/meta.d.ts +67 -0
- package/ui/util/meta.js +33 -0
- package/ui/util/meta.ts +97 -0
- package/ui/util/notice.d.ts +26 -0
- package/ui/util/notice.js +82 -0
- package/ui/util/notice.ts +103 -0
- package/ui/util/refresh.d.ts +2 -0
- package/ui/util/refresh.js +9 -0
- package/ui/util/refresh.ts +11 -0
- package/ui/util/scroll.d.ts +11 -0
- package/ui/util/scroll.js +32 -0
- package/ui/util/scroll.ts +40 -0
- package/ui/util/state.d.ts +11 -0
- package/ui/util/state.js +42 -0
- package/ui/util/state.ts +44 -0
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Field } from "./Field.js";
|
|
4
|
+
import { requireForm, useField } from "./FormContext.js";
|
|
5
|
+
import { SchemaInput } from "./SchemaInput.js";
|
|
6
|
+
/** Show a `<Field>` for a named property in the current form. */
|
|
7
|
+
export function FormField({ name, ...props }) {
|
|
8
|
+
const field = useField(name);
|
|
9
|
+
const { schema, message } = field;
|
|
10
|
+
return (_jsx(Field, { ...schema, message: message, required: props.required, children: _jsx(SchemaInput, { ...field, ...props }) }));
|
|
11
|
+
}
|
|
12
|
+
/** List of `<Field>` elements for every schema property in the current form. */
|
|
13
|
+
export function FormFields() {
|
|
14
|
+
const form = useStore(requireForm());
|
|
15
|
+
return (_jsx(_Fragment, { children: Object.keys(form.schema.props).map(name => (_jsx(FormField, { name: name }, name))) }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Field } from "./Field.js";
|
|
4
|
+
import { requireForm, useField } from "./FormContext.js";
|
|
5
|
+
import type { InputProps } from "./Input.js";
|
|
6
|
+
import { SchemaInput } from "./SchemaInput.js";
|
|
7
|
+
|
|
8
|
+
/** Show a `<Field>` for a named property in the current form. */
|
|
9
|
+
export function FormField({ name, ...props }: InputProps): ReactElement {
|
|
10
|
+
const field = useField(name);
|
|
11
|
+
const { schema, message } = field;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Field {...schema} message={message} required={props.required}>
|
|
15
|
+
<SchemaInput {...field} {...props} />
|
|
16
|
+
</Field>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** List of `<Field>` elements for every schema property in the current form. */
|
|
21
|
+
export function FormFields(): ReactElement {
|
|
22
|
+
const form = useStore(requireForm());
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
{Object.keys(form.schema.props).map(name => (
|
|
26
|
+
<FormField key={name} name={name} />
|
|
27
|
+
))}
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
export interface FormFooterProps {
|
|
3
|
+
children?: ReactNode | undefined;
|
|
4
|
+
submit?: ReactNode | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Show a form footer with custom submit text.
|
|
8
|
+
* - Shows an elements row containing a submit button (and any additional buttons provided as `children`).
|
|
9
|
+
* - Shows a `<FormMessage>` beneath the buttons that shows any error message set on the form.
|
|
10
|
+
*/
|
|
11
|
+
export declare function FormFooter({ children, submit }: FormFooterProps): ReactElement;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Elements } from "../block/Elements.js";
|
|
3
|
+
import { Footer } from "../block/Section.js";
|
|
4
|
+
import { FormMessage } from "./FormMessage.js";
|
|
5
|
+
import { SubmitButton } from "./SubmitButton.js";
|
|
6
|
+
/**
|
|
7
|
+
* Show a form footer with custom submit text.
|
|
8
|
+
* - Shows an elements row containing a submit button (and any additional buttons provided as `children`).
|
|
9
|
+
* - Shows a `<FormMessage>` beneath the buttons that shows any error message set on the form.
|
|
10
|
+
*/
|
|
11
|
+
export function FormFooter({ children, submit }) {
|
|
12
|
+
return (_jsxs(Footer, { children: [_jsxs(Elements, { reverse: true, children: [_jsx(SubmitButton, { children: submit }), children] }), _jsx(FormMessage, {})] }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Elements } from "../block/Elements.js";
|
|
3
|
+
import { Footer } from "../block/Section.js";
|
|
4
|
+
import { FormMessage } from "./FormMessage.js";
|
|
5
|
+
import { SubmitButton } from "./SubmitButton.js";
|
|
6
|
+
|
|
7
|
+
export interface FormFooterProps {
|
|
8
|
+
children?: ReactNode | undefined;
|
|
9
|
+
submit?: ReactNode | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Show a form footer with custom submit text.
|
|
14
|
+
* - Shows an elements row containing a submit button (and any additional buttons provided as `children`).
|
|
15
|
+
* - Shows a `<FormMessage>` beneath the buttons that shows any error message set on the form.
|
|
16
|
+
*/
|
|
17
|
+
export function FormFooter({ children, submit }: FormFooterProps): ReactElement {
|
|
18
|
+
return (
|
|
19
|
+
<Footer>
|
|
20
|
+
<Elements reverse>
|
|
21
|
+
<SubmitButton>{submit}</SubmitButton>
|
|
22
|
+
{children}
|
|
23
|
+
</Elements>
|
|
24
|
+
<FormMessage />
|
|
25
|
+
</Footer>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { InputProps } from "./Input.js";
|
|
3
|
+
export interface FormInputProps extends InputProps {
|
|
4
|
+
}
|
|
5
|
+
/** Show a `SchemaInput` for each property in the current form. */
|
|
6
|
+
export declare function FormInput({ name, ...props }: FormInputProps): ReactElement;
|
|
7
|
+
/** Show a `SchemaInput` for a named property in the current form. */
|
|
8
|
+
export declare function FormInputs(): ReactElement;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { requireForm, useField } from "./FormContext.js";
|
|
3
|
+
import { SchemaInput } from "./SchemaInput.js";
|
|
4
|
+
/** Show a `SchemaInput` for each property in the current form. */
|
|
5
|
+
export function FormInput({ name, ...props }) {
|
|
6
|
+
const field = useField(name);
|
|
7
|
+
return _jsx(SchemaInput, { ...field, ...props });
|
|
8
|
+
}
|
|
9
|
+
/** Show a `SchemaInput` for a named property in the current form. */
|
|
10
|
+
export function FormInputs() {
|
|
11
|
+
return (_jsx(_Fragment, { children: Object.keys(requireForm().schema.props).map(name => (_jsx(FormInput, { name: name }, name))) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { requireForm, useField } from "./FormContext.js";
|
|
3
|
+
import type { InputProps } from "./Input.js";
|
|
4
|
+
import { SchemaInput } from "./SchemaInput.js";
|
|
5
|
+
|
|
6
|
+
export interface FormInputProps extends InputProps {}
|
|
7
|
+
|
|
8
|
+
/** Show a `SchemaInput` for each property in the current form. */
|
|
9
|
+
export function FormInput({ name, ...props }: FormInputProps): ReactElement {
|
|
10
|
+
const field = useField(name);
|
|
11
|
+
return <SchemaInput {...field} {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Show a `SchemaInput` for a named property in the current form. */
|
|
15
|
+
export function FormInputs(): ReactElement {
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{Object.keys(requireForm().schema.props).map(name => (
|
|
19
|
+
<FormInput key={name} name={name} />
|
|
20
|
+
))}
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Message } from "../notice/Message.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
/** Show the "main" message for the form as a `<Message>` */
|
|
6
|
+
export function FormMessage(props) {
|
|
7
|
+
const message = useStore(requireForm().messages).get("");
|
|
8
|
+
if (!message)
|
|
9
|
+
return null;
|
|
10
|
+
return (_jsx(Message, { status: "error", ...props, children: message }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Message, type MessageProps } from "../notice/Message.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
|
|
6
|
+
/** Show the "main" message for the form as a `<Message>` */
|
|
7
|
+
|
|
8
|
+
export function FormMessage(props: Omit<MessageProps, "children">): ReactElement | null {
|
|
9
|
+
const message = useStore(requireForm().messages).get("");
|
|
10
|
+
if (!message) return null;
|
|
11
|
+
return (
|
|
12
|
+
<Message status="error" {...props}>
|
|
13
|
+
{message}
|
|
14
|
+
</Message>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Notice } from "../notice/Notice.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
/** Show the "main" message for the form as a `<Notice>` */
|
|
6
|
+
export function FormNotice(props) {
|
|
7
|
+
const message = useStore(requireForm().messages).get("");
|
|
8
|
+
if (!message)
|
|
9
|
+
return null;
|
|
10
|
+
return (_jsx(Notice, { status: "error", ...props, children: message }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { Notice, type NoticeProps } from "../notice/Notice.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
|
|
6
|
+
/** Show the "main" message for the form as a `<Notice>` */
|
|
7
|
+
|
|
8
|
+
export function FormNotice(props: Omit<NoticeProps, "children">): ReactElement | null {
|
|
9
|
+
const message = useStore(requireForm().messages).get("");
|
|
10
|
+
if (!message) return null;
|
|
11
|
+
return (
|
|
12
|
+
<Notice status="error" {...props}>
|
|
13
|
+
{message}
|
|
14
|
+
</Notice>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { notifySuccess } from "../util/notice.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
/** Publish the "main" message of a form as a global notice. */
|
|
6
|
+
export function FormNotify() {
|
|
7
|
+
const message = useStore(requireForm().messages).get("");
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
notifySuccess(message);
|
|
10
|
+
}, [message]);
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { notifySuccess } from "../util/notice.js";
|
|
4
|
+
import { requireForm } from "./FormContext.js";
|
|
5
|
+
|
|
6
|
+
/** Publish the "main" message of a form as a global notice. */
|
|
7
|
+
|
|
8
|
+
export function FormNotify(): void {
|
|
9
|
+
const message = useStore(requireForm().messages).get("");
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
notifySuccess(message);
|
|
12
|
+
}, [message]);
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { DataSchema } from "../../schema/DataSchema.js";
|
|
2
|
+
import { Schema } from "../../schema/Schema.js";
|
|
3
|
+
import { DataStore } from "../../store/DataStore.js";
|
|
4
|
+
import { DictionaryStore } from "../../store/DictionaryStore.js";
|
|
5
|
+
import type { Data, DataKey } from "../../util/data.js";
|
|
6
|
+
import type { ImmutableDictionary } from "../../util/dictionary.js";
|
|
7
|
+
import type { Arguments } from "../../util/function.js";
|
|
8
|
+
/** Store the current value of a form. */
|
|
9
|
+
export declare class FormStore<T extends Data> extends DataStore<Partial<T>> implements AsyncDisposable {
|
|
10
|
+
/** Unique ID for the form. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** Key used for mounting the form */
|
|
13
|
+
readonly key: string;
|
|
14
|
+
/** Schema for the current form. */
|
|
15
|
+
readonly schema: DataSchema<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Store named error messages for individual fields.
|
|
18
|
+
* - Throwing a string triggers changes in this.
|
|
19
|
+
* - Rows prefixed with `fieldName:` are shown on those specific fields.
|
|
20
|
+
* - See `splitMessages()` in `shelving` for more information.
|
|
21
|
+
*/
|
|
22
|
+
readonly messages: DictionaryStore<string>;
|
|
23
|
+
/** Get the current valid value for this form (throws string for invalid values). */
|
|
24
|
+
get validated(): T;
|
|
25
|
+
get reason(): unknown;
|
|
26
|
+
set reason(reason: unknown);
|
|
27
|
+
constructor(schema: DataSchema<T>, partialData?: Partial<T>, messages?: ImmutableDictionary<string> | string | undefined);
|
|
28
|
+
/** Get a named schema for a field of this form. */
|
|
29
|
+
requireSchema<K extends DataKey<T>>(name: K): Schema<T[K]>;
|
|
30
|
+
/** Publish a value for a field of this form. */
|
|
31
|
+
publish<K extends DataKey<T>>(name: K, unsafeValue: T[K]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Validate and submit the current values of the form.
|
|
34
|
+
*
|
|
35
|
+
* @param callback Optional callback that takes the current (validated) value of the form, processes it (possibly asynchronously) and returns any new values.
|
|
36
|
+
*/
|
|
37
|
+
submit<A extends Arguments>(callback?: ((value: T, ...args: A) => void) | undefined, ...args: A): boolean | Promise<boolean>;
|
|
38
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { RequiredError } from "../../error/RequiredError.js";
|
|
2
|
+
import { Schema } from "../../schema/Schema.js";
|
|
3
|
+
import { DataStore } from "../../store/DataStore.js";
|
|
4
|
+
import { DictionaryStore } from "../../store/DictionaryStore.js";
|
|
5
|
+
import { awaitDispose } from "../../util/dispose.js";
|
|
6
|
+
import { splitMessage } from "../../util/error.js";
|
|
7
|
+
import { getRandomKey } from "../../util/random.js";
|
|
8
|
+
/** Store the current value of a form. */
|
|
9
|
+
export class FormStore extends DataStore {
|
|
10
|
+
/** Unique ID for the form. */
|
|
11
|
+
id = getRandomKey();
|
|
12
|
+
/** Key used for mounting the form */
|
|
13
|
+
key;
|
|
14
|
+
/** Schema for the current form. */
|
|
15
|
+
schema;
|
|
16
|
+
/**
|
|
17
|
+
* Store named error messages for individual fields.
|
|
18
|
+
* - Throwing a string triggers changes in this.
|
|
19
|
+
* - Rows prefixed with `fieldName:` are shown on those specific fields.
|
|
20
|
+
* - See `splitMessages()` in `shelving` for more information.
|
|
21
|
+
*/
|
|
22
|
+
messages = new DictionaryStore();
|
|
23
|
+
/** Get the current valid value for this form (throws string for invalid values). */
|
|
24
|
+
get validated() {
|
|
25
|
+
return (this.value = this.schema.validate(this.value));
|
|
26
|
+
}
|
|
27
|
+
get reason() {
|
|
28
|
+
return super.reason;
|
|
29
|
+
}
|
|
30
|
+
set reason(reason) {
|
|
31
|
+
if (typeof reason === "string") {
|
|
32
|
+
this.messages.value = splitMessage(reason);
|
|
33
|
+
super.reason = undefined;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
super.reason = reason;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
constructor(schema, partialData = {}, messages) {
|
|
40
|
+
super(partialData);
|
|
41
|
+
this.key = `${this.id}:${JSON.stringify(partialData)}`;
|
|
42
|
+
this.schema = schema;
|
|
43
|
+
if (messages)
|
|
44
|
+
this.messages.value = typeof messages === "string" ? splitMessage(messages) : messages;
|
|
45
|
+
}
|
|
46
|
+
/** Get a named schema for a field of this form. */
|
|
47
|
+
requireSchema(name) {
|
|
48
|
+
const schema = this.schema.props[name];
|
|
49
|
+
if (schema instanceof Schema)
|
|
50
|
+
return schema;
|
|
51
|
+
throw new RequiredError(`Schema "${name}" does not exist in form`, { received: name, caller: this.requireSchema });
|
|
52
|
+
}
|
|
53
|
+
/** Publish a value for a field of this form. */
|
|
54
|
+
publish(name, unsafeValue) {
|
|
55
|
+
this.abort();
|
|
56
|
+
// Clear main message and this named message.
|
|
57
|
+
this.messages.delete("");
|
|
58
|
+
this.messages.delete(name);
|
|
59
|
+
try {
|
|
60
|
+
const value = this.requireSchema(name).validate(unsafeValue);
|
|
61
|
+
this.set(name, value);
|
|
62
|
+
}
|
|
63
|
+
catch (thrown) {
|
|
64
|
+
if (typeof thrown === "string")
|
|
65
|
+
this.messages.set(name, thrown);
|
|
66
|
+
else
|
|
67
|
+
this.reason = thrown;
|
|
68
|
+
// Save the value _even if_ it didn't validate so it's persisted.
|
|
69
|
+
// Everything gets validated before submit.
|
|
70
|
+
this.set(name, unsafeValue);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Validate and submit the current values of the form.
|
|
75
|
+
*
|
|
76
|
+
* @param callback Optional callback that takes the current (validated) value of the form, processes it (possibly asynchronously) and returns any new values.
|
|
77
|
+
*/
|
|
78
|
+
submit(callback, ...args) {
|
|
79
|
+
try {
|
|
80
|
+
const value = this.validated;
|
|
81
|
+
if (callback)
|
|
82
|
+
return this.run(callback, value, ...args);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
catch (thrown) {
|
|
86
|
+
this.reason = thrown;
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Implement `AsyncDisposable`
|
|
91
|
+
async [Symbol.asyncDispose]() {
|
|
92
|
+
await awaitDispose(this.messages, // Dispose of messages store.
|
|
93
|
+
super[Symbol.asyncDispose]());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { RequiredError } from "../../error/RequiredError.js";
|
|
2
|
+
import type { DataSchema } from "../../schema/DataSchema.js";
|
|
3
|
+
import { Schema } from "../../schema/Schema.js";
|
|
4
|
+
import { DataStore } from "../../store/DataStore.js";
|
|
5
|
+
import { DictionaryStore } from "../../store/DictionaryStore.js";
|
|
6
|
+
import type { Data, DataKey } from "../../util/data.js";
|
|
7
|
+
import type { ImmutableDictionary } from "../../util/dictionary.js";
|
|
8
|
+
import { awaitDispose } from "../../util/dispose.js";
|
|
9
|
+
import { splitMessage } from "../../util/error.js";
|
|
10
|
+
import type { Arguments } from "../../util/function.js";
|
|
11
|
+
import { getRandomKey } from "../../util/random.js";
|
|
12
|
+
|
|
13
|
+
/** Store the current value of a form. */
|
|
14
|
+
export class FormStore<T extends Data> extends DataStore<Partial<T>> implements AsyncDisposable {
|
|
15
|
+
/** Unique ID for the form. */
|
|
16
|
+
readonly id = getRandomKey();
|
|
17
|
+
|
|
18
|
+
/** Key used for mounting the form */
|
|
19
|
+
readonly key: string;
|
|
20
|
+
|
|
21
|
+
/** Schema for the current form. */
|
|
22
|
+
readonly schema: DataSchema<T>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Store named error messages for individual fields.
|
|
26
|
+
* - Throwing a string triggers changes in this.
|
|
27
|
+
* - Rows prefixed with `fieldName:` are shown on those specific fields.
|
|
28
|
+
* - See `splitMessages()` in `shelving` for more information.
|
|
29
|
+
*/
|
|
30
|
+
readonly messages = new DictionaryStore<string>();
|
|
31
|
+
|
|
32
|
+
/** Get the current valid value for this form (throws string for invalid values). */
|
|
33
|
+
get validated(): T {
|
|
34
|
+
return (this.value = this.schema.validate(this.value));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override get reason(): unknown {
|
|
38
|
+
return super.reason;
|
|
39
|
+
}
|
|
40
|
+
override set reason(reason: unknown) {
|
|
41
|
+
if (typeof reason === "string") {
|
|
42
|
+
this.messages.value = splitMessage(reason);
|
|
43
|
+
super.reason = undefined;
|
|
44
|
+
} else {
|
|
45
|
+
super.reason = reason;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor(schema: DataSchema<T>, partialData: Partial<T> = {}, messages?: ImmutableDictionary<string> | string | undefined) {
|
|
50
|
+
super(partialData);
|
|
51
|
+
this.key = `${this.id}:${JSON.stringify(partialData)}`;
|
|
52
|
+
this.schema = schema;
|
|
53
|
+
if (messages) this.messages.value = typeof messages === "string" ? splitMessage(messages) : messages;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Get a named schema for a field of this form. */
|
|
57
|
+
requireSchema<K extends DataKey<T>>(name: K): Schema<T[K]> {
|
|
58
|
+
const schema = this.schema.props[name];
|
|
59
|
+
if (schema instanceof Schema) return schema as Schema<T[K]>;
|
|
60
|
+
throw new RequiredError(`Schema "${name}" does not exist in form`, { received: name, caller: this.requireSchema });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Publish a value for a field of this form. */
|
|
64
|
+
publish<K extends DataKey<T>>(name: K, unsafeValue: T[K]): void {
|
|
65
|
+
this.abort();
|
|
66
|
+
|
|
67
|
+
// Clear main message and this named message.
|
|
68
|
+
this.messages.delete("");
|
|
69
|
+
this.messages.delete(name);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const value = this.requireSchema(name).validate(unsafeValue);
|
|
73
|
+
this.set(name, value);
|
|
74
|
+
} catch (thrown) {
|
|
75
|
+
if (typeof thrown === "string") this.messages.set(name, thrown);
|
|
76
|
+
else this.reason = thrown;
|
|
77
|
+
|
|
78
|
+
// Save the value _even if_ it didn't validate so it's persisted.
|
|
79
|
+
// Everything gets validated before submit.
|
|
80
|
+
this.set(name, unsafeValue);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Validate and submit the current values of the form.
|
|
86
|
+
*
|
|
87
|
+
* @param callback Optional callback that takes the current (validated) value of the form, processes it (possibly asynchronously) and returns any new values.
|
|
88
|
+
*/
|
|
89
|
+
submit<A extends Arguments>(callback?: ((value: T, ...args: A) => void) | undefined, ...args: A): boolean | Promise<boolean> {
|
|
90
|
+
try {
|
|
91
|
+
const value = this.validated;
|
|
92
|
+
if (callback) return this.run(callback, value, ...args);
|
|
93
|
+
return true;
|
|
94
|
+
} catch (thrown) {
|
|
95
|
+
this.reason = thrown;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Implement `AsyncDisposable`
|
|
101
|
+
override async [Symbol.asyncDispose]() {
|
|
102
|
+
await awaitDispose(
|
|
103
|
+
this.messages, // Dispose of messages store.
|
|
104
|
+
super[Symbol.asyncDispose](),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { type ClickableProps } from "./Clickable.js";
|
|
3
|
+
export declare const RADIO_CLASS: string | undefined;
|
|
4
|
+
export declare const CHECKBOX_CLASS: string | undefined;
|
|
5
|
+
export declare const PLACEHOLDER_CLASS: string | undefined;
|
|
6
|
+
export declare const INPUT_CLASS: string | undefined;
|
|
7
|
+
export declare const TEXT_INPUT_CLASS: string;
|
|
8
|
+
export declare const MULTILINE_TEXT_INPUT_CLASS: string;
|
|
9
|
+
export declare const SELECT_INPUT_CLASS: string;
|
|
10
|
+
export declare const EMPTY_OPTION_INPUT_CLASS: string | undefined;
|
|
11
|
+
export declare const VALUE_OPTION_INPUT_CLASS: string | undefined;
|
|
12
|
+
export declare const ELEMENTS_INPUT_CLASS: string;
|
|
13
|
+
export declare const ELEMENTS_BUTTON_INPUT_CLASS: string;
|
|
14
|
+
export declare const PLACEHOLDER_ELEMENTS_BUTTON_INPUT_CLASS: string;
|
|
15
|
+
export declare const ELEMENTS_LABEL_INPUT_CLASS: string;
|
|
16
|
+
export declare const PLACEHOLDER_ELEMENTS_LABEL_INPUT_CLASS: string;
|
|
17
|
+
export declare const WRAPPER_INPUT_CLASS: string;
|
|
18
|
+
/** Props all inputs allow. */
|
|
19
|
+
export interface InputProps {
|
|
20
|
+
/** The `name=""` prop of the input. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** Friendly title for the input. */
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
/** Placeholder for the input. Defaults to `title`. Set to `""` to show no placeholder. */
|
|
25
|
+
placeholder?: string | undefined;
|
|
26
|
+
/** Whether the input is required. */
|
|
27
|
+
required?: boolean | undefined;
|
|
28
|
+
/** Whether the input is disabled. */
|
|
29
|
+
disabled?: boolean | undefined;
|
|
30
|
+
/** Any error message for the input. */
|
|
31
|
+
message?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** "Value inputs" are inputs that generate a value, like `<input>` or `<textarea>` */
|
|
34
|
+
export interface ValueInputProps<O, I = never> extends InputProps {
|
|
35
|
+
/** The current value of the input. */
|
|
36
|
+
value?: O | I | undefined;
|
|
37
|
+
/** Called when the value for the input changes, so you can make changes based on the new value (or `undefined` to set back to default). */
|
|
38
|
+
onValue(value: O | undefined): void;
|
|
39
|
+
}
|
|
40
|
+
/** Return either a `<button>` or an `<a href="">` styled as an input, based on whether an `onClick` or `href` prop is provided. */
|
|
41
|
+
export declare function Input({ title, placeholder, disabled, href, onClick, target, download, children }: InputProps & ClickableProps): ReactElement;
|
|
42
|
+
/** Input that is loading. */
|
|
43
|
+
export declare const LOADING_INPUT: import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
/** Wraps an input with support for absolutely-positioned `data-slot` icon elements on either side. */
|
|
45
|
+
export declare function InputWrapper({ children }: {
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}): ReactElement;
|
package/ui/form/Input.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ELEMENTS_CSS } from "../block/Elements.js";
|
|
3
|
+
import { LOADING } from "../misc/Loading.js";
|
|
4
|
+
import { getClass } from "../util/css.js";
|
|
5
|
+
import { getClickable } from "./Clickable.js";
|
|
6
|
+
import INPUT_CSS from "./Input.module.css";
|
|
7
|
+
// Precomposed classes.
|
|
8
|
+
export const RADIO_CLASS = INPUT_CSS.radio;
|
|
9
|
+
export const CHECKBOX_CLASS = INPUT_CSS.radio;
|
|
10
|
+
export const PLACEHOLDER_CLASS = INPUT_CSS.placeholder;
|
|
11
|
+
export const INPUT_CLASS = INPUT_CSS.input;
|
|
12
|
+
export const TEXT_INPUT_CLASS = getClass(INPUT_CSS.input, INPUT_CSS.text);
|
|
13
|
+
export const MULTILINE_TEXT_INPUT_CLASS = getClass(TEXT_INPUT_CLASS, INPUT_CSS.multiline);
|
|
14
|
+
export const SELECT_INPUT_CLASS = getClass(INPUT_CSS.input, INPUT_CSS.select);
|
|
15
|
+
export const EMPTY_OPTION_INPUT_CLASS = INPUT_CSS.empty;
|
|
16
|
+
export const VALUE_OPTION_INPUT_CLASS = INPUT_CSS.value;
|
|
17
|
+
export const ELEMENTS_INPUT_CLASS = getClass(INPUT_CSS.input, ELEMENTS_CSS.elements, ELEMENTS_CSS.center);
|
|
18
|
+
export const ELEMENTS_BUTTON_INPUT_CLASS = getClass(INPUT_CSS.input, INPUT_CSS.button, ELEMENTS_CSS.elements, ELEMENTS_CSS.center);
|
|
19
|
+
export const PLACEHOLDER_ELEMENTS_BUTTON_INPUT_CLASS = getClass(ELEMENTS_BUTTON_INPUT_CLASS, INPUT_CSS.placeholder);
|
|
20
|
+
export const ELEMENTS_LABEL_INPUT_CLASS = getClass(INPUT_CSS.input, INPUT_CSS.label, ELEMENTS_CSS.elements, ELEMENTS_CSS.left);
|
|
21
|
+
export const PLACEHOLDER_ELEMENTS_LABEL_INPUT_CLASS = getClass(ELEMENTS_LABEL_INPUT_CLASS, INPUT_CSS.placeholder);
|
|
22
|
+
export const WRAPPER_INPUT_CLASS = getClass(INPUT_CSS.input, INPUT_CSS.wrapper);
|
|
23
|
+
/** Return either a `<button>` or an `<a href="">` styled as an input, based on whether an `onClick` or `href` prop is provided. */
|
|
24
|
+
export function Input({
|
|
25
|
+
// name,
|
|
26
|
+
title, placeholder = title,
|
|
27
|
+
// message,
|
|
28
|
+
disabled, href, onClick, target, download, children, }) {
|
|
29
|
+
return getClickable({
|
|
30
|
+
disabled,
|
|
31
|
+
href,
|
|
32
|
+
onClick,
|
|
33
|
+
target,
|
|
34
|
+
download,
|
|
35
|
+
children: children || placeholder,
|
|
36
|
+
}, getClass(INPUT_CSS.input, INPUT_CSS.button, children ? undefined : INPUT_CSS.placeholder));
|
|
37
|
+
}
|
|
38
|
+
/** Input that is loading. */
|
|
39
|
+
export const LOADING_INPUT = _jsx("div", { className: ELEMENTS_INPUT_CLASS, children: LOADING });
|
|
40
|
+
/** Wraps an input with support for absolutely-positioned `data-slot` icon elements on either side. */
|
|
41
|
+
export function InputWrapper({ children }) {
|
|
42
|
+
return _jsx("div", { className: WRAPPER_INPUT_CLASS, children: children });
|
|
43
|
+
}
|