@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,22 @@
|
|
|
1
|
+
export const ModalContextName = "Modal";
|
|
2
|
+
|
|
3
|
+
/** The shared context for modal components (Contextual, Prompt and Modal) */
|
|
4
|
+
export interface ModalContext {
|
|
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: ModalState;
|
|
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 ModalState {
|
|
21
|
+
visible: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface ModalProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** Whether the modal is visible */
|
|
10
|
+
visible?: boolean,
|
|
11
|
+
/** A function to be called when the user selects a response */
|
|
12
|
+
callback?: ((value: any) => void),
|
|
13
|
+
/** Raised when the modal is opened or closed */
|
|
14
|
+
ontoggle?: (open: boolean) => void,
|
|
15
|
+
/** Raised when the modal has opened */
|
|
16
|
+
onopen?: () => void,
|
|
17
|
+
/** Raised when the modal has closed */
|
|
18
|
+
onclose?: (result: any) => void,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A modal window that can be used to show rich content or obtain information from a user.
|
|
23
|
+
*
|
|
24
|
+
* See [the WAI ARIA guidelines for Modals](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
|
|
25
|
+
*
|
|
26
|
+
* The structure of a Modal is:
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* <Modal>
|
|
30
|
+
* <ModalOverlay />
|
|
31
|
+
* <ModalTrigger /> (optional)
|
|
32
|
+
* <ModalContent />
|
|
33
|
+
* </Modal>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function Modal(
|
|
37
|
+
$parent: ParentNode,
|
|
38
|
+
$anchor: Node | null,
|
|
39
|
+
$props: ModalProps | undefined,
|
|
40
|
+
$context?: Record<PropertyKey, any>,
|
|
41
|
+
$slots?: Record<string, SlotRender>,
|
|
42
|
+
): void;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
interface ModalContentProps {
|
|
47
|
+
/** An ID for the root element */
|
|
48
|
+
id?: string;
|
|
49
|
+
/** Class name(s) for the root element */
|
|
50
|
+
class?: string,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The content that is displayed for a Modal when it is open, displayed
|
|
55
|
+
* alongside an element.
|
|
56
|
+
*/
|
|
57
|
+
declare function ModalContent(
|
|
58
|
+
$parent: ParentNode,
|
|
59
|
+
$anchor: Node | null,
|
|
60
|
+
$props: ModalContentProps | undefined,
|
|
61
|
+
$context?: Record<PropertyKey, any>,
|
|
62
|
+
$slots?: Record<string, SlotRender>,
|
|
63
|
+
): void;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
interface ModalOverlayProps {
|
|
68
|
+
/** An ID for the root element */
|
|
69
|
+
id?: string;
|
|
70
|
+
/** Class name(s) for the root element */
|
|
71
|
+
class?: string,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The background overlay for a modal popup component (e.g. Context, Dialog or Popover).
|
|
76
|
+
* Adding an overlay automatically sets the component's `modal` value to true.
|
|
77
|
+
*/
|
|
78
|
+
declare function ModalOverlay(
|
|
79
|
+
$parent: ParentNode,
|
|
80
|
+
$anchor: Node | null,
|
|
81
|
+
$props: ModalOverlayProps | undefined,
|
|
82
|
+
$context?: Record<PropertyKey, any>,
|
|
83
|
+
$slots?: Record<string, SlotRender>,
|
|
84
|
+
): void;
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
interface ModalTriggerProps {
|
|
89
|
+
/** An ID for the root element */
|
|
90
|
+
id?: string;
|
|
91
|
+
/** Class name(s) for the root element */
|
|
92
|
+
class?: string,
|
|
93
|
+
/** Whether the modal is activated by click/press or by hover **/
|
|
94
|
+
activation?: "press" | "hover"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The button that causes a Modal to appear or disappear.
|
|
99
|
+
*/
|
|
100
|
+
declare function ModalTrigger(
|
|
101
|
+
$parent: ParentNode,
|
|
102
|
+
$anchor: Node | null,
|
|
103
|
+
$props: ModalTriggerProps | undefined,
|
|
104
|
+
$context?: Record<PropertyKey, any>,
|
|
105
|
+
$slots?: Record<string, SlotRender>,
|
|
106
|
+
): void;
|
|
107
|
+
|
|
108
|
+
export { Modal, ModalContent, ModalOverlay, ModalTrigger };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/Modal/Modal.torp
|
|
2
|
+
import Modal_default from "./Modal.torp";
|
|
3
|
+
|
|
4
|
+
// src/Modal/ModalContent.torp
|
|
5
|
+
import ModalContent_default from "./ModalContent.torp";
|
|
6
|
+
|
|
7
|
+
// src/Modal/ModalOverlay.torp
|
|
8
|
+
import ModalOverlay_default from "./ModalOverlay.torp";
|
|
9
|
+
|
|
10
|
+
// src/Modal/ModalTrigger.torp
|
|
11
|
+
import ModalTrigger_default from "./ModalTrigger.torp";
|
|
12
|
+
|
|
13
|
+
// src/Modal/showModal.ts
|
|
14
|
+
function showModal(modal, props, target) {
|
|
15
|
+
modal(target || document.body, null, props);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/Modal/showPrompt.ts
|
|
19
|
+
function showPrompt(modal, props, target) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const allProps = Object.assign({}, props, { callback: resolve });
|
|
22
|
+
modal(target || document.body, null, allProps);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
Modal_default as Modal,
|
|
27
|
+
ModalContent_default as ModalContent,
|
|
28
|
+
ModalOverlay_default as ModalOverlay,
|
|
29
|
+
ModalTrigger_default as ModalTrigger,
|
|
30
|
+
showModal,
|
|
31
|
+
showPrompt
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Modal/showModal.ts","../../src/Modal/showPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline modal\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showModal(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Create the modal\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tmodal(target || document.body, null, props);\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code, and asynchronously returns the value selected by the user.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showPrompt(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<any> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the callback\n\t\tconst allProps = Object.assign({}, props, { callback: resolve });\n\n\t\t// Create the modal\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tmodal(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAUe,SAAR,UACN,OACA,OACA,QACO;AAGP,QAAM,UAAU,SAAS,MAAM,MAAM,KAAK;AAC3C;;;ACTe,SAAR,WACN,OACA,OACA,QACe;AACf,SAAO,IAAI,QAAQ,CAAC,YAAY;AAE/B,UAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,UAAU,QAAQ,CAAC;AAI/D,UAAM,UAAU,SAAS,MAAM,MAAM,QAAQ;AAAA,EAC9C,CAAC;AACF;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// TODO: Allow passing in a variable -- so that you can show an inline modal
|
|
2
|
+
import type { Component } from "@torpor/view";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shows a modal component in code.
|
|
6
|
+
* @param modal The modal component
|
|
7
|
+
* @param props The properties for the modal component
|
|
8
|
+
* @param target The target element to show the modal in
|
|
9
|
+
* @returns The value selected by the user
|
|
10
|
+
*/
|
|
11
|
+
export default function showModal(
|
|
12
|
+
modal: Component,
|
|
13
|
+
props?: Record<PropertyKey, any>,
|
|
14
|
+
target?: Element,
|
|
15
|
+
): void {
|
|
16
|
+
// Create the modal
|
|
17
|
+
// TODO: This needs to clean up after itself, like the mount methods do
|
|
18
|
+
modal(target || document.body, null, props);
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Component } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shows a modal component in code, and asynchronously returns the value selected by the user.
|
|
5
|
+
* @param modal The modal component
|
|
6
|
+
* @param props The properties for the modal component
|
|
7
|
+
* @param target The target element to show the modal in
|
|
8
|
+
* @returns The value selected by the user
|
|
9
|
+
*/
|
|
10
|
+
export default function showPrompt(
|
|
11
|
+
modal: Component,
|
|
12
|
+
props?: Record<PropertyKey, any>,
|
|
13
|
+
target?: Element,
|
|
14
|
+
): Promise<any> {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
// Add the promise as the callback
|
|
17
|
+
const allProps = Object.assign({}, props, { callback: resolve });
|
|
18
|
+
|
|
19
|
+
// Create the modal
|
|
20
|
+
// TODO: This needs to clean up after itself, like the use methods do
|
|
21
|
+
modal(target || document.body, null, allProps);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -6,6 +6,17 @@ import {
|
|
|
6
6
|
type NavMenuPopoutContext
|
|
7
7
|
} from "./NavMenuTypes";
|
|
8
8
|
|
|
9
|
+
interface NavMenuProps {
|
|
10
|
+
/** An ID for the root element */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Class name(s) for the root element */
|
|
13
|
+
class?: string,
|
|
14
|
+
/** An ARIA label for describing the menu to screen readers */
|
|
15
|
+
ariaLabel?: string | undefined,
|
|
16
|
+
/** The orientation of the menu, which affects keyboard navigation */
|
|
17
|
+
orientation?: "horizontal" | "vertical",
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
/**
|
|
10
21
|
* A list of links for navigating a website.
|
|
11
22
|
*
|
|
@@ -21,12 +32,9 @@ import {
|
|
|
21
32
|
* ...
|
|
22
33
|
* </NavMenu>
|
|
23
34
|
* ```
|
|
24
|
-
*
|
|
25
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the menu to screen readers
|
|
26
|
-
* @prop {"horizontal" | "vertical"} orientation -- The orientation of the menu, which affects keyboard navigation
|
|
27
35
|
*/
|
|
28
|
-
export default function NavMenu($props:
|
|
29
|
-
$props
|
|
36
|
+
export default function NavMenu($props: NavMenuProps | undefined) {
|
|
37
|
+
let orientation = $props?.orientation ?? "horizontal";
|
|
30
38
|
|
|
31
39
|
// A collection containing the state and some functions for each item
|
|
32
40
|
let itemStates: ItemState[] = [];
|
|
@@ -51,7 +59,7 @@ export default function NavMenu($props: any) {
|
|
|
51
59
|
$context[NavMenuContextName] = context;
|
|
52
60
|
|
|
53
61
|
// If the NavMenu is not in a popout, focus its first item. Otherwise the popout will call focusFirstElement, below
|
|
54
|
-
function handleFocus(
|
|
62
|
+
function handleFocus() {
|
|
55
63
|
if (!popoutContext && itemStates.length) {
|
|
56
64
|
itemStates[0].setFocused();
|
|
57
65
|
}
|
|
@@ -164,12 +172,12 @@ export default function NavMenu($props: any) {
|
|
|
164
172
|
|
|
165
173
|
@render {
|
|
166
174
|
<nav
|
|
167
|
-
{$props
|
|
168
|
-
class={`torp-nav-menu ${$props
|
|
175
|
+
{$props?.id}
|
|
176
|
+
class={`torp-nav-menu ${$props?.class ?? ""}`.trim()}
|
|
169
177
|
tabindex="0"
|
|
170
178
|
role="menubar"
|
|
171
|
-
aria-label={$props
|
|
172
|
-
aria-orientation={
|
|
179
|
+
aria-label={$props?.ariaLabel}
|
|
180
|
+
aria-orientation={orientation}
|
|
173
181
|
onfocus={handleFocus}
|
|
174
182
|
>
|
|
175
183
|
<slot />
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuButtonProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether this button is disabled */
|
|
9
|
+
disabled?: boolean,
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* A button that is placed in a NavMenu to carry out a non-navigation action such as logging out.
|
|
5
14
|
*
|
|
6
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
7
15
|
*/
|
|
8
|
-
export default function NavMenuButton($props:
|
|
9
|
-
/** Set when the item is disabled */
|
|
10
|
-
let dataDisabled = $props.disabled || undefined;
|
|
11
|
-
|
|
16
|
+
export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
|
|
12
17
|
let button: HTMLButtonElement;
|
|
13
18
|
|
|
14
19
|
// Get stuff out of the NavMenuContext
|
|
@@ -27,13 +32,13 @@ export default function NavMenuButton($props: any) {
|
|
|
27
32
|
|
|
28
33
|
@render {
|
|
29
34
|
<button
|
|
30
|
-
{$props
|
|
31
|
-
class={`torp-nav-menu-button ${$props
|
|
35
|
+
{$props?.id}
|
|
36
|
+
class={`torp-nav-menu-button ${$props?.class ?? ""}`.trim()}
|
|
32
37
|
type="button"
|
|
33
|
-
{$props
|
|
38
|
+
{$props?.disabled}
|
|
34
39
|
role="menuitem"
|
|
35
|
-
aria-disabled={$props
|
|
36
|
-
data-disabled={
|
|
40
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
41
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
37
42
|
onkeydown
|
|
38
43
|
onkeydown={handleItemKey}
|
|
39
44
|
onclick
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuElementProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether this button is disabled */
|
|
9
|
+
disabled?: boolean,
|
|
10
|
+
/** An element that can be focused via keyboard navigation */
|
|
11
|
+
element?: HTMLElement,
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* An element of any type that can be placed in a NavMenu.
|
|
5
16
|
*
|
|
6
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
7
|
-
* @prop {HTMLElement} element -- An element that can be focused via keyboard navigation
|
|
8
17
|
*/
|
|
9
|
-
export default function NavMenuElement($props:
|
|
10
|
-
/** Set when the item is disabled */
|
|
11
|
-
let dataDisabled = $props.disabled || undefined;
|
|
12
|
-
|
|
18
|
+
export default function NavMenuElement($props: NavMenuElementProps | undefined) {
|
|
13
19
|
// Get stuff out of the NavMenuContext
|
|
14
20
|
const menuContext = $context[NavMenuContextName] as NavMenuContext;
|
|
15
21
|
if (!menuContext) {
|
|
@@ -21,17 +27,19 @@ export default function NavMenuElement($props: any) {
|
|
|
21
27
|
const { index } = registerItem(setFocused);
|
|
22
28
|
|
|
23
29
|
function setFocused() {
|
|
24
|
-
element
|
|
30
|
+
if ($props?.element) {
|
|
31
|
+
$props.element.focus();
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
@render {
|
|
28
36
|
<div
|
|
29
|
-
{$props
|
|
30
|
-
class={`torp-nav-menu-div ${$props
|
|
37
|
+
{$props?.id}
|
|
38
|
+
class={`torp-nav-menu-div ${$props?.class ?? ""}`.trim()}
|
|
31
39
|
type="div"
|
|
32
40
|
role="menuitem"
|
|
33
|
-
aria-disabled={$props
|
|
34
|
-
data-disabled={
|
|
41
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
42
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
35
43
|
onkeydown
|
|
36
44
|
onkeydown={handleItemKey}
|
|
37
45
|
onclick
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuGroupProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** An ARIA label for describing the group to screen readers */
|
|
9
|
+
ariaLabel?: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* A container for a logical group of navigation menu items.
|
|
5
|
-
*
|
|
6
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the group to screen readers
|
|
7
14
|
*/
|
|
8
|
-
export default function NavMenuGroup($props:
|
|
15
|
+
export default function NavMenuGroup($props: NavMenuGroupProps | undefined) {
|
|
9
16
|
let $state = $watch({
|
|
10
17
|
headerId: ""
|
|
11
18
|
});
|
|
@@ -18,10 +25,10 @@ export default function NavMenuGroup($props: any) {
|
|
|
18
25
|
|
|
19
26
|
@render {
|
|
20
27
|
<div
|
|
21
|
-
{$props
|
|
22
|
-
class={`torp-nav-menu-group ${$props
|
|
28
|
+
{$props?.id}
|
|
29
|
+
class={`torp-nav-menu-group ${$props?.class ?? ""}`.trim()}
|
|
23
30
|
role="group"
|
|
24
|
-
aria-label={$props
|
|
31
|
+
aria-label={$props?.ariaLabel}
|
|
25
32
|
aria-labelledby={$state.headerId}
|
|
26
33
|
>
|
|
27
34
|
<slot />
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
|
+
interface NavMenuGroupHeaderProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The type of HTML header to use */
|
|
10
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* The header for a NavMenuGroup.
|
|
6
|
-
*
|
|
7
|
-
* @prop {"h1" | "h2" | "h3" | "h4" | "h5" | "h6"} as -- The type of HTML header to use
|
|
8
15
|
*/
|
|
9
|
-
export default function NavMenuGroupHeader($props:
|
|
10
|
-
|
|
16
|
+
export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps | undefined) {
|
|
17
|
+
let defaultId = getId();
|
|
11
18
|
|
|
12
19
|
const context = $context[NavMenuGroupContextName] as NavMenuGroupContext;
|
|
13
20
|
if (!context) {
|
|
@@ -16,13 +23,13 @@ export default function NavMenuGroupHeader($props: any) {
|
|
|
16
23
|
let $state = context.state;
|
|
17
24
|
|
|
18
25
|
// Set the header ID now that we know what it is
|
|
19
|
-
$state.headerId = $props
|
|
26
|
+
$state.headerId = $props?.id ?? defaultId;
|
|
20
27
|
|
|
21
28
|
@render {
|
|
29
|
+
@// TODO: self={$props.as}
|
|
22
30
|
<h4
|
|
23
|
-
|
|
24
|
-
{$props
|
|
25
|
-
class={`torp-nav-menu-group-header ${$props.class ?? ""}`.trim()}
|
|
31
|
+
id={$props?.id ?? defaultId}
|
|
32
|
+
class={`torp-nav-menu-group-header ${$props?.class ?? ""}`.trim()}
|
|
26
33
|
>
|
|
27
34
|
<slot />
|
|
28
35
|
</h4>
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
|
|
2
2
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
|
+
interface NavMenuLinkProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The URL for the menu link */
|
|
10
|
+
href: string,
|
|
11
|
+
/** Whether the menu link should open in a new tab/window */
|
|
12
|
+
newWindow?: boolean,
|
|
13
|
+
/** Whether this link is disabled */
|
|
14
|
+
disabled?: boolean,
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
/**
|
|
5
18
|
* A link that is placed in a NavMenu and signals a response by a user.
|
|
6
19
|
*
|
|
7
|
-
* @prop {string} href -- The URL for the menu link
|
|
8
|
-
* @prop {newWindow} boolean -- Whether the menu link should open in a new tab/window
|
|
9
|
-
* @prop {boolean} disabled -- Whether this link is disabled
|
|
10
20
|
*/
|
|
11
|
-
export default function NavMenuLink($props:
|
|
12
|
-
$props.newWindow ??= false;
|
|
13
|
-
|
|
14
|
-
/** Set when the item is disabled */
|
|
15
|
-
let dataDisabled = $props.disabled || undefined;
|
|
16
|
-
|
|
21
|
+
export default function NavMenuLink($props: NavMenuLinkProps | undefined) {
|
|
17
22
|
let link: HTMLAnchorElement;
|
|
18
23
|
|
|
19
24
|
// Get stuff out of the NavMenuContext
|
|
@@ -32,14 +37,14 @@ export default function NavMenuLink($props: any) {
|
|
|
32
37
|
|
|
33
38
|
@render {
|
|
34
39
|
<a
|
|
35
|
-
{$props
|
|
36
|
-
class={`torp-nav-menu-link ${$props
|
|
37
|
-
|
|
38
|
-
{$props
|
|
39
|
-
target={$props
|
|
40
|
+
{$props?.id}
|
|
41
|
+
class={`torp-nav-menu-link ${$props?.class ?? ""}`.trim()}
|
|
42
|
+
{$props?.href}
|
|
43
|
+
{$props?.disabled}
|
|
44
|
+
target={$props?.newWindow ? "_blank" : undefined}
|
|
40
45
|
role="menuitem"
|
|
41
|
-
aria-disabled={$props
|
|
42
|
-
data-disabled={
|
|
46
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
47
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
43
48
|
onkeydown
|
|
44
49
|
onkeydown={handleItemKey}
|
|
45
50
|
onclick
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuPopoutProps {
|
|
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,18 +22,24 @@ import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTy
|
|
|
7
22
|
*
|
|
8
23
|
* ```
|
|
9
24
|
* <NavMenuPopout>
|
|
10
|
-
*
|
|
25
|
+
* <NavMenuPopoutButton />
|
|
11
26
|
* <NavMenuPopoutContent />
|
|
12
27
|
* </NavMenuPopout>
|
|
13
28
|
* ```
|
|
14
|
-
*
|
|
15
|
-
* @prop {boolean} visible -- Whether the popout is visible
|
|
16
29
|
*/
|
|
17
|
-
export default function NavMenuPopout($props:
|
|
18
|
-
$props.visible ??= false;
|
|
19
|
-
|
|
30
|
+
export default function NavMenuPopout($props: NavMenuPopoutProps | undefined) {
|
|
20
31
|
let $state = $watch({
|
|
21
|
-
visible:
|
|
32
|
+
visible: false
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Sync props and state
|
|
36
|
+
$run(() => {
|
|
37
|
+
$state.visible = $props?.visible ?? false;
|
|
38
|
+
});
|
|
39
|
+
$run(() => {
|
|
40
|
+
if ($props !== undefined) {
|
|
41
|
+
$props.visible = $state.visible;
|
|
42
|
+
}
|
|
22
43
|
});
|
|
23
44
|
|
|
24
45
|
let result: any;
|
|
@@ -29,18 +50,13 @@ export default function NavMenuPopout($props: any) {
|
|
|
29
50
|
};
|
|
30
51
|
$context[NavMenuPopoutContextName] = context;
|
|
31
52
|
|
|
32
|
-
// Copy props into state whenever they change
|
|
33
|
-
$run(() => {
|
|
34
|
-
$state.visible = $props.visible ?? false;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
53
|
// Dispatch the toggle event when the popout is opened or closed
|
|
38
54
|
let firstToggle = true;
|
|
39
55
|
$run(() => {
|
|
40
|
-
const ontoggle = $props
|
|
41
|
-
const onopen = $props
|
|
42
|
-
const onclose = $props
|
|
43
|
-
const visible = $
|
|
56
|
+
const ontoggle = $props?.ontoggle;
|
|
57
|
+
const onopen = $props?.onopen;
|
|
58
|
+
const onclose = $props?.onclose;
|
|
59
|
+
const visible = $state.visible;
|
|
44
60
|
if (firstToggle) {
|
|
45
61
|
firstToggle = false;
|
|
46
62
|
} else {
|
|
@@ -59,8 +75,8 @@ export default function NavMenuPopout($props: any) {
|
|
|
59
75
|
|
|
60
76
|
@render {
|
|
61
77
|
<div
|
|
62
|
-
{$props
|
|
63
|
-
class={`torp-nav-menu-popout ${$props
|
|
78
|
+
{$props?.id}
|
|
79
|
+
class={`torp-nav-menu-popout ${$props?.class ?? ""}`.trim()}
|
|
64
80
|
onmouseleave={handleMouseLeave}
|
|
65
81
|
>
|
|
66
82
|
<slot />
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import {
|
|
3
2
|
NavMenuContextName,
|
|
4
3
|
NavMenuPopoutContextName,
|
|
@@ -6,17 +5,23 @@ import {
|
|
|
6
5
|
type NavMenuPopoutContext,
|
|
7
6
|
} from "./NavMenuTypes";
|
|
8
7
|
|
|
8
|
+
interface NavMenuPopoutButtonProps {
|
|
9
|
+
/** An ID for the root element */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Class name(s) for the root element */
|
|
12
|
+
class?: string,
|
|
13
|
+
/** The delay before showing the popout, in milliseconds */
|
|
14
|
+
hoverDelay?: number,
|
|
15
|
+
/** Whether this button is disabled */
|
|
16
|
+
disabled?: boolean,
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
/**
|
|
10
20
|
* A button that is placed in a NavMenu and signals a response by a user.
|
|
11
21
|
*
|
|
12
|
-
* @prop {number} hoverDelay -- The delay before showing the popout, in milliseconds
|
|
13
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
14
22
|
*/
|
|
15
|
-
export default function NavMenuPopoutButton($props:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** Set when the item is disabled */
|
|
19
|
-
let dataDisabled = $props.disabled || undefined;
|
|
23
|
+
export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps | undefined) {
|
|
24
|
+
let defaultHoverDelay = 500;
|
|
20
25
|
|
|
21
26
|
let button: HTMLButtonElement;
|
|
22
27
|
let interval: NodeJS.Timeout | undefined;
|
|
@@ -66,16 +71,16 @@ export default function NavMenuPopoutButton($props: any) {
|
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
function handleMouseEnter() {
|
|
69
|
-
if ($props
|
|
74
|
+
if ($props?.disabled) return;
|
|
70
75
|
|
|
71
76
|
// Handle the hover after a delay
|
|
72
77
|
if (!interval) {
|
|
73
|
-
interval = setTimeout(() => $state.visible = true, $props
|
|
78
|
+
interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
function handleMouseLeave() {
|
|
78
|
-
if ($props
|
|
83
|
+
if ($props?.disabled) return;
|
|
79
84
|
|
|
80
85
|
// Prevent short hovers or touches from firing the event
|
|
81
86
|
if (interval) {
|
|
@@ -85,26 +90,26 @@ export default function NavMenuPopoutButton($props: any) {
|
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
function handleMouseMove() {
|
|
88
|
-
if ($props
|
|
93
|
+
if ($props?.disabled) return;
|
|
89
94
|
|
|
90
95
|
// Reset the interval on mouse move
|
|
91
96
|
if (interval) {
|
|
92
97
|
clearTimeout(interval);
|
|
93
|
-
interval = setTimeout(() => $state.visible = true, $props
|
|
98
|
+
interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
@render {
|
|
98
103
|
<button
|
|
99
|
-
{$props
|
|
100
|
-
class={`torp-nav-menu-popout-button ${$props
|
|
104
|
+
{$props?.id}
|
|
105
|
+
class={`torp-nav-menu-popout-button ${$props?.class ?? ""}`.trim()}
|
|
101
106
|
type="button"
|
|
102
|
-
{$props
|
|
107
|
+
{$props?.disabled}
|
|
103
108
|
role="menuitem"
|
|
104
109
|
aria-haspopup="true"
|
|
105
110
|
aria-expanded={$state.visible.toString()}
|
|
106
|
-
aria-disabled={$props
|
|
107
|
-
data-disabled={
|
|
111
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
112
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
108
113
|
onkeydown={handlePopoutKey}
|
|
109
114
|
onclick={handleClick}
|
|
110
115
|
onfocus={() => handleItemFocus(index)}
|