@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
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { MenuBarContextName, type MenuBarContext, type ItemState } from "./MenuBarTypes";
|
|
2
2
|
|
|
3
|
+
interface MenuBarProps {
|
|
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 menu to screen readers */
|
|
9
|
+
ariaLabel?: string,
|
|
10
|
+
/** The orientation of the menu, which affects keyboard navigation */
|
|
11
|
+
orientation?: "horizontal" | "vertical",
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* A menu bar, similar to that shown at the top of Windows applications or at the top of the screen on Macs.
|
|
5
16
|
*
|
|
@@ -9,20 +20,17 @@ import { MenuBarContextName, type MenuBarContext, type ItemState } from "./MenuB
|
|
|
9
20
|
*
|
|
10
21
|
* ```
|
|
11
22
|
* <MenuBar>
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* <MenuBarItem>
|
|
24
|
+
* <MenuBarItemTrigger />
|
|
25
|
+
* <MenuBarItemContent>
|
|
26
|
+
* <Menu />
|
|
27
|
+
* </MenuBarItemContent>
|
|
28
|
+
* </MenuBarItem>
|
|
18
29
|
* </MenuBar>
|
|
19
30
|
* ```
|
|
20
|
-
*
|
|
21
|
-
* @prop {string} ariaLabel -- An ARIA label for describing the menu to screen readers
|
|
22
|
-
* @prop {"horizontal" | "vertical"} orientation -- The orientation of the menu, which affects keyboard navigation
|
|
23
31
|
*/
|
|
24
|
-
export default function MenuBar() {
|
|
25
|
-
$props
|
|
32
|
+
export default function MenuBar($props: MenuBarProps | undefined) {
|
|
33
|
+
let orientation = $props?.orientation ?? "horizontal";
|
|
26
34
|
|
|
27
35
|
let $state = $watch({
|
|
28
36
|
active: false,
|
|
@@ -43,7 +51,7 @@ export default function MenuBar() {
|
|
|
43
51
|
$context[MenuBarContextName] = context;
|
|
44
52
|
|
|
45
53
|
function registerItem(setVisible: (value: boolean) => void, setFocused: () => void) {
|
|
46
|
-
// Add the item
|
|
54
|
+
// Add the item's state to the array and return its index
|
|
47
55
|
const newItemState: ItemState = {
|
|
48
56
|
setVisible,
|
|
49
57
|
setFocused
|
|
@@ -137,12 +145,12 @@ export default function MenuBar() {
|
|
|
137
145
|
|
|
138
146
|
@render {
|
|
139
147
|
<div
|
|
140
|
-
{$props
|
|
141
|
-
class={`torp-menu-bar ${$props
|
|
148
|
+
{$props?.id}
|
|
149
|
+
class={`torp-menu-bar ${$props?.class ?? ""}`.trim()}
|
|
142
150
|
tabindex="-1"
|
|
143
151
|
role="menubar"
|
|
144
|
-
aria-label={$props
|
|
145
|
-
aria-orientation={
|
|
152
|
+
aria-label={$props?.ariaLabel}
|
|
153
|
+
aria-orientation={orientation}
|
|
146
154
|
>
|
|
147
155
|
<slot />
|
|
148
156
|
</div>
|
|
@@ -6,6 +6,21 @@ import {
|
|
|
6
6
|
} from "./MenuBarTypes";
|
|
7
7
|
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
8
8
|
|
|
9
|
+
interface MenuBarItemProps {
|
|
10
|
+
/** An ID for the root element */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Class name(s) for the root element */
|
|
13
|
+
class?: string,
|
|
14
|
+
/** Whether the item is visible */
|
|
15
|
+
visible?: boolean,
|
|
16
|
+
/** Raised when the item is opened or closed */
|
|
17
|
+
ontoggle?: (visible: boolean) => void,
|
|
18
|
+
/** Raised when the item has opened */
|
|
19
|
+
onopen?: () => void,
|
|
20
|
+
/** Raised when the item has closed */
|
|
21
|
+
onclose?: (result: any) => void,
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
/**
|
|
10
25
|
* A popout that is attached to a menubar button and can be used to show a submenu.
|
|
11
26
|
*
|
|
@@ -13,21 +28,14 @@ import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes
|
|
|
13
28
|
*
|
|
14
29
|
* ```
|
|
15
30
|
* <MenuBarItem>
|
|
16
|
-
*
|
|
17
|
-
*
|
|
31
|
+
* <MenuBarItemTrigger /> (optional)
|
|
32
|
+
* <MenuBarItemContent />
|
|
18
33
|
* </MenuBarItem>
|
|
19
34
|
* ```
|
|
20
|
-
*
|
|
21
|
-
* @prop {boolean} visible -- Whether the item is visible
|
|
22
|
-
* @prop {(boolean) => void} ontoggle -- Called when the item is opened or closed
|
|
23
|
-
* @prop {() => void} onopen -- Called when the item has opened
|
|
24
|
-
* @prop {() => void} onclose -- Called when the item has closed
|
|
25
35
|
*/
|
|
26
|
-
export default function MenuBarItem() {
|
|
27
|
-
$props.visible ??= false;
|
|
28
|
-
|
|
36
|
+
export default function MenuBarItem($props: MenuBarItemProps | undefined) {
|
|
29
37
|
let $state = $watch({
|
|
30
|
-
visible: $props
|
|
38
|
+
visible: $props?.visible ?? false
|
|
31
39
|
});
|
|
32
40
|
|
|
33
41
|
let result: any;
|
|
@@ -72,9 +80,9 @@ export default function MenuBarItem() {
|
|
|
72
80
|
|
|
73
81
|
let firstToggle = true;
|
|
74
82
|
$run(() => {
|
|
75
|
-
const ontoggle = $props
|
|
76
|
-
const onopen = $props
|
|
77
|
-
const onclose = $props
|
|
83
|
+
const ontoggle = $props?.ontoggle;
|
|
84
|
+
const onopen = $props?.onopen;
|
|
85
|
+
const onclose = $props?.onclose;
|
|
78
86
|
const visible = $state.visible;
|
|
79
87
|
if (firstToggle) {
|
|
80
88
|
firstToggle = false;
|
|
@@ -95,8 +103,8 @@ export default function MenuBarItem() {
|
|
|
95
103
|
|
|
96
104
|
@render {
|
|
97
105
|
<div
|
|
98
|
-
{$props
|
|
99
|
-
class={`torp-menu-bar-item ${$props
|
|
106
|
+
{$props?.id}
|
|
107
|
+
class={`torp-menu-bar-item ${$props?.class ?? ""}`.trim()}
|
|
100
108
|
>
|
|
101
109
|
<slot />
|
|
102
110
|
</div>
|
|
@@ -7,16 +7,21 @@ import {
|
|
|
7
7
|
type MenuBarItemContext
|
|
8
8
|
} from "./MenuBarTypes";
|
|
9
9
|
|
|
10
|
+
interface MenuBarItemContentProps {
|
|
11
|
+
/** An ID for the root element */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Class name(s) for the root element */
|
|
14
|
+
class?: string,
|
|
15
|
+
/** Where the popout will be shown, relative to the popout button */
|
|
16
|
+
side?: "top" | "right" | "bottom" | "left",
|
|
17
|
+
/** How the popout will be aligned, relative to the popout button */
|
|
18
|
+
alignment?: "start" | "center" | "end",
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
/**
|
|
11
22
|
* The content that is displayed for a MenuBarItem when it is open.
|
|
12
|
-
*
|
|
13
|
-
* @prop {"top" | "right" | "bottom" | "left"} side -- Where the popout will be shown, relative to the popout button
|
|
14
|
-
* @prop {"start" | "center" | "end"} alignment -- How the popout will be aligned, relative to the popout button
|
|
15
23
|
*/
|
|
16
|
-
export default function MenuBarItemContent() {
|
|
17
|
-
$props.side ??= "bottom";
|
|
18
|
-
$props.alignment ??= "start";
|
|
19
|
-
|
|
24
|
+
export default function MenuBarItemContent($props: MenuBarItemContentProps | undefined) {
|
|
20
25
|
let div: HTMLDivElement;
|
|
21
26
|
let closeOnClick = false;
|
|
22
27
|
let shown = false;
|
|
@@ -80,7 +85,7 @@ export default function MenuBarItemContent() {
|
|
|
80
85
|
|
|
81
86
|
function handleDocumentClick(e: MouseEvent) {
|
|
82
87
|
if (closeOnClick && !div.contains(e.target as HTMLElement)) {
|
|
83
|
-
context.active = false;
|
|
88
|
+
//context.active = false;
|
|
84
89
|
setVisible(false);
|
|
85
90
|
}
|
|
86
91
|
}
|
|
@@ -90,14 +95,16 @@ export default function MenuBarItemContent() {
|
|
|
90
95
|
throw new Error("MenuBarItemContent must have an anchor element");
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
let side = $props?.side ?? "bottom";
|
|
99
|
+
let alignment = $props?.alignment ?? "start";
|
|
100
|
+
setPopoverPosition(itemContext.anchorElement, div, side, alignment);
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
@render {
|
|
97
104
|
@if ($state.visible) {
|
|
98
105
|
<div
|
|
99
|
-
{$props
|
|
100
|
-
class={`torp-menu-bar-item-content ${$props
|
|
106
|
+
{$props?.id}
|
|
107
|
+
class={`torp-menu-bar-item-content ${$props?.class ?? ""}`.trim()}
|
|
101
108
|
&ref={div}
|
|
102
109
|
onmount={show}
|
|
103
110
|
>
|
|
@@ -5,14 +5,20 @@ import {
|
|
|
5
5
|
type MenuBarItemContext
|
|
6
6
|
} from "./MenuBarTypes";
|
|
7
7
|
|
|
8
|
+
interface MenuBarItemTriggerProps {
|
|
9
|
+
/** An ID for the root element */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Class name(s) for the root element */
|
|
12
|
+
class?: string,
|
|
13
|
+
/** Whether this button is disabled */
|
|
14
|
+
disabled?: boolean,
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
/**
|
|
9
18
|
* A button that is placed in a MenuBar and opens a submenu.
|
|
10
19
|
*
|
|
11
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
12
20
|
*/
|
|
13
|
-
export default function MenuBarItemTrigger() {
|
|
14
|
-
$props.disabled ??= false;
|
|
15
|
-
|
|
21
|
+
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | undefined) {
|
|
16
22
|
let button: HTMLButtonElement;
|
|
17
23
|
|
|
18
24
|
// Get stuff out of the MenuBarContext
|
|
@@ -67,15 +73,15 @@ export default function MenuBarItemTrigger() {
|
|
|
67
73
|
|
|
68
74
|
@render {
|
|
69
75
|
<button
|
|
70
|
-
{$props
|
|
71
|
-
class={`torp-menu-bar-item-button ${$props
|
|
76
|
+
{$props?.id}
|
|
77
|
+
class={`torp-menu-bar-item-button ${$props?.class ?? ""}`.trim()}
|
|
72
78
|
type="button"
|
|
73
|
-
{$props
|
|
79
|
+
{$props?.disabled}
|
|
74
80
|
role="menuitem"
|
|
75
81
|
aria-haspopup="true"
|
|
76
82
|
aria-expanded={($state.visible ?? false).toString()}
|
|
77
|
-
aria-disabled={$props
|
|
78
|
-
data-disabled={$props
|
|
83
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
84
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
79
85
|
onkeydown={handleKey}
|
|
80
86
|
onclick={handleClick}
|
|
81
87
|
onfocus={() => handleButtonFocus(index)}
|
package/dist/MenuBar/index.d.ts
CHANGED
|
@@ -1,72 +1,123 @@
|
|
|
1
1
|
import { type SlotRender } from "@torpor/view";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
interface MenuBarProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** An ARIA label for describing the menu to screen readers */
|
|
10
|
+
ariaLabel?: string,
|
|
11
|
+
/** The orientation of the menu, which affects keyboard navigation */
|
|
12
|
+
orientation?: "horizontal" | "vertical",
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
16
|
+
* A menu bar, similar to that shown at the top of Windows applications or at the top of the screen on Macs.
|
|
17
|
+
*
|
|
18
|
+
* See [the WAI ARIA guidelines for Menus](https://www.w3.org/WAI/ARIA/apg/patterns/menu/).
|
|
19
|
+
*
|
|
20
|
+
* The structure of a MenuBar is:
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* <MenuBar>
|
|
24
|
+
* <MenuBarItem>
|
|
25
|
+
* <MenuBarItemTrigger />
|
|
26
|
+
* <MenuBarItemContent>
|
|
27
|
+
* <Menu />
|
|
28
|
+
* </MenuBarItemContent>
|
|
29
|
+
* </MenuBarItem>
|
|
30
|
+
* </MenuBar>
|
|
31
|
+
* ```
|
|
11
32
|
*/
|
|
12
33
|
declare function MenuBar(
|
|
13
34
|
$parent: ParentNode,
|
|
14
35
|
$anchor: Node | null,
|
|
15
|
-
$props
|
|
36
|
+
$props: MenuBarProps | undefined,
|
|
16
37
|
$context?: Record<PropertyKey, any>,
|
|
17
38
|
$slots?: Record<string, SlotRender>,
|
|
18
39
|
): void;
|
|
19
40
|
|
|
20
41
|
|
|
21
42
|
|
|
43
|
+
interface MenuBarItemProps {
|
|
44
|
+
/** An ID for the root element */
|
|
45
|
+
id?: string;
|
|
46
|
+
/** Class name(s) for the root element */
|
|
47
|
+
class?: string,
|
|
48
|
+
/** Whether the item is visible */
|
|
49
|
+
visible?: boolean,
|
|
50
|
+
/** Raised when the item is opened or closed */
|
|
51
|
+
ontoggle?: (visible: boolean) => void,
|
|
52
|
+
/** Raised when the item has opened */
|
|
53
|
+
onopen?: () => void,
|
|
54
|
+
/** Raised when the item has closed */
|
|
55
|
+
onclose?: (result: any) => void,
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
59
|
+
* A popout that is attached to a menubar button and can be used to show a submenu.
|
|
60
|
+
*
|
|
61
|
+
* The structure of a MenuBarItem is:
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
* <MenuBarItem>
|
|
65
|
+
* <MenuBarItemTrigger /> (optional)
|
|
66
|
+
* <MenuBarItemContent />
|
|
67
|
+
* </MenuBarItem>
|
|
68
|
+
* ```
|
|
29
69
|
*/
|
|
30
70
|
declare function MenuBarItem(
|
|
31
71
|
$parent: ParentNode,
|
|
32
72
|
$anchor: Node | null,
|
|
33
|
-
$props
|
|
73
|
+
$props: MenuBarItemProps | undefined,
|
|
34
74
|
$context?: Record<PropertyKey, any>,
|
|
35
75
|
$slots?: Record<string, SlotRender>,
|
|
36
76
|
): void;
|
|
37
77
|
|
|
38
78
|
|
|
39
79
|
|
|
80
|
+
interface MenuBarItemContentProps {
|
|
81
|
+
/** An ID for the root element */
|
|
82
|
+
id?: string;
|
|
83
|
+
/** Class name(s) for the root element */
|
|
84
|
+
class?: string,
|
|
85
|
+
/** Where the popout will be shown, relative to the popout button */
|
|
86
|
+
side?: "top" | "right" | "bottom" | "left",
|
|
87
|
+
/** How the popout will be aligned, relative to the popout button */
|
|
88
|
+
alignment?: "start" | "center" | "end",
|
|
89
|
+
}
|
|
90
|
+
|
|
40
91
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param $parent -- The parent node.
|
|
43
|
-
* @param $anchor -- The node to mount the component before.
|
|
44
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
45
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
46
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
92
|
+
* The content that is displayed for a MenuBarItem when it is open.
|
|
47
93
|
*/
|
|
48
94
|
declare function MenuBarItemContent(
|
|
49
95
|
$parent: ParentNode,
|
|
50
96
|
$anchor: Node | null,
|
|
51
|
-
$props
|
|
97
|
+
$props: MenuBarItemContentProps | undefined,
|
|
52
98
|
$context?: Record<PropertyKey, any>,
|
|
53
99
|
$slots?: Record<string, SlotRender>,
|
|
54
100
|
): void;
|
|
55
101
|
|
|
56
102
|
|
|
57
103
|
|
|
104
|
+
interface MenuBarItemTriggerProps {
|
|
105
|
+
/** An ID for the root element */
|
|
106
|
+
id?: string;
|
|
107
|
+
/** Class name(s) for the root element */
|
|
108
|
+
class?: string,
|
|
109
|
+
/** Whether this button is disabled */
|
|
110
|
+
disabled?: boolean,
|
|
111
|
+
}
|
|
112
|
+
|
|
58
113
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @param $anchor -- The node to mount the component before.
|
|
62
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
63
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
64
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
114
|
+
* A button that is placed in a MenuBar and opens a submenu.
|
|
115
|
+
*
|
|
65
116
|
*/
|
|
66
117
|
declare function MenuBarItemTrigger(
|
|
67
118
|
$parent: ParentNode,
|
|
68
119
|
$anchor: Node | null,
|
|
69
|
-
$props
|
|
120
|
+
$props: MenuBarItemTriggerProps | undefined,
|
|
70
121
|
$context?: Record<PropertyKey, any>,
|
|
71
122
|
$slots?: Record<string, SlotRender>,
|
|
72
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
|
+
}
|