@torpor/ui 0.2.1 → 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 +23 -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/Field.torp +2 -4
- package/dist/Form/Form.torp +7 -9
- package/dist/Form/Input.torp +20 -17
- package/dist/Form/Label.torp +1 -1
- package/dist/Form/Message.torp +1 -1
- package/dist/Form/index.d.ts +18 -4
- 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/Field.torp +2 -4
- package/src/Form/Form.torp +7 -9
- package/src/Form/Input.torp +20 -17
- package/src/Form/Label.torp +1 -1
- package/src/Form/Message.torp +1 -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
|
@@ -21,11 +21,7 @@ interface MenuBarItemContentProps {
|
|
|
21
21
|
/**
|
|
22
22
|
* The content that is displayed for a MenuBarItem when it is open.
|
|
23
23
|
*/
|
|
24
|
-
export default function MenuBarItemContent($props: MenuBarItemContentProps) {
|
|
25
|
-
$props ??= $watch({});
|
|
26
|
-
$props.side ??= "bottom";
|
|
27
|
-
$props.alignment ??= "start";
|
|
28
|
-
|
|
24
|
+
export default function MenuBarItemContent($props: MenuBarItemContentProps | undefined) {
|
|
29
25
|
let div: HTMLDivElement;
|
|
30
26
|
let closeOnClick = false;
|
|
31
27
|
let shown = false;
|
|
@@ -89,7 +85,7 @@ export default function MenuBarItemContent($props: MenuBarItemContentProps) {
|
|
|
89
85
|
|
|
90
86
|
function handleDocumentClick(e: MouseEvent) {
|
|
91
87
|
if (closeOnClick && !div.contains(e.target as HTMLElement)) {
|
|
92
|
-
context.active = false;
|
|
88
|
+
//context.active = false;
|
|
93
89
|
setVisible(false);
|
|
94
90
|
}
|
|
95
91
|
}
|
|
@@ -99,14 +95,16 @@ export default function MenuBarItemContent($props: MenuBarItemContentProps) {
|
|
|
99
95
|
throw new Error("MenuBarItemContent must have an anchor element");
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
|
|
98
|
+
let side = $props?.side ?? "bottom";
|
|
99
|
+
let alignment = $props?.alignment ?? "start";
|
|
100
|
+
setPopoverPosition(itemContext.anchorElement, div, side, alignment);
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
@render {
|
|
106
104
|
@if ($state.visible) {
|
|
107
105
|
<div
|
|
108
|
-
{$props
|
|
109
|
-
class={`torp-menu-bar-item-content ${$props
|
|
106
|
+
{$props?.id}
|
|
107
|
+
class={`torp-menu-bar-item-content ${$props?.class ?? ""}`.trim()}
|
|
110
108
|
&ref={div}
|
|
111
109
|
onmount={show}
|
|
112
110
|
>
|
|
@@ -18,10 +18,7 @@ interface MenuBarItemTriggerProps {
|
|
|
18
18
|
* A button that is placed in a MenuBar and opens a submenu.
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps) {
|
|
22
|
-
$props ??= $watch({});
|
|
23
|
-
$props.disabled ??= false;
|
|
24
|
-
|
|
21
|
+
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | undefined) {
|
|
25
22
|
let button: HTMLButtonElement;
|
|
26
23
|
|
|
27
24
|
// Get stuff out of the MenuBarContext
|
|
@@ -76,15 +73,15 @@ export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps) {
|
|
|
76
73
|
|
|
77
74
|
@render {
|
|
78
75
|
<button
|
|
79
|
-
{$props
|
|
80
|
-
class={`torp-menu-bar-item-button ${$props
|
|
76
|
+
{$props?.id}
|
|
77
|
+
class={`torp-menu-bar-item-button ${$props?.class ?? ""}`.trim()}
|
|
81
78
|
type="button"
|
|
82
|
-
{$props
|
|
79
|
+
{$props?.disabled}
|
|
83
80
|
role="menuitem"
|
|
84
81
|
aria-haspopup="true"
|
|
85
82
|
aria-expanded={($state.visible ?? false).toString()}
|
|
86
|
-
aria-disabled={$props
|
|
87
|
-
data-disabled={$props
|
|
83
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
84
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
88
85
|
onkeydown={handleKey}
|
|
89
86
|
onclick={handleClick}
|
|
90
87
|
onfocus={() => handleButtonFocus(index)}
|
package/dist/MenuBar/index.d.ts
CHANGED
|
@@ -21,19 +21,19 @@ interface MenuBarProps {
|
|
|
21
21
|
*
|
|
22
22
|
* ```
|
|
23
23
|
* <MenuBar>
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
24
|
+
* <MenuBarItem>
|
|
25
|
+
* <MenuBarItemTrigger />
|
|
26
|
+
* <MenuBarItemContent>
|
|
27
|
+
* <Menu />
|
|
28
|
+
* </MenuBarItemContent>
|
|
29
|
+
* </MenuBarItem>
|
|
30
30
|
* </MenuBar>
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare function MenuBar(
|
|
34
34
|
$parent: ParentNode,
|
|
35
35
|
$anchor: Node | null,
|
|
36
|
-
$props: MenuBarProps,
|
|
36
|
+
$props: MenuBarProps | undefined,
|
|
37
37
|
$context?: Record<PropertyKey, any>,
|
|
38
38
|
$slots?: Record<string, SlotRender>,
|
|
39
39
|
): void;
|
|
@@ -47,12 +47,12 @@ interface MenuBarItemProps {
|
|
|
47
47
|
class?: string,
|
|
48
48
|
/** Whether the item is visible */
|
|
49
49
|
visible?: boolean,
|
|
50
|
-
/**
|
|
50
|
+
/** Raised when the item is opened or closed */
|
|
51
51
|
ontoggle?: (visible: boolean) => void,
|
|
52
|
-
/**
|
|
52
|
+
/** Raised when the item has opened */
|
|
53
53
|
onopen?: () => void,
|
|
54
|
-
/**
|
|
55
|
-
onclose?: () => void,
|
|
54
|
+
/** Raised when the item has closed */
|
|
55
|
+
onclose?: (result: any) => void,
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -62,15 +62,15 @@ interface MenuBarItemProps {
|
|
|
62
62
|
*
|
|
63
63
|
* ```
|
|
64
64
|
* <MenuBarItem>
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* <MenuBarItemTrigger /> (optional)
|
|
66
|
+
* <MenuBarItemContent />
|
|
67
67
|
* </MenuBarItem>
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
declare function MenuBarItem(
|
|
71
71
|
$parent: ParentNode,
|
|
72
72
|
$anchor: Node | null,
|
|
73
|
-
$props: MenuBarItemProps,
|
|
73
|
+
$props: MenuBarItemProps | undefined,
|
|
74
74
|
$context?: Record<PropertyKey, any>,
|
|
75
75
|
$slots?: Record<string, SlotRender>,
|
|
76
76
|
): void;
|
|
@@ -94,7 +94,7 @@ interface MenuBarItemContentProps {
|
|
|
94
94
|
declare function MenuBarItemContent(
|
|
95
95
|
$parent: ParentNode,
|
|
96
96
|
$anchor: Node | null,
|
|
97
|
-
$props: MenuBarItemContentProps,
|
|
97
|
+
$props: MenuBarItemContentProps | undefined,
|
|
98
98
|
$context?: Record<PropertyKey, any>,
|
|
99
99
|
$slots?: Record<string, SlotRender>,
|
|
100
100
|
): void;
|
|
@@ -117,7 +117,7 @@ interface MenuBarItemTriggerProps {
|
|
|
117
117
|
declare function MenuBarItemTrigger(
|
|
118
118
|
$parent: ParentNode,
|
|
119
119
|
$anchor: Node | null,
|
|
120
|
-
$props: MenuBarItemTriggerProps,
|
|
120
|
+
$props: MenuBarItemTriggerProps | undefined,
|
|
121
121
|
$context?: Record<PropertyKey, any>,
|
|
122
122
|
$slots?: Record<string, SlotRender>,
|
|
123
123
|
): void;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ModalContextName, type ModalContext, type ModalState } from "./ModalTypes";
|
|
2
|
+
|
|
3
|
+
interface ModalProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether the modal is visible */
|
|
9
|
+
visible?: boolean,
|
|
10
|
+
/** A function to be called when the user selects a response */
|
|
11
|
+
callback?: ((value: any) => void),
|
|
12
|
+
/** Raised when the modal is opened or closed */
|
|
13
|
+
ontoggle?: (open: boolean) => void,
|
|
14
|
+
/** Raised when the modal has opened */
|
|
15
|
+
onopen?: () => void,
|
|
16
|
+
/** Raised when the modal has closed */
|
|
17
|
+
onclose?: (result: any) => void,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A modal window that can be used to show rich content or obtain information from a user.
|
|
22
|
+
*
|
|
23
|
+
* See [the WAI ARIA guidelines for Modals](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
|
|
24
|
+
*
|
|
25
|
+
* The structure of a Modal is:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* <Modal>
|
|
29
|
+
* <ModalOverlay />
|
|
30
|
+
* <ModalTrigger /> (optional)
|
|
31
|
+
* <ModalContent />
|
|
32
|
+
* </Modal>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export default function Modal($props: ModalProps | undefined) {
|
|
36
|
+
let $state: ModalState = $watch({
|
|
37
|
+
visible: false,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Sync props and state
|
|
41
|
+
$run(() => {
|
|
42
|
+
$state.visible = $props?.visible ?? false;
|
|
43
|
+
});
|
|
44
|
+
$run(() => {
|
|
45
|
+
if ($props !== undefined) {
|
|
46
|
+
$props.visible = $state.visible;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let result: any;
|
|
51
|
+
|
|
52
|
+
// Set the context to pass down to items
|
|
53
|
+
let context: ModalContext = {
|
|
54
|
+
handleButton,
|
|
55
|
+
handleClickOutside,
|
|
56
|
+
state: $state,
|
|
57
|
+
};
|
|
58
|
+
$context[ModalContextName] = context;
|
|
59
|
+
|
|
60
|
+
// Dispatch the toggle event when the modal is opened or closed
|
|
61
|
+
let firstToggle = true;
|
|
62
|
+
$run(() => {
|
|
63
|
+
const ontoggle = $props?.ontoggle;
|
|
64
|
+
const onopen = $props?.onopen;
|
|
65
|
+
const onclose = $props?.onclose;
|
|
66
|
+
const visible = $state.visible;
|
|
67
|
+
if (firstToggle) {
|
|
68
|
+
firstToggle = false;
|
|
69
|
+
} else {
|
|
70
|
+
if (ontoggle) ontoggle(visible);
|
|
71
|
+
if (visible) {
|
|
72
|
+
if (onopen) onopen()
|
|
73
|
+
} else {
|
|
74
|
+
if (onclose) onclose(result);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
80
|
+
// Get the button's result
|
|
81
|
+
switch (type) {
|
|
82
|
+
case "confirm": {
|
|
83
|
+
result = value || true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case "cancel": {
|
|
87
|
+
result = value || false;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
91
|
+
result = value;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Hide the modal
|
|
97
|
+
$state.visible = false;
|
|
98
|
+
|
|
99
|
+
// Call the callback
|
|
100
|
+
if ($props?.callback) {
|
|
101
|
+
$props?.callback(result);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function handleClickOutside(e: MouseEvent) {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
$state.visible = false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@render {
|
|
111
|
+
<div
|
|
112
|
+
{$props?.id}
|
|
113
|
+
class={`torp-modal ${$props?.class ?? ""}`.trim()}
|
|
114
|
+
>
|
|
115
|
+
<slot />
|
|
116
|
+
</div>
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
2
|
+
import { ModalContextName, type ModalContext } from "./ModalTypes";
|
|
3
|
+
|
|
4
|
+
interface ModalContentProps {
|
|
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 content that is displayed for a Modal when it is open, displayed
|
|
13
|
+
* alongside an element.
|
|
14
|
+
*/
|
|
15
|
+
export default function ModalContent($props: ModalContentProps | undefined) {
|
|
16
|
+
let div: HTMLDivElement;
|
|
17
|
+
let shown = false;
|
|
18
|
+
let closeOnClick = false;
|
|
19
|
+
|
|
20
|
+
// Get stuff out of the ModalContext
|
|
21
|
+
const context = $context[ModalContextName] as ModalContext;
|
|
22
|
+
if (!context) {
|
|
23
|
+
throw new Error("ModalContent must be contained within a Modal");
|
|
24
|
+
}
|
|
25
|
+
let $state = context.state;
|
|
26
|
+
|
|
27
|
+
$run(() => {
|
|
28
|
+
if (!$state.visible) {
|
|
29
|
+
hide();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function show() {
|
|
34
|
+
shown = true;
|
|
35
|
+
|
|
36
|
+
// HACK: Because this Modal could be shown with a click, we need to wait for another mousedown
|
|
37
|
+
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
38
|
+
closeOnClick = false;
|
|
39
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
40
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hide() {
|
|
44
|
+
if (!shown) return;
|
|
45
|
+
|
|
46
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
47
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleDocumentMouseDown() {
|
|
51
|
+
closeOnClick = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function handleDocumentClick(e: MouseEvent) {
|
|
55
|
+
if (
|
|
56
|
+
closeOnClick &&
|
|
57
|
+
div &&
|
|
58
|
+
!div.contains(e.target as HTMLElement)
|
|
59
|
+
) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
context.handleClickOutside!(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@render {
|
|
66
|
+
@if ($state.visible) {
|
|
67
|
+
<div
|
|
68
|
+
{$props?.id}
|
|
69
|
+
class={`torp-modal-content ${$props?.class ?? ""}`.trim()}
|
|
70
|
+
&ref={div}
|
|
71
|
+
onmount={show}
|
|
72
|
+
>
|
|
73
|
+
<slot />
|
|
74
|
+
</div>
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { disableScroll } from "../mount/disableScroll";
|
|
2
|
+
import { ModalContextName, type ModalContext } from "./ModalTypes";
|
|
3
|
+
|
|
4
|
+
interface ModalOverlayProps {
|
|
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 modal popup component (e.g. Context, Dialog or Popover).
|
|
13
|
+
* Adding an overlay automatically sets the component's `modal` value to true.
|
|
14
|
+
*/
|
|
15
|
+
export default function ModalOverlay($props: ModalOverlayProps | undefined) {
|
|
16
|
+
// Get stuff out of the ModalContext
|
|
17
|
+
const context = $context[ModalContextName] as ModalContext;
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error("ModalOverlay must be contained within a Modal");
|
|
20
|
+
}
|
|
21
|
+
let $state = context.state;
|
|
22
|
+
|
|
23
|
+
// Any popup with an overlay is modal
|
|
24
|
+
$state.modal = true;
|
|
25
|
+
|
|
26
|
+
@render {
|
|
27
|
+
@if ($state.visible) {
|
|
28
|
+
<div
|
|
29
|
+
{$props?.id}
|
|
30
|
+
class={`torp-modal-overlay ${$props?.class ?? ""}`.trim()}
|
|
31
|
+
tabindex="-1"
|
|
32
|
+
onmount={(el) => disableScroll(el)}
|
|
33
|
+
>
|
|
34
|
+
<slot />
|
|
35
|
+
</div>
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ModalContextName, type ModalContext } from "./ModalTypes";
|
|
2
|
+
import hoverTrigger from "../mount/hoverTrigger";
|
|
3
|
+
|
|
4
|
+
interface ModalTriggerProps {
|
|
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 activated by click/press or by hover **/
|
|
10
|
+
activation?: "press" | "hover"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The button that causes a Modal to appear or disappear.
|
|
15
|
+
*/
|
|
16
|
+
export default function ModalTrigger($props: ModalTriggerProps | undefined) {
|
|
17
|
+
let activation = $props?.activation ?? "press";
|
|
18
|
+
|
|
19
|
+
// Get stuff out of the ModalContext
|
|
20
|
+
const context = $context[ModalContextName] as ModalContext;
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error("ModalTrigger must be contained within a Modal");
|
|
23
|
+
}
|
|
24
|
+
let $state = context.state;
|
|
25
|
+
|
|
26
|
+
function handleClick() {
|
|
27
|
+
if (activation !== "press") return;
|
|
28
|
+
|
|
29
|
+
$state.visible = !$state.visible;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function handleHover() {
|
|
33
|
+
if (activation !== "hover") return;
|
|
34
|
+
|
|
35
|
+
$state.visible = !$state.visible
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@render {
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
{$props?.id}
|
|
42
|
+
class={`torp-modal-trigger ${$props?.class ?? ""}`.trim()}
|
|
43
|
+
onclick={handleClick}
|
|
44
|
+
onmount={(el) => hoverTrigger(el, { onHover: handleHover, onExit: handleHover })}
|
|
45
|
+
&ref={context.anchorElement}
|
|
46
|
+
>
|
|
47
|
+
<slot />
|
|
48
|
+
</button>
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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
|
+
}
|