@torpor/ui 0.3.7 → 1.0.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/README.md +83 -7
- package/dist/Accordion/Accordion.torp +43 -165
- package/dist/Accordion/AccordionContent.torp +6 -6
- package/dist/Accordion/AccordionHeader.torp +7 -11
- package/dist/Accordion/AccordionItem.torp +24 -24
- package/dist/Accordion/AccordionTrigger.torp +17 -8
- package/dist/Accordion/AccordionTypes.ts +6 -6
- package/dist/Accordion/index.d.ts +23 -25
- package/dist/Accordion/index.js +6 -22
- package/dist/Breadcrumb/Breadcrumb.torp +12 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +6 -6
- package/dist/Breadcrumb/BreadcrumbList.torp +21 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +4 -4
- package/dist/Breadcrumb/index.d.ts +39 -15
- package/dist/Breadcrumb/index.js +5 -14
- package/dist/Calendar/Calendar.torp +163 -156
- package/dist/Calendar/CalendarDay.torp +91 -45
- package/dist/Calendar/CalendarDayHeader.torp +36 -0
- package/dist/Calendar/CalendarGrid.torp +104 -0
- package/dist/Calendar/CalendarGridHeader.torp +43 -0
- package/dist/Calendar/CalendarHeader.torp +48 -0
- package/dist/Calendar/CalendarHeaderTrigger.torp +54 -0
- package/dist/Calendar/CalendarTypes.ts +25 -4
- package/dist/Calendar/buildDays.ts +54 -0
- package/dist/Calendar/index.d.ts +191 -5
- package/dist/Calendar/index.js +8 -10
- package/dist/Carousel/Carousel.torp +180 -0
- package/dist/Carousel/CarouselIndicators.torp +65 -0
- package/dist/Carousel/CarouselNext.torp +43 -0
- package/dist/Carousel/CarouselPrevious.torp +44 -0
- package/dist/Carousel/CarouselSlide.torp +57 -0
- package/dist/Carousel/CarouselTypes.ts +28 -0
- package/dist/Carousel/index.d.ts +147 -0
- package/dist/Carousel/index.js +6 -0
- package/dist/Charts/BarChart.torp +70 -0
- package/dist/Charts/Chart.torp +120 -0
- package/dist/Charts/ChartBars.torp +78 -0
- package/dist/Charts/ChartColumns.torp +66 -0
- package/dist/Charts/ChartGrid.torp +54 -0
- package/dist/Charts/ChartLines.torp +60 -0
- package/dist/Charts/ChartTypes.ts +25 -0
- package/dist/Charts/ChartXAxis.torp +83 -0
- package/dist/Charts/ChartYAxis.torp +105 -0
- package/dist/Charts/ColumnChart.torp +70 -0
- package/dist/{Chart → Charts}/GridLines.torp +7 -4
- package/dist/Charts/LineChart.torp +73 -0
- package/dist/{Chart → Charts}/PieChart.torp +14 -20
- package/dist/{Chart → Charts}/ScatterChart.torp +45 -38
- package/dist/{Chart → Charts}/SparkLine.torp +16 -19
- package/dist/{Chart → Charts}/XAxis.torp +18 -12
- package/dist/{Chart → Charts}/YAxis.torp +15 -9
- package/dist/Charts/index.d.ts +469 -0
- package/dist/Charts/index.js +17 -0
- package/dist/ColorPicker/ColorPalette.torp +154 -0
- package/dist/ColorPicker/ColorPicker.torp +157 -0
- package/dist/ColorPicker/index.d.ts +85 -0
- package/dist/ColorPicker/index.js +3 -0
- package/dist/ComboBox/ComboBox.torp +205 -0
- package/dist/ComboBox/ComboBoxContent.torp +112 -0
- package/dist/ComboBox/ComboBoxInput.torp +145 -0
- package/dist/ComboBox/ComboBoxTrigger.torp +49 -0
- package/dist/ComboBox/ComboBoxTypes.ts +39 -0
- package/dist/ComboBox/index.d.ts +152 -0
- package/dist/ComboBox/index.js +6 -0
- package/dist/CommandPalette/CommandPalette.torp +220 -0
- package/dist/CommandPalette/CommandTypes.ts +14 -0
- package/dist/CommandPalette/index.d.ts +45 -0
- package/dist/CommandPalette/index.js +2 -0
- package/dist/Contextual/Contextual.torp +39 -52
- package/dist/Contextual/ContextualContent.torp +29 -73
- package/dist/Contextual/ContextualHover.torp +112 -0
- package/dist/Contextual/ContextualTrigger.torp +31 -42
- package/dist/Contextual/ContextualTypes.ts +5 -18
- package/dist/Contextual/index.d.ts +44 -27
- package/dist/Contextual/index.js +5 -14
- package/dist/DataGrid/DataGrid.torp +496 -0
- package/dist/DataGrid/DataGridTypes.ts +25 -0
- package/dist/DataGrid/index.d.ts +90 -0
- package/dist/DataGrid/index.js +3 -0
- package/dist/DataGrid/sortRows.ts +32 -0
- package/dist/DatePicker/DatePicker.torp +222 -0
- package/dist/DatePicker/DatePickerHeader.torp +20 -0
- package/dist/DatePicker/index.d.ts +55 -0
- package/dist/DatePicker/index.js +2 -0
- package/dist/DateRangePicker/DateRangePicker.torp +311 -0
- package/dist/DateRangePicker/DateRangePickerDay.torp +137 -0
- package/dist/DateRangePicker/DateRangePickerTypes.ts +21 -0
- package/dist/DateRangePicker/index.d.ts +76 -0
- package/dist/DateRangePicker/index.js +3 -0
- package/dist/Dialog/Dialog.torp +33 -30
- package/dist/Dialog/DialogBody.torp +5 -9
- package/dist/Dialog/DialogButton.torp +14 -11
- package/dist/Dialog/DialogFooter.torp +3 -7
- package/dist/Dialog/DialogHeader.torp +6 -10
- package/dist/Dialog/DialogTypes.ts +2 -2
- package/dist/Dialog/index.d.ts +28 -26
- package/dist/Dialog/index.js +6 -22
- package/dist/Disclosure/Disclosure.torp +18 -18
- package/dist/Disclosure/DisclosureContent.torp +5 -6
- package/dist/Disclosure/DisclosureHeader.torp +7 -11
- package/dist/Disclosure/DisclosureTrigger.torp +4 -5
- package/dist/Disclosure/DisclosureTypes.ts +1 -1
- package/dist/Disclosure/index.d.ts +14 -16
- package/dist/Disclosure/index.js +5 -18
- package/dist/Drawer/Drawer.torp +21 -51
- package/dist/Drawer/DrawerContent.torp +67 -13
- package/dist/Drawer/DrawerOverlay.torp +4 -4
- package/dist/Drawer/DrawerTrigger.torp +16 -4
- package/dist/Drawer/DrawerTypes.ts +4 -1
- package/dist/Drawer/index.d.ts +16 -20
- package/dist/Drawer/index.js +5 -18
- package/dist/FocusGroup/FocusGroup.torp +70 -0
- package/dist/FocusGroup/FocusGroupButton.torp +59 -0
- package/dist/FocusGroup/FocusGroupTypes.ts +14 -0
- package/dist/FocusGroup/index.d.ts +44 -0
- package/dist/FocusGroup/index.js +3 -0
- package/dist/Form/CheckBox.torp +28 -20
- package/dist/Form/Field.torp +17 -17
- package/dist/Form/File.torp +31 -22
- package/dist/Form/FileDrop.torp +187 -0
- package/dist/Form/Form.torp +24 -22
- package/dist/Form/FormTypes.ts +2 -0
- package/dist/Form/FormValues.torp +37 -0
- package/dist/Form/Hidden.torp +4 -12
- package/dist/Form/Input.torp +38 -32
- package/dist/Form/Label.torp +3 -3
- package/dist/Form/Message.torp +13 -5
- package/dist/Form/MessageSummary.torp +39 -0
- package/dist/Form/Option.torp +11 -7
- package/dist/Form/Select.torp +32 -28
- package/dist/Form/TextArea.torp +35 -31
- package/dist/Form/Toggle.torp +109 -0
- package/dist/Form/index.d.ts +198 -77
- package/dist/Form/index.js +16 -46
- package/dist/ListBox/ListBox.torp +374 -0
- package/dist/ListBox/ListBoxItem.torp +131 -0
- package/dist/ListBox/ListBoxSeparator.torp +29 -0
- package/dist/ListBox/ListBoxTypes.ts +41 -0
- package/dist/ListBox/LoadedListBoxItems.torp +41 -0
- package/dist/ListBox/index.d.ts +136 -0
- package/dist/ListBox/index.js +4 -0
- package/dist/MaskedInput/MaskedInput.torp +143 -0
- package/dist/MaskedInput/index.d.ts +52 -0
- package/dist/MaskedInput/index.js +2 -0
- package/dist/Menu/Menu.torp +90 -70
- package/dist/Menu/MenuButton.torp +17 -10
- package/dist/Menu/MenuCheck.torp +22 -18
- package/dist/Menu/MenuGroup.torp +4 -4
- package/dist/Menu/MenuIndicator.torp +5 -13
- package/dist/Menu/MenuPopout.torp +20 -50
- package/dist/Menu/MenuPopoutContent.torp +15 -66
- package/dist/Menu/MenuPopoutTrigger.torp +19 -100
- package/dist/Menu/MenuRadio.torp +25 -26
- package/dist/Menu/MenuRadioGroup.torp +25 -68
- package/dist/Menu/MenuSeparator.torp +3 -2
- package/dist/Menu/MenuTypes.ts +12 -21
- package/dist/Menu/index.d.ts +45 -51
- package/dist/Menu/index.js +12 -46
- package/dist/MenuBar/MenuBar.torp +31 -83
- package/dist/MenuBar/MenuBarItem.torp +34 -55
- package/dist/MenuBar/MenuBarItemContent.torp +15 -101
- package/dist/MenuBar/MenuBarItemTrigger.torp +20 -55
- package/dist/MenuBar/MenuBarTypes.ts +13 -12
- package/dist/MenuBar/index.d.ts +17 -19
- package/dist/MenuBar/index.js +5 -18
- package/dist/Modal/Modal.torp +28 -48
- package/dist/Modal/ModalContent.torp +21 -44
- package/dist/Modal/ModalOverlay.torp +4 -4
- package/dist/Modal/ModalTrigger.torp +16 -32
- package/dist/Modal/ModalTypes.ts +6 -17
- package/dist/Modal/index.d.ts +17 -29
- package/dist/Modal/index.js +29 -28
- package/dist/Modal/index.js.map +1 -1
- package/dist/Modal/showPrompt.ts +2 -2
- package/dist/NavMenu/NavMenu.torp +22 -104
- package/dist/NavMenu/NavMenuButton.torp +10 -8
- package/dist/NavMenu/NavMenuElement.torp +6 -7
- package/dist/NavMenu/NavMenuGroup.torp +5 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -8
- package/dist/NavMenu/NavMenuLink.torp +7 -10
- package/dist/NavMenu/NavMenuPopout.torp +16 -61
- package/dist/NavMenu/NavMenuPopoutContent.torp +14 -73
- package/dist/NavMenu/NavMenuPopoutTrigger.torp +47 -0
- package/dist/NavMenu/NavMenuSeparator.torp +3 -6
- package/dist/NavMenu/NavMenuTypes.ts +6 -15
- package/dist/NavMenu/index.d.ts +55 -55
- package/dist/NavMenu/index.js +11 -42
- package/dist/Notification/Notification.torp +12 -24
- package/dist/Notification/NotificationClose.torp +6 -3
- package/dist/Notification/NotificationContainer.torp +3 -7
- package/dist/Notification/NotificationContent.torp +3 -7
- package/dist/Notification/NotificationTypes.ts +1 -1
- package/dist/Notification/index.d.ts +15 -12
- package/dist/Notification/index.js +22 -32
- package/dist/Notification/index.js.map +1 -1
- package/dist/NumberInput/NumberInput.torp +255 -0
- package/dist/NumberInput/index.d.ts +44 -0
- package/dist/NumberInput/index.js +2 -0
- package/dist/Pagination/Pagination.torp +152 -0
- package/dist/Pagination/PaginationItem.torp +137 -0
- package/dist/Pagination/PaginationTypes.ts +22 -0
- package/dist/Pagination/buildPages.ts +61 -0
- package/dist/Pagination/index.d.ts +63 -0
- package/dist/Pagination/index.js +3 -0
- package/dist/Popover/Popover.torp +39 -52
- package/dist/Popover/PopoverContent.torp +27 -76
- package/dist/Popover/PopoverHover.torp +90 -0
- package/dist/Popover/PopoverTrigger.torp +17 -40
- package/dist/Popover/PopoverTypes.ts +5 -18
- package/dist/Popover/index.d.ts +40 -25
- package/dist/Popover/index.js +18 -18
- package/dist/Popover/index.js.map +1 -1
- package/dist/Progress/Progress.torp +88 -0
- package/dist/Progress/index.d.ts +37 -0
- package/dist/Progress/index.js +2 -0
- package/dist/Rating/Rating.torp +225 -0
- package/dist/Rating/index.d.ts +44 -0
- package/dist/Rating/index.js +2 -0
- package/dist/SegmentedControl/SegmentedControl.torp +233 -0
- package/dist/SegmentedControl/SegmentedControlTypes.ts +26 -0
- package/dist/SegmentedControl/SegmentedItem.torp +78 -0
- package/dist/SegmentedControl/index.d.ts +74 -0
- package/dist/SegmentedControl/index.js +3 -0
- package/dist/SelectBox/SelectBox.torp +190 -0
- package/dist/SelectBox/SelectBoxContent.torp +107 -0
- package/dist/SelectBox/SelectBoxTrigger.torp +141 -0
- package/dist/SelectBox/SelectBoxTypes.ts +33 -0
- package/dist/SelectBox/index.d.ts +112 -0
- package/dist/SelectBox/index.js +5 -0
- package/dist/Slider/Slider.torp +248 -0
- package/dist/Slider/index.d.ts +45 -0
- package/dist/Slider/index.js +2 -0
- package/dist/Splitter/Splitter.torp +156 -0
- package/dist/Splitter/SplitterHandle.torp +161 -0
- package/dist/Splitter/SplitterPane.torp +63 -0
- package/dist/Splitter/SplitterTypes.ts +31 -0
- package/dist/Splitter/index.d.ts +103 -0
- package/dist/Splitter/index.js +4 -0
- package/dist/Stepper/Stepper.torp +146 -0
- package/dist/Stepper/StepperMarker.torp +24 -0
- package/dist/Stepper/StepperNext.torp +44 -0
- package/dist/Stepper/StepperPrevious.torp +44 -0
- package/dist/Stepper/StepperStep.torp +90 -0
- package/dist/Stepper/StepperTypes.ts +30 -0
- package/dist/Stepper/index.d.ts +149 -0
- package/dist/Stepper/index.js +6 -0
- package/dist/TabGroup/TabContent.torp +6 -6
- package/dist/TabGroup/TabGroup.torp +97 -113
- package/dist/TabGroup/TabGroupTypes.ts +3 -3
- package/dist/TabGroup/TabHeader.torp +23 -19
- package/dist/TabGroup/TabList.torp +8 -21
- package/dist/TabGroup/TabTrigger.torp +6 -7
- package/dist/TabGroup/index.d.ts +26 -26
- package/dist/TabGroup/index.js +6 -22
- package/dist/TagInput/TagInput.torp +378 -0
- package/dist/TagInput/index.d.ts +48 -0
- package/dist/TagInput/index.js +2 -0
- package/dist/TimePicker/TimePicker.torp +462 -0
- package/dist/TimePicker/index.d.ts +53 -0
- package/dist/TimePicker/index.js +2 -0
- package/dist/ToolBar/ToolBar.torp +117 -0
- package/dist/ToolBar/ToolBarButton.torp +56 -0
- package/dist/ToolBar/ToolBarElement.torp +51 -0
- package/dist/ToolBar/ToolBarPopout.torp +45 -0
- package/dist/ToolBar/ToolBarPopoutContent.torp +34 -0
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +47 -0
- package/dist/ToolBar/ToolBarSeparator.torp +21 -0
- package/dist/ToolBar/ToolBarTypes.ts +28 -0
- package/dist/ToolBar/index.d.ts +210 -0
- package/dist/ToolBar/index.js +8 -0
- package/dist/Tree/Tree.torp +395 -0
- package/dist/Tree/TreeItem.torp +176 -0
- package/dist/Tree/TreeItemChildren.torp +60 -0
- package/dist/Tree/TreeItemContent.torp +46 -0
- package/dist/Tree/TreeItemLabel.torp +94 -0
- package/dist/Tree/TreeItemTrigger.torp +78 -0
- package/dist/Tree/TreeLoadedChildren.torp +122 -0
- package/dist/Tree/TreeTypes.ts +63 -0
- package/dist/Tree/index.d.ts +262 -0
- package/dist/Tree/index.js +7 -0
- package/dist/icons/ChevronDoubleLeft.torp +19 -0
- package/dist/icons/ChevronDoubleRight.torp +19 -0
- package/dist/icons/index.d.ts +61 -1
- package/dist/icons/index.js +17 -58
- package/dist/loader-DEeG5vFY.js +44 -0
- package/dist/loader-DEeG5vFY.js.map +1 -0
- package/dist/motion/index.d.ts +12 -8
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +72 -88
- package/dist/motion/index.js.map +1 -1
- package/dist/mount/draggable.ts +63 -0
- package/dist/mount/dropTarget.ts +108 -0
- package/dist/mount/hoverTrigger.ts +1 -1
- package/dist/utils/$handle.ts +23 -0
- package/dist/utils/LoadedItems.torp +47 -0
- package/dist/utils/PopoutClickTrigger.torp +99 -0
- package/dist/utils/PopoutTypes.ts +82 -0
- package/dist/utils/SubmenuPopout.torp +89 -0
- package/dist/utils/SubmenuPopoutContent.torp +87 -0
- package/dist/utils/SubmenuPopoutTrigger.torp +160 -0
- package/dist/utils/chartColors.ts +13 -13
- package/dist/utils/chartLayout.ts +143 -0
- package/dist/utils/chartUtils.ts +1 -1
- package/dist/utils/colorUtils.ts +103 -0
- package/dist/utils/createItemGroup.ts +152 -0
- package/dist/utils/dateUtils.ts +8 -7
- package/dist/utils/documentEvents.ts +4 -4
- package/dist/utils/dragState.ts +86 -0
- package/dist/utils/focusGroup.ts +204 -0
- package/dist/utils/focusItem.ts +44 -0
- package/dist/utils/formField.ts +70 -0
- package/dist/utils/hoverOpen.ts +50 -0
- package/dist/utils/hoverReveal.ts +194 -0
- package/dist/utils/loader.ts +113 -0
- package/dist/utils/maskUtils.ts +98 -0
- package/dist/utils/popoutContent.ts +137 -0
- package/dist/utils/reorderList.ts +52 -0
- package/package.json +116 -25
- package/dist/Accordion/index.js.map +0 -1
- package/dist/Breadcrumb/index.js.map +0 -1
- package/dist/Calendar/index.js.map +0 -1
- package/dist/Chart/BarChart.torp +0 -159
- package/dist/Chart/LineChart.torp +0 -196
- package/dist/Chart/index.d.ts +0 -220
- package/dist/Chart/index.js +0 -34
- package/dist/Chart/index.js.map +0 -1
- package/dist/Contextual/index.js.map +0 -1
- package/dist/Dialog/index.js.map +0 -1
- package/dist/Disclosure/index.js.map +0 -1
- package/dist/Drawer/index.js.map +0 -1
- package/dist/Form/index.js.map +0 -1
- package/dist/Menu/index.js.map +0 -1
- package/dist/MenuBar/index.js.map +0 -1
- package/dist/NavMenu/NavMenuPopoutButton.torp +0 -129
- package/dist/NavMenu/index.js.map +0 -1
- package/dist/TabGroup/index.js.map +0 -1
- package/dist/icons/index.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/metafile-esm.json +0 -1
- package/dist/motion/fade.ts +0 -16
- package/dist/motion/grow.ts +0 -23
- package/dist/motion/measure.ts +0 -28
- package/dist/motion/slide.ts +0 -45
- package/dist/mount/index.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -2
- /package/dist/{Chart → Charts}/DataSeries.ts +0 -0
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import getId from "../utils/getId";
|
|
3
|
+
import { createPopoutContent } from "../utils/popoutContent";
|
|
4
|
+
import { type ModalContext, ModalContextName } from "./ModalTypes";
|
|
4
5
|
|
|
5
6
|
interface ModalContentProps {
|
|
6
7
|
/** An ID for the root element */
|
|
7
8
|
id?: string;
|
|
8
9
|
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue
|
|
10
|
+
class?: ClassValue;
|
|
10
11
|
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue
|
|
12
|
+
style?: StyleValue;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
* The content that is displayed for a Modal when it is open
|
|
16
|
-
* alongside an element.
|
|
16
|
+
* The content that is displayed for a Modal when it is open.
|
|
17
17
|
*/
|
|
18
18
|
export default function ModalContent($props: ModalContentProps | undefined) {
|
|
19
|
-
let
|
|
20
|
-
let shown = false;
|
|
21
|
-
let closeOnClick = false;
|
|
19
|
+
let defaultId = getId();
|
|
22
20
|
|
|
23
21
|
// Get stuff out of the ModalContext
|
|
24
22
|
const context = $context[ModalContextName] as ModalContext;
|
|
@@ -27,52 +25,31 @@ export default function ModalContent($props: ModalContentProps | undefined) {
|
|
|
27
25
|
}
|
|
28
26
|
let $state = context.state;
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hide();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
function show() {
|
|
37
|
-
shown = true;
|
|
38
|
-
|
|
39
|
-
// HACK: Because this Modal could be shown with a click, we need to wait for another mousedown
|
|
40
|
-
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
41
|
-
closeOnClick = false;
|
|
42
|
-
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
43
|
-
addDocumentEvent("click", handleDocumentClick);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function hide() {
|
|
47
|
-
if (!shown) return;
|
|
28
|
+
// Set the content ID so that the trigger can use it with aria-controls
|
|
29
|
+
$state.contentId = $props?.id ?? defaultId;
|
|
48
30
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
const popout = createPopoutContent({
|
|
32
|
+
getAnchor: () => undefined,
|
|
33
|
+
getContent: () => div,
|
|
34
|
+
close: (e) => context.handleClickOutside?.(e),
|
|
35
|
+
});
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
closeOnClick = true;
|
|
55
|
-
}
|
|
37
|
+
let div: HTMLDivElement;
|
|
56
38
|
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
div &&
|
|
61
|
-
!div.contains(e.target as HTMLElement)
|
|
62
|
-
) {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
context.handleClickOutside!(e);
|
|
39
|
+
$run(() => {
|
|
40
|
+
if (!$state.visible) {
|
|
41
|
+
popout.hide();
|
|
65
42
|
}
|
|
66
|
-
}
|
|
43
|
+
});
|
|
67
44
|
|
|
68
45
|
@render {
|
|
69
46
|
@if ($state.visible) {
|
|
70
47
|
<div
|
|
71
|
-
{$props?.id}
|
|
48
|
+
id={$props?.id ?? defaultId}
|
|
72
49
|
class={["torp-modal-content", $props?.class]}
|
|
73
50
|
{$props?.style}
|
|
74
51
|
&ref={div}
|
|
75
|
-
onmount={show}
|
|
52
|
+
onmount={(_el) => popout.show()}
|
|
76
53
|
>
|
|
77
54
|
<slot />
|
|
78
55
|
</div>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import { disableScroll } from "../mount/disableScroll";
|
|
3
|
-
import {
|
|
3
|
+
import { type ModalContext, ModalContextName } from "./ModalTypes";
|
|
4
4
|
|
|
5
5
|
interface ModalOverlayProps {
|
|
6
6
|
/** An ID for the root element */
|
|
7
7
|
id?: string;
|
|
8
8
|
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue
|
|
9
|
+
class?: ClassValue;
|
|
10
10
|
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue
|
|
11
|
+
style?: StyleValue;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -33,7 +33,7 @@ export default function ModalOverlay($props: ModalOverlayProps | undefined) {
|
|
|
33
33
|
class={["torp-modal-overlay", $props?.class]}
|
|
34
34
|
{$props?.style}
|
|
35
35
|
tabindex="-1"
|
|
36
|
-
onmount={(
|
|
36
|
+
onmount={(_el) => disableScroll()}
|
|
37
37
|
>
|
|
38
38
|
<slot />
|
|
39
39
|
</div>
|
|
@@ -1,54 +1,38 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import PopoutClickTrigger from "../utils/PopoutClickTrigger.torp";
|
|
3
|
+
import { type ModalContext, ModalContextName } from "./ModalTypes";
|
|
4
4
|
|
|
5
5
|
interface ModalTriggerProps {
|
|
6
6
|
/** An ID for the root element */
|
|
7
7
|
id?: string;
|
|
8
8
|
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue
|
|
9
|
+
class?: ClassValue;
|
|
10
10
|
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue
|
|
12
|
-
/** Whether the modal is activated by click/press or by hover **/
|
|
13
|
-
activation?: "press" | "hover"
|
|
11
|
+
style?: StyleValue;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
* The button that
|
|
15
|
+
* The button that opens a Modal when pressed.
|
|
16
|
+
*
|
|
17
|
+
* Modals require a deliberate act to open, so there is no hover activation.
|
|
18
18
|
*/
|
|
19
|
-
export default function ModalTrigger($props
|
|
20
|
-
let activation = $props?.activation ?? "press";
|
|
21
|
-
|
|
19
|
+
export default function ModalTrigger($props?: ModalTriggerProps) {
|
|
22
20
|
// Get stuff out of the ModalContext
|
|
23
21
|
const context = $context[ModalContextName] as ModalContext;
|
|
24
22
|
if (!context) {
|
|
25
23
|
throw new Error("ModalTrigger must be contained within a Modal");
|
|
26
24
|
}
|
|
27
|
-
let $state = context.state;
|
|
28
|
-
|
|
29
|
-
function handleClick() {
|
|
30
|
-
if (activation !== "press") return;
|
|
31
|
-
|
|
32
|
-
$state.visible = !$state.visible;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function handleHover() {
|
|
36
|
-
if (activation !== "hover") return;
|
|
37
|
-
|
|
38
|
-
$state.visible = !$state.visible
|
|
39
|
-
}
|
|
40
25
|
|
|
41
26
|
@render {
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
{$props?.
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
&ref={context.anchorElement}
|
|
27
|
+
<PopoutClickTrigger
|
|
28
|
+
id={$props?.id}
|
|
29
|
+
class={$props?.class ?? "torp-modal-trigger"}
|
|
30
|
+
style={$props?.style}
|
|
31
|
+
context={context}
|
|
32
|
+
tag="button"
|
|
33
|
+
event="click"
|
|
50
34
|
>
|
|
51
35
|
<slot />
|
|
52
|
-
</
|
|
36
|
+
</PopoutClickTrigger>
|
|
53
37
|
}
|
|
54
38
|
}
|
package/dist/Modal/ModalTypes.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { type PopoutContext, type PopoutState } from "../utils/PopoutTypes";
|
|
2
|
+
|
|
3
|
+
export const ModalContextName: unique symbol = Symbol.for("torp.Modal");
|
|
2
4
|
|
|
3
5
|
/** The shared context for modal components (Contextual, Prompt and Modal) */
|
|
4
|
-
export interface ModalContext {
|
|
5
|
-
handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
|
|
6
|
-
// HACK: We need to be able to let children (i.e. Dialogs) override the click outside functionality
|
|
7
|
-
// There may be a more elegant way to accomplish this too
|
|
8
|
-
handleClickOutside?: (e: MouseEvent) => void;
|
|
6
|
+
export interface ModalContext extends PopoutContext {
|
|
9
7
|
state: ModalState;
|
|
10
|
-
// HACK: focusFirstElement is necessary because if we focus the first element e.g. in a Dialog's
|
|
11
|
-
// onMount, it will scroll the page to the focused element and mess up our careful positioning
|
|
12
|
-
// We need to be able to manually set the order to
|
|
13
|
-
// 1. set visible (so we have an element with content)
|
|
14
|
-
// 2. set position (so the element is in the right place)
|
|
15
|
-
// 3. set focus (for accessibility)
|
|
16
|
-
// There may be a more elegant way to accomplish this!
|
|
17
|
-
focusFirstElement?: () => void;
|
|
18
8
|
}
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
10
|
+
/** A modal's state is exactly the shared popout state */
|
|
11
|
+
export type ModalState = PopoutState;
|
package/dist/Modal/index.d.ts
CHANGED
|
@@ -5,19 +5,15 @@ interface ModalProps {
|
|
|
5
5
|
/** An ID for the root element */
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
10
|
+
style?: StyleValue;
|
|
11
11
|
/** Whether the modal is visible */
|
|
12
|
-
visible
|
|
13
|
-
/** A function to be called when the user selects a response */
|
|
14
|
-
callback?: ((value: any) => void),
|
|
15
|
-
/** Raised when the modal is opened or closed */
|
|
16
|
-
ontoggle?: (open: boolean) => void,
|
|
12
|
+
visible: Bindable<boolean | undefined>;
|
|
17
13
|
/** Raised when the modal has opened */
|
|
18
|
-
onopen?: () => void
|
|
14
|
+
onopen?: () => void;
|
|
19
15
|
/** Raised when the modal has closed */
|
|
20
|
-
onclose?: (result: any) => void
|
|
16
|
+
onclose?: (result: any) => void;
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
/**
|
|
@@ -49,14 +45,13 @@ interface ModalContentProps {
|
|
|
49
45
|
/** An ID for the root element */
|
|
50
46
|
id?: string;
|
|
51
47
|
/** Classes for the root element */
|
|
52
|
-
class?: ClassValue
|
|
48
|
+
class?: ClassValue;
|
|
53
49
|
/** Styles for the root element */
|
|
54
|
-
style?: StyleValue
|
|
50
|
+
style?: StyleValue;
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
|
-
* The content that is displayed for a Modal when it is open
|
|
59
|
-
* alongside an element.
|
|
54
|
+
* The content that is displayed for a Modal when it is open.
|
|
60
55
|
*/
|
|
61
56
|
declare function ModalContent(
|
|
62
57
|
$parent: ParentNode,
|
|
@@ -72,9 +67,9 @@ interface ModalOverlayProps {
|
|
|
72
67
|
/** An ID for the root element */
|
|
73
68
|
id?: string;
|
|
74
69
|
/** Classes for the root element */
|
|
75
|
-
class?: ClassValue
|
|
70
|
+
class?: ClassValue;
|
|
76
71
|
/** Styles for the root element */
|
|
77
|
-
style?: StyleValue
|
|
72
|
+
style?: StyleValue;
|
|
78
73
|
}
|
|
79
74
|
|
|
80
75
|
/**
|
|
@@ -91,26 +86,19 @@ declare function ModalOverlay(
|
|
|
91
86
|
|
|
92
87
|
|
|
93
88
|
|
|
94
|
-
interface ModalTriggerProps {
|
|
95
|
-
/** An ID for the root element */
|
|
96
|
-
id?: string;
|
|
97
|
-
/** Classes for the root element */
|
|
98
|
-
class?: ClassValue,
|
|
99
|
-
/** Styles for the root element */
|
|
100
|
-
style?: StyleValue,
|
|
101
|
-
/** Whether the modal is activated by click/press or by hover **/
|
|
102
|
-
activation?: "press" | "hover"
|
|
103
|
-
}
|
|
104
|
-
|
|
105
89
|
/**
|
|
106
|
-
* The button that
|
|
90
|
+
* The button that opens a Modal when pressed.
|
|
91
|
+
*
|
|
92
|
+
* Modals require a deliberate act to open, so there is no hover activation.
|
|
107
93
|
*/
|
|
108
94
|
declare function ModalTrigger(
|
|
109
95
|
$parent: ParentNode,
|
|
110
96
|
$anchor: Node | null,
|
|
111
|
-
$props
|
|
97
|
+
$props?: ModalTriggerProps,
|
|
112
98
|
$context?: Record<PropertyKey, any>,
|
|
113
99
|
$slots?: Record<string, SlotRender>,
|
|
114
100
|
): void;
|
|
115
101
|
|
|
116
|
-
export { Modal, ModalContent, ModalOverlay, ModalTrigger };
|
|
102
|
+
export { Modal, ModalContent, ModalOverlay, ModalTrigger };
|
|
103
|
+
export { default as showModal } from "./showModal";
|
|
104
|
+
export { default as showPrompt } from "./showPrompt";
|
package/dist/Modal/index.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// src/Modal/showModal.ts
|
|
1
|
+
import Modal from "./Modal.torp";
|
|
2
|
+
import ModalContent from "./ModalContent.torp";
|
|
3
|
+
import ModalOverlay from "./ModalOverlay.torp";
|
|
4
|
+
import ModalTrigger from "./ModalTrigger.torp";
|
|
5
|
+
//#region src/Modal/showModal.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shows a modal component in code.
|
|
8
|
+
* @param modal The modal component
|
|
9
|
+
* @param props The properties for the modal component
|
|
10
|
+
* @param target The target element to show the modal in
|
|
11
|
+
* @returns The value selected by the user
|
|
12
|
+
*/
|
|
14
13
|
function showModal(modal, props, target) {
|
|
15
|
-
|
|
14
|
+
modal(target || document.body, null, props);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/Modal/showPrompt.ts
|
|
18
|
+
/**
|
|
19
|
+
* Shows a modal component in code, and asynchronously returns the value selected by the user.
|
|
20
|
+
* @param modal The modal component
|
|
21
|
+
* @param props The properties for the modal component
|
|
22
|
+
* @param target The target element to show the modal in
|
|
23
|
+
* @returns The value selected by the user
|
|
24
|
+
*/
|
|
19
25
|
function showPrompt(modal, props, target) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const allProps = Object.assign({}, props, { onclose: resolve });
|
|
28
|
+
modal(target || document.body, null, allProps);
|
|
29
|
+
});
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ModalOverlay_default as ModalOverlay,
|
|
29
|
-
ModalTrigger_default as ModalTrigger,
|
|
30
|
-
showModal,
|
|
31
|
-
showPrompt
|
|
32
|
-
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { Modal, ModalContent, ModalOverlay, ModalTrigger, showModal, showPrompt };
|
|
33
|
+
|
|
33
34
|
//# sourceMappingURL=index.js.map
|
package/dist/Modal/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Modal/showModal.ts","../../src/Modal/showPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline modal\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showModal(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Create the modal\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tmodal(target || document.body, null, props);\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code, and asynchronously returns the value selected by the user.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showPrompt(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<any> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/Modal/showModal.ts","../../src/Modal/showPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline modal\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showModal(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Create the modal\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tmodal(target || document.body, null, props);\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code, and asynchronously returns the value selected by the user.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showPrompt(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<any> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the onclose handler\n\t\tconst allProps = Object.assign({}, props, { onclose: resolve });\n\n\t\t// Create the modal\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tmodal(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAwB,UACvB,OACA,OACA,QACO;CAGP,MAAM,UAAU,SAAS,MAAM,MAAM,KAAK;AAC3C;;;;;;;;;;ACTA,SAAwB,WACvB,OACA,OACA,QACe;CACf,OAAO,IAAI,SAAS,YAAY;EAE/B,MAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,SAAS,QAAQ,CAAC;EAI9D,MAAM,UAAU,SAAS,MAAM,MAAM,QAAQ;CAC9C,CAAC;AACF"}
|
package/dist/Modal/showPrompt.ts
CHANGED
|
@@ -13,8 +13,8 @@ export default function showPrompt(
|
|
|
13
13
|
target?: Element,
|
|
14
14
|
): Promise<any> {
|
|
15
15
|
return new Promise((resolve) => {
|
|
16
|
-
// Add the promise as the
|
|
17
|
-
const allProps = Object.assign({}, props, {
|
|
16
|
+
// Add the promise as the onclose handler
|
|
17
|
+
const allProps = Object.assign({}, props, { onclose: resolve });
|
|
18
18
|
|
|
19
19
|
// Create the modal
|
|
20
20
|
// TODO: This needs to clean up after itself, like the use methods do
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type ItemState,
|
|
6
|
-
NavMenuPopoutContextName,
|
|
7
|
-
type NavMenuPopoutContext
|
|
8
|
-
} from "./NavMenuTypes";
|
|
2
|
+
import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
|
|
3
|
+
import { createFocusGroup } from "../utils/focusGroup";
|
|
4
|
+
import { type ItemState, type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
|
|
9
5
|
|
|
10
6
|
interface NavMenuProps {
|
|
11
7
|
/** An ID for the root element */
|
|
12
8
|
id?: string;
|
|
13
9
|
/** Classes for the root element */
|
|
14
|
-
class?: ClassValue
|
|
10
|
+
class?: ClassValue;
|
|
15
11
|
/** Styles for the root element */
|
|
16
|
-
style?: StyleValue
|
|
12
|
+
style?: StyleValue;
|
|
17
13
|
/** An ARIA label for describing the menu to screen readers */
|
|
18
|
-
ariaLabel?: string | undefined
|
|
14
|
+
ariaLabel?: string | undefined;
|
|
19
15
|
/** The orientation of the menu, which affects keyboard navigation */
|
|
20
|
-
orientation?: "horizontal" | "vertical"
|
|
16
|
+
orientation?: "horizontal" | "vertical";
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
/**
|
|
@@ -39,139 +35,61 @@ interface NavMenuProps {
|
|
|
39
35
|
export default function NavMenu($props: NavMenuProps | undefined) {
|
|
40
36
|
let orientation = $props?.orientation ?? "horizontal";
|
|
41
37
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
let focusIndex = -1;
|
|
38
|
+
// The focus group owns the item ledger and roving-tabindex bookkeeping
|
|
39
|
+
const group = createFocusGroup<ItemState>();
|
|
45
40
|
|
|
46
41
|
// Check whether this is a menu in a popout
|
|
47
|
-
const popoutContext = $context[
|
|
42
|
+
const popoutContext = $context[PopoutContextName] as PopoutContext;
|
|
48
43
|
const inPopout = !!popoutContext;
|
|
49
44
|
let popoutState = popoutContext?.state;
|
|
50
45
|
|
|
51
46
|
// Set the focusFirstElement method in the PopoverContext(s) so that it can be called after everything has been shown
|
|
52
47
|
if (popoutContext) {
|
|
53
|
-
popoutContext.focusFirstElement =
|
|
48
|
+
popoutContext.focusFirstElement = group.focusFirstItem;
|
|
49
|
+
popoutContext.focusLastElement = group.focusLastItem;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
// Set the context to pass down to items
|
|
57
53
|
let context: NavMenuContext = {
|
|
58
54
|
handleItemFocus,
|
|
59
55
|
handleItemKey,
|
|
60
|
-
registerItem
|
|
56
|
+
registerItem,
|
|
61
57
|
};
|
|
62
58
|
$context[NavMenuContextName] = context;
|
|
63
59
|
|
|
64
60
|
// If the NavMenu is not in a popout, focus its first item. Otherwise the popout will call focusFirstElement, below
|
|
65
61
|
function handleFocus() {
|
|
66
|
-
if (!popoutContext && itemStates.length) {
|
|
67
|
-
|
|
62
|
+
if (!popoutContext && group.itemStates.length) {
|
|
63
|
+
group.focusFirstItem();
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
itemStates[0].setFocused();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function registerItem(setFocused: () => void) {
|
|
78
|
-
// Add the item's state to the array and return its index
|
|
79
|
-
const newItemState: ItemState = {
|
|
80
|
-
setFocused
|
|
81
|
-
};
|
|
82
|
-
itemStates.push(newItemState);
|
|
83
|
-
itemStates = itemStates;
|
|
84
|
-
return { index: itemStates.length - 1 };
|
|
67
|
+
function registerItem(item: ItemState) {
|
|
68
|
+
return group.registerItem(item);
|
|
85
69
|
}
|
|
86
70
|
|
|
87
71
|
function handleItemFocus(index: number) {
|
|
88
|
-
|
|
72
|
+
group.handleItemFocus(index);
|
|
89
73
|
}
|
|
90
74
|
|
|
91
75
|
function handleItemKey(e: KeyboardEvent) {
|
|
92
76
|
switch (e.key) {
|
|
93
|
-
case "Esc":
|
|
94
77
|
case "Escape": {
|
|
95
78
|
if (inPopout) {
|
|
96
79
|
e.preventDefault();
|
|
97
|
-
//setPopoutVisible(false);
|
|
98
80
|
popoutState.visible = false;
|
|
99
81
|
}
|
|
100
82
|
break;
|
|
101
83
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
focusItem("next");
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case "Left":
|
|
111
|
-
case "ArrowLeft": {
|
|
112
|
-
if (orientation === "horizontal") {
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
focusItem("previous");
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "Down":
|
|
119
|
-
case "ArrowDown": {
|
|
120
|
-
if (orientation === "vertical") {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
focusItem("next");
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case "Up":
|
|
127
|
-
case "ArrowUp": {
|
|
128
|
-
if (orientation === "vertical") {
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
focusItem("previous");
|
|
131
|
-
} else {
|
|
132
|
-
// TODO: This should be based on what side the menu shows on
|
|
133
|
-
// And on the orientation
|
|
134
|
-
if (inPopout) {
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
popoutState.visible = false;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case "Home": {
|
|
142
|
-
e.preventDefault();
|
|
143
|
-
focusItem("start");
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
case "End": {
|
|
147
|
-
e.preventDefault();
|
|
148
|
-
focusItem("end");
|
|
84
|
+
default: {
|
|
85
|
+
group.handleGroupKey(group.getFocusIndex(), e, {
|
|
86
|
+
vertical: orientation === "vertical",
|
|
87
|
+
});
|
|
149
88
|
break;
|
|
150
89
|
}
|
|
151
90
|
}
|
|
152
91
|
}
|
|
153
92
|
|
|
154
|
-
function focusItem(target: "start" | "previous" | "next" | "end") {
|
|
155
|
-
switch (target) {
|
|
156
|
-
case "start": {
|
|
157
|
-
focusIndex = 0;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case "previous": {
|
|
161
|
-
focusIndex = Math.max(0, focusIndex - 1);
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "next": {
|
|
165
|
-
focusIndex = Math.min(itemStates.length - 1, focusIndex + 1);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case "end": {
|
|
169
|
-
focusIndex = itemStates.length - 1;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
itemStates[focusIndex]?.setFocused();
|
|
174
|
-
}
|
|
175
93
|
|
|
176
94
|
@render {
|
|
177
95
|
<nav
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
2
|
+
import { type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
4
|
interface NavMenuButtonProps {
|
|
5
5
|
/** An ID for the root element */
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
10
|
+
style?: StyleValue;
|
|
11
11
|
/** Whether this button is disabled */
|
|
12
|
-
disabled?: boolean
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Raised when the button is clicked */
|
|
14
|
+
onclick?: (e: MouseEvent) => void;
|
|
15
|
+
/** Raised when a key is pressed down */
|
|
16
|
+
onkeydown?: (e: KeyboardEvent) => void;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -27,7 +31,7 @@ export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
|
|
|
27
31
|
const { registerItem, handleItemKey, handleItemFocus } = menuContext;
|
|
28
32
|
|
|
29
33
|
// Register this item with the parent NavMenu and store the index
|
|
30
|
-
const { index } = registerItem(setFocused);
|
|
34
|
+
const { index } = registerItem({ setFocused, disabled: $props?.disabled });
|
|
31
35
|
|
|
32
36
|
function setFocused() {
|
|
33
37
|
button.focus();
|
|
@@ -42,10 +46,8 @@ export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
|
|
|
42
46
|
{$props?.disabled}
|
|
43
47
|
role="menuitem"
|
|
44
48
|
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
45
|
-
data-disabled={$props?.disabled ? "true" : undefined}
|
|
46
|
-
onkeydown
|
|
47
49
|
onkeydown={handleItemKey}
|
|
48
|
-
onclick
|
|
50
|
+
{$props?.onclick}
|
|
49
51
|
onfocus={() => handleItemFocus(index)}
|
|
50
52
|
&ref={button}
|
|
51
53
|
>
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
2
|
+
import { type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
|
|
3
3
|
|
|
4
4
|
interface NavMenuElementProps {
|
|
5
5
|
/** An ID for the root element */
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
10
|
+
style?: StyleValue;
|
|
11
11
|
/** Whether this button is disabled */
|
|
12
|
-
disabled?: boolean
|
|
12
|
+
disabled?: boolean;
|
|
13
13
|
/** An element that can be focused via keyboard navigation */
|
|
14
|
-
element?: HTMLElement
|
|
14
|
+
element?: HTMLElement;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -27,7 +27,7 @@ export default function NavMenuElement($props: NavMenuElementProps | undefined)
|
|
|
27
27
|
const { registerItem, handleItemKey, handleItemFocus } = menuContext;
|
|
28
28
|
|
|
29
29
|
// Register this item with the parent NavMenu and store the index
|
|
30
|
-
const { index } = registerItem(setFocused);
|
|
30
|
+
const { index } = registerItem({ setFocused, disabled: $props?.disabled });
|
|
31
31
|
|
|
32
32
|
function setFocused() {
|
|
33
33
|
if ($props?.element) {
|
|
@@ -43,7 +43,6 @@ export default function NavMenuElement($props: NavMenuElementProps | undefined)
|
|
|
43
43
|
type="div"
|
|
44
44
|
role="menuitem"
|
|
45
45
|
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
46
|
-
data-disabled={$props?.disabled ? "true" : undefined}
|
|
47
46
|
onkeydown
|
|
48
47
|
onkeydown={handleItemKey}
|
|
49
48
|
onclick
|