@torpor/ui 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/Accordion/Accordion.torp +29 -22
- package/dist/Accordion/AccordionContent.torp +7 -8
- package/dist/Accordion/AccordionHeader.torp +4 -6
- package/dist/Accordion/AccordionItem.torp +15 -12
- package/dist/Accordion/AccordionTrigger.torp +6 -7
- package/dist/Accordion/AccordionTypes.ts +4 -3
- package/dist/Accordion/index.d.ts +5 -5
- package/dist/Breadcrumb/Breadcrumb.torp +9 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/dist/Breadcrumb/index.d.ts +8 -7
- package/dist/Calendar/Calendar.torp +12 -13
- package/dist/Calendar/CalendarDay.torp +3 -3
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/dist/Contextual/ContextualTrigger.torp +66 -0
- package/dist/Contextual/ContextualTypes.ts +30 -0
- package/dist/Contextual/index.d.ts +90 -0
- package/dist/Contextual/index.js +14 -0
- package/dist/Contextual/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +38 -72
- package/dist/Dialog/DialogBody.torp +6 -8
- package/dist/Dialog/DialogButton.torp +14 -12
- package/dist/Dialog/DialogFooter.torp +3 -5
- package/dist/Dialog/DialogHeader.torp +6 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +16 -11
- package/dist/Disclosure/Disclosure.torp +22 -23
- package/dist/Disclosure/DisclosureContent.torp +7 -8
- package/dist/Disclosure/DisclosureHeader.torp +5 -7
- package/dist/Disclosure/DisclosureTrigger.torp +7 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +12 -12
- package/dist/Drawer/Drawer.torp +101 -70
- package/dist/Drawer/DrawerContent.torp +80 -0
- package/dist/Drawer/DrawerOverlay.torp +38 -0
- package/dist/Drawer/DrawerTrigger.torp +35 -0
- package/dist/Drawer/DrawerTypes.ts +24 -0
- package/dist/Drawer/index.d.ts +90 -3
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/CheckBox.torp +91 -0
- package/dist/Form/Field.torp +2 -4
- package/dist/Form/File.torp +106 -0
- package/dist/Form/Form.torp +17 -10
- package/dist/Form/FormTypes.ts +5 -0
- package/dist/Form/Input.torp +28 -17
- package/dist/Form/Label.torp +1 -1
- package/dist/Form/Message.torp +1 -1
- package/dist/Form/Option.torp +24 -0
- package/dist/Form/Select.torp +97 -0
- package/dist/Form/TextArea.torp +101 -0
- package/dist/Form/index.d.ts +192 -5
- package/dist/Form/index.js +21 -1
- package/dist/Menu/Menu.torp +16 -15
- package/dist/Menu/MenuButton.torp +19 -13
- package/dist/Menu/MenuCheck.torp +18 -14
- package/dist/Menu/MenuGroup.torp +4 -6
- package/dist/Menu/MenuIndicator.torp +5 -7
- package/dist/Menu/MenuPopout.torp +12 -15
- package/dist/Menu/MenuPopoutContent.torp +6 -8
- package/dist/Menu/MenuPopoutTrigger.torp +12 -14
- package/dist/Menu/MenuRadio.torp +14 -14
- package/dist/Menu/MenuRadioGroup.torp +22 -14
- package/dist/Menu/MenuSeparator.torp +3 -5
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +28 -22
- package/dist/MenuBar/MenuBar.torp +13 -14
- package/dist/MenuBar/MenuBarItem.torp +13 -16
- package/dist/MenuBar/MenuBarItemContent.torp +7 -9
- package/dist/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/dist/MenuBar/index.d.ts +16 -16
- package/dist/Modal/Modal.torp +118 -0
- package/dist/Modal/ModalContent.torp +77 -0
- package/dist/Modal/ModalOverlay.torp +38 -0
- package/dist/Modal/ModalTrigger.torp +50 -0
- package/dist/Modal/ModalTypes.ts +22 -0
- package/dist/Modal/index.d.ts +108 -0
- package/dist/Modal/index.js +33 -0
- package/dist/Modal/index.js.map +1 -0
- package/dist/Modal/showModal.ts +19 -0
- package/dist/Modal/showPrompt.ts +23 -0
- package/dist/NavMenu/NavMenu.torp +7 -8
- package/dist/NavMenu/NavMenuButton.torp +6 -8
- package/dist/NavMenu/NavMenuElement.torp +8 -8
- package/dist/NavMenu/NavMenuGroup.torp +4 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/dist/NavMenu/NavMenuLink.torp +8 -11
- package/dist/NavMenu/NavMenuPopout.torp +25 -17
- package/dist/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/dist/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/dist/NavMenu/NavMenuSeparator.torp +3 -5
- package/dist/NavMenu/index.d.ts +17 -11
- package/dist/Notification/Notification.torp +22 -13
- package/dist/Notification/NotificationClose.torp +3 -5
- package/dist/Notification/NotificationContainer.torp +3 -5
- package/dist/Notification/NotificationContent.torp +3 -5
- package/dist/Notification/index.d.ts +4 -4
- package/dist/Popover/Popover.torp +31 -25
- package/dist/Popover/PopoverContent.torp +35 -10
- package/dist/Popover/PopoverTrigger.torp +24 -4
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +16 -124
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +12 -9
- package/dist/TabGroup/TabGroup.torp +41 -35
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +15 -8
- package/dist/TabGroup/TabList.torp +4 -6
- package/dist/TabGroup/TabTrigger.torp +8 -9
- package/dist/TabGroup/index.d.ts +14 -6
- package/dist/icons/ArrowDown.torp +3 -1
- package/dist/icons/ArrowLeft.torp +3 -1
- package/dist/icons/ArrowRight.torp +3 -1
- package/dist/icons/ArrowUp.torp +3 -1
- package/dist/icons/Bars.torp +3 -1
- package/dist/icons/Check.torp +3 -1
- package/dist/icons/ChevronDown.torp +3 -1
- package/dist/icons/ChevronLeft.torp +3 -1
- package/dist/icons/ChevronRight.torp +3 -1
- package/dist/icons/ChevronUp.torp +3 -1
- package/dist/icons/Cross.torp +3 -1
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +3 -1
- package/dist/icons/Minus.torp +3 -1
- package/dist/icons/Plus.torp +3 -1
- package/dist/icons/index.d.ts +271 -14
- package/dist/index.d.ts +17 -4
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +15 -6
- package/dist/motion/grow.ts +23 -0
- package/dist/motion/index.d.ts +19 -2
- package/dist/motion/index.js +93 -3
- package/dist/motion/index.js.map +1 -1
- package/dist/motion/measure.ts +28 -0
- package/dist/motion/slide.ts +45 -0
- package/dist/mount/clickPopover.ts +51 -0
- package/dist/mount/contextPopover.ts +51 -0
- package/dist/mount/hoverPopover.ts +58 -0
- package/package.json +21 -14
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +29 -22
- package/src/Accordion/AccordionContent.torp +7 -8
- package/src/Accordion/AccordionHeader.torp +4 -6
- package/src/Accordion/AccordionItem.torp +15 -12
- package/src/Accordion/AccordionTrigger.torp +6 -7
- package/src/Accordion/AccordionTypes.ts +4 -3
- package/src/Breadcrumb/Breadcrumb.torp +9 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/src/Calendar/Calendar.torp +12 -13
- package/src/Calendar/CalendarDay.torp +3 -3
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/src/Contextual/ContextualTrigger.torp +66 -0
- package/src/Contextual/ContextualTypes.ts +30 -0
- package/src/Contextual/index.ts +5 -0
- package/src/Dialog/Dialog.torp +38 -72
- package/src/Dialog/DialogBody.torp +6 -8
- package/src/Dialog/DialogButton.torp +14 -12
- package/src/Dialog/DialogFooter.torp +3 -5
- package/src/Dialog/DialogHeader.torp +6 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +22 -23
- package/src/Disclosure/DisclosureContent.torp +7 -8
- package/src/Disclosure/DisclosureHeader.torp +5 -7
- package/src/Disclosure/DisclosureTrigger.torp +7 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +101 -70
- package/src/Drawer/DrawerContent.torp +80 -0
- package/src/Drawer/DrawerOverlay.torp +38 -0
- package/src/Drawer/DrawerTrigger.torp +35 -0
- package/src/Drawer/DrawerTypes.ts +24 -0
- package/src/Drawer/index.ts +4 -1
- package/src/Form/CheckBox.torp +91 -0
- package/src/Form/Field.torp +2 -4
- package/src/Form/File.torp +106 -0
- package/src/Form/Form.torp +17 -10
- package/src/Form/FormTypes.ts +5 -0
- package/src/Form/Input.torp +28 -17
- package/src/Form/Label.torp +1 -1
- package/src/Form/Message.torp +1 -1
- package/src/Form/Option.torp +24 -0
- package/src/Form/Select.torp +97 -0
- package/src/Form/TextArea.torp +101 -0
- package/src/Form/index.ts +6 -1
- package/src/Menu/Menu.torp +16 -15
- package/src/Menu/MenuButton.torp +19 -13
- package/src/Menu/MenuCheck.torp +18 -14
- package/src/Menu/MenuGroup.torp +4 -6
- package/src/Menu/MenuIndicator.torp +5 -7
- package/src/Menu/MenuPopout.torp +12 -15
- package/src/Menu/MenuPopoutContent.torp +6 -8
- package/src/Menu/MenuPopoutTrigger.torp +12 -14
- package/src/Menu/MenuRadio.torp +14 -14
- package/src/Menu/MenuRadioGroup.torp +22 -14
- package/src/Menu/MenuSeparator.torp +3 -5
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +13 -14
- package/src/MenuBar/MenuBarItem.torp +13 -16
- package/src/MenuBar/MenuBarItemContent.torp +7 -9
- package/src/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/src/Modal/Modal.torp +118 -0
- package/src/Modal/ModalContent.torp +77 -0
- package/src/Modal/ModalOverlay.torp +38 -0
- package/src/Modal/ModalTrigger.torp +50 -0
- package/src/Modal/ModalTypes.ts +22 -0
- package/src/Modal/index.ts +10 -0
- package/src/Modal/showModal.ts +19 -0
- package/src/Modal/showPrompt.ts +23 -0
- package/src/NavMenu/NavMenu.torp +7 -8
- package/src/NavMenu/NavMenuButton.torp +6 -8
- package/src/NavMenu/NavMenuElement.torp +8 -8
- package/src/NavMenu/NavMenuGroup.torp +4 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/src/NavMenu/NavMenuLink.torp +8 -11
- package/src/NavMenu/NavMenuPopout.torp +25 -17
- package/src/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/src/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/src/NavMenu/NavMenuSeparator.torp +3 -5
- package/src/Notification/Notification.torp +22 -13
- package/src/Notification/NotificationClose.torp +3 -5
- package/src/Notification/NotificationContainer.torp +3 -5
- package/src/Notification/NotificationContent.torp +3 -5
- package/src/Popover/Popover.torp +31 -25
- package/src/Popover/PopoverContent.torp +35 -10
- package/src/Popover/PopoverTrigger.torp +24 -4
- package/src/Popover/PopoverTypes.ts +1 -1
- package/src/Popover/index.ts +1 -24
- package/src/Slider/Slider.torp +3 -3
- package/src/TabGroup/TabContent.torp +12 -9
- package/src/TabGroup/TabGroup.torp +41 -35
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +15 -8
- package/src/TabGroup/TabList.torp +4 -6
- package/src/TabGroup/TabTrigger.torp +8 -9
- package/src/icons/ArrowDown.torp +3 -1
- package/src/icons/ArrowLeft.torp +3 -1
- package/src/icons/ArrowRight.torp +3 -1
- package/src/icons/ArrowUp.torp +3 -1
- package/src/icons/Bars.torp +3 -1
- package/src/icons/Check.torp +3 -1
- package/src/icons/ChevronDown.torp +3 -1
- package/src/icons/ChevronLeft.torp +3 -1
- package/src/icons/ChevronRight.torp +3 -1
- package/src/icons/ChevronUp.torp +3 -1
- package/src/icons/Cross.torp +3 -1
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +3 -1
- package/src/icons/Minus.torp +3 -1
- package/src/icons/Plus.torp +3 -1
- package/src/motion/fade.ts +15 -6
- package/src/motion/grow.ts +23 -0
- package/src/motion/index.ts +4 -1
- package/src/motion/measure.ts +28 -0
- package/src/motion/slide.ts +45 -0
- package/src/mount/clickPopover.ts +51 -0
- package/src/mount/contextPopover.ts +51 -0
- package/src/mount/hoverPopover.ts +58 -0
- package/test/Accordion/components/AccordionAccessibility.torp +1 -3
- package/test/Accordion/components/AccordionKeyboard.torp +1 -3
- package/test/Accordion/components/AccordionList.torp +1 -3
- package/test/Accordion/components/AccordionMultiple.torp +2 -4
- package/test/Accordion/components/AccordionSingle.torp +2 -4
- package/test/Dialog/accessibility-modal.test.ts +2 -2
- package/test/Dialog/components/DialogAccessibility.torp +8 -14
- package/test/Dialog/components/DialogFunction.torp +20 -4
- package/test/Dialog/components/DialogModal.torp +30 -0
- package/test/Dialog/components/DialogVariable.torp +7 -7
- package/test/Disclosure/components/DisclosureTest.torp +1 -3
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/Notification/components/NotificationFunction.torp +0 -3
- package/test/Notification/components/NotificationVariable.torp +1 -1
- package/test/Popover/components/PopoverFunction.torp +37 -0
- package/test/Popover/components/PopoverTrigger.torp +36 -0
- package/test/Popover/components/{PromptVariable.torp → PopoverVariable.torp} +5 -3
- package/test/Popover/function.test.ts +2 -7
- package/test/Popover/trigger.test.ts +27 -0
- package/test/Popover/variable.test.ts +2 -2
- package/test/TabGroup/components/TabGroupAccessibility.torp +1 -3
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -3
- package/test/TabGroup/components/TabGroupList.torp +1 -3
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -3
- package/tsup.config.ts +2 -0
- package/dist/Popover/PopoverContentAnchored.torp +0 -113
- package/dist/Popover/PopoverOverlay.torp +0 -39
- package/dist/Popover/PopoverTriggerContextual.torp +0 -46
- package/dist/Popover/PopoverTriggerHover.torp +0 -47
- package/dist/Popover/mountClickPopover.ts +0 -50
- package/dist/Popover/mountContextPopover.ts +0 -50
- package/dist/Popover/mountHoverPopover.ts +0 -57
- package/dist/Popover/showPopoverPrompt.ts +0 -23
- package/src/Popover/PopoverContentAnchored.torp +0 -113
- package/src/Popover/PopoverOverlay.torp +0 -39
- package/src/Popover/PopoverTriggerContextual.torp +0 -46
- package/src/Popover/PopoverTriggerHover.torp +0 -47
- package/src/Popover/mountClickPopover.ts +0 -50
- package/src/Popover/mountContextPopover.ts +0 -50
- package/src/Popover/mountHoverPopover.ts +0 -57
- package/src/Popover/showPopoverPrompt.ts +0 -23
- package/test/Dialog/components/CustomDialog.torp +0 -20
- package/test/Popover/components/PromptFunction.torp +0 -19
|
@@ -13,12 +13,12 @@ interface MenuBarItemProps {
|
|
|
13
13
|
class?: string,
|
|
14
14
|
/** Whether the item is visible */
|
|
15
15
|
visible?: boolean,
|
|
16
|
-
/**
|
|
16
|
+
/** Raised when the item is opened or closed */
|
|
17
17
|
ontoggle?: (visible: boolean) => void,
|
|
18
|
-
/**
|
|
18
|
+
/** Raised when the item has opened */
|
|
19
19
|
onopen?: () => void,
|
|
20
|
-
/**
|
|
21
|
-
onclose?: () => void,
|
|
20
|
+
/** Raised when the item has closed */
|
|
21
|
+
onclose?: (result: any) => void,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -28,17 +28,14 @@ interface MenuBarItemProps {
|
|
|
28
28
|
*
|
|
29
29
|
* ```
|
|
30
30
|
* <MenuBarItem>
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* <MenuBarItemTrigger /> (optional)
|
|
32
|
+
* <MenuBarItemContent />
|
|
33
33
|
* </MenuBarItem>
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export default function MenuBarItem($props: MenuBarItemProps) {
|
|
37
|
-
$props ??= $watch({});
|
|
38
|
-
$props.visible ??= false;
|
|
39
|
-
|
|
36
|
+
export default function MenuBarItem($props: MenuBarItemProps | undefined) {
|
|
40
37
|
let $state = $watch({
|
|
41
|
-
visible: $props
|
|
38
|
+
visible: $props?.visible ?? false
|
|
42
39
|
});
|
|
43
40
|
|
|
44
41
|
let result: any;
|
|
@@ -83,9 +80,9 @@ export default function MenuBarItem($props: MenuBarItemProps) {
|
|
|
83
80
|
|
|
84
81
|
let firstToggle = true;
|
|
85
82
|
$run(() => {
|
|
86
|
-
const ontoggle = $props
|
|
87
|
-
const onopen = $props
|
|
88
|
-
const onclose = $props
|
|
83
|
+
const ontoggle = $props?.ontoggle;
|
|
84
|
+
const onopen = $props?.onopen;
|
|
85
|
+
const onclose = $props?.onclose;
|
|
89
86
|
const visible = $state.visible;
|
|
90
87
|
if (firstToggle) {
|
|
91
88
|
firstToggle = false;
|
|
@@ -106,8 +103,8 @@ export default function MenuBarItem($props: MenuBarItemProps) {
|
|
|
106
103
|
|
|
107
104
|
@render {
|
|
108
105
|
<div
|
|
109
|
-
{$props
|
|
110
|
-
class={`torp-menu-bar-item ${$props
|
|
106
|
+
{$props?.id}
|
|
107
|
+
class={`torp-menu-bar-item ${$props?.class ?? ""}`.trim()}
|
|
111
108
|
>
|
|
112
109
|
<slot />
|
|
113
110
|
</div>
|
|
@@ -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)}
|
|
@@ -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,10 @@
|
|
|
1
|
+
import Modal from "./Modal.torp";
|
|
2
|
+
import ModalContent from "./ModalContent.torp";
|
|
3
|
+
import ModalOverlay from "./ModalOverlay.torp";
|
|
4
|
+
import ModalTrigger from "./ModalTrigger.torp";
|
|
5
|
+
import showModal from "./showModal";
|
|
6
|
+
import showPrompt from "./showPrompt";
|
|
7
|
+
|
|
8
|
+
export { Modal, ModalContent, ModalOverlay, ModalTrigger };
|
|
9
|
+
|
|
10
|
+
export { showModal, showPrompt };
|
|
@@ -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
|
+
}
|
package/src/NavMenu/NavMenu.torp
CHANGED
|
@@ -33,9 +33,8 @@ interface NavMenuProps {
|
|
|
33
33
|
* </NavMenu>
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export default function NavMenu($props: NavMenuProps) {
|
|
37
|
-
$props
|
|
38
|
-
$props.orientation ||= "horizontal";
|
|
36
|
+
export default function NavMenu($props: NavMenuProps | undefined) {
|
|
37
|
+
let orientation = $props?.orientation ?? "horizontal";
|
|
39
38
|
|
|
40
39
|
// A collection containing the state and some functions for each item
|
|
41
40
|
let itemStates: ItemState[] = [];
|
|
@@ -60,7 +59,7 @@ export default function NavMenu($props: NavMenuProps) {
|
|
|
60
59
|
$context[NavMenuContextName] = context;
|
|
61
60
|
|
|
62
61
|
// If the NavMenu is not in a popout, focus its first item. Otherwise the popout will call focusFirstElement, below
|
|
63
|
-
function handleFocus(
|
|
62
|
+
function handleFocus() {
|
|
64
63
|
if (!popoutContext && itemStates.length) {
|
|
65
64
|
itemStates[0].setFocused();
|
|
66
65
|
}
|
|
@@ -173,12 +172,12 @@ export default function NavMenu($props: NavMenuProps) {
|
|
|
173
172
|
|
|
174
173
|
@render {
|
|
175
174
|
<nav
|
|
176
|
-
{$props
|
|
177
|
-
class={`torp-nav-menu ${$props
|
|
175
|
+
{$props?.id}
|
|
176
|
+
class={`torp-nav-menu ${$props?.class ?? ""}`.trim()}
|
|
178
177
|
tabindex="0"
|
|
179
178
|
role="menubar"
|
|
180
|
-
aria-label={$props
|
|
181
|
-
aria-orientation={
|
|
179
|
+
aria-label={$props?.ariaLabel}
|
|
180
|
+
aria-orientation={orientation}
|
|
182
181
|
onfocus={handleFocus}
|
|
183
182
|
>
|
|
184
183
|
<slot />
|
|
@@ -13,9 +13,7 @@ interface NavMenuButtonProps {
|
|
|
13
13
|
* A button that is placed in a NavMenu to carry out a non-navigation action such as logging out.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
export default function NavMenuButton($props: NavMenuButtonProps) {
|
|
17
|
-
$props ??= $watch({});
|
|
18
|
-
|
|
16
|
+
export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
|
|
19
17
|
let button: HTMLButtonElement;
|
|
20
18
|
|
|
21
19
|
// Get stuff out of the NavMenuContext
|
|
@@ -34,13 +32,13 @@ export default function NavMenuButton($props: NavMenuButtonProps) {
|
|
|
34
32
|
|
|
35
33
|
@render {
|
|
36
34
|
<button
|
|
37
|
-
{$props
|
|
38
|
-
class={`torp-nav-menu-button ${$props
|
|
35
|
+
{$props?.id}
|
|
36
|
+
class={`torp-nav-menu-button ${$props?.class ?? ""}`.trim()}
|
|
39
37
|
type="button"
|
|
40
|
-
{$props
|
|
38
|
+
{$props?.disabled}
|
|
41
39
|
role="menuitem"
|
|
42
|
-
aria-disabled={$props
|
|
43
|
-
data-disabled={$props
|
|
40
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
41
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
44
42
|
onkeydown
|
|
45
43
|
onkeydown={handleItemKey}
|
|
46
44
|
onclick
|
|
@@ -15,9 +15,7 @@ interface NavMenuElementProps {
|
|
|
15
15
|
* An element of any type that can be placed in a NavMenu.
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
|
-
export default function NavMenuElement($props: NavMenuElementProps) {
|
|
19
|
-
$props ??= $watch({});
|
|
20
|
-
|
|
18
|
+
export default function NavMenuElement($props: NavMenuElementProps | undefined) {
|
|
21
19
|
// Get stuff out of the NavMenuContext
|
|
22
20
|
const menuContext = $context[NavMenuContextName] as NavMenuContext;
|
|
23
21
|
if (!menuContext) {
|
|
@@ -29,17 +27,19 @@ export default function NavMenuElement($props: NavMenuElementProps) {
|
|
|
29
27
|
const { index } = registerItem(setFocused);
|
|
30
28
|
|
|
31
29
|
function setFocused() {
|
|
32
|
-
element
|
|
30
|
+
if ($props?.element) {
|
|
31
|
+
$props.element.focus();
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
@render {
|
|
36
36
|
<div
|
|
37
|
-
{$props
|
|
38
|
-
class={`torp-nav-menu-div ${$props
|
|
37
|
+
{$props?.id}
|
|
38
|
+
class={`torp-nav-menu-div ${$props?.class ?? ""}`.trim()}
|
|
39
39
|
type="div"
|
|
40
40
|
role="menuitem"
|
|
41
|
-
aria-disabled={$props
|
|
42
|
-
data-disabled={$props
|
|
41
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
42
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
43
43
|
onkeydown
|
|
44
44
|
onkeydown={handleItemKey}
|
|
45
45
|
onclick
|
|
@@ -12,9 +12,7 @@ interface NavMenuGroupProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* A container for a logical group of navigation menu items.
|
|
14
14
|
*/
|
|
15
|
-
export default function NavMenuGroup($props: NavMenuGroupProps) {
|
|
16
|
-
$props ??= $watch({});
|
|
17
|
-
|
|
15
|
+
export default function NavMenuGroup($props: NavMenuGroupProps | undefined) {
|
|
18
16
|
let $state = $watch({
|
|
19
17
|
headerId: ""
|
|
20
18
|
});
|
|
@@ -27,10 +25,10 @@ export default function NavMenuGroup($props: NavMenuGroupProps) {
|
|
|
27
25
|
|
|
28
26
|
@render {
|
|
29
27
|
<div
|
|
30
|
-
{$props
|
|
31
|
-
class={`torp-nav-menu-group ${$props
|
|
28
|
+
{$props?.id}
|
|
29
|
+
class={`torp-nav-menu-group ${$props?.class ?? ""}`.trim()}
|
|
32
30
|
role="group"
|
|
33
|
-
aria-label={$props
|
|
31
|
+
aria-label={$props?.ariaLabel}
|
|
34
32
|
aria-labelledby={$state.headerId}
|
|
35
33
|
>
|
|
36
34
|
<slot />
|
|
@@ -13,9 +13,8 @@ interface NavMenuGroupHeaderProps {
|
|
|
13
13
|
/**
|
|
14
14
|
* The header for a NavMenuGroup.
|
|
15
15
|
*/
|
|
16
|
-
export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps) {
|
|
17
|
-
|
|
18
|
-
$props.id ??= getId();
|
|
16
|
+
export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps | undefined) {
|
|
17
|
+
let defaultId = getId();
|
|
19
18
|
|
|
20
19
|
const context = $context[NavMenuGroupContextName] as NavMenuGroupContext;
|
|
21
20
|
if (!context) {
|
|
@@ -24,13 +23,13 @@ export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps) {
|
|
|
24
23
|
let $state = context.state;
|
|
25
24
|
|
|
26
25
|
// Set the header ID now that we know what it is
|
|
27
|
-
$state.headerId = $props
|
|
26
|
+
$state.headerId = $props?.id ?? defaultId;
|
|
28
27
|
|
|
29
28
|
@render {
|
|
30
29
|
@// TODO: self={$props.as}
|
|
31
30
|
<h4
|
|
32
|
-
{$props
|
|
33
|
-
class={`torp-nav-menu-group-header ${$props
|
|
31
|
+
id={$props?.id ?? defaultId}
|
|
32
|
+
class={`torp-nav-menu-group-header ${$props?.class ?? ""}`.trim()}
|
|
34
33
|
>
|
|
35
34
|
<slot />
|
|
36
35
|
</h4>
|