@torpor/ui 0.1.7 → 0.2.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 +47 -0
- package/dist/Accordion/Accordion.torp +25 -13
- package/dist/Accordion/AccordionContent.torp +15 -8
- package/dist/Accordion/AccordionHeader.torp +16 -7
- package/dist/Accordion/AccordionItem.torp +24 -10
- package/dist/Accordion/AccordionTrigger.torp +16 -8
- package/dist/Accordion/AccordionTypes.ts +2 -0
- package/dist/Accordion/index.d.ts +157 -0
- package/dist/Breadcrumb/Breadcrumb.torp +42 -0
- package/dist/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/dist/Breadcrumb/index.d.ts +84 -0
- package/dist/Breadcrumb/index.js +14 -0
- package/dist/Calendar/Calendar.torp +273 -0
- package/dist/Calendar/CalendarDay.torp +75 -0
- package/dist/Calendar/CalendarTypes.ts +22 -0
- package/dist/Calendar/index.d.ts +36 -0
- package/dist/Calendar/index.js +10 -0
- package/dist/Calendar/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +16 -6
- package/dist/Dialog/DialogBody.torp +13 -5
- package/dist/Dialog/DialogButton.torp +18 -6
- package/dist/Dialog/DialogFooter.torp +13 -3
- package/dist/Dialog/DialogHeader.torp +13 -4
- package/dist/Dialog/index.d.ts +135 -0
- package/dist/Disclosure/Disclosure.torp +79 -0
- package/dist/Disclosure/DisclosureContent.torp +43 -0
- package/dist/Disclosure/DisclosureHeader.torp +43 -0
- package/dist/Disclosure/DisclosureTrigger.torp +44 -0
- package/dist/Disclosure/DisclosureTypes.ts +14 -0
- package/dist/Disclosure/index.d.ts +113 -0
- package/dist/Disclosure/index.js +18 -0
- package/dist/Disclosure/index.js.map +1 -0
- package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +20 -19
- package/dist/Drawer/index.d.ts +21 -0
- package/dist/Drawer/index.js +6 -0
- package/dist/Drawer/index.js.map +1 -0
- package/dist/Form/Field.torp +93 -0
- package/dist/Form/Form.torp +131 -0
- package/dist/Form/FormTypes.ts +30 -0
- package/dist/Form/Input.torp +94 -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 +117 -0
- package/dist/Form/index.js +22 -0
- package/dist/Form/index.js.map +1 -0
- package/dist/Menu/Menu.torp +169 -0
- package/dist/Menu/MenuButton.torp +64 -0
- package/dist/Menu/MenuCheck.torp +81 -0
- package/dist/Menu/MenuGroup.torp +29 -0
- package/dist/Menu/MenuIndicator.torp +38 -0
- package/dist/Menu/MenuPopout.torp +82 -0
- package/dist/Menu/MenuPopoutContent.torp +83 -0
- package/dist/Menu/MenuPopoutTrigger.torp +126 -0
- package/dist/Menu/MenuRadio.torp +99 -0
- package/dist/Menu/MenuRadioGroup.torp +97 -0
- package/dist/Menu/MenuSeparator.torp +24 -0
- package/dist/Menu/MenuTypes.ts +58 -0
- package/dist/Menu/index.d.ts +293 -0
- package/dist/Menu/index.js +46 -0
- package/dist/Menu/index.js.map +1 -0
- package/dist/MenuBar/MenuBar.torp +159 -0
- package/dist/MenuBar/MenuBarItem.torp +115 -0
- package/dist/MenuBar/MenuBarItemContent.torp +117 -0
- package/dist/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/dist/MenuBar/MenuBarTypes.ts +36 -0
- package/dist/MenuBar/index.d.ts +125 -0
- package/dist/MenuBar/index.js +18 -0
- package/dist/MenuBar/index.js.map +1 -0
- package/dist/NavMenu/NavMenu.torp +15 -6
- package/dist/NavMenu/NavMenuButton.torp +14 -7
- package/dist/NavMenu/NavMenuElement.torp +16 -8
- package/dist/NavMenu/NavMenuGroup.torp +14 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/dist/NavMenu/NavMenuLink.torp +18 -10
- package/dist/NavMenu/NavMenuPopout.torp +13 -5
- package/dist/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/dist/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/dist/NavMenu/NavMenuSeparator.torp +12 -3
- package/dist/NavMenu/index.d.ts +259 -0
- package/dist/Notification/Notification.torp +58 -0
- package/dist/Notification/NotificationClose.torp +37 -0
- package/dist/Notification/NotificationContainer.torp +24 -0
- package/dist/Notification/NotificationContent.torp +23 -0
- package/dist/Notification/NotificationTypes.ts +5 -0
- package/dist/Notification/index.d.ts +92 -0
- package/dist/Notification/index.js +36 -0
- package/dist/Notification/index.js.map +1 -0
- package/dist/Notification/showNotification.ts +30 -0
- package/dist/Popover/Popover.torp +22 -8
- package/dist/Popover/PopoverContent.torp +41 -29
- package/dist/Popover/PopoverContentAnchored.torp +52 -44
- package/dist/Popover/PopoverContentContextual.torp +49 -37
- package/dist/Popover/PopoverOverlay.torp +13 -4
- package/dist/Popover/PopoverTrigger.torp +12 -3
- package/dist/Popover/PopoverTriggerContextual.torp +12 -3
- package/dist/Popover/PopoverTriggerHover.torp +14 -5
- package/dist/Popover/index.d.ts +191 -0
- package/dist/TabGroup/TabContent.torp +13 -7
- package/dist/TabGroup/TabGroup.torp +23 -11
- package/dist/TabGroup/TabHeader.torp +16 -7
- package/dist/TabGroup/TabList.torp +15 -6
- package/dist/TabGroup/TabTrigger.torp +14 -6
- package/dist/TabGroup/index.d.ts +150 -0
- package/dist/icons/ArrowDown.torp +15 -0
- package/dist/icons/ArrowLeft.torp +15 -0
- package/dist/icons/ArrowRight.torp +15 -0
- package/dist/icons/ArrowUp.torp +15 -0
- package/dist/icons/Bars.torp +17 -0
- package/dist/icons/Check.torp +15 -0
- package/dist/icons/ChevronDown.torp +15 -0
- package/dist/icons/ChevronLeft.torp +15 -0
- package/dist/icons/ChevronRight.torp +15 -0
- package/dist/icons/ChevronUp.torp +15 -0
- package/dist/icons/Cross.torp +16 -0
- package/dist/icons/Loading.torp +16 -0
- package/dist/icons/Minus.torp +15 -0
- package/dist/icons/Plus.torp +16 -0
- package/dist/icons/index.d.ts +142 -0
- package/dist/icons/index.js +58 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/{motion.d.cts → index.d.ts} +2 -2
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +7 -0
- package/dist/motion/index.d.ts +2 -0
- package/dist/{motion.js → motion/index.js} +1 -1
- package/dist/motion/index.js.map +1 -0
- package/dist/mount/index.d.ts +2 -0
- package/dist/utils/dateUtils.ts +244 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/setPopoverPosition.ts +4 -0
- package/package.json +60 -35
- package/scripts/postbuild.ts +42 -5
- package/src/Accordion/Accordion.torp +25 -13
- package/src/Accordion/AccordionContent.torp +15 -8
- package/src/Accordion/AccordionHeader.torp +16 -7
- package/src/Accordion/AccordionItem.torp +24 -10
- package/src/Accordion/AccordionTrigger.torp +16 -8
- package/src/Accordion/AccordionTypes.ts +2 -0
- package/src/Breadcrumb/Breadcrumb.torp +42 -0
- package/src/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/src/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/src/Breadcrumb/index.ts +5 -0
- package/src/Calendar/Calendar.torp +273 -0
- package/src/Calendar/CalendarDay.torp +75 -0
- package/src/Calendar/CalendarTypes.ts +22 -0
- package/src/Calendar/index.ts +4 -0
- package/src/Dialog/Dialog.torp +16 -6
- package/src/Dialog/DialogBody.torp +13 -5
- package/src/Dialog/DialogButton.torp +18 -6
- package/src/Dialog/DialogFooter.torp +13 -3
- package/src/Dialog/DialogHeader.torp +13 -4
- package/src/Disclosure/Disclosure.torp +79 -0
- package/src/Disclosure/DisclosureContent.torp +43 -0
- package/src/Disclosure/DisclosureHeader.torp +43 -0
- package/src/Disclosure/DisclosureTrigger.torp +44 -0
- package/src/Disclosure/DisclosureTypes.ts +14 -0
- package/src/Disclosure/index.ts +6 -0
- package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +20 -19
- package/src/Drawer/index.ts +3 -0
- package/src/Form/Field.torp +93 -0
- package/src/Form/Form.torp +131 -0
- package/src/Form/FormTypes.ts +30 -0
- package/src/Form/Input.torp +94 -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 +169 -0
- package/src/Menu/MenuButton.torp +64 -0
- package/src/Menu/MenuCheck.torp +81 -0
- package/src/Menu/MenuGroup.torp +29 -0
- package/src/Menu/MenuIndicator.torp +38 -0
- package/src/Menu/MenuPopout.torp +82 -0
- package/src/Menu/MenuPopoutContent.torp +83 -0
- package/src/Menu/MenuPopoutTrigger.torp +126 -0
- package/src/Menu/MenuRadio.torp +99 -0
- package/src/Menu/MenuRadioGroup.torp +97 -0
- package/src/Menu/MenuSeparator.torp +24 -0
- package/src/Menu/MenuTypes.ts +58 -0
- package/src/Menu/index.ts +25 -0
- package/src/MenuBar/MenuBar.torp +159 -0
- package/src/MenuBar/MenuBarItem.torp +115 -0
- package/src/MenuBar/MenuBarItemContent.torp +117 -0
- package/src/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/src/MenuBar/MenuBarTypes.ts +36 -0
- package/src/MenuBar/index.ts +6 -0
- package/src/NavMenu/NavMenu.torp +15 -6
- package/src/NavMenu/NavMenuButton.torp +14 -7
- package/src/NavMenu/NavMenuElement.torp +16 -8
- package/src/NavMenu/NavMenuGroup.torp +14 -5
- package/src/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/src/NavMenu/NavMenuLink.torp +18 -10
- package/src/NavMenu/NavMenuPopout.torp +13 -5
- package/src/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/src/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/src/NavMenu/NavMenuSeparator.torp +12 -3
- package/src/Notification/Notification.torp +58 -0
- package/src/Notification/NotificationClose.torp +37 -0
- package/src/Notification/NotificationContainer.torp +24 -0
- package/src/Notification/NotificationContent.torp +23 -0
- package/src/Notification/NotificationTypes.ts +5 -0
- package/src/Notification/index.ts +13 -0
- package/src/Notification/showNotification.ts +30 -0
- package/src/Popover/Popover.torp +22 -8
- package/src/Popover/PopoverContent.torp +41 -29
- package/src/Popover/PopoverContentAnchored.torp +52 -44
- package/src/Popover/PopoverContentContextual.torp +49 -37
- package/src/Popover/PopoverOverlay.torp +13 -4
- package/src/Popover/PopoverTrigger.torp +12 -3
- package/src/Popover/PopoverTriggerContextual.torp +12 -3
- package/src/Popover/PopoverTriggerHover.torp +14 -5
- package/src/Slider/Slider.torp +83 -0
- package/src/Slider/index.ts +3 -0
- package/src/TabGroup/TabContent.torp +13 -7
- package/src/TabGroup/TabGroup.torp +23 -11
- package/src/TabGroup/TabHeader.torp +16 -7
- package/src/TabGroup/TabList.torp +15 -6
- package/src/TabGroup/TabTrigger.torp +14 -6
- package/src/icons/ArrowDown.torp +15 -0
- package/src/icons/ArrowLeft.torp +15 -0
- package/src/icons/ArrowRight.torp +15 -0
- package/src/icons/ArrowUp.torp +15 -0
- package/src/icons/Bars.torp +17 -0
- package/src/icons/Check.torp +15 -0
- package/src/icons/ChevronDown.torp +15 -0
- package/src/icons/ChevronLeft.torp +15 -0
- package/src/icons/ChevronRight.torp +15 -0
- package/src/icons/ChevronUp.torp +15 -0
- package/src/icons/Cross.torp +16 -0
- package/src/icons/Loading.torp +16 -0
- package/src/icons/Minus.torp +15 -0
- package/src/icons/Plus.torp +16 -0
- package/src/icons/index.ts +31 -0
- package/src/motion/fade.ts +2 -2
- package/src/motion/index.ts +3 -0
- package/src/utils/dateUtils.ts +244 -0
- package/src/utils/setPopoverPosition.ts +4 -0
- package/test/Accordion/components/AccordionAccessibility.torp +2 -0
- package/test/Accordion/components/AccordionKeyboard.torp +2 -0
- package/test/Accordion/components/AccordionList.torp +2 -0
- package/test/Accordion/components/AccordionMultiple.torp +2 -0
- package/test/Accordion/components/AccordionSingle.torp +2 -0
- package/test/Breadcrumb/accessibility.test.ts +29 -0
- package/test/Breadcrumb/basic.test.ts +17 -0
- package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
- package/test/Calendar/components/CalendarTest.torp +9 -0
- package/test/Calendar/default.test.ts +18 -0
- package/test/Dialog/components/DialogAccessibility.torp +5 -5
- package/test/Disclosure/accessibility.test.ts +31 -0
- package/test/Disclosure/components/DisclosureTest.torp +19 -0
- package/test/Disclosure/default.test.ts +15 -0
- package/test/Disclosure/toggle.test.ts +20 -0
- 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 +83 -0
- package/test/Menu/basic.test.ts +58 -0
- package/test/Menu/components/MenuAccessibility.torp +59 -0
- package/test/Menu/components/MenuBasic.torp +58 -0
- package/test/MenuBar/accessibility.test.ts +87 -0
- package/test/MenuBar/basic.test.ts +22 -0
- package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
- package/test/MenuBar/components/MenuBarBasic.torp +25 -0
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- package/test/Notification/accessibility.test.ts +21 -0
- package/test/Notification/components/CustomNotification.torp +14 -0
- package/test/Notification/components/NotificationAccessibility.torp +14 -0
- package/test/Notification/components/NotificationFunction.torp +20 -0
- package/test/Notification/components/NotificationVariable.torp +22 -0
- package/test/Notification/function.test.ts +25 -0
- package/test/Notification/variable.test.ts +25 -0
- package/test/Popover/components/CustomDialog.torp +25 -0
- package/test/Popover/components/PromptFunction.torp +19 -0
- package/test/Popover/components/PromptVariable.torp +38 -0
- package/test/Popover/function.test.ts +26 -0
- package/test/Popover/variable.test.ts +27 -0
- package/test/TabGroup/components/TabGroupAccessibility.torp +2 -0
- package/test/TabGroup/components/TabGroupKeyboard.torp +2 -0
- package/test/TabGroup/components/TabGroupList.torp +2 -0
- package/test/TabGroup/components/TabGroupTrigger.torp +2 -0
- package/tsup.config.ts +12 -4
- package/dist/Accordion/index.cjs +0 -53
- package/dist/Accordion/index.cjs.map +0 -1
- package/dist/Dialog/index.cjs +0 -53
- package/dist/Dialog/index.cjs.map +0 -1
- package/dist/NavMenu/index.cjs +0 -78
- package/dist/NavMenu/index.cjs.map +0 -1
- package/dist/Offscreen/index.cjs +0 -33
- package/dist/Offscreen/index.cjs.map +0 -1
- package/dist/Offscreen/index.js +0 -6
- package/dist/Popover/index.cjs +0 -222
- package/dist/Popover/index.cjs.map +0 -1
- package/dist/TabGroup/index.cjs +0 -53
- package/dist/TabGroup/index.cjs.map +0 -1
- package/dist/metafile-cjs.json +0 -1
- package/dist/motion.cjs +0 -34
- package/dist/motion.cjs.map +0 -1
- package/dist/motion.d.ts +0 -6
- package/dist/motion.js.map +0 -1
- package/src/Accordion.ts +0 -7
- package/src/Dialog.ts +0 -7
- package/src/NavMenu.ts +0 -23
- package/src/Offscreen/index.ts +0 -3
- package/src/Popover.ts +0 -29
- package/src/TabGroup.ts +0 -7
- package/src/motion.ts +0 -3
- /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MenuBarContextName,
|
|
3
|
+
MenuBarItemContextName,
|
|
4
|
+
type MenuBarContext,
|
|
5
|
+
type MenuBarItemContext
|
|
6
|
+
} from "./MenuBarTypes";
|
|
7
|
+
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
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
|
+
/** Called when the item is opened or closed */
|
|
17
|
+
ontoggle?: (visible: boolean) => void,
|
|
18
|
+
/** Called when the item has opened */
|
|
19
|
+
onopen?: () => void,
|
|
20
|
+
/** Called when the item has closed */
|
|
21
|
+
onclose?: () => void,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A popout that is attached to a menubar button and can be used to show a submenu.
|
|
26
|
+
*
|
|
27
|
+
* The structure of a MenuBarItem is:
|
|
28
|
+
*
|
|
29
|
+
* ```
|
|
30
|
+
* <MenuBarItem>
|
|
31
|
+
* <MenuBarItemTrigger /> (optional)
|
|
32
|
+
* <MenuBarItemContent />
|
|
33
|
+
* </MenuBarItem>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export default function MenuBarItem($props: MenuBarItemProps) {
|
|
37
|
+
$props ??= $watch({});
|
|
38
|
+
$props.visible ??= false;
|
|
39
|
+
|
|
40
|
+
let $state = $watch({
|
|
41
|
+
visible: $props.visible
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
let result: any;
|
|
45
|
+
|
|
46
|
+
// Get stuff out of the MenuBarContext
|
|
47
|
+
const menubarContext = $context[MenuBarContextName] as MenuBarContext;
|
|
48
|
+
if (!menubarContext) {
|
|
49
|
+
throw new Error("MenuBarItem must be contained within a MenuBar");
|
|
50
|
+
}
|
|
51
|
+
const { handleItemShow } = menubarContext;
|
|
52
|
+
|
|
53
|
+
// Set the context to pass down to items
|
|
54
|
+
let context: MenuBarItemContext = {
|
|
55
|
+
setVisible,
|
|
56
|
+
state: $state,
|
|
57
|
+
index: -1
|
|
58
|
+
};
|
|
59
|
+
$context[MenuBarItemContextName] = context;
|
|
60
|
+
|
|
61
|
+
// Set the context to pass down to items
|
|
62
|
+
let popoverContext: PopoverContext = {
|
|
63
|
+
setVisible,
|
|
64
|
+
handleButton,
|
|
65
|
+
modal: false,
|
|
66
|
+
state: $state,
|
|
67
|
+
//anchorElement: anchor,
|
|
68
|
+
};
|
|
69
|
+
$context[PopoverContextName] = popoverContext;
|
|
70
|
+
|
|
71
|
+
$mount(() => {
|
|
72
|
+
setVisible();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
function setVisible(value: boolean) {
|
|
76
|
+
if (!value || menubarContext.state.active) {
|
|
77
|
+
$state.visible = value;
|
|
78
|
+
if (value) {
|
|
79
|
+
handleItemShow(context.index);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let firstToggle = true;
|
|
85
|
+
$run(() => {
|
|
86
|
+
const ontoggle = $props.ontoggle;
|
|
87
|
+
const onopen = $props.onopen;
|
|
88
|
+
const onclose = $props.onclose;
|
|
89
|
+
const visible = $state.visible;
|
|
90
|
+
if (firstToggle) {
|
|
91
|
+
firstToggle = false;
|
|
92
|
+
} else {
|
|
93
|
+
if (ontoggle) ontoggle(visible);
|
|
94
|
+
if (visible) {
|
|
95
|
+
if (onopen) onopen()
|
|
96
|
+
} else {
|
|
97
|
+
if (onclose) onclose(result);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
103
|
+
menubarContext.state.active = false;
|
|
104
|
+
setVisible(false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@render {
|
|
108
|
+
<div
|
|
109
|
+
{$props.id}
|
|
110
|
+
class={`torp-menu-bar-item ${$props.class ?? ""}`.trim()}
|
|
111
|
+
>
|
|
112
|
+
<slot />
|
|
113
|
+
</div>
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
2
|
+
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
3
|
+
import {
|
|
4
|
+
MenuBarContextName,
|
|
5
|
+
MenuBarItemContextName,
|
|
6
|
+
type MenuBarContext,
|
|
7
|
+
type MenuBarItemContext
|
|
8
|
+
} from "./MenuBarTypes";
|
|
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
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The content that is displayed for a MenuBarItem when it is open.
|
|
23
|
+
*/
|
|
24
|
+
export default function MenuBarItemContent($props: MenuBarItemContentProps) {
|
|
25
|
+
$props ??= $watch({});
|
|
26
|
+
$props.side ??= "bottom";
|
|
27
|
+
$props.alignment ??= "start";
|
|
28
|
+
|
|
29
|
+
let div: HTMLDivElement;
|
|
30
|
+
let closeOnClick = false;
|
|
31
|
+
let shown = false;
|
|
32
|
+
|
|
33
|
+
// Get stuff out of the MenuBarContext
|
|
34
|
+
const context = $context[MenuBarContextName] as MenuBarContext;
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("MenuBarItemContent must be contained within a MenuBar");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Get stuff out of the MenuBarItemContext
|
|
40
|
+
const itemContext = $context[MenuBarItemContextName] as MenuBarItemContext;
|
|
41
|
+
if (!itemContext) {
|
|
42
|
+
throw new Error("MenuBarItemContent must be contained within a MenuBarItem");
|
|
43
|
+
}
|
|
44
|
+
const { state: $state, setVisible } = itemContext;
|
|
45
|
+
|
|
46
|
+
$run(() => {
|
|
47
|
+
if (!$state.visible) {
|
|
48
|
+
hide();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function show() {
|
|
53
|
+
shown = true;
|
|
54
|
+
|
|
55
|
+
// HACK: Because this Contextual could be shown with a click, we need to wait for another mousedown
|
|
56
|
+
// before we close on click. Otherwise the click immediately bubbles to the document. I guess
|
|
57
|
+
// we could require the user to preventDefault after calling showContextual, but that seems very
|
|
58
|
+
// error-prone?
|
|
59
|
+
closeOnClick = false;
|
|
60
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
61
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
62
|
+
|
|
63
|
+
// Set the position and listen for window resize and scroll to reset the position
|
|
64
|
+
setPosition();
|
|
65
|
+
addEventListener("resize", setPosition);
|
|
66
|
+
addEventListener("scroll", setPosition);
|
|
67
|
+
if (itemContext.focusFirstElement) {
|
|
68
|
+
itemContext.focusFirstElement();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function hide() {
|
|
73
|
+
if (!shown) return;
|
|
74
|
+
|
|
75
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
76
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
77
|
+
|
|
78
|
+
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
79
|
+
removeEventListener("resize", setPosition);
|
|
80
|
+
removeEventListener("scroll", setPosition);
|
|
81
|
+
if (itemContext.anchorElement?.focus) {
|
|
82
|
+
itemContext.anchorElement.focus();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function handleDocumentMouseDown() {
|
|
87
|
+
closeOnClick = true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function handleDocumentClick(e: MouseEvent) {
|
|
91
|
+
if (closeOnClick && !div.contains(e.target as HTMLElement)) {
|
|
92
|
+
context.active = false;
|
|
93
|
+
setVisible(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function setPosition() {
|
|
98
|
+
if (!itemContext.anchorElement) {
|
|
99
|
+
throw new Error("MenuBarItemContent must have an anchor element");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setPopoverPosition(itemContext.anchorElement, div, $props.side, $props.alignment);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@render {
|
|
106
|
+
@if ($state.visible) {
|
|
107
|
+
<div
|
|
108
|
+
{$props.id}
|
|
109
|
+
class={`torp-menu-bar-item-content ${$props.class ?? ""}`.trim()}
|
|
110
|
+
&ref={div}
|
|
111
|
+
onmount={show}
|
|
112
|
+
>
|
|
113
|
+
<slot />
|
|
114
|
+
</div>
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MenuBarContextName,
|
|
3
|
+
MenuBarItemContextName,
|
|
4
|
+
type MenuBarContext,
|
|
5
|
+
type MenuBarItemContext
|
|
6
|
+
} from "./MenuBarTypes";
|
|
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
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A button that is placed in a MenuBar and opens a submenu.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps) {
|
|
22
|
+
$props ??= $watch({});
|
|
23
|
+
$props.disabled ??= false;
|
|
24
|
+
|
|
25
|
+
let button: HTMLButtonElement;
|
|
26
|
+
|
|
27
|
+
// Get stuff out of the MenuBarContext
|
|
28
|
+
const menubarContext = $context[MenuBarContextName] as MenuBarContext;
|
|
29
|
+
if (!menubarContext) {
|
|
30
|
+
throw new Error("MenuBarItemTrigger must be contained within a MenuBar");
|
|
31
|
+
}
|
|
32
|
+
const { registerItem, handleButtonKey, handleButtonFocus } = menubarContext;
|
|
33
|
+
|
|
34
|
+
// Get stuff out of the MenuBarItemContext
|
|
35
|
+
const itemContext = $context[MenuBarItemContextName] as MenuBarItemContext;
|
|
36
|
+
if (!itemContext) {
|
|
37
|
+
throw new Error("MenuBarItemTrigger must be contained within a MenuBarItem");
|
|
38
|
+
}
|
|
39
|
+
const { state: $state, setVisible } = itemContext;
|
|
40
|
+
|
|
41
|
+
// Register this item with the parent MenuBar and store the index
|
|
42
|
+
const { index } = registerItem(setVisible, setFocused);
|
|
43
|
+
|
|
44
|
+
$mount(() => {
|
|
45
|
+
// Set the anchor element to the button when it exists
|
|
46
|
+
//itemContext.anchorElement = button;
|
|
47
|
+
itemContext.index = index;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function setFocused() {
|
|
51
|
+
button.focus();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function handleClick() {
|
|
55
|
+
menubarContext.state.active = !menubarContext.state.active;
|
|
56
|
+
setVisible(menubarContext.state.active);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleKey(e: KeyboardEvent) {
|
|
60
|
+
switch (e.key) {
|
|
61
|
+
case "Down":
|
|
62
|
+
case "ArrowDown":
|
|
63
|
+
// TODO: This should be based on what side the menu shows on
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
menubarContext.state.active = true;
|
|
66
|
+
setVisible(true);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
handleButtonKey(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleMouseEnter() {
|
|
74
|
+
setVisible(true);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@render {
|
|
78
|
+
<button
|
|
79
|
+
{$props.id}
|
|
80
|
+
class={`torp-menu-bar-item-button ${$props.class ?? ""}`.trim()}
|
|
81
|
+
type="button"
|
|
82
|
+
{$props.disabled}
|
|
83
|
+
role="menuitem"
|
|
84
|
+
aria-haspopup="true"
|
|
85
|
+
aria-expanded={($state.visible ?? false).toString()}
|
|
86
|
+
aria-disabled={$props.disabled ? "true" : undefined}
|
|
87
|
+
data-disabled={$props.disabled ? "true" : undefined}
|
|
88
|
+
onkeydown={handleKey}
|
|
89
|
+
onclick={handleClick}
|
|
90
|
+
onfocus={() => handleButtonFocus(index)}
|
|
91
|
+
onmouseenter={handleMouseEnter}
|
|
92
|
+
&ref={button}
|
|
93
|
+
onmount={(el) => itemContext.anchorElement = el}
|
|
94
|
+
>
|
|
95
|
+
<slot />
|
|
96
|
+
</button>
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const MenuBarContextName = "MenuBar";
|
|
2
|
+
export const MenuBarItemContextName = "MenuBarItem";
|
|
3
|
+
|
|
4
|
+
export interface MenuBarContext {
|
|
5
|
+
/** Called from a MenuBarItem when it is shown, to hide others */
|
|
6
|
+
handleItemShow: (index: number) => void;
|
|
7
|
+
|
|
8
|
+
/** Called from a MenuBarButton when its button is focused */
|
|
9
|
+
handleButtonFocus: (index: number) => void;
|
|
10
|
+
|
|
11
|
+
/** Called from a MenuBarButton when a key is pressed */
|
|
12
|
+
handleButtonKey: (e: KeyboardEvent) => void;
|
|
13
|
+
|
|
14
|
+
/** Called from each MenuBarButton to register itself with this MenuBar */
|
|
15
|
+
registerItem: (setVisible: (value: boolean) => void, setFocused: () => void) => { index: number };
|
|
16
|
+
|
|
17
|
+
state: {
|
|
18
|
+
/** Whether a menubar item is showing its content. If so, changing to another item should show its content */
|
|
19
|
+
active: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MenuBarItemContext {
|
|
24
|
+
setVisible: (value: boolean) => void;
|
|
25
|
+
state: {
|
|
26
|
+
visible: boolean;
|
|
27
|
+
};
|
|
28
|
+
index: number;
|
|
29
|
+
anchorElement?: HTMLElement;
|
|
30
|
+
focusFirstElement?: () => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ItemState {
|
|
34
|
+
setVisible: (value: boolean) => void;
|
|
35
|
+
setFocused: () => void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import MenuBar from "./MenuBar.torp";
|
|
2
|
+
import MenuBarItem from "./MenuBarItem.torp";
|
|
3
|
+
import MenuBarItemContent from "./MenuBarItemContent.torp";
|
|
4
|
+
import MenuBarItemTrigger from "./MenuBarItemTrigger.torp";
|
|
5
|
+
|
|
6
|
+
export { MenuBar, MenuBarItem, MenuBarItemTrigger, MenuBarItemContent };
|
package/src/NavMenu/NavMenu.torp
CHANGED
|
@@ -6,6 +6,17 @@ import {
|
|
|
6
6
|
type NavMenuPopoutContext
|
|
7
7
|
} from "./NavMenuTypes";
|
|
8
8
|
|
|
9
|
+
interface NavMenuProps {
|
|
10
|
+
/** An ID for the root element */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Class name(s) for the root element */
|
|
13
|
+
class?: string,
|
|
14
|
+
/** An ARIA label for describing the menu to screen readers */
|
|
15
|
+
ariaLabel?: string | undefined,
|
|
16
|
+
/** The orientation of the menu, which affects keyboard navigation */
|
|
17
|
+
orientation?: "horizontal" | "vertical",
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
/**
|
|
10
21
|
* A list of links for navigating a website.
|
|
11
22
|
*
|
|
@@ -21,11 +32,9 @@ import {
|
|
|
21
32
|
* ...
|
|
22
33
|
* </NavMenu>
|
|
23
34
|
* ```
|
|
24
|
-
*
|
|
25
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the menu to screen readers
|
|
26
|
-
* @prop {"horizontal" | "vertical"} orientation -- The orientation of the menu, which affects keyboard navigation
|
|
27
35
|
*/
|
|
28
|
-
export default function NavMenu($props:
|
|
36
|
+
export default function NavMenu($props: NavMenuProps) {
|
|
37
|
+
$props ??= $watch({});
|
|
29
38
|
$props.orientation ||= "horizontal";
|
|
30
39
|
|
|
31
40
|
// A collection containing the state and some functions for each item
|
|
@@ -164,7 +173,7 @@ export default function NavMenu($props: any) {
|
|
|
164
173
|
|
|
165
174
|
@render {
|
|
166
175
|
<nav
|
|
167
|
-
|
|
176
|
+
{$props.id}
|
|
168
177
|
class={`torp-nav-menu ${$props.class ?? ""}`.trim()}
|
|
169
178
|
tabindex="0"
|
|
170
179
|
role="menubar"
|
|
@@ -172,7 +181,7 @@ export default function NavMenu($props: any) {
|
|
|
172
181
|
aria-orientation={$props.orientation}
|
|
173
182
|
onfocus={handleFocus}
|
|
174
183
|
>
|
|
175
|
-
|
|
184
|
+
<slot />
|
|
176
185
|
</nav>
|
|
177
186
|
}
|
|
178
187
|
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuButtonProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether this button is disabled */
|
|
9
|
+
disabled?: boolean,
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* A button that is placed in a NavMenu to carry out a non-navigation action such as logging out.
|
|
5
14
|
*
|
|
6
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
7
15
|
*/
|
|
8
|
-
export default function NavMenuButton($props:
|
|
9
|
-
|
|
10
|
-
let dataDisabled = $props.disabled || undefined;
|
|
16
|
+
export default function NavMenuButton($props: NavMenuButtonProps) {
|
|
17
|
+
$props ??= $watch({});
|
|
11
18
|
|
|
12
19
|
let button: HTMLButtonElement;
|
|
13
20
|
|
|
@@ -27,20 +34,20 @@ export default function NavMenuButton($props: any) {
|
|
|
27
34
|
|
|
28
35
|
@render {
|
|
29
36
|
<button
|
|
30
|
-
|
|
37
|
+
{$props.id}
|
|
31
38
|
class={`torp-nav-menu-button ${$props.class ?? ""}`.trim()}
|
|
32
39
|
type="button"
|
|
33
40
|
{$props.disabled}
|
|
34
41
|
role="menuitem"
|
|
35
42
|
aria-disabled={$props.disabled ? "true" : undefined}
|
|
36
|
-
data-disabled={
|
|
43
|
+
data-disabled={$props.disabled ? "true" : undefined}
|
|
37
44
|
onkeydown
|
|
38
45
|
onkeydown={handleItemKey}
|
|
39
46
|
onclick
|
|
40
47
|
onfocus={() => handleItemFocus(index)}
|
|
41
48
|
&ref={button}
|
|
42
49
|
>
|
|
43
|
-
|
|
50
|
+
<slot />
|
|
44
51
|
</button>
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuElementProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether this button is disabled */
|
|
9
|
+
disabled?: boolean,
|
|
10
|
+
/** An element that can be focused via keyboard navigation */
|
|
11
|
+
element?: HTMLElement,
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* An element of any type that can be placed in a NavMenu.
|
|
5
16
|
*
|
|
6
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
7
|
-
* @prop {HTMLElement} element -- An element that can be focused via keyboard navigation
|
|
8
17
|
*/
|
|
9
|
-
export default function NavMenuElement($props:
|
|
10
|
-
|
|
11
|
-
let dataDisabled = $props.disabled || undefined;
|
|
18
|
+
export default function NavMenuElement($props: NavMenuElementProps) {
|
|
19
|
+
$props ??= $watch({});
|
|
12
20
|
|
|
13
21
|
// Get stuff out of the NavMenuContext
|
|
14
22
|
const menuContext = $context[NavMenuContextName] as NavMenuContext;
|
|
@@ -26,18 +34,18 @@ export default function NavMenuElement($props: any) {
|
|
|
26
34
|
|
|
27
35
|
@render {
|
|
28
36
|
<div
|
|
29
|
-
|
|
37
|
+
{$props.id}
|
|
30
38
|
class={`torp-nav-menu-div ${$props.class ?? ""}`.trim()}
|
|
31
39
|
type="div"
|
|
32
40
|
role="menuitem"
|
|
33
41
|
aria-disabled={$props.disabled ? "true" : undefined}
|
|
34
|
-
data-disabled={
|
|
42
|
+
data-disabled={$props.disabled ? "true" : undefined}
|
|
35
43
|
onkeydown
|
|
36
44
|
onkeydown={handleItemKey}
|
|
37
45
|
onclick
|
|
38
46
|
onfocus={() => handleItemFocus(index)}
|
|
39
47
|
>
|
|
40
|
-
|
|
48
|
+
<slot />
|
|
41
49
|
</div>
|
|
42
50
|
}
|
|
43
51
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
|
|
2
2
|
|
|
3
|
+
interface NavMenuGroupProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** An ARIA label for describing the group to screen readers */
|
|
9
|
+
ariaLabel?: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* A container for a logical group of navigation menu items.
|
|
5
|
-
*
|
|
6
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the group to screen readers
|
|
7
14
|
*/
|
|
8
|
-
export default function NavMenuGroup($props:
|
|
15
|
+
export default function NavMenuGroup($props: NavMenuGroupProps) {
|
|
16
|
+
$props ??= $watch({});
|
|
17
|
+
|
|
9
18
|
let $state = $watch({
|
|
10
19
|
headerId: ""
|
|
11
20
|
});
|
|
@@ -18,13 +27,13 @@ export default function NavMenuGroup($props: any) {
|
|
|
18
27
|
|
|
19
28
|
@render {
|
|
20
29
|
<div
|
|
21
|
-
|
|
30
|
+
{$props.id}
|
|
22
31
|
class={`torp-nav-menu-group ${$props.class ?? ""}`.trim()}
|
|
23
32
|
role="group"
|
|
24
33
|
aria-label={$props.ariaLabel}
|
|
25
34
|
aria-labelledby={$state.headerId}
|
|
26
35
|
>
|
|
27
|
-
|
|
36
|
+
<slot />
|
|
28
37
|
</div>
|
|
29
38
|
}
|
|
30
39
|
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
|
+
interface NavMenuGroupHeaderProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The type of HTML header to use */
|
|
10
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* The header for a NavMenuGroup.
|
|
6
|
-
*
|
|
7
|
-
* @prop {"h1" | "h2" | "h3" | "h4" | "h5" | "h6"} as -- The type of HTML header to use
|
|
8
15
|
*/
|
|
9
|
-
export default function NavMenuGroupHeader($props:
|
|
16
|
+
export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps) {
|
|
17
|
+
$props ??= $watch({});
|
|
10
18
|
$props.id ??= getId();
|
|
11
19
|
|
|
12
20
|
const context = $context[NavMenuGroupContextName] as NavMenuGroupContext;
|
|
@@ -19,12 +27,12 @@ export default function NavMenuGroupHeader($props: any) {
|
|
|
19
27
|
$state.headerId = $props.id;
|
|
20
28
|
|
|
21
29
|
@render {
|
|
30
|
+
@// TODO: self={$props.as}
|
|
22
31
|
<h4
|
|
23
|
-
|
|
24
|
-
id={$props.id}
|
|
32
|
+
{$props.id}
|
|
25
33
|
class={`torp-nav-menu-group-header ${$props.class ?? ""}`.trim()}
|
|
26
34
|
>
|
|
27
|
-
|
|
35
|
+
<slot />
|
|
28
36
|
</h4>
|
|
29
37
|
}
|
|
30
38
|
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
|
|
2
2
|
import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
|
+
interface NavMenuLinkProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The URL for the menu link */
|
|
10
|
+
href: string,
|
|
11
|
+
/** Whether the menu link should open in a new tab/window */
|
|
12
|
+
newWindow?: boolean,
|
|
13
|
+
/** Whether this link is disabled */
|
|
14
|
+
disabled?: boolean,
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
/**
|
|
5
18
|
* A link that is placed in a NavMenu and signals a response by a user.
|
|
6
19
|
*
|
|
7
|
-
* @prop {string} href -- The URL for the menu link
|
|
8
|
-
* @prop {newWindow} boolean -- Whether the menu link should open in a new tab/window
|
|
9
|
-
* @prop {boolean} disabled -- Whether this link is disabled
|
|
10
20
|
*/
|
|
11
|
-
export default function NavMenuLink($props:
|
|
21
|
+
export default function NavMenuLink($props: NavMenuLinkProps) {
|
|
22
|
+
$props ??= $watch({ href: "#" });
|
|
12
23
|
$props.newWindow ??= false;
|
|
13
24
|
|
|
14
|
-
/** Set when the item is disabled */
|
|
15
|
-
let dataDisabled = $props.disabled || undefined;
|
|
16
|
-
|
|
17
25
|
let link: HTMLAnchorElement;
|
|
18
26
|
|
|
19
27
|
// Get stuff out of the NavMenuContext
|
|
@@ -32,21 +40,21 @@ export default function NavMenuLink($props: any) {
|
|
|
32
40
|
|
|
33
41
|
@render {
|
|
34
42
|
<a
|
|
35
|
-
|
|
43
|
+
{$props.id}
|
|
36
44
|
class={`torp-nav-menu-link ${$props.class ?? ""}`.trim()}
|
|
37
45
|
href={$props.href}
|
|
38
46
|
{$props.disabled}
|
|
39
47
|
target={$props.newWindow ? "_blank" : undefined}
|
|
40
48
|
role="menuitem"
|
|
41
49
|
aria-disabled={$props.disabled ? "true" : undefined}
|
|
42
|
-
data-disabled={
|
|
50
|
+
data-disabled={$props.disabled ? "true" : undefined}
|
|
43
51
|
onkeydown
|
|
44
52
|
onkeydown={handleItemKey}
|
|
45
53
|
onclick
|
|
46
54
|
onfocus={() => handleItemFocus(index)}
|
|
47
55
|
&ref={link}
|
|
48
56
|
>
|
|
49
|
-
|
|
57
|
+
<slot />
|
|
50
58
|
</a>
|
|
51
59
|
}
|
|
52
60
|
}
|