@torpor/ui 0.2.0 → 0.3.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/CHANGELOG.md +35 -0
- package/dist/Accordion/Accordion.torp +44 -25
- package/dist/Accordion/AccordionContent.torp +18 -12
- package/dist/Accordion/AccordionHeader.torp +15 -8
- package/dist/Accordion/AccordionItem.torp +34 -17
- package/dist/Accordion/AccordionTrigger.torp +17 -10
- package/dist/Accordion/AccordionTypes.ts +6 -3
- package/dist/Accordion/index.d.ts +100 -35
- package/dist/Breadcrumb/Breadcrumb.torp +18 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +14 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +10 -3
- package/dist/Breadcrumb/index.d.ts +50 -21
- package/dist/Calendar/Calendar.torp +21 -14
- package/dist/Calendar/CalendarDay.torp +12 -4
- package/dist/Calendar/index.d.ts +16 -18
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +21 -12
- 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 +49 -73
- package/dist/Dialog/DialogBody.torp +15 -9
- package/dist/Dialog/DialogButton.torp +27 -13
- package/dist/Dialog/DialogFooter.torp +11 -3
- package/dist/Dialog/DialogHeader.torp +15 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +83 -35
- package/dist/Disclosure/Disclosure.torp +34 -25
- package/dist/Disclosure/DisclosureContent.torp +18 -12
- package/dist/Disclosure/DisclosureHeader.torp +16 -9
- package/dist/Disclosure/DisclosureTrigger.torp +15 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +67 -28
- package/dist/Drawer/Drawer.torp +109 -68
- 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 +96 -8
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/Field.torp +91 -0
- package/dist/Form/Form.torp +129 -0
- package/dist/Form/FormTypes.ts +30 -0
- package/dist/Form/Input.torp +97 -0
- package/dist/Form/Label.torp +31 -0
- package/dist/Form/Message.torp +35 -0
- package/dist/Form/StandardSchemaV1.ts +70 -0
- package/dist/Form/index.d.ts +131 -0
- package/dist/Form/index.js +22 -0
- package/dist/Form/index.js.map +1 -0
- package/dist/Menu/Menu.torp +25 -15
- package/dist/Menu/MenuButton.torp +30 -13
- package/dist/Menu/MenuCheck.torp +29 -14
- package/dist/Menu/MenuGroup.torp +14 -6
- package/dist/Menu/MenuIndicator.torp +14 -7
- package/dist/Menu/MenuPopout.torp +23 -15
- package/dist/Menu/MenuPopoutContent.torp +17 -10
- package/dist/Menu/MenuPopoutTrigger.torp +23 -16
- package/dist/Menu/MenuRadio.torp +27 -16
- package/dist/Menu/MenuRadioGroup.torp +34 -15
- package/dist/Menu/MenuSeparator.torp +11 -3
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +176 -77
- package/dist/MenuBar/MenuBar.torp +24 -16
- package/dist/MenuBar/MenuBarItem.torp +24 -16
- package/dist/MenuBar/MenuBarItemContent.torp +18 -11
- package/dist/MenuBar/MenuBarItemTrigger.torp +15 -9
- package/dist/MenuBar/index.d.ts +79 -28
- 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 +18 -10
- package/dist/NavMenu/NavMenuButton.torp +15 -10
- package/dist/NavMenu/NavMenuElement.torp +19 -11
- package/dist/NavMenu/NavMenuGroup.torp +13 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +15 -8
- package/dist/NavMenu/NavMenuLink.torp +21 -16
- package/dist/NavMenu/NavMenuPopout.torp +34 -18
- package/dist/NavMenu/NavMenuPopoutButton.torp +23 -18
- package/dist/NavMenu/NavMenuPopoutContent.torp +23 -13
- package/dist/NavMenu/NavMenuSeparator.torp +10 -3
- package/dist/NavMenu/index.d.ts +153 -70
- package/dist/Notification/Notification.torp +35 -16
- package/dist/Notification/NotificationClose.torp +10 -3
- package/dist/Notification/NotificationContainer.torp +11 -3
- package/dist/Notification/NotificationContent.torp +11 -3
- package/dist/Notification/index.d.ts +46 -28
- package/dist/Popover/Popover.torp +48 -28
- package/dist/Popover/PopoverContent.torp +42 -8
- package/dist/Popover/PopoverTrigger.torp +32 -3
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +48 -111
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +20 -11
- package/dist/TabGroup/TabGroup.torp +58 -40
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +26 -10
- package/dist/TabGroup/TabList.torp +14 -7
- package/dist/TabGroup/TabTrigger.torp +17 -10
- package/dist/TabGroup/index.d.ts +101 -35
- package/dist/icons/ArrowDown.torp +5 -3
- package/dist/icons/ArrowLeft.torp +5 -3
- package/dist/icons/ArrowRight.torp +5 -3
- package/dist/icons/ArrowUp.torp +5 -3
- package/dist/icons/Bars.torp +5 -3
- package/dist/icons/Check.torp +5 -3
- package/dist/icons/ChevronDown.torp +5 -3
- package/dist/icons/ChevronLeft.torp +5 -3
- package/dist/icons/ChevronRight.torp +5 -3
- package/dist/icons/ChevronUp.torp +5 -3
- package/dist/icons/Cross.torp +5 -3
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +5 -3
- package/dist/icons/Minus.torp +5 -3
- package/dist/icons/Plus.torp +5 -3
- package/dist/icons/index.d.ts +271 -126
- 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 +28 -12
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +44 -25
- package/src/Accordion/AccordionContent.torp +18 -12
- package/src/Accordion/AccordionHeader.torp +15 -8
- package/src/Accordion/AccordionItem.torp +34 -17
- package/src/Accordion/AccordionTrigger.torp +17 -10
- package/src/Accordion/AccordionTypes.ts +6 -3
- package/src/Breadcrumb/Breadcrumb.torp +18 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +14 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +10 -3
- package/src/Calendar/Calendar.torp +21 -14
- package/src/Calendar/CalendarDay.torp +12 -4
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +21 -12
- 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 +49 -73
- package/src/Dialog/DialogBody.torp +15 -9
- package/src/Dialog/DialogButton.torp +27 -13
- package/src/Dialog/DialogFooter.torp +11 -3
- package/src/Dialog/DialogHeader.torp +15 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +34 -25
- package/src/Disclosure/DisclosureContent.torp +18 -12
- package/src/Disclosure/DisclosureHeader.torp +16 -9
- package/src/Disclosure/DisclosureTrigger.torp +15 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +109 -68
- 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/Field.torp +91 -0
- package/src/Form/Form.torp +129 -0
- package/src/Form/FormTypes.ts +30 -0
- package/src/Form/Input.torp +97 -0
- package/src/Form/Label.torp +31 -0
- package/src/Form/Message.torp +35 -0
- package/src/Form/StandardSchemaV1.ts +70 -0
- package/src/Form/index.ts +7 -0
- package/src/Menu/Menu.torp +25 -15
- package/src/Menu/MenuButton.torp +30 -13
- package/src/Menu/MenuCheck.torp +29 -14
- package/src/Menu/MenuGroup.torp +14 -6
- package/src/Menu/MenuIndicator.torp +14 -7
- package/src/Menu/MenuPopout.torp +23 -15
- package/src/Menu/MenuPopoutContent.torp +17 -10
- package/src/Menu/MenuPopoutTrigger.torp +23 -16
- package/src/Menu/MenuRadio.torp +27 -16
- package/src/Menu/MenuRadioGroup.torp +34 -15
- package/src/Menu/MenuSeparator.torp +11 -3
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +24 -16
- package/src/MenuBar/MenuBarItem.torp +24 -16
- package/src/MenuBar/MenuBarItemContent.torp +18 -11
- package/src/MenuBar/MenuBarItemTrigger.torp +15 -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 +18 -10
- package/src/NavMenu/NavMenuButton.torp +15 -10
- package/src/NavMenu/NavMenuElement.torp +19 -11
- package/src/NavMenu/NavMenuGroup.torp +13 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +15 -8
- package/src/NavMenu/NavMenuLink.torp +21 -16
- package/src/NavMenu/NavMenuPopout.torp +34 -18
- package/src/NavMenu/NavMenuPopoutButton.torp +23 -18
- package/src/NavMenu/NavMenuPopoutContent.torp +23 -13
- package/src/NavMenu/NavMenuSeparator.torp +10 -3
- package/src/Notification/Notification.torp +35 -16
- package/src/Notification/NotificationClose.torp +10 -3
- package/src/Notification/NotificationContainer.torp +11 -3
- package/src/Notification/NotificationContent.torp +11 -3
- package/src/Popover/Popover.torp +48 -28
- package/src/Popover/PopoverContent.torp +42 -8
- package/src/Popover/PopoverTrigger.torp +32 -3
- 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 +20 -11
- package/src/TabGroup/TabGroup.torp +58 -40
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +26 -10
- package/src/TabGroup/TabList.torp +14 -7
- package/src/TabGroup/TabTrigger.torp +17 -10
- package/src/icons/ArrowDown.torp +5 -3
- package/src/icons/ArrowLeft.torp +5 -3
- package/src/icons/ArrowRight.torp +5 -3
- package/src/icons/ArrowUp.torp +5 -3
- package/src/icons/Bars.torp +5 -3
- package/src/icons/Check.torp +5 -3
- package/src/icons/ChevronDown.torp +5 -3
- package/src/icons/ChevronLeft.torp +5 -3
- package/src/icons/ChevronRight.torp +5 -3
- package/src/icons/ChevronUp.torp +5 -3
- package/src/icons/Cross.torp +5 -3
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +5 -3
- package/src/icons/Minus.torp +5 -3
- package/src/icons/Plus.torp +5 -3
- 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 -1
- package/test/Accordion/components/AccordionKeyboard.torp +1 -1
- package/test/Accordion/components/AccordionList.torp +1 -1
- package/test/Accordion/components/AccordionMultiple.torp +2 -2
- package/test/Accordion/components/AccordionSingle.torp +2 -2
- 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/accessibility.test.ts +3 -2
- package/test/Disclosure/components/DisclosureTest.torp +1 -1
- package/test/Disclosure/toggle.test.ts +3 -2
- package/test/Form/components/FieldTest.torp +25 -0
- package/test/Form/components/FormTest.torp +31 -0
- package/test/Form/components/InputTest.torp +9 -0
- package/test/Form/field.test.ts +34 -0
- package/test/Form/form.test.ts +34 -0
- package/test/Form/input.test.ts +19 -0
- package/test/Menu/accessibility.test.ts +3 -2
- package/test/Menu/basic.test.ts +11 -10
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/MenuBar/accessibility.test.ts +3 -2
- package/test/MenuBar/basic.test.ts +3 -2
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- 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 -1
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -1
- package/test/TabGroup/components/TabGroupList.torp +1 -1
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -1
- package/tsup.config.ts +3 -1
- package/dist/Popover/PopoverContentAnchored.torp +0 -106
- package/dist/Popover/PopoverOverlay.torp +0 -30
- package/dist/Popover/PopoverTriggerContextual.torp +0 -37
- package/dist/Popover/PopoverTriggerHover.torp +0 -38
- 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 -106
- package/src/Popover/PopoverOverlay.torp +0 -30
- package/src/Popover/PopoverTriggerContextual.torp +0 -37
- package/src/Popover/PopoverTriggerHover.torp +0 -38
- 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,97 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface InputProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The input type */
|
|
10
|
+
type?: "text" | "number" | "password" | "email" | "url" | "tel",
|
|
11
|
+
/** The name of the input's form data field */
|
|
12
|
+
name?: 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
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A standard input in a form.
|
|
27
|
+
*/
|
|
28
|
+
export default function Input($props: InputProps | undefined) {
|
|
29
|
+
let defaultId = getId();
|
|
30
|
+
|
|
31
|
+
let type = $props?.type ?? "text";
|
|
32
|
+
let name = $props?.name
|
|
33
|
+
|
|
34
|
+
let blurred = false;
|
|
35
|
+
|
|
36
|
+
// Get stuff out of the FormContext and FieldContext
|
|
37
|
+
const formContext = $context[FormContextName] as FormContext;
|
|
38
|
+
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
39
|
+
if (fieldContext) {
|
|
40
|
+
name ??= fieldContext.name;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Use the FieldContext's state, or create a new one
|
|
44
|
+
let $state = fieldContext?.state ?? $watch({
|
|
45
|
+
inputId: $props?.id ?? defaultId,
|
|
46
|
+
value: $props?.value,
|
|
47
|
+
errors: {} as Record<string, string>,
|
|
48
|
+
valid: false,
|
|
49
|
+
message: "",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Binding
|
|
53
|
+
$run(() => {
|
|
54
|
+
if ($props !== undefined) {
|
|
55
|
+
$props.value = $state.value;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Set the input ID now that we know it and it will get linked with the associated label
|
|
60
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
61
|
+
|
|
62
|
+
// NOTE: Adapted this from https://stackoverflow.com/a/57393751,
|
|
63
|
+
// not sure if it's still a good way to do things
|
|
64
|
+
function handleInput(e: Event & { currentTarget: EventTarget & HTMLInputElement }) {
|
|
65
|
+
$state.value = $props!.type?.match(/^(number|range)$/) ? +e.currentTarget.value : e.currentTarget.value;
|
|
66
|
+
if (formContext) {
|
|
67
|
+
formContext.validate();
|
|
68
|
+
}
|
|
69
|
+
if (fieldContext && blurred) {
|
|
70
|
+
fieldContext.validate();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function handleBlur() {
|
|
75
|
+
if (fieldContext) {
|
|
76
|
+
fieldContext.validate();
|
|
77
|
+
}
|
|
78
|
+
blurred = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@render {
|
|
82
|
+
<input
|
|
83
|
+
id={$props?.id ?? defaultId}
|
|
84
|
+
class={`torp-input ${$props?.class ?? ""}`.trim()}
|
|
85
|
+
{type}
|
|
86
|
+
{name}
|
|
87
|
+
&value={$state.value}
|
|
88
|
+
{$props?.placeholder}
|
|
89
|
+
{$props?.readonly}
|
|
90
|
+
{$props?.maxlength}
|
|
91
|
+
aria-label={$props?.ariaLabel}
|
|
92
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
93
|
+
oninput={handleInput}
|
|
94
|
+
onblur={handleBlur}
|
|
95
|
+
/>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FieldContextName, type FieldContext } from "./FormTypes";
|
|
2
|
+
|
|
3
|
+
interface LabelProps {
|
|
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
|
+
* A label to describe the contents of an input in a form.
|
|
12
|
+
*/
|
|
13
|
+
export default function Label($props: LabelProps | undefined) {
|
|
14
|
+
// Get stuff out of the FieldContext
|
|
15
|
+
const context = $context[FieldContextName] as FieldContext;
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error("Label must be contained within a Field");
|
|
18
|
+
}
|
|
19
|
+
let { state: $state } = context;
|
|
20
|
+
|
|
21
|
+
@render {
|
|
22
|
+
<label
|
|
23
|
+
{$props?.id}
|
|
24
|
+
class={`torp-label ${$props?.class ?? ""}`.trim()}
|
|
25
|
+
for={$state.inputId}
|
|
26
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
27
|
+
>
|
|
28
|
+
<slot />
|
|
29
|
+
</label>
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FieldContextName, type FieldContext } from "./FormTypes";
|
|
2
|
+
|
|
3
|
+
interface MessageProps {
|
|
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
|
+
* A validation message to show when the contents of an input component have
|
|
12
|
+
* problems that need to be fixed.
|
|
13
|
+
*/
|
|
14
|
+
export default function Message($props: MessageProps | undefined) {
|
|
15
|
+
// Get stuff out of the FieldContext
|
|
16
|
+
const context = $context[FieldContextName] as FieldContext;
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error("Message must be contained within a Field");
|
|
19
|
+
}
|
|
20
|
+
const { state: $state } = context;
|
|
21
|
+
|
|
22
|
+
@render {
|
|
23
|
+
@if ($state.message) {
|
|
24
|
+
<div
|
|
25
|
+
{$props?.id}
|
|
26
|
+
class={`torp-message ${$props?.class ?? ""}`.trim()}
|
|
27
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
28
|
+
>
|
|
29
|
+
<slot name="message">
|
|
30
|
+
{$state.message}
|
|
31
|
+
</slot>
|
|
32
|
+
</div>
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// From https://github.com/standard-schema/standard-schema
|
|
2
|
+
|
|
3
|
+
/** The Standard Schema interface. */
|
|
4
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard Schema properties. */
|
|
6
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare namespace StandardSchemaV1 {
|
|
10
|
+
/** The Standard Schema properties interface. */
|
|
11
|
+
export interface Props<Input = unknown, Output = Input> {
|
|
12
|
+
/** The version number of the standard. */
|
|
13
|
+
readonly version: 1;
|
|
14
|
+
/** The vendor name of the schema library. */
|
|
15
|
+
readonly vendor: string;
|
|
16
|
+
/** Validates unknown input values. */
|
|
17
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
18
|
+
/** Inferred types associated with the schema. */
|
|
19
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The result interface of the validate function. */
|
|
23
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
24
|
+
|
|
25
|
+
/** The result interface if validation succeeds. */
|
|
26
|
+
export interface SuccessResult<Output> {
|
|
27
|
+
/** The typed output value. */
|
|
28
|
+
readonly value: Output;
|
|
29
|
+
/** The non-existent issues. */
|
|
30
|
+
readonly issues?: undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The result interface if validation fails. */
|
|
34
|
+
export interface FailureResult {
|
|
35
|
+
/** The issues of failed validation. */
|
|
36
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The issue interface of the failure output. */
|
|
40
|
+
export interface Issue {
|
|
41
|
+
/** The error message of the issue. */
|
|
42
|
+
readonly message: string;
|
|
43
|
+
/** The path of the issue, if any. */
|
|
44
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The path segment interface of the issue. */
|
|
48
|
+
export interface PathSegment {
|
|
49
|
+
/** The key representing a path segment. */
|
|
50
|
+
readonly key: PropertyKey;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Standard Schema types interface. */
|
|
54
|
+
export interface Types<Input = unknown, Output = Input> {
|
|
55
|
+
/** The input type of the schema. */
|
|
56
|
+
readonly input: Input;
|
|
57
|
+
/** The output type of the schema. */
|
|
58
|
+
readonly output: Output;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Infers the input type of a Standard Schema. */
|
|
62
|
+
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<
|
|
63
|
+
Schema["~standard"]["types"]
|
|
64
|
+
>["input"];
|
|
65
|
+
|
|
66
|
+
/** Infers the output type of a Standard Schema. */
|
|
67
|
+
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<
|
|
68
|
+
Schema["~standard"]["types"]
|
|
69
|
+
>["output"];
|
|
70
|
+
}
|
package/src/Menu/Menu.torp
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ContextualContextName } from "../Contextual/ContextualTypes";
|
|
2
|
+
import { ModalContextName } from "../Modal/ModalTypes";
|
|
1
3
|
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
2
4
|
import {
|
|
3
5
|
MenuContextName,
|
|
@@ -7,6 +9,15 @@ import {
|
|
|
7
9
|
type MenuPopoutContext
|
|
8
10
|
} from "./MenuTypes";
|
|
9
11
|
|
|
12
|
+
interface MenuProps {
|
|
13
|
+
/** An ID for the root element */
|
|
14
|
+
id?: string;
|
|
15
|
+
/** Class name(s) for the root element */
|
|
16
|
+
class?: string,
|
|
17
|
+
/** An ARIA label for describing the menu to screen readers */
|
|
18
|
+
ariaLabel?: string,
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
/**
|
|
11
22
|
* A list of choices for the user, such as a set of actions or functions. A
|
|
12
23
|
* menu is usually hidden until made visible by the user.
|
|
@@ -17,27 +28,26 @@ import {
|
|
|
17
28
|
*
|
|
18
29
|
* ```
|
|
19
30
|
* <Menu>
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
31
|
+
* <MenuButton />
|
|
32
|
+
* <MenuSeparator /> (optional)
|
|
33
|
+
* <MenuGroup> (optional)
|
|
34
|
+
* <MenuButton />
|
|
35
|
+
* </MenuGroup>
|
|
25
36
|
* </Menu>
|
|
26
37
|
* ```
|
|
27
|
-
*
|
|
28
|
-
* @prop {string} ariaLabel -- An ARIA label for describing the menu to screen readers
|
|
29
38
|
*/
|
|
30
|
-
export default function Menu() {
|
|
39
|
+
export default function Menu($props: MenuProps | undefined) {
|
|
31
40
|
// A collection containing the state and some functions for each item
|
|
32
41
|
let itemStates: ItemState[] = [];
|
|
33
42
|
let focusIndex = -1;
|
|
34
43
|
|
|
35
44
|
// Get stuff out of the PopoverContext
|
|
36
|
-
|
|
45
|
+
// HACK: share state in PopupState and extend in context/modal/popover
|
|
46
|
+
const popoverContext = $context[ContextualContextName] ?? $context[ModalContextName] ?? $context[PopoverContextName] as PopoverContext;
|
|
37
47
|
if (!popoverContext) {
|
|
38
|
-
throw new Error("Menu must be contained within a
|
|
48
|
+
throw new Error("Menu must be contained within a Context, Modal or Popover");
|
|
39
49
|
}
|
|
40
|
-
const { setVisible, handleButton,
|
|
50
|
+
const { setVisible, handleButton, visible } = popoverContext;
|
|
41
51
|
|
|
42
52
|
// Check whether this is a menu in a popout
|
|
43
53
|
const popoutContext = $context[MenuPopoutContextName] as MenuPopoutContext;
|
|
@@ -68,7 +78,7 @@ export default function Menu() {
|
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
function registerItem(setFocused: () => void) {
|
|
71
|
-
// Add the item
|
|
81
|
+
// Add the item's state to the array and return its index
|
|
72
82
|
const newItemState: ItemState = {
|
|
73
83
|
setFocused
|
|
74
84
|
};
|
|
@@ -147,11 +157,11 @@ export default function Menu() {
|
|
|
147
157
|
|
|
148
158
|
@render {
|
|
149
159
|
<div
|
|
150
|
-
{$props
|
|
151
|
-
class={`torp-menu ${$props
|
|
160
|
+
{$props?.id}
|
|
161
|
+
class={`torp-menu ${$props?.class ?? ""}`.trim()}
|
|
152
162
|
tabindex="-1"
|
|
153
163
|
role="menu"
|
|
154
|
-
aria-label={$props
|
|
164
|
+
aria-label={$props?.ariaLabel}
|
|
155
165
|
aria-orientation="vertical"
|
|
156
166
|
>
|
|
157
167
|
<slot />
|
package/src/Menu/MenuButton.torp
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { MenuContextName, type MenuContext } from "./MenuTypes";
|
|
2
2
|
|
|
3
|
+
interface MenuButtonProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover */
|
|
9
|
+
value?: any,
|
|
10
|
+
/** Whether this button is disabled */
|
|
11
|
+
disabled?: boolean,
|
|
12
|
+
/** Raised when the button is clicked */
|
|
13
|
+
onclick?: (e: MouseEvent) => void,
|
|
14
|
+
/** Raised when a key is pressed down */
|
|
15
|
+
onkeydown?: (e: KeyboardEvent) => void,
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* A button that is placed in a Menu or MenuGroup and signals a response by a user.
|
|
5
20
|
*
|
|
6
|
-
* @prop {any} value -- The value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover
|
|
7
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
8
21
|
*/
|
|
9
|
-
export default function MenuButton() {
|
|
22
|
+
export default function MenuButton($props: MenuButtonProps | undefined) {
|
|
10
23
|
let button: HTMLButtonElement;
|
|
11
24
|
|
|
12
25
|
// Get stuff out of the MenuContext
|
|
@@ -19,14 +32,18 @@ export default function MenuButton() {
|
|
|
19
32
|
// Register this item with the parent Menu and store the index
|
|
20
33
|
const { index } = registerItem(setFocused);
|
|
21
34
|
|
|
22
|
-
function handleKeyDown(e) {
|
|
35
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
23
36
|
handleItemKey(e);
|
|
24
|
-
if ($props
|
|
37
|
+
if ($props?.onkeydown) {
|
|
38
|
+
$props.onkeydown(e);
|
|
39
|
+
}
|
|
25
40
|
}
|
|
26
41
|
|
|
27
|
-
function handleClick(e) {
|
|
28
|
-
handleButton($props
|
|
29
|
-
if ($props
|
|
42
|
+
function handleClick(e: MouseEvent) {
|
|
43
|
+
handleButton($props?.value);
|
|
44
|
+
if ($props?.onclick) {
|
|
45
|
+
$props.onclick(e);
|
|
46
|
+
}
|
|
30
47
|
}
|
|
31
48
|
|
|
32
49
|
function setFocused() {
|
|
@@ -35,13 +52,13 @@ export default function MenuButton() {
|
|
|
35
52
|
|
|
36
53
|
@render {
|
|
37
54
|
<button
|
|
38
|
-
{$props
|
|
39
|
-
class={`torp-menu-button ${$props
|
|
55
|
+
{$props?.id}
|
|
56
|
+
class={`torp-menu-button ${$props?.class ?? ""}`.trim()}
|
|
40
57
|
type="button"
|
|
41
|
-
{$props
|
|
58
|
+
{$props?.disabled}
|
|
42
59
|
role="menuitem"
|
|
43
|
-
aria-disabled={$props
|
|
44
|
-
data-disabled={$props
|
|
60
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
61
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
45
62
|
onkeydown={handleKeyDown}
|
|
46
63
|
onclick={handleClick}
|
|
47
64
|
onfocus={() => handleItemFocus(index)}
|
package/src/Menu/MenuCheck.torp
CHANGED
|
@@ -5,20 +5,33 @@ import {
|
|
|
5
5
|
type MenuContext
|
|
6
6
|
} from "./MenuTypes";
|
|
7
7
|
|
|
8
|
+
interface MenuCheckProps {
|
|
9
|
+
/** An ID for the root element */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Class name(s) for the root element */
|
|
12
|
+
class?: string,
|
|
13
|
+
/** Whether this item is checked */
|
|
14
|
+
checked?: boolean,
|
|
15
|
+
/** Whether this item is disabled */
|
|
16
|
+
disabled?: boolean,
|
|
17
|
+
/** Raised when the checkbox is clicked */
|
|
18
|
+
onclick?: (e: MouseEvent) => void,
|
|
19
|
+
}
|
|
20
|
+
|
|
8
21
|
/**
|
|
9
22
|
* A button that is placed in a Menu or MenuGroup to allow the user to turn an
|
|
10
23
|
* option on or off.
|
|
11
24
|
*
|
|
12
|
-
* @prop {boolean} checked -- Whether this item is checked
|
|
13
|
-
* @prop {boolean} disabled -- Whether this item is disabled
|
|
14
25
|
*/
|
|
15
|
-
export default function MenuCheck() {
|
|
26
|
+
export default function MenuCheck($props: MenuCheckProps | undefined) {
|
|
16
27
|
let $state = $watch({
|
|
17
|
-
checked: $props
|
|
28
|
+
checked: $props?.checked ?? false
|
|
18
29
|
});
|
|
19
30
|
|
|
20
31
|
$run(() => {
|
|
21
|
-
$props
|
|
32
|
+
if ($props !== undefined) {
|
|
33
|
+
$props.checked = $state.checked;
|
|
34
|
+
}
|
|
22
35
|
});
|
|
23
36
|
|
|
24
37
|
let button: HTMLButtonElement;
|
|
@@ -43,22 +56,24 @@ export default function MenuCheck() {
|
|
|
43
56
|
button.focus();
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
function handleClick() {
|
|
59
|
+
function handleClick(e: MouseEvent) {
|
|
47
60
|
$state.checked = !$state.checked;
|
|
48
|
-
if ($props
|
|
61
|
+
if ($props?.onclick) {
|
|
62
|
+
$props.onclick(e);
|
|
63
|
+
}
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
@render {
|
|
52
67
|
<button
|
|
53
|
-
{$props
|
|
54
|
-
class={`torp-menu-check ${$props
|
|
68
|
+
{$props?.id}
|
|
69
|
+
class={`torp-menu-check ${$props?.class ?? ""}`.trim()}
|
|
55
70
|
type="button"
|
|
56
|
-
{$props
|
|
71
|
+
{$props?.disabled}
|
|
57
72
|
role="menuitemcheckbox"
|
|
58
|
-
aria-checked={$props
|
|
59
|
-
aria-disabled={$props
|
|
60
|
-
data-state={$props
|
|
61
|
-
data-disabled={$props
|
|
73
|
+
aria-checked={$props?.checked ? "true" : "false"}
|
|
74
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
75
|
+
data-state={$props?.checked ? "checked" : "unchecked"}
|
|
76
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
62
77
|
onkeydown={handleItemKey}
|
|
63
78
|
onclick={handleClick}
|
|
64
79
|
onfocus={() => handleItemFocus(index)}
|
package/src/Menu/MenuGroup.torp
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
interface MenuGroupProps {
|
|
3
|
+
/** An ID for the root element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Class name(s) for the root element */
|
|
6
|
+
class?: string,
|
|
7
|
+
/** An ARIA label for describing the group to screen readers */
|
|
8
|
+
ariaLabel?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* A container for a logical group of menu items.
|
|
3
|
-
*
|
|
4
|
-
* @prop {string} ariaLabel -- An ARIA label for describing the group to screen readers
|
|
5
13
|
*/
|
|
6
|
-
export default function MenuGroup() {
|
|
14
|
+
export default function MenuGroup($props: MenuGroupProps | undefined) {
|
|
7
15
|
// TODO: Intercept the context to steal toggleItem??
|
|
8
16
|
|
|
9
17
|
@render {
|
|
10
18
|
<div
|
|
11
|
-
{$props
|
|
12
|
-
class={`torp-menu-group ${$props
|
|
19
|
+
{$props?.id}
|
|
20
|
+
class={`torp-menu-group ${$props?.class ?? ""}`.trim()}
|
|
13
21
|
role="group"
|
|
14
|
-
aria-label={$props
|
|
22
|
+
aria-label={$props?.ariaLabel}
|
|
15
23
|
>
|
|
16
24
|
<slot />
|
|
17
25
|
</div>
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { MenuButtonContextName, type MenuButtonContext } from "./MenuTypes";
|
|
2
2
|
|
|
3
|
+
interface MenuIndicatorProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether this item is disabled */
|
|
9
|
+
disabled?: boolean,
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* An indicator for a MenuCheck or MenuRadio component, which is displayed
|
|
5
14
|
* when the value of checked is true.
|
|
6
|
-
*
|
|
7
|
-
* @prop {boolean} disabled -- Whether this item is disabled
|
|
8
15
|
*/
|
|
9
|
-
export default function MenuIndicator() {
|
|
16
|
+
export default function MenuIndicator($props: MenuIndicatorProps | undefined) {
|
|
10
17
|
// Get stuff out of the MenuButtonContext
|
|
11
18
|
const context = $context[MenuButtonContextName] as MenuButtonContext;
|
|
12
19
|
if (!context) {
|
|
@@ -17,10 +24,10 @@ export default function MenuIndicator() {
|
|
|
17
24
|
@render {
|
|
18
25
|
@if ($state.checked) {
|
|
19
26
|
<div
|
|
20
|
-
{$props
|
|
21
|
-
class={`torp-menu-indicator ${$props
|
|
22
|
-
aria-disabled={$props
|
|
23
|
-
data-disabled={$props
|
|
27
|
+
{$props?.id}
|
|
28
|
+
class={`torp-menu-indicator ${$props?.class ?? ""}`.trim()}
|
|
29
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
30
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
24
31
|
>
|
|
25
32
|
<slot />
|
|
26
33
|
</div>
|
package/src/Menu/MenuPopout.torp
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { MenuPopoutContextName, type MenuPopoutContext } from "./MenuTypes";
|
|
2
2
|
|
|
3
|
+
interface MenuPopoutProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether the popout is visible */
|
|
9
|
+
visible?: boolean,
|
|
10
|
+
/** Raised when the popout is opened or closed */
|
|
11
|
+
ontoggle?: (open: boolean) => void,
|
|
12
|
+
/** Raised when the popout has opened */
|
|
13
|
+
onopen?: () => void,
|
|
14
|
+
/** Raised when the popout has closed */
|
|
15
|
+
onclose?: (result: any) => void,
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* A popout that is attached to a menu button and can be used to show a submenu.
|
|
5
20
|
*
|
|
@@ -7,21 +22,14 @@ import { MenuPopoutContextName, type MenuPopoutContext } from "./MenuTypes";
|
|
|
7
22
|
*
|
|
8
23
|
* ```
|
|
9
24
|
* <MenuPopout>
|
|
10
|
-
*
|
|
25
|
+
* <MenuPopoutTrigger /> (optional)
|
|
11
26
|
* <MenuPopoutContent />
|
|
12
27
|
* </MenuPopout>
|
|
13
28
|
* ```
|
|
14
|
-
*
|
|
15
|
-
* @prop {boolean} visible -- Whether the popout is visible
|
|
16
|
-
* @prop {(boolean) => void} ontoggle -- Called when the popout is opened or closed
|
|
17
|
-
* @prop {() => void} onopen -- Called when the popout has opened
|
|
18
|
-
* @prop {() => void} onclose -- Called when the popout has closed
|
|
19
29
|
*/
|
|
20
|
-
export default function MenuPopout($props) {
|
|
21
|
-
$props.visible ??= false;
|
|
22
|
-
|
|
30
|
+
export default function MenuPopout($props: MenuPopoutProps | undefined) {
|
|
23
31
|
let $state = $watch({
|
|
24
|
-
visible: $props
|
|
32
|
+
visible: $props?.visible ?? false
|
|
25
33
|
});
|
|
26
34
|
|
|
27
35
|
let result: any;
|
|
@@ -39,9 +47,9 @@ export default function MenuPopout($props) {
|
|
|
39
47
|
|
|
40
48
|
let firstToggle = true;
|
|
41
49
|
$run(() => {
|
|
42
|
-
const ontoggle = $props
|
|
43
|
-
const onopen = $props
|
|
44
|
-
const onclose = $props
|
|
50
|
+
const ontoggle = $props?.ontoggle;
|
|
51
|
+
const onopen = $props?.onopen;
|
|
52
|
+
const onclose = $props?.onclose;
|
|
45
53
|
const visible = $state.visible;
|
|
46
54
|
if (firstToggle) {
|
|
47
55
|
firstToggle = false;
|
|
@@ -61,8 +69,8 @@ export default function MenuPopout($props) {
|
|
|
61
69
|
|
|
62
70
|
@render {
|
|
63
71
|
<div
|
|
64
|
-
{$props
|
|
65
|
-
class={`torp-menu-popout ${$props
|
|
72
|
+
{$props?.id}
|
|
73
|
+
class={`torp-menu-popout ${$props?.class ?? ""}`.trim()}
|
|
66
74
|
onmouseleave={handleMouseLeave}
|
|
67
75
|
>
|
|
68
76
|
<slot />
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
3
3
|
import { MenuPopoutContextName, type MenuPopoutContext } from "./MenuTypes";
|
|
4
4
|
|
|
5
|
+
interface MenuPopoutContentProps {
|
|
6
|
+
/** An ID for the root element */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Class name(s) for the root element */
|
|
9
|
+
class?: string,
|
|
10
|
+
/** Where the popout will be shown, relative to the popout button */
|
|
11
|
+
side?: "top" | "right" | "bottom" | "left",
|
|
12
|
+
/** How the popout will be aligned, relative to the popout button */
|
|
13
|
+
alignment?: "start" | "center" | "end",
|
|
14
|
+
}
|
|
15
|
+
|
|
5
16
|
/**
|
|
6
17
|
* The content that is displayed for a MenuPopout when it is open.
|
|
7
|
-
*
|
|
8
|
-
* @prop {"top" | "right" | "bottom" | "left"} side -- Where the popout will be shown, relative to the popout button
|
|
9
|
-
* @prop {"start" | "center" | "end"} alignment -- How the popout will be aligned, relative to the popout button
|
|
10
18
|
*/
|
|
11
|
-
export default function MenuPopoutContent() {
|
|
12
|
-
$props.side ??= "right";
|
|
13
|
-
$props.alignment ??= "start";
|
|
14
|
-
|
|
19
|
+
export default function MenuPopoutContent($props: MenuPopoutContentProps | undefined) {
|
|
15
20
|
let div: HTMLDivElement;
|
|
16
21
|
let shown = false;
|
|
17
22
|
|
|
@@ -56,14 +61,16 @@ export default function MenuPopoutContent() {
|
|
|
56
61
|
throw new Error("MenuPopoutContent must have an anchor element");
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
let side = $props?.side ?? "right";
|
|
65
|
+
let alignment = $props?.alignment ?? "start";
|
|
66
|
+
setPopoverPosition(popoutContext.anchorElement, div, side, alignment);
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
@render {
|
|
63
70
|
@if ($state.visible) {
|
|
64
71
|
<div
|
|
65
|
-
{$props
|
|
66
|
-
class={`torp-menu-popout-content ${$props
|
|
72
|
+
{$props?.id}
|
|
73
|
+
class={`torp-menu-popout-content ${$props?.class ?? ""}`.trim()}
|
|
67
74
|
&ref={div}
|
|
68
75
|
onmount={show}
|
|
69
76
|
>
|