@torpor/ui 0.1.6 → 0.2.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 +47 -0
- package/dist/Accordion/Accordion.torp +2 -2
- package/dist/Accordion/AccordionContent.torp +2 -2
- package/dist/Accordion/AccordionHeader.torp +2 -2
- package/dist/Accordion/AccordionItem.torp +2 -2
- package/dist/Accordion/AccordionTrigger.torp +2 -2
- package/dist/Accordion/index.d.ts +92 -0
- package/dist/Breadcrumb/Breadcrumb.torp +33 -0
- package/dist/Breadcrumb/BreadcrumbItem.torp +19 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +16 -0
- package/dist/Breadcrumb/index.d.ts +56 -0
- package/dist/Breadcrumb/index.js +14 -0
- package/dist/Calendar/Calendar.torp +265 -0
- package/dist/Calendar/CalendarDay.torp +67 -0
- package/dist/Calendar/CalendarTypes.ts +22 -0
- package/dist/Calendar/index.d.ts +38 -0
- package/dist/Calendar/index.js +10 -0
- package/dist/Calendar/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +3 -3
- package/dist/Dialog/DialogBody.torp +2 -2
- package/dist/Dialog/DialogButton.torp +2 -2
- package/dist/Dialog/DialogFooter.torp +2 -2
- package/dist/Dialog/DialogHeader.torp +2 -2
- package/dist/Dialog/index.d.ts +92 -0
- package/dist/Disclosure/Disclosure.torp +69 -0
- package/dist/Disclosure/DisclosureContent.torp +36 -0
- package/dist/Disclosure/DisclosureHeader.torp +34 -0
- package/dist/Disclosure/DisclosureTrigger.torp +36 -0
- package/dist/Disclosure/DisclosureTypes.ts +14 -0
- package/dist/Disclosure/index.d.ts +74 -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} +10 -19
- package/dist/Drawer/index.d.ts +20 -0
- package/dist/Drawer/index.js +6 -0
- package/dist/Drawer/index.js.map +1 -0
- package/dist/Menu/Menu.torp +160 -0
- package/dist/Menu/MenuButton.torp +53 -0
- package/dist/Menu/MenuCheck.torp +70 -0
- package/dist/Menu/MenuGroup.torp +19 -0
- package/dist/Menu/MenuIndicator.torp +29 -0
- package/dist/Menu/MenuPopout.torp +71 -0
- package/dist/Menu/MenuPopoutContent.torp +74 -0
- package/dist/Menu/MenuPopoutTrigger.torp +117 -0
- package/dist/Menu/MenuRadio.torp +88 -0
- package/dist/Menu/MenuRadioGroup.torp +86 -0
- package/dist/Menu/MenuSeparator.torp +14 -0
- package/dist/Menu/MenuTypes.ts +58 -0
- package/dist/Menu/index.d.ts +200 -0
- package/dist/Menu/index.js +46 -0
- package/dist/Menu/index.js.map +1 -0
- package/dist/MenuBar/MenuBar.torp +150 -0
- package/dist/MenuBar/MenuBarItem.torp +104 -0
- package/dist/MenuBar/MenuBarItemContent.torp +108 -0
- package/dist/MenuBar/MenuBarItemTrigger.torp +89 -0
- package/dist/MenuBar/MenuBarTypes.ts +36 -0
- package/dist/MenuBar/index.d.ts +74 -0
- package/dist/MenuBar/index.js +18 -0
- package/dist/MenuBar/index.js.map +1 -0
- package/dist/NavMenu/NavMenu.torp +2 -2
- package/dist/NavMenu/NavMenuButton.torp +2 -2
- package/dist/NavMenu/NavMenuElement.torp +2 -2
- package/dist/NavMenu/NavMenuGroup.torp +2 -2
- package/dist/NavMenu/NavMenuGroupHeader.torp +2 -2
- package/dist/NavMenu/NavMenuLink.torp +2 -2
- package/dist/NavMenu/NavMenuPopout.torp +2 -2
- package/dist/NavMenu/NavMenuPopoutButton.torp +3 -3
- package/dist/NavMenu/NavMenuPopoutContent.torp +29 -27
- package/dist/NavMenu/NavMenuSeparator.torp +2 -2
- package/dist/NavMenu/index.d.ts +182 -0
- package/dist/Notification/Notification.torp +48 -0
- package/dist/Notification/NotificationClose.torp +28 -0
- package/dist/Notification/NotificationContainer.torp +14 -0
- package/dist/Notification/NotificationContent.torp +13 -0
- package/dist/Notification/NotificationTypes.ts +5 -0
- package/dist/Notification/index.d.ts +74 -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 +2 -2
- package/dist/Popover/PopoverContent.torp +31 -28
- package/dist/Popover/PopoverContentAnchored.torp +39 -38
- package/dist/Popover/PopoverContentContextual.torp +39 -36
- package/dist/Popover/PopoverOverlay.torp +3 -3
- package/dist/Popover/PopoverTrigger.torp +2 -2
- package/dist/Popover/PopoverTriggerContextual.torp +2 -2
- package/dist/Popover/PopoverTriggerHover.torp +3 -3
- package/dist/Popover/index.d.ts +146 -0
- package/dist/TabGroup/TabContent.torp +2 -2
- package/dist/TabGroup/TabGroup.torp +2 -2
- package/dist/TabGroup/TabHeader.torp +3 -3
- package/dist/TabGroup/TabList.torp +2 -2
- package/dist/TabGroup/TabTrigger.torp +2 -2
- package/dist/TabGroup/index.d.ts +92 -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 +254 -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 +51 -35
- package/scripts/postbuild.ts +42 -5
- package/src/Accordion/Accordion.torp +2 -2
- package/src/Accordion/AccordionContent.torp +2 -2
- package/src/Accordion/AccordionHeader.torp +2 -2
- package/src/Accordion/AccordionItem.torp +2 -2
- package/src/Accordion/AccordionTrigger.torp +2 -2
- package/src/Breadcrumb/Breadcrumb.torp +33 -0
- package/src/Breadcrumb/BreadcrumbItem.torp +19 -0
- package/src/Breadcrumb/BreadcrumbSeparator.torp +16 -0
- package/src/Breadcrumb/index.ts +5 -0
- package/src/Calendar/Calendar.torp +265 -0
- package/src/Calendar/CalendarDay.torp +67 -0
- package/src/Calendar/CalendarTypes.ts +22 -0
- package/src/Calendar/index.ts +4 -0
- package/src/Dialog/Dialog.torp +3 -3
- package/src/Dialog/DialogBody.torp +2 -2
- package/src/Dialog/DialogButton.torp +2 -2
- package/src/Dialog/DialogFooter.torp +2 -2
- package/src/Dialog/DialogHeader.torp +2 -2
- package/src/Disclosure/Disclosure.torp +69 -0
- package/src/Disclosure/DisclosureContent.torp +36 -0
- package/src/Disclosure/DisclosureHeader.torp +34 -0
- package/src/Disclosure/DisclosureTrigger.torp +36 -0
- package/src/Disclosure/DisclosureTypes.ts +14 -0
- package/src/Disclosure/index.ts +6 -0
- package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +10 -19
- package/src/Drawer/index.ts +3 -0
- package/src/Menu/Menu.torp +160 -0
- package/src/Menu/MenuButton.torp +53 -0
- package/src/Menu/MenuCheck.torp +70 -0
- package/src/Menu/MenuGroup.torp +19 -0
- package/src/Menu/MenuIndicator.torp +29 -0
- package/src/Menu/MenuPopout.torp +71 -0
- package/src/Menu/MenuPopoutContent.torp +74 -0
- package/src/Menu/MenuPopoutTrigger.torp +117 -0
- package/src/Menu/MenuRadio.torp +88 -0
- package/src/Menu/MenuRadioGroup.torp +86 -0
- package/src/Menu/MenuSeparator.torp +14 -0
- package/src/Menu/MenuTypes.ts +58 -0
- package/src/Menu/index.ts +25 -0
- package/src/MenuBar/MenuBar.torp +150 -0
- package/src/MenuBar/MenuBarItem.torp +104 -0
- package/src/MenuBar/MenuBarItemContent.torp +108 -0
- package/src/MenuBar/MenuBarItemTrigger.torp +89 -0
- package/src/MenuBar/MenuBarTypes.ts +36 -0
- package/src/MenuBar/index.ts +6 -0
- package/src/NavMenu/NavMenu.torp +2 -2
- package/src/NavMenu/NavMenuButton.torp +2 -2
- package/src/NavMenu/NavMenuElement.torp +2 -2
- package/src/NavMenu/NavMenuGroup.torp +2 -2
- package/src/NavMenu/NavMenuGroupHeader.torp +2 -2
- package/src/NavMenu/NavMenuLink.torp +2 -2
- package/src/NavMenu/NavMenuPopout.torp +2 -2
- package/src/NavMenu/NavMenuPopoutButton.torp +3 -3
- package/src/NavMenu/NavMenuPopoutContent.torp +29 -27
- package/src/NavMenu/NavMenuSeparator.torp +2 -2
- package/src/Notification/Notification.torp +48 -0
- package/src/Notification/NotificationClose.torp +28 -0
- package/src/Notification/NotificationContainer.torp +14 -0
- package/src/Notification/NotificationContent.torp +13 -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 +2 -2
- package/src/Popover/PopoverContent.torp +31 -28
- package/src/Popover/PopoverContentAnchored.torp +39 -38
- package/src/Popover/PopoverContentContextual.torp +39 -36
- package/src/Popover/PopoverOverlay.torp +3 -3
- package/src/Popover/PopoverTrigger.torp +2 -2
- package/src/Popover/PopoverTriggerContextual.torp +2 -2
- package/src/Popover/PopoverTriggerHover.torp +3 -3
- package/src/Slider/Slider.torp +83 -0
- package/src/Slider/index.ts +3 -0
- package/src/TabGroup/TabContent.torp +2 -2
- package/src/TabGroup/TabGroup.torp +2 -2
- package/src/TabGroup/TabHeader.torp +3 -3
- package/src/TabGroup/TabList.torp +2 -2
- package/src/TabGroup/TabTrigger.torp +2 -2
- 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/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/Dialog/components/DialogFunction.torp +4 -6
- package/test/Dialog/components/DialogVariable.torp +19 -21
- package/test/Disclosure/accessibility.test.ts +30 -0
- package/test/Disclosure/components/DisclosureTest.torp +17 -0
- package/test/Disclosure/default.test.ts +15 -0
- package/test/Disclosure/toggle.test.ts +19 -0
- package/test/Menu/accessibility.test.ts +82 -0
- package/test/Menu/basic.test.ts +57 -0
- package/test/Menu/components/MenuAccessibility.torp +59 -0
- package/test/Menu/components/MenuBasic.torp +58 -0
- package/test/MenuBar/accessibility.test.ts +86 -0
- package/test/MenuBar/basic.test.ts +21 -0
- package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
- package/test/MenuBar/components/MenuBarBasic.torp +25 -0
- 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/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,108 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* 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
|
+
*/
|
|
16
|
+
export default function MenuBarItemContent() {
|
|
17
|
+
$props.side ??= "bottom";
|
|
18
|
+
$props.alignment ??= "start";
|
|
19
|
+
|
|
20
|
+
let div: HTMLDivElement;
|
|
21
|
+
let closeOnClick = false;
|
|
22
|
+
let shown = false;
|
|
23
|
+
|
|
24
|
+
// Get stuff out of the MenuBarContext
|
|
25
|
+
const context = $context[MenuBarContextName] as MenuBarContext;
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error("MenuBarItemContent must be contained within a MenuBar");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Get stuff out of the MenuBarItemContext
|
|
31
|
+
const itemContext = $context[MenuBarItemContextName] as MenuBarItemContext;
|
|
32
|
+
if (!itemContext) {
|
|
33
|
+
throw new Error("MenuBarItemContent must be contained within a MenuBarItem");
|
|
34
|
+
}
|
|
35
|
+
const { state: $state, setVisible } = itemContext;
|
|
36
|
+
|
|
37
|
+
$run(() => {
|
|
38
|
+
if (!$state.visible) {
|
|
39
|
+
hide();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function show() {
|
|
44
|
+
shown = true;
|
|
45
|
+
|
|
46
|
+
// HACK: Because this Contextual could be shown with a click, we need to wait for another mousedown
|
|
47
|
+
// before we close on click. Otherwise the click immediately bubbles to the document. I guess
|
|
48
|
+
// we could require the user to preventDefault after calling showContextual, but that seems very
|
|
49
|
+
// error-prone?
|
|
50
|
+
closeOnClick = false;
|
|
51
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
52
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
53
|
+
|
|
54
|
+
// Set the position and listen for window resize and scroll to reset the position
|
|
55
|
+
setPosition();
|
|
56
|
+
addEventListener("resize", setPosition);
|
|
57
|
+
addEventListener("scroll", setPosition);
|
|
58
|
+
if (itemContext.focusFirstElement) {
|
|
59
|
+
itemContext.focusFirstElement();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function hide() {
|
|
64
|
+
if (!shown) return;
|
|
65
|
+
|
|
66
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
67
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
68
|
+
|
|
69
|
+
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
70
|
+
removeEventListener("resize", setPosition);
|
|
71
|
+
removeEventListener("scroll", setPosition);
|
|
72
|
+
if (itemContext.anchorElement?.focus) {
|
|
73
|
+
itemContext.anchorElement.focus();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function handleDocumentMouseDown() {
|
|
78
|
+
closeOnClick = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function handleDocumentClick(e: MouseEvent) {
|
|
82
|
+
if (closeOnClick && !div.contains(e.target as HTMLElement)) {
|
|
83
|
+
context.active = false;
|
|
84
|
+
setVisible(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setPosition() {
|
|
89
|
+
if (!itemContext.anchorElement) {
|
|
90
|
+
throw new Error("MenuBarItemContent must have an anchor element");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setPopoverPosition(itemContext.anchorElement, div, $props.side, $props.alignment);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@render {
|
|
97
|
+
@if ($state.visible) {
|
|
98
|
+
<div
|
|
99
|
+
{$props.id}
|
|
100
|
+
class={`torp-menu-bar-item-content ${$props.class ?? ""}`.trim()}
|
|
101
|
+
&ref={div}
|
|
102
|
+
onmount={show}
|
|
103
|
+
>
|
|
104
|
+
<slot />
|
|
105
|
+
</div>
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MenuBarContextName,
|
|
3
|
+
MenuBarItemContextName,
|
|
4
|
+
type MenuBarContext,
|
|
5
|
+
type MenuBarItemContext
|
|
6
|
+
} from "./MenuBarTypes";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A button that is placed in a MenuBar and opens a submenu.
|
|
10
|
+
*
|
|
11
|
+
* @prop {boolean} disabled -- Whether this button is disabled
|
|
12
|
+
*/
|
|
13
|
+
export default function MenuBarItemTrigger() {
|
|
14
|
+
$props.disabled ??= false;
|
|
15
|
+
|
|
16
|
+
let button: HTMLButtonElement;
|
|
17
|
+
|
|
18
|
+
// Get stuff out of the MenuBarContext
|
|
19
|
+
const menubarContext = $context[MenuBarContextName] as MenuBarContext;
|
|
20
|
+
if (!menubarContext) {
|
|
21
|
+
throw new Error("MenuBarItemTrigger must be contained within a MenuBar");
|
|
22
|
+
}
|
|
23
|
+
const { registerItem, handleButtonKey, handleButtonFocus } = menubarContext;
|
|
24
|
+
|
|
25
|
+
// Get stuff out of the MenuBarItemContext
|
|
26
|
+
const itemContext = $context[MenuBarItemContextName] as MenuBarItemContext;
|
|
27
|
+
if (!itemContext) {
|
|
28
|
+
throw new Error("MenuBarItemTrigger must be contained within a MenuBarItem");
|
|
29
|
+
}
|
|
30
|
+
const { state: $state, setVisible } = itemContext;
|
|
31
|
+
|
|
32
|
+
// Register this item with the parent MenuBar and store the index
|
|
33
|
+
const { index } = registerItem(setVisible, setFocused);
|
|
34
|
+
|
|
35
|
+
$mount(() => {
|
|
36
|
+
// Set the anchor element to the button when it exists
|
|
37
|
+
//itemContext.anchorElement = button;
|
|
38
|
+
itemContext.index = index;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function setFocused() {
|
|
42
|
+
button.focus();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function handleClick() {
|
|
46
|
+
menubarContext.state.active = !menubarContext.state.active;
|
|
47
|
+
setVisible(menubarContext.state.active);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleKey(e: KeyboardEvent) {
|
|
51
|
+
switch (e.key) {
|
|
52
|
+
case "Down":
|
|
53
|
+
case "ArrowDown":
|
|
54
|
+
// TODO: This should be based on what side the menu shows on
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
menubarContext.state.active = true;
|
|
57
|
+
setVisible(true);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
handleButtonKey(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleMouseEnter() {
|
|
65
|
+
setVisible(true);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@render {
|
|
69
|
+
<button
|
|
70
|
+
{$props.id}
|
|
71
|
+
class={`torp-menu-bar-item-button ${$props.class ?? ""}`.trim()}
|
|
72
|
+
type="button"
|
|
73
|
+
{$props.disabled}
|
|
74
|
+
role="menuitem"
|
|
75
|
+
aria-haspopup="true"
|
|
76
|
+
aria-expanded={($state.visible ?? false).toString()}
|
|
77
|
+
aria-disabled={$props.disabled ? "true" : undefined}
|
|
78
|
+
data-disabled={$props.disabled ? "true" : undefined}
|
|
79
|
+
onkeydown={handleKey}
|
|
80
|
+
onclick={handleClick}
|
|
81
|
+
onfocus={() => handleButtonFocus(index)}
|
|
82
|
+
onmouseenter={handleMouseEnter}
|
|
83
|
+
&ref={button}
|
|
84
|
+
onmount={(el) => itemContext.anchorElement = el}
|
|
85
|
+
>
|
|
86
|
+
<slot />
|
|
87
|
+
</button>
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -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,74 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mounts or hydrates the component into the supplied parent node.
|
|
6
|
+
* @param $parent -- The parent node.
|
|
7
|
+
* @param $anchor -- The node to mount the component before.
|
|
8
|
+
* @param $props -- The values that have been passed into the component as properties.
|
|
9
|
+
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
10
|
+
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
11
|
+
*/
|
|
12
|
+
declare function MenuBar(
|
|
13
|
+
$parent: ParentNode,
|
|
14
|
+
$anchor: Node | null,
|
|
15
|
+
$props?: Record<PropertyKey, any>,
|
|
16
|
+
$context?: Record<PropertyKey, any>,
|
|
17
|
+
$slots?: Record<string, SlotRender>,
|
|
18
|
+
): void;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Mounts or hydrates the component into the supplied parent node.
|
|
24
|
+
* @param $parent -- The parent node.
|
|
25
|
+
* @param $anchor -- The node to mount the component before.
|
|
26
|
+
* @param $props -- The values that have been passed into the component as properties.
|
|
27
|
+
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
28
|
+
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
29
|
+
*/
|
|
30
|
+
declare function MenuBarItem(
|
|
31
|
+
$parent: ParentNode,
|
|
32
|
+
$anchor: Node | null,
|
|
33
|
+
$props?: Record<PropertyKey, any>,
|
|
34
|
+
$context?: Record<PropertyKey, any>,
|
|
35
|
+
$slots?: Record<string, SlotRender>,
|
|
36
|
+
): void;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mounts or hydrates the component into the supplied parent node.
|
|
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.
|
|
47
|
+
*/
|
|
48
|
+
declare function MenuBarItemContent(
|
|
49
|
+
$parent: ParentNode,
|
|
50
|
+
$anchor: Node | null,
|
|
51
|
+
$props?: Record<PropertyKey, any>,
|
|
52
|
+
$context?: Record<PropertyKey, any>,
|
|
53
|
+
$slots?: Record<string, SlotRender>,
|
|
54
|
+
): void;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Mounts or hydrates the component into the supplied parent node.
|
|
60
|
+
* @param $parent -- The parent node.
|
|
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.
|
|
65
|
+
*/
|
|
66
|
+
declare function MenuBarItemTrigger(
|
|
67
|
+
$parent: ParentNode,
|
|
68
|
+
$anchor: Node | null,
|
|
69
|
+
$props?: Record<PropertyKey, any>,
|
|
70
|
+
$context?: Record<PropertyKey, any>,
|
|
71
|
+
$slots?: Record<string, SlotRender>,
|
|
72
|
+
): void;
|
|
73
|
+
|
|
74
|
+
export { MenuBar, MenuBarItem, MenuBarItemContent, MenuBarItemTrigger };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/MenuBar/MenuBar.torp
|
|
2
|
+
import MenuBar_default from "./MenuBar.torp";
|
|
3
|
+
|
|
4
|
+
// src/MenuBar/MenuBarItem.torp
|
|
5
|
+
import MenuBarItem_default from "./MenuBarItem.torp";
|
|
6
|
+
|
|
7
|
+
// src/MenuBar/MenuBarItemContent.torp
|
|
8
|
+
import MenuBarItemContent_default from "./MenuBarItemContent.torp";
|
|
9
|
+
|
|
10
|
+
// src/MenuBar/MenuBarItemTrigger.torp
|
|
11
|
+
import MenuBarItemTrigger_default from "./MenuBarItemTrigger.torp";
|
|
12
|
+
export {
|
|
13
|
+
MenuBar_default as MenuBar,
|
|
14
|
+
MenuBarItem_default as MenuBarItem,
|
|
15
|
+
MenuBarItemContent_default as MenuBarItemContent,
|
|
16
|
+
MenuBarItemTrigger_default as MenuBarItemTrigger
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -164,7 +164,7 @@ export default function NavMenu($props: any) {
|
|
|
164
164
|
|
|
165
165
|
@render {
|
|
166
166
|
<nav
|
|
167
|
-
|
|
167
|
+
{$props.id}
|
|
168
168
|
class={`torp-nav-menu ${$props.class ?? ""}`.trim()}
|
|
169
169
|
tabindex="0"
|
|
170
170
|
role="menubar"
|
|
@@ -172,7 +172,7 @@ export default function NavMenu($props: any) {
|
|
|
172
172
|
aria-orientation={$props.orientation}
|
|
173
173
|
onfocus={handleFocus}
|
|
174
174
|
>
|
|
175
|
-
|
|
175
|
+
<slot />
|
|
176
176
|
</nav>
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -27,7 +27,7 @@ export default function NavMenuButton($props: any) {
|
|
|
27
27
|
|
|
28
28
|
@render {
|
|
29
29
|
<button
|
|
30
|
-
|
|
30
|
+
{$props.id}
|
|
31
31
|
class={`torp-nav-menu-button ${$props.class ?? ""}`.trim()}
|
|
32
32
|
type="button"
|
|
33
33
|
{$props.disabled}
|
|
@@ -40,7 +40,7 @@ export default function NavMenuButton($props: any) {
|
|
|
40
40
|
onfocus={() => handleItemFocus(index)}
|
|
41
41
|
&ref={button}
|
|
42
42
|
>
|
|
43
|
-
|
|
43
|
+
<slot />
|
|
44
44
|
</button>
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -26,7 +26,7 @@ export default function NavMenuElement($props: any) {
|
|
|
26
26
|
|
|
27
27
|
@render {
|
|
28
28
|
<div
|
|
29
|
-
|
|
29
|
+
{$props.id}
|
|
30
30
|
class={`torp-nav-menu-div ${$props.class ?? ""}`.trim()}
|
|
31
31
|
type="div"
|
|
32
32
|
role="menuitem"
|
|
@@ -37,7 +37,7 @@ export default function NavMenuElement($props: any) {
|
|
|
37
37
|
onclick
|
|
38
38
|
onfocus={() => handleItemFocus(index)}
|
|
39
39
|
>
|
|
40
|
-
|
|
40
|
+
<slot />
|
|
41
41
|
</div>
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -18,13 +18,13 @@ export default function NavMenuGroup($props: any) {
|
|
|
18
18
|
|
|
19
19
|
@render {
|
|
20
20
|
<div
|
|
21
|
-
|
|
21
|
+
{$props.id}
|
|
22
22
|
class={`torp-nav-menu-group ${$props.class ?? ""}`.trim()}
|
|
23
23
|
role="group"
|
|
24
24
|
aria-label={$props.ariaLabel}
|
|
25
25
|
aria-labelledby={$state.headerId}
|
|
26
26
|
>
|
|
27
|
-
|
|
27
|
+
<slot />
|
|
28
28
|
</div>
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -21,10 +21,10 @@ export default function NavMenuGroupHeader($props: any) {
|
|
|
21
21
|
@render {
|
|
22
22
|
<h4
|
|
23
23
|
@// TODO: self={$props.as}
|
|
24
|
-
|
|
24
|
+
{$props.id}
|
|
25
25
|
class={`torp-nav-menu-group-header ${$props.class ?? ""}`.trim()}
|
|
26
26
|
>
|
|
27
|
-
|
|
27
|
+
<slot />
|
|
28
28
|
</h4>
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -32,7 +32,7 @@ export default function NavMenuLink($props: any) {
|
|
|
32
32
|
|
|
33
33
|
@render {
|
|
34
34
|
<a
|
|
35
|
-
|
|
35
|
+
{$props.id}
|
|
36
36
|
class={`torp-nav-menu-link ${$props.class ?? ""}`.trim()}
|
|
37
37
|
href={$props.href}
|
|
38
38
|
{$props.disabled}
|
|
@@ -46,7 +46,7 @@ export default function NavMenuLink($props: any) {
|
|
|
46
46
|
onfocus={() => handleItemFocus(index)}
|
|
47
47
|
&ref={link}
|
|
48
48
|
>
|
|
49
|
-
|
|
49
|
+
<slot />
|
|
50
50
|
</a>
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -59,11 +59,11 @@ export default function NavMenuPopout($props: any) {
|
|
|
59
59
|
|
|
60
60
|
@render {
|
|
61
61
|
<div
|
|
62
|
-
|
|
62
|
+
{$props.id}
|
|
63
63
|
class={`torp-nav-menu-popout ${$props.class ?? ""}`.trim()}
|
|
64
64
|
onmouseleave={handleMouseLeave}
|
|
65
65
|
>
|
|
66
|
-
|
|
66
|
+
<slot />
|
|
67
67
|
</div>
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -96,7 +96,7 @@ export default function NavMenuPopoutButton($props: any) {
|
|
|
96
96
|
|
|
97
97
|
@render {
|
|
98
98
|
<button
|
|
99
|
-
|
|
99
|
+
{$props.id}
|
|
100
100
|
class={`torp-nav-menu-popout-button ${$props.class ?? ""}`.trim()}
|
|
101
101
|
type="button"
|
|
102
102
|
{$props.disabled}
|
|
@@ -112,9 +112,9 @@ export default function NavMenuPopoutButton($props: any) {
|
|
|
112
112
|
onmouseleave={handleMouseLeave}
|
|
113
113
|
onmousemove={handleMouseMove}
|
|
114
114
|
&ref={button}
|
|
115
|
-
|
|
115
|
+
onmount={(el) => popoutContext.anchorElement = el }
|
|
116
116
|
>
|
|
117
|
-
|
|
117
|
+
<slot />
|
|
118
118
|
</button>
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -14,6 +14,7 @@ export default function NavMenuPopoutContent($props: any) {
|
|
|
14
14
|
$props.alignment ??= "start";
|
|
15
15
|
|
|
16
16
|
let div: HTMLDivElement;
|
|
17
|
+
let shown = false;
|
|
17
18
|
|
|
18
19
|
// Get stuff out of the NavMenuPopoutContext
|
|
19
20
|
const context = $context[NavMenuPopoutContextName] as NavMenuPopoutContext;
|
|
@@ -22,35 +23,36 @@ export default function NavMenuPopoutContent($props: any) {
|
|
|
22
23
|
}
|
|
23
24
|
let $state = context.state;
|
|
24
25
|
|
|
25
|
-
let first = true;
|
|
26
26
|
$run(() => {
|
|
27
|
-
|
|
27
|
+
if (!$state.visible) {
|
|
28
|
+
hide();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
function show() {
|
|
33
|
+
shown = true;
|
|
34
|
+
|
|
35
|
+
// Set the position and listen for window resize and scroll to reset the position
|
|
36
|
+
setPosition();
|
|
37
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
38
|
+
scrollParent.addEventListener("resize", setPosition);
|
|
39
|
+
scrollParent.addEventListener("scroll", setPosition);
|
|
40
|
+
if (context.focusFirstElement) {
|
|
41
|
+
context.focusFirstElement();
|
|
32
42
|
}
|
|
43
|
+
}
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
scrollParent.addEventListener("scroll", setPosition);
|
|
44
|
-
} else {
|
|
45
|
-
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
46
|
-
const scrollParent = getScrollParent(context.anchorElement)
|
|
47
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
48
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
49
|
-
if (context.anchorElement?.focus) {
|
|
50
|
-
context.anchorElement.focus();
|
|
51
|
-
}
|
|
45
|
+
function hide() {
|
|
46
|
+
if (!shown) return;
|
|
47
|
+
|
|
48
|
+
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
49
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
50
|
+
scrollParent.removeEventListener("resize", setPosition);
|
|
51
|
+
scrollParent.removeEventListener("scroll", setPosition);
|
|
52
|
+
if (context.anchorElement?.focus) {
|
|
53
|
+
context.anchorElement.focus();
|
|
52
54
|
}
|
|
53
|
-
}
|
|
55
|
+
}
|
|
54
56
|
|
|
55
57
|
function setPosition() {
|
|
56
58
|
if (!context.anchorElement) {
|
|
@@ -65,12 +67,12 @@ export default function NavMenuPopoutContent($props: any) {
|
|
|
65
67
|
@render {
|
|
66
68
|
@if ($state.visible) {
|
|
67
69
|
<div
|
|
68
|
-
|
|
70
|
+
{$props.id}
|
|
69
71
|
class={`torp-nav-menu-popout-content ${$props.class ?? ""}`.trim()}
|
|
70
72
|
&ref={div}
|
|
71
|
-
|
|
73
|
+
onmount={show}
|
|
72
74
|
>
|
|
73
|
-
|
|
75
|
+
<slot />
|
|
74
76
|
</div>
|
|
75
77
|
}
|
|
76
78
|
}
|