@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,27 +1,25 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import SubmenuPopout from "../utils/SubmenuPopout.torp";
|
|
2
3
|
import {
|
|
4
|
+
type MenuBarContext,
|
|
3
5
|
MenuBarContextName,
|
|
6
|
+
type MenuBarItemContext,
|
|
4
7
|
MenuBarItemContextName,
|
|
5
|
-
type MenuBarContext,
|
|
6
|
-
type MenuBarItemContext
|
|
7
8
|
} from "./MenuBarTypes";
|
|
8
|
-
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
9
9
|
|
|
10
10
|
interface MenuBarItemProps {
|
|
11
11
|
/** An ID for the root element */
|
|
12
12
|
id?: string;
|
|
13
13
|
/** Classes for the root element */
|
|
14
|
-
class?: ClassValue
|
|
14
|
+
class?: ClassValue;
|
|
15
15
|
/** Styles for the root element */
|
|
16
|
-
style?: StyleValue
|
|
16
|
+
style?: StyleValue;
|
|
17
17
|
/** Whether the item is visible */
|
|
18
|
-
visible?: boolean
|
|
19
|
-
/** Raised when the item is opened or closed */
|
|
20
|
-
ontoggle?: (visible: boolean) => void,
|
|
18
|
+
visible?: boolean;
|
|
21
19
|
/** Raised when the item has opened */
|
|
22
|
-
onopen?: () => void
|
|
20
|
+
onopen?: () => void;
|
|
23
21
|
/** Raised when the item has closed */
|
|
24
|
-
onclose?: (result: any) => void
|
|
22
|
+
onclose?: (result: any) => void;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
/**
|
|
@@ -38,79 +36,60 @@ interface MenuBarItemProps {
|
|
|
38
36
|
*/
|
|
39
37
|
export default function MenuBarItem($props: MenuBarItemProps | undefined) {
|
|
40
38
|
let $state = $watch({
|
|
41
|
-
visible:
|
|
39
|
+
visible: false,
|
|
40
|
+
contentId: undefined,
|
|
41
|
+
triggerId: undefined,
|
|
42
|
+
contentRole: undefined,
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
let result: any;
|
|
45
|
-
|
|
46
45
|
// Get stuff out of the MenuBarContext
|
|
47
46
|
const menubarContext = $context[MenuBarContextName] as MenuBarContext;
|
|
48
47
|
if (!menubarContext) {
|
|
49
48
|
throw new Error("MenuBarItem must be contained within a MenuBar");
|
|
50
49
|
}
|
|
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;
|
|
50
|
+
const { handleItemShow, handleAdjacentItem } = menubarContext;
|
|
60
51
|
|
|
61
|
-
// Set the context to pass down to
|
|
62
|
-
let
|
|
52
|
+
// Set the context to pass down to the trigger and content
|
|
53
|
+
let itemContext: MenuBarItemContext = {
|
|
63
54
|
setVisible,
|
|
64
|
-
handleButton,
|
|
65
|
-
modal: false,
|
|
66
55
|
state: $state,
|
|
67
|
-
|
|
56
|
+
index: -1,
|
|
68
57
|
};
|
|
69
|
-
$context[
|
|
58
|
+
$context[MenuBarItemContextName] = itemContext;
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
function handleNavigateMenuBar(target: "previous" | "next") {
|
|
61
|
+
// Called from a contained Menu when focus should move to an adjacent
|
|
62
|
+
// menubar item; the MenuBar moves focus and opens that item's menu
|
|
63
|
+
handleAdjacentItem(itemContext.index, target);
|
|
64
|
+
}
|
|
74
65
|
|
|
75
66
|
function setVisible(value: boolean) {
|
|
76
67
|
if (!value || menubarContext.state.active) {
|
|
77
68
|
$state.visible = value;
|
|
78
69
|
if (value) {
|
|
79
|
-
handleItemShow(
|
|
70
|
+
handleItemShow(itemContext.index);
|
|
80
71
|
}
|
|
81
72
|
}
|
|
82
73
|
}
|
|
83
74
|
|
|
84
|
-
|
|
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) {
|
|
75
|
+
function handleButton(_type: "confirm" | "cancel" | undefined, _value?: any) {
|
|
103
76
|
menubarContext.state.active = false;
|
|
104
77
|
setVisible(false);
|
|
105
78
|
}
|
|
106
79
|
|
|
107
80
|
@render {
|
|
108
|
-
<
|
|
109
|
-
{$props?.id}
|
|
81
|
+
<SubmenuPopout
|
|
82
|
+
id={$props?.id}
|
|
110
83
|
class={["torp-menu-bar-item", $props?.class]}
|
|
111
|
-
{$props?.style}
|
|
84
|
+
style={$props?.style}
|
|
85
|
+
visible={$props?.visible}
|
|
86
|
+
onopen={$props?.onopen}
|
|
87
|
+
onclose={$props?.onclose}
|
|
88
|
+
state={$state}
|
|
89
|
+
context={{ handleButton, navigateMenuBar: handleNavigateMenuBar }}
|
|
90
|
+
closeOnMouseLeave={false}
|
|
112
91
|
>
|
|
113
92
|
<slot />
|
|
114
|
-
</
|
|
93
|
+
</SubmenuPopout>
|
|
115
94
|
}
|
|
116
95
|
}
|
|
@@ -1,119 +1,33 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
4
|
-
import {
|
|
5
|
-
MenuBarContextName,
|
|
6
|
-
MenuBarItemContextName,
|
|
7
|
-
type MenuBarContext,
|
|
8
|
-
type MenuBarItemContext
|
|
9
|
-
} from "./MenuBarTypes";
|
|
2
|
+
import SubmenuPopoutContent from "../utils/SubmenuPopoutContent.torp";
|
|
10
3
|
|
|
11
4
|
interface MenuBarItemContentProps {
|
|
12
5
|
/** An ID for the root element */
|
|
13
6
|
id?: string;
|
|
14
7
|
/** Classes for the root element */
|
|
15
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
16
9
|
/** Styles for the root element */
|
|
17
|
-
style?: StyleValue
|
|
10
|
+
style?: StyleValue;
|
|
18
11
|
/** Where the popout will be shown, relative to the popout button */
|
|
19
|
-
side?: "top" | "right" | "bottom" | "left"
|
|
12
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
20
13
|
/** How the popout will be aligned, relative to the popout button */
|
|
21
|
-
alignment?: "start" | "center" | "end"
|
|
14
|
+
alignment?: "start" | "center" | "end";
|
|
22
15
|
}
|
|
23
16
|
|
|
24
17
|
/**
|
|
25
18
|
* The content that is displayed for a MenuBarItem when it is open.
|
|
26
19
|
*/
|
|
27
20
|
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
21
|
@render {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
22
|
+
<SubmenuPopoutContent
|
|
23
|
+
id={$props?.id}
|
|
24
|
+
class={["torp-menu-bar-item-content", $props?.class]}
|
|
25
|
+
style={$props?.style}
|
|
26
|
+
side={$props?.side}
|
|
27
|
+
alignment={$props?.alignment}
|
|
28
|
+
closeOnEscape={false}
|
|
29
|
+
>
|
|
30
|
+
<slot />
|
|
31
|
+
</SubmenuPopoutContent>
|
|
118
32
|
}
|
|
119
33
|
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import SubmenuPopoutTrigger from "../utils/SubmenuPopoutTrigger.torp";
|
|
2
3
|
import {
|
|
4
|
+
type MenuBarContext,
|
|
3
5
|
MenuBarContextName,
|
|
6
|
+
type MenuBarItemContext,
|
|
4
7
|
MenuBarItemContextName,
|
|
5
|
-
type MenuBarContext,
|
|
6
|
-
type MenuBarItemContext
|
|
7
8
|
} from "./MenuBarTypes";
|
|
8
9
|
|
|
9
10
|
interface MenuBarItemTriggerProps {
|
|
10
11
|
/** An ID for the root element */
|
|
11
12
|
id?: string;
|
|
12
13
|
/** Classes for the root element */
|
|
13
|
-
class?: ClassValue
|
|
14
|
+
class?: ClassValue;
|
|
14
15
|
/** Styles for the root element */
|
|
15
|
-
style?: StyleValue
|
|
16
|
+
style?: StyleValue;
|
|
16
17
|
/** Whether this button is disabled */
|
|
17
|
-
disabled?: boolean
|
|
18
|
+
disabled?: boolean;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -22,8 +23,6 @@ interface MenuBarItemTriggerProps {
|
|
|
22
23
|
*
|
|
23
24
|
*/
|
|
24
25
|
export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | undefined) {
|
|
25
|
-
let button: HTMLButtonElement;
|
|
26
|
-
|
|
27
26
|
// Get stuff out of the MenuBarContext
|
|
28
27
|
const menubarContext = $context[MenuBarContextName] as MenuBarContext;
|
|
29
28
|
if (!menubarContext) {
|
|
@@ -36,64 +35,30 @@ export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | und
|
|
|
36
35
|
if (!itemContext) {
|
|
37
36
|
throw new Error("MenuBarItemTrigger must be contained within a MenuBarItem");
|
|
38
37
|
}
|
|
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
38
|
|
|
54
39
|
function handleClick() {
|
|
55
40
|
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);
|
|
41
|
+
itemContext.setVisible(menubarContext.state.active);
|
|
75
42
|
}
|
|
76
43
|
|
|
77
44
|
@render {
|
|
78
|
-
<
|
|
79
|
-
{$props?.id}
|
|
45
|
+
<SubmenuPopoutTrigger
|
|
46
|
+
id={$props?.id}
|
|
80
47
|
class={["torp-menu-bar-item-button", $props?.class]}
|
|
81
|
-
{$props?.style}
|
|
82
|
-
|
|
83
|
-
{$props?.disabled}
|
|
48
|
+
style={$props?.style}
|
|
49
|
+
disabled={$props?.disabled}
|
|
84
50
|
role="menuitem"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
51
|
+
openKey="ArrowDown"
|
|
52
|
+
hoverDelay={0}
|
|
53
|
+
registerItem={registerItem}
|
|
54
|
+
handleItemKey={handleButtonKey}
|
|
55
|
+
handleItemFocus={handleButtonFocus}
|
|
56
|
+
setVisible={itemContext.setVisible}
|
|
57
|
+
onRegister={(index: number) => (itemContext.index = index)}
|
|
58
|
+
onActivate={() => (menubarContext.state.active = true)}
|
|
90
59
|
onclick={handleClick}
|
|
91
|
-
onfocus={() => handleButtonFocus(index)}
|
|
92
|
-
onmouseenter={handleMouseEnter}
|
|
93
|
-
&ref={button}
|
|
94
|
-
onmount={(el) => itemContext.anchorElement = el}
|
|
95
60
|
>
|
|
96
61
|
<slot />
|
|
97
|
-
</
|
|
62
|
+
</SubmenuPopoutTrigger>
|
|
98
63
|
}
|
|
99
64
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type PopoutState, type SubmenuItemState } from "../utils/PopoutTypes";
|
|
2
|
+
|
|
3
|
+
export const MenuBarContextName: unique symbol = Symbol.for("torp.MenuBar");
|
|
4
|
+
export const MenuBarItemContextName: unique symbol = Symbol.for("torp.MenuBarItem");
|
|
3
5
|
|
|
4
6
|
export interface MenuBarContext {
|
|
5
7
|
/** Called from a MenuBarItem when it is shown, to hide others */
|
|
@@ -11,8 +13,14 @@ export interface MenuBarContext {
|
|
|
11
13
|
/** Called from a MenuBarButton when a key is pressed */
|
|
12
14
|
handleButtonKey: (e: KeyboardEvent) => void;
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Called from a MenuBarItem when a contained menu signals that focus should
|
|
18
|
+
* move to an adjacent item, opening its menu
|
|
19
|
+
*/
|
|
20
|
+
handleAdjacentItem: (index: number, target: "previous" | "next") => void;
|
|
21
|
+
|
|
14
22
|
/** Called from each MenuBarButton to register itself with this MenuBar */
|
|
15
|
-
registerItem: (
|
|
23
|
+
registerItem: (item: ItemState) => { index: number };
|
|
16
24
|
|
|
17
25
|
state: {
|
|
18
26
|
/** Whether a menubar item is showing its content. If so, changing to another item should show its content */
|
|
@@ -22,15 +30,8 @@ export interface MenuBarContext {
|
|
|
22
30
|
|
|
23
31
|
export interface MenuBarItemContext {
|
|
24
32
|
setVisible: (value: boolean) => void;
|
|
25
|
-
state:
|
|
26
|
-
visible: boolean;
|
|
27
|
-
};
|
|
33
|
+
state: PopoutState;
|
|
28
34
|
index: number;
|
|
29
|
-
anchorElement?: HTMLElement;
|
|
30
|
-
focusFirstElement?: () => void;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export
|
|
34
|
-
setVisible: (value: boolean) => void;
|
|
35
|
-
setFocused: () => void;
|
|
36
|
-
}
|
|
37
|
+
export type ItemState = SubmenuItemState;
|
package/dist/MenuBar/index.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ interface MenuBarProps {
|
|
|
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
|
/** An ARIA label for describing the menu to screen readers */
|
|
12
|
-
ariaLabel?: string
|
|
12
|
+
ariaLabel?: string;
|
|
13
13
|
/** The orientation of the menu, which affects keyboard navigation */
|
|
14
|
-
orientation?: "horizontal" | "vertical"
|
|
14
|
+
orientation?: "horizontal" | "vertical";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -46,17 +46,15 @@ interface MenuBarItemProps {
|
|
|
46
46
|
/** An ID for the root element */
|
|
47
47
|
id?: string;
|
|
48
48
|
/** Classes for the root element */
|
|
49
|
-
class?: ClassValue
|
|
49
|
+
class?: ClassValue;
|
|
50
50
|
/** Styles for the root element */
|
|
51
|
-
style?: StyleValue
|
|
51
|
+
style?: StyleValue;
|
|
52
52
|
/** Whether the item is visible */
|
|
53
|
-
visible?: boolean
|
|
54
|
-
/** Raised when the item is opened or closed */
|
|
55
|
-
ontoggle?: (visible: boolean) => void,
|
|
53
|
+
visible?: boolean;
|
|
56
54
|
/** Raised when the item has opened */
|
|
57
|
-
onopen?: () => void
|
|
55
|
+
onopen?: () => void;
|
|
58
56
|
/** Raised when the item has closed */
|
|
59
|
-
onclose?: (result: any) => void
|
|
57
|
+
onclose?: (result: any) => void;
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
/**
|
|
@@ -85,13 +83,13 @@ interface MenuBarItemContentProps {
|
|
|
85
83
|
/** An ID for the root element */
|
|
86
84
|
id?: string;
|
|
87
85
|
/** Classes for the root element */
|
|
88
|
-
class?: ClassValue
|
|
86
|
+
class?: ClassValue;
|
|
89
87
|
/** Styles for the root element */
|
|
90
|
-
style?: StyleValue
|
|
88
|
+
style?: StyleValue;
|
|
91
89
|
/** Where the popout will be shown, relative to the popout button */
|
|
92
|
-
side?: "top" | "right" | "bottom" | "left"
|
|
90
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
93
91
|
/** How the popout will be aligned, relative to the popout button */
|
|
94
|
-
alignment?: "start" | "center" | "end"
|
|
92
|
+
alignment?: "start" | "center" | "end";
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
/**
|
|
@@ -111,11 +109,11 @@ interface MenuBarItemTriggerProps {
|
|
|
111
109
|
/** An ID for the root element */
|
|
112
110
|
id?: string;
|
|
113
111
|
/** Classes for the root element */
|
|
114
|
-
class?: ClassValue
|
|
112
|
+
class?: ClassValue;
|
|
115
113
|
/** Styles for the root element */
|
|
116
|
-
style?: StyleValue
|
|
114
|
+
style?: StyleValue;
|
|
117
115
|
/** Whether this button is disabled */
|
|
118
|
-
disabled?: boolean
|
|
116
|
+
disabled?: boolean;
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
/**
|
|
@@ -130,4 +128,4 @@ declare function MenuBarItemTrigger(
|
|
|
130
128
|
$slots?: Record<string, SlotRender>,
|
|
131
129
|
): void;
|
|
132
130
|
|
|
133
|
-
export { MenuBar, MenuBarItem, MenuBarItemContent, MenuBarItemTrigger };
|
|
131
|
+
export { MenuBar, MenuBarItem, MenuBarItemContent, MenuBarItemTrigger };
|
package/dist/MenuBar/index.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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
|
+
export { MenuBar, MenuBarItem, MenuBarItemContent, MenuBarItemTrigger };
|
package/dist/Modal/Modal.torp
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
1
|
+
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import $handle from "../utils/$handle";
|
|
3
|
+
import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
|
|
4
|
+
import { type ModalContext, ModalContextName, type ModalState } from "./ModalTypes";
|
|
3
5
|
|
|
4
6
|
interface ModalProps {
|
|
5
7
|
/** An ID for the root element */
|
|
6
8
|
id?: string;
|
|
7
9
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
10
|
+
class?: ClassValue;
|
|
9
11
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
12
|
+
style?: StyleValue;
|
|
11
13
|
/** 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,
|
|
14
|
+
visible: Bindable<boolean | undefined>;
|
|
17
15
|
/** Raised when the modal has opened */
|
|
18
|
-
onopen?: () => void
|
|
16
|
+
onopen?: () => void;
|
|
19
17
|
/** Raised when the modal has closed */
|
|
20
|
-
onclose?: (result: any) => void
|
|
18
|
+
onclose?: (result: any) => void;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
/**
|
|
@@ -38,18 +36,13 @@ interface ModalProps {
|
|
|
38
36
|
export default function Modal($props: ModalProps | undefined) {
|
|
39
37
|
let $state: ModalState = $watch({
|
|
40
38
|
visible: false,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$run(() => {
|
|
45
|
-
$state.visible = $props?.visible ?? false;
|
|
46
|
-
});
|
|
47
|
-
$run(() => {
|
|
48
|
-
if ($props !== undefined) {
|
|
49
|
-
$props.visible = $state.visible;
|
|
50
|
-
}
|
|
39
|
+
contentId: undefined,
|
|
40
|
+
triggerId: undefined,
|
|
41
|
+
contentRole: undefined,
|
|
51
42
|
});
|
|
52
43
|
|
|
44
|
+
$bind($state, $props, "visible");
|
|
45
|
+
|
|
53
46
|
let result: any;
|
|
54
47
|
|
|
55
48
|
// Set the context to pass down to items
|
|
@@ -60,22 +53,18 @@ export default function Modal($props: ModalProps | undefined) {
|
|
|
60
53
|
};
|
|
61
54
|
$context[ModalContextName] = context;
|
|
62
55
|
|
|
63
|
-
//
|
|
64
|
-
let
|
|
65
|
-
$
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
// Set the context to pass down to items
|
|
57
|
+
let popoutContext: PopoutContext = context;
|
|
58
|
+
$context[PopoutContextName] = popoutContext;
|
|
59
|
+
|
|
60
|
+
// Dispatch the open/close events when the modal is opened or closed
|
|
61
|
+
$handle((first) => {
|
|
69
62
|
const visible = $state.visible;
|
|
70
|
-
if (
|
|
71
|
-
|
|
63
|
+
if (first) return;
|
|
64
|
+
if (visible) {
|
|
65
|
+
$props?.onopen?.();
|
|
72
66
|
} else {
|
|
73
|
-
|
|
74
|
-
if (visible) {
|
|
75
|
-
if (onopen) onopen()
|
|
76
|
-
} else {
|
|
77
|
-
if (onclose) onclose(result);
|
|
78
|
-
}
|
|
67
|
+
$props?.onclose?.(result);
|
|
79
68
|
}
|
|
80
69
|
});
|
|
81
70
|
|
|
@@ -83,11 +72,11 @@ export default function Modal($props: ModalProps | undefined) {
|
|
|
83
72
|
// Get the button's result
|
|
84
73
|
switch (type) {
|
|
85
74
|
case "confirm": {
|
|
86
|
-
result = value
|
|
75
|
+
result = value ?? true;
|
|
87
76
|
break;
|
|
88
77
|
}
|
|
89
78
|
case "cancel": {
|
|
90
|
-
result = value
|
|
79
|
+
result = value ?? false;
|
|
91
80
|
break;
|
|
92
81
|
}
|
|
93
82
|
default: {
|
|
@@ -98,24 +87,15 @@ export default function Modal($props: ModalProps | undefined) {
|
|
|
98
87
|
|
|
99
88
|
// Hide the modal
|
|
100
89
|
$state.visible = false;
|
|
101
|
-
|
|
102
|
-
// Call the callback
|
|
103
|
-
if ($props?.callback) {
|
|
104
|
-
$props?.callback(result);
|
|
105
|
-
}
|
|
106
90
|
}
|
|
107
91
|
|
|
108
|
-
function handleClickOutside(e: MouseEvent) {
|
|
92
|
+
function handleClickOutside(e: MouseEvent | KeyboardEvent) {
|
|
109
93
|
e.preventDefault();
|
|
110
94
|
$state.visible = false;
|
|
111
95
|
}
|
|
112
96
|
|
|
113
97
|
@render {
|
|
114
|
-
<div
|
|
115
|
-
{$props?.id}
|
|
116
|
-
class={["torp-modal", $props?.class]}
|
|
117
|
-
{$props?.style}
|
|
118
|
-
>
|
|
98
|
+
<div {$props?.id} class={["torp-modal", $props?.class]} {$props?.style}>
|
|
119
99
|
<slot />
|
|
120
100
|
</div>
|
|
121
101
|
}
|