@torpor/ui 0.3.5 → 0.3.6
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/dist/metafile-esm.json +1 -1
- package/package.json +5 -2
- package/CHANGELOG.md +0 -344
- package/scripts/postbuild.ts +0 -127
- package/src/Accordion/Accordion.torp +0 -230
- package/src/Accordion/AccordionContent.torp +0 -46
- package/src/Accordion/AccordionHeader.torp +0 -45
- package/src/Accordion/AccordionItem.torp +0 -101
- package/src/Accordion/AccordionTrigger.torp +0 -70
- package/src/Accordion/AccordionTypes.ts +0 -36
- package/src/Accordion/index.ts +0 -7
- package/src/Breadcrumb/Breadcrumb.torp +0 -45
- package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
- package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
- package/src/Breadcrumb/index.ts +0 -5
- package/src/Calendar/Calendar.torp +0 -277
- package/src/Calendar/CalendarDay.torp +0 -78
- package/src/Calendar/CalendarTypes.ts +0 -22
- package/src/Calendar/index.ts +0 -4
- package/src/Contextual/Contextual.torp +0 -129
- package/src/Contextual/ContextualContent.torp +0 -112
- package/src/Contextual/ContextualTrigger.torp +0 -70
- package/src/Contextual/ContextualTypes.ts +0 -30
- package/src/Contextual/index.ts +0 -5
- package/src/Dialog/Dialog.torp +0 -136
- package/src/Dialog/DialogBody.torp +0 -44
- package/src/Dialog/DialogButton.torp +0 -66
- package/src/Dialog/DialogFooter.torp +0 -25
- package/src/Dialog/DialogHeader.torp +0 -45
- package/src/Dialog/DialogTypes.ts +0 -17
- package/src/Dialog/index.ts +0 -7
- package/src/Disclosure/Disclosure.torp +0 -82
- package/src/Disclosure/DisclosureContent.torp +0 -46
- package/src/Disclosure/DisclosureHeader.torp +0 -45
- package/src/Disclosure/DisclosureTrigger.torp +0 -47
- package/src/Disclosure/DisclosureTypes.ts +0 -13
- package/src/Disclosure/index.ts +0 -6
- package/src/Drawer/Drawer.torp +0 -127
- package/src/Drawer/DrawerContent.torp +0 -83
- package/src/Drawer/DrawerOverlay.torp +0 -42
- package/src/Drawer/DrawerTrigger.torp +0 -39
- package/src/Drawer/DrawerTypes.ts +0 -24
- package/src/Drawer/index.ts +0 -6
- package/src/Form/CheckBox.torp +0 -94
- package/src/Form/Field.torp +0 -95
- package/src/Form/File.torp +0 -102
- package/src/Form/Form.torp +0 -147
- package/src/Form/FormTypes.ts +0 -35
- package/src/Form/Hidden.torp +0 -25
- package/src/Form/Input.torp +0 -112
- package/src/Form/Label.torp +0 -35
- package/src/Form/Message.torp +0 -39
- package/src/Form/Option.torp +0 -28
- package/src/Form/Select.torp +0 -101
- package/src/Form/StandardSchemaV1.ts +0 -70
- package/src/Form/TextArea.torp +0 -105
- package/src/Form/index.ts +0 -13
- package/src/Menu/Menu.torp +0 -174
- package/src/Menu/MenuButton.torp +0 -74
- package/src/Menu/MenuCheck.torp +0 -89
- package/src/Menu/MenuGroup.torp +0 -31
- package/src/Menu/MenuIndicator.torp +0 -40
- package/src/Menu/MenuPopout.torp +0 -83
- package/src/Menu/MenuPopoutContent.torp +0 -84
- package/src/Menu/MenuPopoutTrigger.torp +0 -128
- package/src/Menu/MenuRadio.torp +0 -103
- package/src/Menu/MenuRadioGroup.torp +0 -109
- package/src/Menu/MenuSeparator.torp +0 -26
- package/src/Menu/MenuTypes.ts +0 -60
- package/src/Menu/index.ts +0 -25
- package/src/MenuBar/MenuBar.torp +0 -162
- package/src/MenuBar/MenuBarItem.torp +0 -116
- package/src/MenuBar/MenuBarItemContent.torp +0 -119
- package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
- package/src/MenuBar/MenuBarTypes.ts +0 -36
- package/src/MenuBar/index.ts +0 -6
- package/src/Modal/Modal.torp +0 -122
- package/src/Modal/ModalContent.torp +0 -81
- package/src/Modal/ModalOverlay.torp +0 -42
- package/src/Modal/ModalTrigger.torp +0 -54
- package/src/Modal/ModalTypes.ts +0 -22
- package/src/Modal/index.ts +0 -10
- package/src/Modal/showModal.ts +0 -19
- package/src/Modal/showPrompt.ts +0 -23
- package/src/NavMenu/NavMenu.torp +0 -190
- package/src/NavMenu/NavMenuButton.torp +0 -55
- package/src/NavMenu/NavMenuElement.torp +0 -55
- package/src/NavMenu/NavMenuGroup.torp +0 -41
- package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
- package/src/NavMenu/NavMenuLink.torp +0 -60
- package/src/NavMenu/NavMenuPopout.torp +0 -89
- package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
- package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
- package/src/NavMenu/NavMenuSeparator.torp +0 -24
- package/src/NavMenu/NavMenuTypes.ts +0 -32
- package/src/NavMenu/index.ts +0 -23
- package/src/Notification/Notification.torp +0 -71
- package/src/Notification/NotificationClose.torp +0 -39
- package/src/Notification/NotificationContainer.torp +0 -26
- package/src/Notification/NotificationContent.torp +0 -25
- package/src/Notification/NotificationTypes.ts +0 -5
- package/src/Notification/index.ts +0 -13
- package/src/Notification/showNotification.ts +0 -30
- package/src/Popover/Popover.torp +0 -129
- package/src/Popover/PopoverContent.torp +0 -117
- package/src/Popover/PopoverTrigger.torp +0 -62
- package/src/Popover/PopoverTypes.ts +0 -30
- package/src/Popover/index.ts +0 -6
- package/src/Popover/showPopover.ts +0 -24
- package/src/Slider/Slider.torp +0 -84
- package/src/Slider/index.ts +0 -3
- package/src/TabGroup/TabContent.torp +0 -49
- package/src/TabGroup/TabGroup.torp +0 -250
- package/src/TabGroup/TabGroupTypes.ts +0 -44
- package/src/TabGroup/TabHeader.torp +0 -81
- package/src/TabGroup/TabList.torp +0 -61
- package/src/TabGroup/TabTrigger.torp +0 -76
- package/src/TabGroup/index.ts +0 -7
- package/src/ambient.d.ts +0 -7
- package/src/icons/ArrowDown.torp +0 -18
- package/src/icons/ArrowLeft.torp +0 -18
- package/src/icons/ArrowRight.torp +0 -18
- package/src/icons/ArrowUp.torp +0 -18
- package/src/icons/Bars.torp +0 -20
- package/src/icons/Check.torp +0 -18
- package/src/icons/ChevronDown.torp +0 -18
- package/src/icons/ChevronLeft.torp +0 -18
- package/src/icons/ChevronRight.torp +0 -18
- package/src/icons/ChevronUp.torp +0 -18
- package/src/icons/Cross.torp +0 -19
- package/src/icons/IconTypes.ts +0 -10
- package/src/icons/Loading.torp +0 -19
- package/src/icons/Minus.torp +0 -18
- package/src/icons/Plus.torp +0 -19
- package/src/icons/index.ts +0 -31
- package/src/motion/fade.ts +0 -16
- package/src/motion/grow.ts +0 -23
- package/src/motion/index.ts +0 -6
- package/src/motion/measure.ts +0 -28
- package/src/motion/slide.ts +0 -45
- package/src/mount/clickPopover.ts +0 -51
- package/src/mount/contextPopover.ts +0 -51
- package/src/mount/disableScroll.ts +0 -28
- package/src/mount/hoverPopover.ts +0 -58
- package/src/mount/hoverTrigger.ts +0 -59
- package/src/mount/trapFocus.ts +0 -58
- package/src/utils/dateUtils.ts +0 -244
- package/src/utils/documentEvents.ts +0 -17
- package/src/utils/getId.ts +0 -6
- package/src/utils/getScrollParent.ts +0 -22
- package/src/utils/setContextPosition.ts +0 -31
- package/src/utils/setPopoverPosition.ts +0 -142
- package/test/Accordion/accessibility.test.ts +0 -59
- package/test/Accordion/components/AccordionAccessibility.torp +0 -44
- package/test/Accordion/components/AccordionKeyboard.torp +0 -32
- package/test/Accordion/components/AccordionList.torp +0 -23
- package/test/Accordion/components/AccordionMultiple.torp +0 -32
- package/test/Accordion/components/AccordionSingle.torp +0 -32
- package/test/Accordion/for-items.test.ts +0 -52
- package/test/Accordion/keyboard.test.ts +0 -64
- package/test/Accordion/multiple-item-toggle.test.ts +0 -32
- package/test/Accordion/multiple-item-value.test.ts +0 -17
- package/test/Accordion/single-item-toggle.test.ts +0 -31
- package/test/Accordion/single-item-value.test.ts +0 -17
- package/test/Breadcrumb/accessibility.test.ts +0 -29
- package/test/Breadcrumb/basic.test.ts +0 -17
- package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
- package/test/Calendar/components/CalendarTest.torp +0 -9
- package/test/Calendar/default.test.ts +0 -18
- package/test/Dialog/accessibility-alert.test.ts +0 -40
- package/test/Dialog/accessibility-modal.test.ts +0 -52
- package/test/Dialog/components/DialogAccessibility.torp +0 -25
- package/test/Dialog/components/DialogFunction.torp +0 -36
- package/test/Dialog/components/DialogModal.torp +0 -30
- package/test/Dialog/components/DialogVariable.torp +0 -33
- package/test/Dialog/function.test.ts +0 -26
- package/test/Dialog/variable.test.ts +0 -27
- package/test/Disclosure/accessibility.test.ts +0 -31
- package/test/Disclosure/components/DisclosureTest.torp +0 -17
- package/test/Disclosure/default.test.ts +0 -15
- package/test/Disclosure/toggle.test.ts +0 -20
- package/test/Form/components/FieldTest.torp +0 -25
- package/test/Form/components/FormTest.torp +0 -31
- package/test/Form/components/InputTest.torp +0 -9
- package/test/Form/field.test.ts +0 -34
- package/test/Form/form.test.ts +0 -34
- package/test/Form/input.test.ts +0 -19
- package/test/Menu/accessibility.test.ts +0 -83
- package/test/Menu/basic.test.ts +0 -58
- package/test/Menu/components/MenuAccessibility.torp +0 -59
- package/test/Menu/components/MenuBasic.torp +0 -58
- package/test/MenuBar/accessibility.test.ts +0 -87
- package/test/MenuBar/basic.test.ts +0 -22
- package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
- package/test/MenuBar/components/MenuBarBasic.torp +0 -25
- package/test/NavMenu/accessibility.test.ts +0 -97
- package/test/NavMenu/basic.test.ts +0 -22
- package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
- package/test/NavMenu/components/NavMenuBasic.torp +0 -28
- package/test/Notification/accessibility.test.ts +0 -21
- package/test/Notification/components/CustomNotification.torp +0 -14
- package/test/Notification/components/NotificationAccessibility.torp +0 -14
- package/test/Notification/components/NotificationFunction.torp +0 -17
- package/test/Notification/components/NotificationVariable.torp +0 -22
- package/test/Notification/function.test.ts +0 -25
- package/test/Notification/variable.test.ts +0 -25
- package/test/Popover/components/CustomDialog.torp +0 -25
- package/test/Popover/components/PopoverFunction.torp +0 -37
- package/test/Popover/components/PopoverTrigger.torp +0 -36
- package/test/Popover/components/PopoverVariable.torp +0 -40
- package/test/Popover/function.test.ts +0 -21
- package/test/Popover/trigger.test.ts +0 -27
- package/test/Popover/variable.test.ts +0 -27
- package/test/TabGroup/accessibility.test.ts +0 -67
- package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
- package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
- package/test/TabGroup/components/TabGroupList.torp +0 -26
- package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
- package/test/TabGroup/for-items.test.ts +0 -52
- package/test/TabGroup/item-trigger.test.ts +0 -33
- package/test/TabGroup/item-value.test.ts +0 -17
- package/test/TabGroup/keyboard.test.ts +0 -72
- package/tsconfig.json +0 -4
- package/tsup.config.ts +0 -37
- package/vitest.config.ts +0 -12
package/src/Menu/MenuTypes.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export const MenuContextName = "Menu";
|
|
2
|
-
export const MenuButtonContextName = "MenuButton";
|
|
3
|
-
export const MenuRadioGroupContextName = "MenuRadioGroup";
|
|
4
|
-
export const MenuPopoutContextName = "MenuPopout";
|
|
5
|
-
|
|
6
|
-
export interface MenuContext {
|
|
7
|
-
setVisible: (value: boolean, result?: any) => void;
|
|
8
|
-
|
|
9
|
-
/** Called from a MenuButton to close the Menu and return a result */
|
|
10
|
-
handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
|
|
11
|
-
|
|
12
|
-
/** Called from a MenuButton when its button is focused */
|
|
13
|
-
handleItemFocus: (index: number) => void;
|
|
14
|
-
|
|
15
|
-
/** Called from a MenuButton when a key is pressed */
|
|
16
|
-
handleItemKey: (e: KeyboardEvent) => void;
|
|
17
|
-
|
|
18
|
-
state: MenuState;
|
|
19
|
-
|
|
20
|
-
/** The element that caused this Menu to be shown */
|
|
21
|
-
anchorElement?: HTMLElement;
|
|
22
|
-
|
|
23
|
-
/** Called from each MenuButton/Check/Radio to register itself with this Menu */
|
|
24
|
-
registerItem: (setFocused: () => void) => { index: number };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface MenuState {
|
|
28
|
-
/** Whether the Menu is visible */
|
|
29
|
-
visible: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface MenuButtonContext {
|
|
33
|
-
state: {
|
|
34
|
-
checked: boolean;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface MenuRadioGroupContext {
|
|
39
|
-
registerItemInGroup: (value: string, setChecked: (value: boolean) => void) => void;
|
|
40
|
-
toggleItem: (value: string) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface MenuPopoutContext {
|
|
44
|
-
setVisible: (value: boolean) => void;
|
|
45
|
-
state: {
|
|
46
|
-
visible: boolean;
|
|
47
|
-
};
|
|
48
|
-
anchorElement?: HTMLElement;
|
|
49
|
-
focusFirstElement?: () => void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface ItemState {
|
|
53
|
-
setFocused: () => void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface RadioGroupItemState {
|
|
57
|
-
value: string;
|
|
58
|
-
checked: boolean;
|
|
59
|
-
setChecked: (value: boolean) => void;
|
|
60
|
-
}
|
package/src/Menu/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Menu from "./Menu.torp";
|
|
2
|
-
import MenuButton from "./MenuButton.torp";
|
|
3
|
-
import MenuCheck from "./MenuCheck.torp";
|
|
4
|
-
import MenuGroup from "./MenuGroup.torp";
|
|
5
|
-
import MenuIndicator from "./MenuIndicator.torp";
|
|
6
|
-
import MenuPopout from "./MenuPopout.torp";
|
|
7
|
-
import MenuPopoutContent from "./MenuPopoutContent.torp";
|
|
8
|
-
import MenuPopoutTrigger from "./MenuPopoutTrigger.torp";
|
|
9
|
-
import MenuRadio from "./MenuRadio.torp";
|
|
10
|
-
import MenuRadioGroup from "./MenuRadioGroup.torp";
|
|
11
|
-
import MenuSeparator from "./MenuSeparator.torp";
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
Menu,
|
|
15
|
-
MenuGroup,
|
|
16
|
-
MenuButton,
|
|
17
|
-
MenuCheck,
|
|
18
|
-
MenuRadio,
|
|
19
|
-
MenuRadioGroup,
|
|
20
|
-
MenuIndicator,
|
|
21
|
-
MenuPopout,
|
|
22
|
-
MenuPopoutTrigger,
|
|
23
|
-
MenuPopoutContent,
|
|
24
|
-
MenuSeparator,
|
|
25
|
-
};
|
package/src/MenuBar/MenuBar.torp
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { MenuBarContextName, type MenuBarContext, type ItemState } from "./MenuBarTypes";
|
|
3
|
-
|
|
4
|
-
interface MenuBarProps {
|
|
5
|
-
/** An ID for the root element */
|
|
6
|
-
id?: string;
|
|
7
|
-
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue,
|
|
9
|
-
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue,
|
|
11
|
-
/** An ARIA label for describing the menu to screen readers */
|
|
12
|
-
ariaLabel?: string,
|
|
13
|
-
/** The orientation of the menu, which affects keyboard navigation */
|
|
14
|
-
orientation?: "horizontal" | "vertical",
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A menu bar, similar to that shown at the top of Windows applications or at the top of the screen on Macs.
|
|
19
|
-
*
|
|
20
|
-
* See [the WAI ARIA guidelines for Menus](https://www.w3.org/WAI/ARIA/apg/patterns/menu/).
|
|
21
|
-
*
|
|
22
|
-
* The structure of a MenuBar is:
|
|
23
|
-
*
|
|
24
|
-
* ```
|
|
25
|
-
* <MenuBar>
|
|
26
|
-
* <MenuBarItem>
|
|
27
|
-
* <MenuBarItemTrigger />
|
|
28
|
-
* <MenuBarItemContent>
|
|
29
|
-
* <Menu />
|
|
30
|
-
* </MenuBarItemContent>
|
|
31
|
-
* </MenuBarItem>
|
|
32
|
-
* </MenuBar>
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export default function MenuBar($props: MenuBarProps | undefined) {
|
|
36
|
-
let orientation = $props?.orientation ?? "horizontal";
|
|
37
|
-
|
|
38
|
-
let $state = $watch({
|
|
39
|
-
active: false,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// A collection containing the state and some functions for each item
|
|
43
|
-
let itemStates: ItemState[] = [];
|
|
44
|
-
let focusIndex = -1;
|
|
45
|
-
|
|
46
|
-
// Set the context to pass down to items
|
|
47
|
-
let context: MenuBarContext = {
|
|
48
|
-
handleItemShow,
|
|
49
|
-
handleButtonFocus,
|
|
50
|
-
handleButtonKey,
|
|
51
|
-
registerItem,
|
|
52
|
-
state: $state
|
|
53
|
-
};
|
|
54
|
-
$context[MenuBarContextName] = context;
|
|
55
|
-
|
|
56
|
-
function registerItem(setVisible: (value: boolean) => void, setFocused: () => void) {
|
|
57
|
-
// Add the item's state to the array and return its index
|
|
58
|
-
const newItemState: ItemState = {
|
|
59
|
-
setVisible,
|
|
60
|
-
setFocused
|
|
61
|
-
};
|
|
62
|
-
itemStates.push(newItemState);
|
|
63
|
-
itemStates = itemStates;
|
|
64
|
-
return { index: itemStates.length - 1 };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function handleItemShow(index: number) {
|
|
68
|
-
// Make sure other items are hidden
|
|
69
|
-
itemStates.forEach((item, i) => {
|
|
70
|
-
if (i !== index) {
|
|
71
|
-
item.setVisible(false);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function handleButtonFocus(index: number) {
|
|
77
|
-
focusIndex = index;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function handleButtonKey(e: KeyboardEvent) {
|
|
81
|
-
switch (e.key) {
|
|
82
|
-
case "Right":
|
|
83
|
-
case "ArrowRight": {
|
|
84
|
-
if (orientation === "horizontal") {
|
|
85
|
-
e.preventDefault();
|
|
86
|
-
focusItem("next");
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
case "Left":
|
|
91
|
-
case "ArrowLeft": {
|
|
92
|
-
if (orientation === "horizontal") {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
focusItem("previous");
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "Down":
|
|
99
|
-
case "ArrowDown": {
|
|
100
|
-
if (orientation === "vertical") {
|
|
101
|
-
e.preventDefault();
|
|
102
|
-
focusItem("next");
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case "Up":
|
|
107
|
-
case "ArrowUp": {
|
|
108
|
-
if (orientation === "vertical") {
|
|
109
|
-
e.preventDefault();
|
|
110
|
-
focusItem("previous");
|
|
111
|
-
}
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case "Home": {
|
|
115
|
-
e.preventDefault();
|
|
116
|
-
focusItem("start");
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
case "End": {
|
|
120
|
-
e.preventDefault();
|
|
121
|
-
focusItem("end");
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function focusItem(target: "start" | "previous" | "next" | "end") {
|
|
128
|
-
switch (target) {
|
|
129
|
-
case "start": {
|
|
130
|
-
focusIndex = 0;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case "previous": {
|
|
134
|
-
focusIndex = Math.max(0, focusIndex - 1);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
case "next": {
|
|
138
|
-
focusIndex = Math.min(itemStates.length - 1, focusIndex + 1);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case "end": {
|
|
142
|
-
focusIndex = itemStates.length - 1;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
itemStates[focusIndex]?.setFocused();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
@render {
|
|
150
|
-
<div
|
|
151
|
-
{$props?.id}
|
|
152
|
-
class={["torp-menu-bar", $props?.class]}
|
|
153
|
-
{$props?.style}
|
|
154
|
-
tabindex="-1"
|
|
155
|
-
role="menubar"
|
|
156
|
-
aria-label={$props?.ariaLabel}
|
|
157
|
-
aria-orientation={orientation}
|
|
158
|
-
>
|
|
159
|
-
<slot />
|
|
160
|
-
</div>
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
3
|
-
MenuBarContextName,
|
|
4
|
-
MenuBarItemContextName,
|
|
5
|
-
type MenuBarContext,
|
|
6
|
-
type MenuBarItemContext
|
|
7
|
-
} from "./MenuBarTypes";
|
|
8
|
-
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
9
|
-
|
|
10
|
-
interface MenuBarItemProps {
|
|
11
|
-
/** An ID for the root element */
|
|
12
|
-
id?: string;
|
|
13
|
-
/** Classes for the root element */
|
|
14
|
-
class?: ClassValue,
|
|
15
|
-
/** Styles for the root element */
|
|
16
|
-
style?: StyleValue,
|
|
17
|
-
/** Whether the item is visible */
|
|
18
|
-
visible?: boolean,
|
|
19
|
-
/** Raised when the item is opened or closed */
|
|
20
|
-
ontoggle?: (visible: boolean) => void,
|
|
21
|
-
/** Raised when the item has opened */
|
|
22
|
-
onopen?: () => void,
|
|
23
|
-
/** Raised when the item has closed */
|
|
24
|
-
onclose?: (result: any) => void,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A popout that is attached to a menubar button and can be used to show a submenu.
|
|
29
|
-
*
|
|
30
|
-
* The structure of a MenuBarItem is:
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
33
|
-
* <MenuBarItem>
|
|
34
|
-
* <MenuBarItemTrigger /> (optional)
|
|
35
|
-
* <MenuBarItemContent />
|
|
36
|
-
* </MenuBarItem>
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export default function MenuBarItem($props: MenuBarItemProps | undefined) {
|
|
40
|
-
let $state = $watch({
|
|
41
|
-
visible: $props?.visible ?? false
|
|
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]}
|
|
111
|
-
{$props?.style}
|
|
112
|
-
>
|
|
113
|
-
<slot />
|
|
114
|
-
</div>
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
3
|
-
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
4
|
-
import {
|
|
5
|
-
MenuBarContextName,
|
|
6
|
-
MenuBarItemContextName,
|
|
7
|
-
type MenuBarContext,
|
|
8
|
-
type MenuBarItemContext
|
|
9
|
-
} from "./MenuBarTypes";
|
|
10
|
-
|
|
11
|
-
interface MenuBarItemContentProps {
|
|
12
|
-
/** An ID for the root element */
|
|
13
|
-
id?: string;
|
|
14
|
-
/** Classes for the root element */
|
|
15
|
-
class?: ClassValue,
|
|
16
|
-
/** Styles for the root element */
|
|
17
|
-
style?: StyleValue,
|
|
18
|
-
/** Where the popout will be shown, relative to the popout button */
|
|
19
|
-
side?: "top" | "right" | "bottom" | "left",
|
|
20
|
-
/** How the popout will be aligned, relative to the popout button */
|
|
21
|
-
alignment?: "start" | "center" | "end",
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The content that is displayed for a MenuBarItem when it is open.
|
|
26
|
-
*/
|
|
27
|
-
export default function MenuBarItemContent($props: MenuBarItemContentProps | undefined) {
|
|
28
|
-
let div: HTMLDivElement;
|
|
29
|
-
let closeOnClick = false;
|
|
30
|
-
let shown = false;
|
|
31
|
-
|
|
32
|
-
// Get stuff out of the MenuBarContext
|
|
33
|
-
const context = $context[MenuBarContextName] as MenuBarContext;
|
|
34
|
-
if (!context) {
|
|
35
|
-
throw new Error("MenuBarItemContent must be contained within a MenuBar");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Get stuff out of the MenuBarItemContext
|
|
39
|
-
const itemContext = $context[MenuBarItemContextName] as MenuBarItemContext;
|
|
40
|
-
if (!itemContext) {
|
|
41
|
-
throw new Error("MenuBarItemContent must be contained within a MenuBarItem");
|
|
42
|
-
}
|
|
43
|
-
const { state: $state, setVisible } = itemContext;
|
|
44
|
-
|
|
45
|
-
$run(() => {
|
|
46
|
-
if (!$state.visible) {
|
|
47
|
-
hide();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
function show() {
|
|
52
|
-
shown = true;
|
|
53
|
-
|
|
54
|
-
// HACK: Because this Contextual could be shown with a click, we need to wait for another mousedown
|
|
55
|
-
// before we close on click. Otherwise the click immediately bubbles to the document. I guess
|
|
56
|
-
// we could require the user to preventDefault after calling showContextual, but that seems very
|
|
57
|
-
// error-prone?
|
|
58
|
-
closeOnClick = false;
|
|
59
|
-
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
60
|
-
addDocumentEvent("click", handleDocumentClick);
|
|
61
|
-
|
|
62
|
-
// Set the position and listen for window resize and scroll to reset the position
|
|
63
|
-
setPosition();
|
|
64
|
-
addEventListener("resize", setPosition);
|
|
65
|
-
addEventListener("scroll", setPosition);
|
|
66
|
-
if (itemContext.focusFirstElement) {
|
|
67
|
-
itemContext.focusFirstElement();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function hide() {
|
|
72
|
-
if (!shown) return;
|
|
73
|
-
|
|
74
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
75
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
76
|
-
|
|
77
|
-
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
78
|
-
removeEventListener("resize", setPosition);
|
|
79
|
-
removeEventListener("scroll", setPosition);
|
|
80
|
-
if (itemContext.anchorElement?.focus) {
|
|
81
|
-
itemContext.anchorElement.focus();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function handleDocumentMouseDown() {
|
|
86
|
-
closeOnClick = true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function handleDocumentClick(e: MouseEvent) {
|
|
90
|
-
if (closeOnClick && !div.contains(e.target as HTMLElement)) {
|
|
91
|
-
//context.active = false;
|
|
92
|
-
setVisible(false);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function setPosition() {
|
|
97
|
-
if (!itemContext.anchorElement) {
|
|
98
|
-
throw new Error("MenuBarItemContent must have an anchor element");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
let side = $props?.side ?? "bottom";
|
|
102
|
-
let alignment = $props?.alignment ?? "start";
|
|
103
|
-
setPopoverPosition(itemContext.anchorElement, div, side, alignment);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@render {
|
|
107
|
-
@if ($state.visible) {
|
|
108
|
-
<div
|
|
109
|
-
{$props?.id}
|
|
110
|
-
class={["torp-menu-bar-item-content", $props?.class]}
|
|
111
|
-
{$props?.style}
|
|
112
|
-
&ref={div}
|
|
113
|
-
onmount={show}
|
|
114
|
-
>
|
|
115
|
-
<slot />
|
|
116
|
-
</div>
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
3
|
-
MenuBarContextName,
|
|
4
|
-
MenuBarItemContextName,
|
|
5
|
-
type MenuBarContext,
|
|
6
|
-
type MenuBarItemContext
|
|
7
|
-
} from "./MenuBarTypes";
|
|
8
|
-
|
|
9
|
-
interface MenuBarItemTriggerProps {
|
|
10
|
-
/** An ID for the root element */
|
|
11
|
-
id?: string;
|
|
12
|
-
/** Classes for the root element */
|
|
13
|
-
class?: ClassValue,
|
|
14
|
-
/** Styles for the root element */
|
|
15
|
-
style?: StyleValue,
|
|
16
|
-
/** Whether this button is disabled */
|
|
17
|
-
disabled?: boolean,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A button that is placed in a MenuBar and opens a submenu.
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | undefined) {
|
|
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]}
|
|
81
|
-
{$props?.style}
|
|
82
|
-
type="button"
|
|
83
|
-
{$props?.disabled}
|
|
84
|
-
role="menuitem"
|
|
85
|
-
aria-haspopup="true"
|
|
86
|
-
aria-expanded={($state.visible ?? false).toString()}
|
|
87
|
-
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
88
|
-
data-disabled={$props?.disabled ? "true" : undefined}
|
|
89
|
-
onkeydown={handleKey}
|
|
90
|
-
onclick={handleClick}
|
|
91
|
-
onfocus={() => handleButtonFocus(index)}
|
|
92
|
-
onmouseenter={handleMouseEnter}
|
|
93
|
-
&ref={button}
|
|
94
|
-
onmount={(el) => itemContext.anchorElement = el}
|
|
95
|
-
>
|
|
96
|
-
<slot />
|
|
97
|
-
</button>
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
package/src/MenuBar/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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 };
|