@torpor/ui 0.2.1 → 0.3.1
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/CHANGELOG.md +32 -0
- package/dist/Accordion/Accordion.torp +29 -22
- package/dist/Accordion/AccordionContent.torp +7 -8
- package/dist/Accordion/AccordionHeader.torp +4 -6
- package/dist/Accordion/AccordionItem.torp +15 -12
- package/dist/Accordion/AccordionTrigger.torp +6 -7
- package/dist/Accordion/AccordionTypes.ts +4 -3
- package/dist/Accordion/index.d.ts +5 -5
- package/dist/Breadcrumb/Breadcrumb.torp +9 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/dist/Breadcrumb/index.d.ts +8 -7
- package/dist/Calendar/Calendar.torp +12 -13
- package/dist/Calendar/CalendarDay.torp +3 -3
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/dist/Contextual/ContextualTrigger.torp +66 -0
- package/dist/Contextual/ContextualTypes.ts +30 -0
- package/dist/Contextual/index.d.ts +90 -0
- package/dist/Contextual/index.js +14 -0
- package/dist/Contextual/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +38 -72
- package/dist/Dialog/DialogBody.torp +6 -8
- package/dist/Dialog/DialogButton.torp +14 -12
- package/dist/Dialog/DialogFooter.torp +3 -5
- package/dist/Dialog/DialogHeader.torp +6 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +16 -11
- package/dist/Disclosure/Disclosure.torp +22 -23
- package/dist/Disclosure/DisclosureContent.torp +7 -8
- package/dist/Disclosure/DisclosureHeader.torp +5 -7
- package/dist/Disclosure/DisclosureTrigger.torp +7 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +12 -12
- package/dist/Drawer/Drawer.torp +101 -70
- package/dist/Drawer/DrawerContent.torp +80 -0
- package/dist/Drawer/DrawerOverlay.torp +38 -0
- package/dist/Drawer/DrawerTrigger.torp +35 -0
- package/dist/Drawer/DrawerTypes.ts +24 -0
- package/dist/Drawer/index.d.ts +90 -3
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/CheckBox.torp +91 -0
- package/dist/Form/Field.torp +2 -4
- package/dist/Form/File.torp +106 -0
- package/dist/Form/Form.torp +17 -10
- package/dist/Form/FormTypes.ts +5 -0
- package/dist/Form/Input.torp +28 -17
- package/dist/Form/Label.torp +1 -1
- package/dist/Form/Message.torp +1 -1
- package/dist/Form/Option.torp +24 -0
- package/dist/Form/Select.torp +97 -0
- package/dist/Form/TextArea.torp +101 -0
- package/dist/Form/index.d.ts +192 -5
- package/dist/Form/index.js +21 -1
- package/dist/Menu/Menu.torp +16 -15
- package/dist/Menu/MenuButton.torp +19 -13
- package/dist/Menu/MenuCheck.torp +18 -14
- package/dist/Menu/MenuGroup.torp +4 -6
- package/dist/Menu/MenuIndicator.torp +5 -7
- package/dist/Menu/MenuPopout.torp +12 -15
- package/dist/Menu/MenuPopoutContent.torp +6 -8
- package/dist/Menu/MenuPopoutTrigger.torp +12 -14
- package/dist/Menu/MenuRadio.torp +14 -14
- package/dist/Menu/MenuRadioGroup.torp +22 -14
- package/dist/Menu/MenuSeparator.torp +3 -5
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +28 -22
- package/dist/MenuBar/MenuBar.torp +13 -14
- package/dist/MenuBar/MenuBarItem.torp +13 -16
- package/dist/MenuBar/MenuBarItemContent.torp +7 -9
- package/dist/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/dist/MenuBar/index.d.ts +16 -16
- package/dist/Modal/Modal.torp +118 -0
- package/dist/Modal/ModalContent.torp +77 -0
- package/dist/Modal/ModalOverlay.torp +38 -0
- package/dist/Modal/ModalTrigger.torp +50 -0
- package/dist/Modal/ModalTypes.ts +22 -0
- package/dist/Modal/index.d.ts +108 -0
- package/dist/Modal/index.js +33 -0
- package/dist/Modal/index.js.map +1 -0
- package/dist/Modal/showModal.ts +19 -0
- package/dist/Modal/showPrompt.ts +23 -0
- package/dist/NavMenu/NavMenu.torp +7 -8
- package/dist/NavMenu/NavMenuButton.torp +6 -8
- package/dist/NavMenu/NavMenuElement.torp +8 -8
- package/dist/NavMenu/NavMenuGroup.torp +4 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/dist/NavMenu/NavMenuLink.torp +8 -11
- package/dist/NavMenu/NavMenuPopout.torp +25 -17
- package/dist/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/dist/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/dist/NavMenu/NavMenuSeparator.torp +3 -5
- package/dist/NavMenu/index.d.ts +17 -11
- package/dist/Notification/Notification.torp +22 -13
- package/dist/Notification/NotificationClose.torp +3 -5
- package/dist/Notification/NotificationContainer.torp +3 -5
- package/dist/Notification/NotificationContent.torp +3 -5
- package/dist/Notification/index.d.ts +4 -4
- package/dist/Popover/Popover.torp +31 -25
- package/dist/Popover/PopoverContent.torp +35 -10
- package/dist/Popover/PopoverTrigger.torp +24 -4
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +16 -124
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +12 -9
- package/dist/TabGroup/TabGroup.torp +41 -35
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +15 -8
- package/dist/TabGroup/TabList.torp +4 -6
- package/dist/TabGroup/TabTrigger.torp +8 -9
- package/dist/TabGroup/index.d.ts +14 -6
- package/dist/icons/ArrowDown.torp +3 -1
- package/dist/icons/ArrowLeft.torp +3 -1
- package/dist/icons/ArrowRight.torp +3 -1
- package/dist/icons/ArrowUp.torp +3 -1
- package/dist/icons/Bars.torp +3 -1
- package/dist/icons/Check.torp +3 -1
- package/dist/icons/ChevronDown.torp +3 -1
- package/dist/icons/ChevronLeft.torp +3 -1
- package/dist/icons/ChevronRight.torp +3 -1
- package/dist/icons/ChevronUp.torp +3 -1
- package/dist/icons/Cross.torp +3 -1
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +3 -1
- package/dist/icons/Minus.torp +3 -1
- package/dist/icons/Plus.torp +3 -1
- package/dist/icons/index.d.ts +271 -14
- package/dist/index.d.ts +17 -4
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +15 -6
- package/dist/motion/grow.ts +23 -0
- package/dist/motion/index.d.ts +19 -2
- package/dist/motion/index.js +93 -3
- package/dist/motion/index.js.map +1 -1
- package/dist/motion/measure.ts +28 -0
- package/dist/motion/slide.ts +45 -0
- package/dist/mount/clickPopover.ts +51 -0
- package/dist/mount/contextPopover.ts +51 -0
- package/dist/mount/hoverPopover.ts +58 -0
- package/package.json +21 -14
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +29 -22
- package/src/Accordion/AccordionContent.torp +7 -8
- package/src/Accordion/AccordionHeader.torp +4 -6
- package/src/Accordion/AccordionItem.torp +15 -12
- package/src/Accordion/AccordionTrigger.torp +6 -7
- package/src/Accordion/AccordionTypes.ts +4 -3
- package/src/Breadcrumb/Breadcrumb.torp +9 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/src/Calendar/Calendar.torp +12 -13
- package/src/Calendar/CalendarDay.torp +3 -3
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/src/Contextual/ContextualTrigger.torp +66 -0
- package/src/Contextual/ContextualTypes.ts +30 -0
- package/src/Contextual/index.ts +5 -0
- package/src/Dialog/Dialog.torp +38 -72
- package/src/Dialog/DialogBody.torp +6 -8
- package/src/Dialog/DialogButton.torp +14 -12
- package/src/Dialog/DialogFooter.torp +3 -5
- package/src/Dialog/DialogHeader.torp +6 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +22 -23
- package/src/Disclosure/DisclosureContent.torp +7 -8
- package/src/Disclosure/DisclosureHeader.torp +5 -7
- package/src/Disclosure/DisclosureTrigger.torp +7 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +101 -70
- package/src/Drawer/DrawerContent.torp +80 -0
- package/src/Drawer/DrawerOverlay.torp +38 -0
- package/src/Drawer/DrawerTrigger.torp +35 -0
- package/src/Drawer/DrawerTypes.ts +24 -0
- package/src/Drawer/index.ts +4 -1
- package/src/Form/CheckBox.torp +91 -0
- package/src/Form/Field.torp +2 -4
- package/src/Form/File.torp +106 -0
- package/src/Form/Form.torp +17 -10
- package/src/Form/FormTypes.ts +5 -0
- package/src/Form/Input.torp +28 -17
- package/src/Form/Label.torp +1 -1
- package/src/Form/Message.torp +1 -1
- package/src/Form/Option.torp +24 -0
- package/src/Form/Select.torp +97 -0
- package/src/Form/TextArea.torp +101 -0
- package/src/Form/index.ts +6 -1
- package/src/Menu/Menu.torp +16 -15
- package/src/Menu/MenuButton.torp +19 -13
- package/src/Menu/MenuCheck.torp +18 -14
- package/src/Menu/MenuGroup.torp +4 -6
- package/src/Menu/MenuIndicator.torp +5 -7
- package/src/Menu/MenuPopout.torp +12 -15
- package/src/Menu/MenuPopoutContent.torp +6 -8
- package/src/Menu/MenuPopoutTrigger.torp +12 -14
- package/src/Menu/MenuRadio.torp +14 -14
- package/src/Menu/MenuRadioGroup.torp +22 -14
- package/src/Menu/MenuSeparator.torp +3 -5
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +13 -14
- package/src/MenuBar/MenuBarItem.torp +13 -16
- package/src/MenuBar/MenuBarItemContent.torp +7 -9
- package/src/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/src/Modal/Modal.torp +118 -0
- package/src/Modal/ModalContent.torp +77 -0
- package/src/Modal/ModalOverlay.torp +38 -0
- package/src/Modal/ModalTrigger.torp +50 -0
- package/src/Modal/ModalTypes.ts +22 -0
- package/src/Modal/index.ts +10 -0
- package/src/Modal/showModal.ts +19 -0
- package/src/Modal/showPrompt.ts +23 -0
- package/src/NavMenu/NavMenu.torp +7 -8
- package/src/NavMenu/NavMenuButton.torp +6 -8
- package/src/NavMenu/NavMenuElement.torp +8 -8
- package/src/NavMenu/NavMenuGroup.torp +4 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/src/NavMenu/NavMenuLink.torp +8 -11
- package/src/NavMenu/NavMenuPopout.torp +25 -17
- package/src/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/src/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/src/NavMenu/NavMenuSeparator.torp +3 -5
- package/src/Notification/Notification.torp +22 -13
- package/src/Notification/NotificationClose.torp +3 -5
- package/src/Notification/NotificationContainer.torp +3 -5
- package/src/Notification/NotificationContent.torp +3 -5
- package/src/Popover/Popover.torp +31 -25
- package/src/Popover/PopoverContent.torp +35 -10
- package/src/Popover/PopoverTrigger.torp +24 -4
- package/src/Popover/PopoverTypes.ts +1 -1
- package/src/Popover/index.ts +1 -24
- package/src/Slider/Slider.torp +3 -3
- package/src/TabGroup/TabContent.torp +12 -9
- package/src/TabGroup/TabGroup.torp +41 -35
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +15 -8
- package/src/TabGroup/TabList.torp +4 -6
- package/src/TabGroup/TabTrigger.torp +8 -9
- package/src/icons/ArrowDown.torp +3 -1
- package/src/icons/ArrowLeft.torp +3 -1
- package/src/icons/ArrowRight.torp +3 -1
- package/src/icons/ArrowUp.torp +3 -1
- package/src/icons/Bars.torp +3 -1
- package/src/icons/Check.torp +3 -1
- package/src/icons/ChevronDown.torp +3 -1
- package/src/icons/ChevronLeft.torp +3 -1
- package/src/icons/ChevronRight.torp +3 -1
- package/src/icons/ChevronUp.torp +3 -1
- package/src/icons/Cross.torp +3 -1
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +3 -1
- package/src/icons/Minus.torp +3 -1
- package/src/icons/Plus.torp +3 -1
- package/src/motion/fade.ts +15 -6
- package/src/motion/grow.ts +23 -0
- package/src/motion/index.ts +4 -1
- package/src/motion/measure.ts +28 -0
- package/src/motion/slide.ts +45 -0
- package/src/mount/clickPopover.ts +51 -0
- package/src/mount/contextPopover.ts +51 -0
- package/src/mount/hoverPopover.ts +58 -0
- package/test/Accordion/components/AccordionAccessibility.torp +1 -3
- package/test/Accordion/components/AccordionKeyboard.torp +1 -3
- package/test/Accordion/components/AccordionList.torp +1 -3
- package/test/Accordion/components/AccordionMultiple.torp +2 -4
- package/test/Accordion/components/AccordionSingle.torp +2 -4
- package/test/Dialog/accessibility-modal.test.ts +2 -2
- package/test/Dialog/components/DialogAccessibility.torp +8 -14
- package/test/Dialog/components/DialogFunction.torp +20 -4
- package/test/Dialog/components/DialogModal.torp +30 -0
- package/test/Dialog/components/DialogVariable.torp +7 -7
- package/test/Disclosure/components/DisclosureTest.torp +1 -3
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/Notification/components/NotificationFunction.torp +0 -3
- package/test/Notification/components/NotificationVariable.torp +1 -1
- package/test/Popover/components/PopoverFunction.torp +37 -0
- package/test/Popover/components/PopoverTrigger.torp +36 -0
- package/test/Popover/components/{PromptVariable.torp → PopoverVariable.torp} +5 -3
- package/test/Popover/function.test.ts +2 -7
- package/test/Popover/trigger.test.ts +27 -0
- package/test/Popover/variable.test.ts +2 -2
- package/test/TabGroup/components/TabGroupAccessibility.torp +1 -3
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -3
- package/test/TabGroup/components/TabGroupList.torp +1 -3
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -3
- package/tsup.config.ts +2 -0
- package/dist/Popover/PopoverContentAnchored.torp +0 -113
- package/dist/Popover/PopoverOverlay.torp +0 -39
- package/dist/Popover/PopoverTriggerContextual.torp +0 -46
- package/dist/Popover/PopoverTriggerHover.torp +0 -47
- package/dist/Popover/mountClickPopover.ts +0 -50
- package/dist/Popover/mountContextPopover.ts +0 -50
- package/dist/Popover/mountHoverPopover.ts +0 -57
- package/dist/Popover/showPopoverPrompt.ts +0 -23
- package/src/Popover/PopoverContentAnchored.torp +0 -113
- package/src/Popover/PopoverOverlay.torp +0 -39
- package/src/Popover/PopoverTriggerContextual.torp +0 -46
- package/src/Popover/PopoverTriggerHover.torp +0 -47
- package/src/Popover/mountClickPopover.ts +0 -50
- package/src/Popover/mountContextPopover.ts +0 -50
- package/src/Popover/mountHoverPopover.ts +0 -57
- package/src/Popover/showPopoverPrompt.ts +0 -23
- package/test/Dialog/components/CustomDialog.torp +0 -20
- package/test/Popover/components/PromptFunction.torp +0 -19
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { disableScroll } from "../mount/disableScroll";
|
|
2
|
+
import { DrawerContextName, type DrawerContext } from "./DrawerTypes";
|
|
3
|
+
|
|
4
|
+
interface DrawerOverlayProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The background overlay for a Drawer component.
|
|
13
|
+
* Adding an overlay automatically sets the component's `modal` value to true.
|
|
14
|
+
*/
|
|
15
|
+
export default function DrawerOverlay($props: DrawerOverlayProps | undefined) {
|
|
16
|
+
// Get stuff out of the DrawerContext
|
|
17
|
+
const context = $context[DrawerContextName] as DrawerContext;
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error("DrawerOverlay must be contained within a Drawer");
|
|
20
|
+
}
|
|
21
|
+
let $state = context.state;
|
|
22
|
+
|
|
23
|
+
// Any drawer with an overlay is modal
|
|
24
|
+
$state.modal = true;
|
|
25
|
+
|
|
26
|
+
@render {
|
|
27
|
+
@if ($state.visible) {
|
|
28
|
+
<div
|
|
29
|
+
{$props?.id}
|
|
30
|
+
class={`torp-drawer-overlay ${$props?.class ?? ""}`.trim()}
|
|
31
|
+
tabindex="-1"
|
|
32
|
+
onmount={(el) => disableScroll(el)}
|
|
33
|
+
>
|
|
34
|
+
<slot />
|
|
35
|
+
</div>
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DrawerContextName, type DrawerContext } from "./DrawerTypes";
|
|
2
|
+
|
|
3
|
+
interface DrawerTriggerProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The button that causes a Drawer to appear or disappear.
|
|
12
|
+
*/
|
|
13
|
+
export default function DrawerTrigger($props: DrawerTriggerProps | undefined) {
|
|
14
|
+
// Get stuff out of the DrawerContext
|
|
15
|
+
const context = $context[DrawerContextName] as DrawerContext;
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error("DrawerTrigger must be contained within a Drawer");
|
|
18
|
+
}
|
|
19
|
+
let $state = context.state;
|
|
20
|
+
|
|
21
|
+
function handleClick() {
|
|
22
|
+
$state.visible = !$state.visible;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@render {
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
{$props?.id}
|
|
29
|
+
class={`torp-drawer-trigger ${$props?.class ?? ""}`.trim()}
|
|
30
|
+
onclick={handleClick}
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</button>
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const DrawerContextName = "Drawer";
|
|
2
|
+
|
|
3
|
+
/** The shared context for drawer components (Contextual, Prompt and Drawer) */
|
|
4
|
+
export interface DrawerContext {
|
|
5
|
+
handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
|
|
6
|
+
// HACK: We need to be able to let children (i.e. Dialogs) override the click outside functionality
|
|
7
|
+
// There may be a more elegant way to accomplish this too
|
|
8
|
+
handleClickOutside?: (e: MouseEvent) => void;
|
|
9
|
+
state: DrawerState;
|
|
10
|
+
// HACK: focusFirstElement is necessary because if we focus the first element e.g. in a Dialog's
|
|
11
|
+
// onMount, it will scroll the page to the focused element and mess up our careful positioning
|
|
12
|
+
// We need to be able to manually set the order to
|
|
13
|
+
// 1. set visible (so we have an element with content)
|
|
14
|
+
// 2. set position (so the element is in the right place)
|
|
15
|
+
// 3. set focus (for accessibility)
|
|
16
|
+
// There may be a more elegant way to accomplish this!
|
|
17
|
+
focusFirstElement?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DrawerState {
|
|
21
|
+
visible: boolean;
|
|
22
|
+
modal: boolean;
|
|
23
|
+
position: "left" | "right" | "top" | "bottom";
|
|
24
|
+
}
|
package/dist/Drawer/index.d.ts
CHANGED
|
@@ -6,16 +6,103 @@ interface DrawerProps {
|
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Class name(s) for the root element */
|
|
8
8
|
class?: string,
|
|
9
|
+
/** Whether the drawer is modal. If true, an overlay should be supplied to obscure outside content, and only the drawer content will be visible to screen readers */
|
|
10
|
+
modal?: boolean,
|
|
11
|
+
/** Whether the drawer is visible */
|
|
9
12
|
visible?: boolean,
|
|
10
|
-
|
|
13
|
+
/** Which side of the window to show the drawer from */
|
|
14
|
+
position?: "left" | "right" | "top" | "bottom",
|
|
15
|
+
/** A function to be called when the user selects a response */
|
|
16
|
+
callback?: ((value: any) => void),
|
|
17
|
+
/** Raised when the drawer is opened or closed */
|
|
18
|
+
ontoggle?: (open: boolean) => void,
|
|
19
|
+
/** Raised when the drawer has opened */
|
|
20
|
+
onopen?: () => void,
|
|
21
|
+
/** Raised when the drawer has closed */
|
|
22
|
+
onclose?: (result: any) => void,
|
|
11
23
|
}
|
|
12
24
|
|
|
25
|
+
/**
|
|
26
|
+
* A drawer that can be used to show rich content or obtain information from a user.
|
|
27
|
+
*
|
|
28
|
+
* See [the WAI ARIA guidelines for Dialogs](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
|
|
29
|
+
*
|
|
30
|
+
* The structure of a Drawer is:
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* <Drawer>
|
|
34
|
+
* <DrawerTrigger /> (optional)
|
|
35
|
+
* <DrawerContent />
|
|
36
|
+
* </Drawer>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
13
39
|
declare function Drawer(
|
|
14
40
|
$parent: ParentNode,
|
|
15
41
|
$anchor: Node | null,
|
|
16
|
-
$props: DrawerProps,
|
|
42
|
+
$props: DrawerProps | undefined,
|
|
17
43
|
$context?: Record<PropertyKey, any>,
|
|
18
44
|
$slots?: Record<string, SlotRender>,
|
|
19
45
|
): void;
|
|
20
46
|
|
|
21
|
-
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
interface DrawerContentProps {
|
|
50
|
+
/** An ID for the root element */
|
|
51
|
+
id?: string;
|
|
52
|
+
/** Class name(s) for the root element */
|
|
53
|
+
class?: string,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The content that is displayed for a Drawer when it is open.
|
|
58
|
+
*/
|
|
59
|
+
declare function DrawerContent(
|
|
60
|
+
$parent: ParentNode,
|
|
61
|
+
$anchor: Node | null,
|
|
62
|
+
$props: DrawerContentProps | undefined,
|
|
63
|
+
$context?: Record<PropertyKey, any>,
|
|
64
|
+
$slots?: Record<string, SlotRender>,
|
|
65
|
+
): void;
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
interface DrawerOverlayProps {
|
|
70
|
+
/** An ID for the root element */
|
|
71
|
+
id?: string;
|
|
72
|
+
/** Class name(s) for the root element */
|
|
73
|
+
class?: string,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The background overlay for a Drawer component.
|
|
78
|
+
* Adding an overlay automatically sets the component's `modal` value to true.
|
|
79
|
+
*/
|
|
80
|
+
declare function DrawerOverlay(
|
|
81
|
+
$parent: ParentNode,
|
|
82
|
+
$anchor: Node | null,
|
|
83
|
+
$props: DrawerOverlayProps | undefined,
|
|
84
|
+
$context?: Record<PropertyKey, any>,
|
|
85
|
+
$slots?: Record<string, SlotRender>,
|
|
86
|
+
): void;
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
interface DrawerTriggerProps {
|
|
91
|
+
/** An ID for the root element */
|
|
92
|
+
id?: string;
|
|
93
|
+
/** Class name(s) for the root element */
|
|
94
|
+
class?: string,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The button that causes a Drawer to appear or disappear.
|
|
99
|
+
*/
|
|
100
|
+
declare function DrawerTrigger(
|
|
101
|
+
$parent: ParentNode,
|
|
102
|
+
$anchor: Node | null,
|
|
103
|
+
$props: DrawerTriggerProps | undefined,
|
|
104
|
+
$context?: Record<PropertyKey, any>,
|
|
105
|
+
$slots?: Record<string, SlotRender>,
|
|
106
|
+
): void;
|
|
107
|
+
|
|
108
|
+
export { Drawer, DrawerContent, DrawerOverlay, DrawerTrigger };
|
package/dist/Drawer/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// src/Drawer/Drawer.torp
|
|
2
2
|
import Drawer_default from "./Drawer.torp";
|
|
3
|
+
|
|
4
|
+
// src/Drawer/DrawerContent.torp
|
|
5
|
+
import DrawerContent_default from "./DrawerContent.torp";
|
|
6
|
+
|
|
7
|
+
// src/Drawer/DrawerOverlay.torp
|
|
8
|
+
import DrawerOverlay_default from "./DrawerOverlay.torp";
|
|
9
|
+
|
|
10
|
+
// src/Drawer/DrawerTrigger.torp
|
|
11
|
+
import DrawerTrigger_default from "./DrawerTrigger.torp";
|
|
3
12
|
export {
|
|
4
|
-
Drawer_default as Drawer
|
|
13
|
+
Drawer_default as Drawer,
|
|
14
|
+
DrawerContent_default as DrawerContent,
|
|
15
|
+
DrawerOverlay_default as DrawerOverlay,
|
|
16
|
+
DrawerTrigger_default as DrawerTrigger
|
|
5
17
|
};
|
|
6
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface CheckBoxProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The name of the checkbox's form data field */
|
|
10
|
+
name?: string,
|
|
11
|
+
/** Whether the checkbox is checked */
|
|
12
|
+
checked?: boolean,
|
|
13
|
+
/** An ARIA label for describing the checkbox to screen readers when there is no associated label element */
|
|
14
|
+
ariaLabel?: string,
|
|
15
|
+
/** Raised on change */
|
|
16
|
+
onchange?: (e: Event) => void,
|
|
17
|
+
/** Raised on input */
|
|
18
|
+
oninput?: (e: Event) => void,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A checkbox input in a form.
|
|
23
|
+
*/
|
|
24
|
+
export default function CheckBox($props: CheckBoxProps | undefined) {
|
|
25
|
+
let defaultId = getId();
|
|
26
|
+
|
|
27
|
+
let name = $props?.name
|
|
28
|
+
|
|
29
|
+
let blurred = false;
|
|
30
|
+
|
|
31
|
+
// Get stuff out of the FormContext and FieldContext
|
|
32
|
+
const formContext = $context[FormContextName] as FormContext;
|
|
33
|
+
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
34
|
+
if (fieldContext) {
|
|
35
|
+
name ??= fieldContext.name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Use the FieldContext's state, or create a new one
|
|
39
|
+
let $state = fieldContext?.state ?? $watch({
|
|
40
|
+
inputId: $props?.id ?? defaultId,
|
|
41
|
+
value: $props?.checked,
|
|
42
|
+
errors: {} as Record<string, string>,
|
|
43
|
+
valid: false,
|
|
44
|
+
message: "",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Binding
|
|
48
|
+
$run(() => {
|
|
49
|
+
if ($props !== undefined) {
|
|
50
|
+
$props.checked = $state.value === true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Set the input ID now that we know it and it will get linked with the associated label
|
|
55
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
56
|
+
|
|
57
|
+
function handleInput(e: Event) {
|
|
58
|
+
if (formContext) {
|
|
59
|
+
formContext.validate();
|
|
60
|
+
}
|
|
61
|
+
if (fieldContext && blurred) {
|
|
62
|
+
fieldContext.validate();
|
|
63
|
+
}
|
|
64
|
+
if ($props?.oninput) {
|
|
65
|
+
$props.oninput(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function handleBlur() {
|
|
70
|
+
if (fieldContext) {
|
|
71
|
+
fieldContext.validate();
|
|
72
|
+
}
|
|
73
|
+
blurred = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@render {
|
|
77
|
+
<input
|
|
78
|
+
id={$props?.id ?? defaultId}
|
|
79
|
+
class={`torp-check-box
|
|
80
|
+
${$props?.class ?? ""}`.trim()}
|
|
81
|
+
type="checkbox"
|
|
82
|
+
{name}
|
|
83
|
+
&checked={$state.checked}
|
|
84
|
+
aria-label={$props?.ariaLabel}
|
|
85
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
86
|
+
onchange={$props?.onchange}
|
|
87
|
+
oninput={handleInput}
|
|
88
|
+
onblur={handleBlur}
|
|
89
|
+
/>
|
|
90
|
+
}
|
|
91
|
+
}
|
package/dist/Form/Field.torp
CHANGED
|
@@ -25,8 +25,6 @@ interface FieldProps {
|
|
|
25
25
|
* component and/or a Message.
|
|
26
26
|
*/
|
|
27
27
|
export default function Field($props: FieldProps) {
|
|
28
|
-
$props ??= $watch({ name: "" });
|
|
29
|
-
|
|
30
28
|
let $state = $watch({
|
|
31
29
|
inputId: "-1",
|
|
32
30
|
value: $props.value,
|
|
@@ -83,8 +81,8 @@ export default function Field($props: FieldProps) {
|
|
|
83
81
|
|
|
84
82
|
@render {
|
|
85
83
|
<div
|
|
86
|
-
{$props
|
|
87
|
-
class={`torp-field ${$props
|
|
84
|
+
{$props?.id}
|
|
85
|
+
class={`torp-field ${$props?.class ?? ""}`.trim()}
|
|
88
86
|
data-valid={$state.valid ? "valid" : "invalid"}
|
|
89
87
|
>
|
|
90
88
|
<slot />
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface FileProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The name of the input's form data field */
|
|
10
|
+
name?: string,
|
|
11
|
+
/** The type of files that this input accepts e.g. `image/*` */
|
|
12
|
+
accepts?: string,
|
|
13
|
+
/** The data value that this field is bound to */
|
|
14
|
+
value?: any,
|
|
15
|
+
/** Text to display when the input value is empty */
|
|
16
|
+
placeholder?: string,
|
|
17
|
+
/** Whether the input should be readonly */
|
|
18
|
+
readonly?: boolean,
|
|
19
|
+
/** The maximum number of characters allowed for the input value */
|
|
20
|
+
maxlength?: number,
|
|
21
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
22
|
+
ariaLabel?: string,
|
|
23
|
+
/** Raised on change */
|
|
24
|
+
onchange?: (e: Event) => void,
|
|
25
|
+
/** Raised on input */
|
|
26
|
+
oninput?: (e: Event) => void,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A file input in a form.
|
|
31
|
+
*/
|
|
32
|
+
export default function Input($props: FileProps | undefined) {
|
|
33
|
+
let defaultId = getId();
|
|
34
|
+
|
|
35
|
+
let name = $props?.name
|
|
36
|
+
|
|
37
|
+
let blurred = false;
|
|
38
|
+
|
|
39
|
+
// Get stuff out of the FormContext and FieldContext
|
|
40
|
+
const formContext = $context[FormContextName] as FormContext;
|
|
41
|
+
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
42
|
+
if (fieldContext) {
|
|
43
|
+
name ??= fieldContext.name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// This will change the form's enctype to `multipart/form-data`
|
|
47
|
+
if (formContext) {
|
|
48
|
+
formContext.state.hasFile = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Use the FieldContext's state, or create a new one
|
|
52
|
+
let $state = fieldContext?.state ?? $watch({
|
|
53
|
+
inputId: $props?.id ?? defaultId,
|
|
54
|
+
value: $props?.value,
|
|
55
|
+
errors: {} as Record<string, string>,
|
|
56
|
+
valid: false,
|
|
57
|
+
message: "",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Binding
|
|
61
|
+
$run(() => {
|
|
62
|
+
if ($props !== undefined) {
|
|
63
|
+
$props.value = $state.value;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Set the input ID now that we know it and it will get linked with the associated label
|
|
68
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
69
|
+
|
|
70
|
+
function handleInput(e: Event & { currentTarget: EventTarget & HTMLInputElement }) {
|
|
71
|
+
if (formContext) {
|
|
72
|
+
formContext.validate();
|
|
73
|
+
}
|
|
74
|
+
if (fieldContext && blurred) {
|
|
75
|
+
fieldContext.validate();
|
|
76
|
+
}
|
|
77
|
+
if ($props?.oninput) {
|
|
78
|
+
$props.oninput(e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function handleBlur() {
|
|
83
|
+
if (fieldContext) {
|
|
84
|
+
fieldContext.validate();
|
|
85
|
+
}
|
|
86
|
+
blurred = true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@render {
|
|
90
|
+
<input
|
|
91
|
+
id={$props?.id ?? defaultId}
|
|
92
|
+
class={`torp-file ${$props?.class ?? ""}`.trim()}
|
|
93
|
+
type="file"
|
|
94
|
+
{name}
|
|
95
|
+
&value={$state.value}
|
|
96
|
+
{$props?.placeholder}
|
|
97
|
+
{$props?.readonly}
|
|
98
|
+
{$props?.maxlength}
|
|
99
|
+
aria-label={$props?.ariaLabel}
|
|
100
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
101
|
+
onchange={$props?.onchange}
|
|
102
|
+
oninput={handleInput}
|
|
103
|
+
onblur={handleBlur}
|
|
104
|
+
/>
|
|
105
|
+
}
|
|
106
|
+
}
|
package/dist/Form/Form.torp
CHANGED
|
@@ -10,6 +10,13 @@ interface FormProps {
|
|
|
10
10
|
data?: any,
|
|
11
11
|
/** Where to post the form's data **/
|
|
12
12
|
action?: string,
|
|
13
|
+
/** The action to use when submitting the form, which defaults to POST */
|
|
14
|
+
method?: string,
|
|
15
|
+
/**
|
|
16
|
+
* The form's encoding type e.g. `multipart/form-data` where there are file
|
|
17
|
+
* inputs. This will be automatically set unless overridden
|
|
18
|
+
*/
|
|
19
|
+
enctype?: string,
|
|
13
20
|
/** The schema validator to use for this form */
|
|
14
21
|
schema?: StandardSchemaV1,
|
|
15
22
|
onsubmit?: (e: SubmitEvent) => boolean | void | Promise<boolean | void>,
|
|
@@ -18,11 +25,10 @@ interface FormProps {
|
|
|
18
25
|
/**
|
|
19
26
|
* A form for submitting values.
|
|
20
27
|
*/
|
|
21
|
-
export default function Form($props: FormProps) {
|
|
22
|
-
$props ??= $watch({});
|
|
23
|
-
|
|
28
|
+
export default function Form($props: FormProps | undefined) {
|
|
24
29
|
let $state = $watch({
|
|
25
|
-
data: $props
|
|
30
|
+
data: $props?.data ?? {},
|
|
31
|
+
hasFile: false,
|
|
26
32
|
issues: [] as ValidationIssue[],
|
|
27
33
|
get valid() {
|
|
28
34
|
return this.issues.length === 0;
|
|
@@ -35,7 +41,7 @@ export default function Form($props: FormProps) {
|
|
|
35
41
|
|
|
36
42
|
// Set the context to pass down to Fields
|
|
37
43
|
let context: FormContext = {
|
|
38
|
-
schema: $props
|
|
44
|
+
schema: $props?.schema,
|
|
39
45
|
state: $state,
|
|
40
46
|
validate: handleValidate
|
|
41
47
|
};
|
|
@@ -43,7 +49,7 @@ export default function Form($props: FormProps) {
|
|
|
43
49
|
$context[FormContextName] = context;
|
|
44
50
|
|
|
45
51
|
async function validate() {
|
|
46
|
-
if ($props
|
|
52
|
+
if ($props?.schema) {
|
|
47
53
|
const validator = $props.schema["~standard"];
|
|
48
54
|
let result = validator.validate($props.data);
|
|
49
55
|
if (result instanceof Promise) {
|
|
@@ -77,7 +83,7 @@ export default function Form($props: FormProps) {
|
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
// Dispatch the submit event for the user to handle
|
|
80
|
-
if ($props
|
|
86
|
+
if ($props?.onsubmit) {
|
|
81
87
|
let userSubmit = $props.onsubmit(e);
|
|
82
88
|
if (userSubmit instanceof Promise) {
|
|
83
89
|
userSubmit = await userSubmit;
|
|
@@ -118,9 +124,10 @@ export default function Form($props: FormProps) {
|
|
|
118
124
|
|
|
119
125
|
@render {
|
|
120
126
|
<form
|
|
121
|
-
{$props
|
|
122
|
-
class={`torp-form ${$props
|
|
123
|
-
method="POST"
|
|
127
|
+
{$props?.id}
|
|
128
|
+
class={`torp-form ${$props?.class ?? ""}`.trim()}
|
|
129
|
+
method={$props?.method ?? "POST"}
|
|
130
|
+
enctype={$props?.enctype ?? ($state.hasFile ? "multipart/form-data" : undefined)}
|
|
124
131
|
onsubmit={handleSubmit}
|
|
125
132
|
@// Set novalidate only if JS is enabled (to override HTML validation)
|
|
126
133
|
onmount={(e) => e.novalidate = true }
|
package/dist/Form/FormTypes.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface ValidationIssue {
|
|
|
11
11
|
export interface FormContext {
|
|
12
12
|
schema?: StandardSchemaV1;
|
|
13
13
|
state: {
|
|
14
|
+
/**
|
|
15
|
+
* Whether there is a file input in the form. If so, the form's enctype
|
|
16
|
+
* will be set to `multipart/form-data`
|
|
17
|
+
*/
|
|
18
|
+
hasFile: boolean;
|
|
14
19
|
issues: ValidationIssue[];
|
|
15
20
|
};
|
|
16
21
|
validate: () => void;
|
package/dist/Form/Input.torp
CHANGED
|
@@ -20,15 +20,20 @@ interface InputProps {
|
|
|
20
20
|
maxlength?: number,
|
|
21
21
|
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
22
22
|
ariaLabel?: string,
|
|
23
|
+
/** Raised on change */
|
|
24
|
+
onchange?: (e: Event) => void,
|
|
25
|
+
/** Raised on input */
|
|
26
|
+
oninput?: (e: Event) => void,
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* A standard input in a form.
|
|
27
31
|
*/
|
|
28
|
-
export default function Input($props: InputProps) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
$props
|
|
32
|
+
export default function Input($props: InputProps | undefined) {
|
|
33
|
+
let defaultId = getId();
|
|
34
|
+
|
|
35
|
+
let type = $props?.type ?? "text";
|
|
36
|
+
let name = $props?.name
|
|
32
37
|
|
|
33
38
|
let blurred = false;
|
|
34
39
|
|
|
@@ -36,13 +41,13 @@ export default function Input($props: InputProps) {
|
|
|
36
41
|
const formContext = $context[FormContextName] as FormContext;
|
|
37
42
|
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
38
43
|
if (fieldContext) {
|
|
39
|
-
|
|
44
|
+
name ??= fieldContext.name;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
// Use the FieldContext's state, or create a new one
|
|
43
48
|
let $state = fieldContext?.state ?? $watch({
|
|
44
|
-
inputId: $props
|
|
45
|
-
value: $props
|
|
49
|
+
inputId: $props?.id ?? defaultId,
|
|
50
|
+
value: $props?.value,
|
|
46
51
|
errors: {} as Record<string, string>,
|
|
47
52
|
valid: false,
|
|
48
53
|
message: "",
|
|
@@ -50,11 +55,13 @@ export default function Input($props: InputProps) {
|
|
|
50
55
|
|
|
51
56
|
// Binding
|
|
52
57
|
$run(() => {
|
|
53
|
-
$props
|
|
58
|
+
if ($props !== undefined) {
|
|
59
|
+
$props.value = $state.value;
|
|
60
|
+
}
|
|
54
61
|
});
|
|
55
62
|
|
|
56
63
|
// Set the input ID now that we know it and it will get linked with the associated label
|
|
57
|
-
$state.inputId = $props
|
|
64
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
58
65
|
|
|
59
66
|
// NOTE: Adapted this from https://stackoverflow.com/a/57393751,
|
|
60
67
|
// not sure if it's still a good way to do things
|
|
@@ -66,6 +73,9 @@ export default function Input($props: InputProps) {
|
|
|
66
73
|
if (fieldContext && blurred) {
|
|
67
74
|
fieldContext.validate();
|
|
68
75
|
}
|
|
76
|
+
if ($props?.oninput) {
|
|
77
|
+
$props.oninput(e);
|
|
78
|
+
}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
function handleBlur() {
|
|
@@ -77,16 +87,17 @@ export default function Input($props: InputProps) {
|
|
|
77
87
|
|
|
78
88
|
@render {
|
|
79
89
|
<input
|
|
80
|
-
{$props
|
|
81
|
-
class={`torp-input ${$props
|
|
82
|
-
{
|
|
90
|
+
id={$props?.id ?? defaultId}
|
|
91
|
+
class={`torp-input ${$props?.class ?? ""}`.trim()}
|
|
92
|
+
{type}
|
|
93
|
+
{name}
|
|
83
94
|
&value={$state.value}
|
|
84
|
-
{$props
|
|
85
|
-
{$props
|
|
86
|
-
{$props
|
|
87
|
-
{$props
|
|
88
|
-
aria-label={$props.ariaLabel}
|
|
95
|
+
{$props?.placeholder}
|
|
96
|
+
{$props?.readonly}
|
|
97
|
+
{$props?.maxlength}
|
|
98
|
+
aria-label={$props?.ariaLabel}
|
|
89
99
|
data-valid={$state.valid ? "valid" : "invalid"}
|
|
100
|
+
onchange={$props?.onchange}
|
|
90
101
|
oninput={handleInput}
|
|
91
102
|
onblur={handleBlur}
|
|
92
103
|
/>
|
package/dist/Form/Label.torp
CHANGED
|
@@ -10,7 +10,7 @@ interface LabelProps {
|
|
|
10
10
|
/**
|
|
11
11
|
* A label to describe the contents of an input in a form.
|
|
12
12
|
*/
|
|
13
|
-
export default function Label($props
|
|
13
|
+
export default function Label($props: LabelProps | undefined) {
|
|
14
14
|
// Get stuff out of the FieldContext
|
|
15
15
|
const context = $context[FieldContextName] as FieldContext;
|
|
16
16
|
if (!context) {
|
package/dist/Form/Message.torp
CHANGED
|
@@ -11,7 +11,7 @@ interface MessageProps {
|
|
|
11
11
|
* A validation message to show when the contents of an input component have
|
|
12
12
|
* problems that need to be fixed.
|
|
13
13
|
*/
|
|
14
|
-
export default function Message($props
|
|
14
|
+
export default function Message($props: MessageProps | undefined) {
|
|
15
15
|
// Get stuff out of the FieldContext
|
|
16
16
|
const context = $context[FieldContextName] as FieldContext;
|
|
17
17
|
if (!context) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface OptionProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The data value that this option has */
|
|
10
|
+
value?: any,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An option in a select.
|
|
15
|
+
*/
|
|
16
|
+
export default function Option($props: OptionProps | undefined) {
|
|
17
|
+
@render {
|
|
18
|
+
<option
|
|
19
|
+
{$props?.id}
|
|
20
|
+
class={`torp-option ${$props?.class ?? ""}`.trim()}
|
|
21
|
+
&value={$state.value}
|
|
22
|
+
/>
|
|
23
|
+
}
|
|
24
|
+
}
|