@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
package/dist/Dialog/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
// src/Dialog/DialogButton.torp
|
|
8
|
-
import DialogButton_default from "./DialogButton.torp";
|
|
9
|
-
|
|
10
|
-
// src/Dialog/DialogFooter.torp
|
|
11
|
-
import DialogFooter_default from "./DialogFooter.torp";
|
|
12
|
-
|
|
13
|
-
// src/Dialog/DialogHeader.torp
|
|
14
|
-
import DialogHeader_default from "./DialogHeader.torp";
|
|
15
|
-
export {
|
|
16
|
-
Dialog_default as Dialog,
|
|
17
|
-
DialogBody_default as DialogBody,
|
|
18
|
-
DialogButton_default as DialogButton,
|
|
19
|
-
DialogFooter_default as DialogFooter,
|
|
20
|
-
DialogHeader_default as DialogHeader
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import Dialog from "./Dialog.torp";
|
|
2
|
+
import DialogBody from "./DialogBody.torp";
|
|
3
|
+
import DialogButton from "./DialogButton.torp";
|
|
4
|
+
import DialogFooter from "./DialogFooter.torp";
|
|
5
|
+
import DialogHeader from "./DialogHeader.torp";
|
|
6
|
+
export { Dialog, DialogBody, DialogButton, DialogFooter, DialogHeader };
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
2
|
+
import $handle from "../utils/$handle";
|
|
3
|
+
import {
|
|
4
|
+
type DisclosureContext,
|
|
5
|
+
DisclosureContextName,
|
|
6
|
+
type DisclosureState,
|
|
7
|
+
} from "./DisclosureTypes";
|
|
3
8
|
|
|
4
9
|
interface DisclosureProps {
|
|
5
10
|
/** An ID for the root element */
|
|
6
11
|
id?: string;
|
|
7
12
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
13
|
+
class?: ClassValue;
|
|
9
14
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
15
|
+
style?: StyleValue;
|
|
11
16
|
/** Whether the disclosure is expanded and its content visible */
|
|
12
|
-
expanded?: boolean
|
|
17
|
+
expanded?: boolean;
|
|
13
18
|
/** If set to true, the user cannot interact with this disclosure */
|
|
14
|
-
disabled?: boolean
|
|
19
|
+
disabled?: boolean;
|
|
15
20
|
/** Raised when the disclosure is opened or closed */
|
|
16
|
-
|
|
21
|
+
onchange?: (open: boolean) => void;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -42,10 +47,12 @@ export default function Disclosure($props: DisclosureProps | undefined) {
|
|
|
42
47
|
|
|
43
48
|
// Update $state with $props
|
|
44
49
|
$run(() => {
|
|
45
|
-
$state.expanded =
|
|
50
|
+
$state.expanded =
|
|
51
|
+
$props?.expanded === true ||
|
|
46
52
|
// @ts-ignore
|
|
47
53
|
$props?.expanded === "true";
|
|
48
|
-
$state.disabled =
|
|
54
|
+
$state.disabled =
|
|
55
|
+
$props?.disabled === true ||
|
|
49
56
|
// @ts-ignore
|
|
50
57
|
$props?.disabled === "true";
|
|
51
58
|
});
|
|
@@ -56,16 +63,10 @@ export default function Disclosure($props: DisclosureProps | undefined) {
|
|
|
56
63
|
};
|
|
57
64
|
$context[DisclosureContextName] = itemContext;
|
|
58
65
|
|
|
59
|
-
// Dispatch the
|
|
60
|
-
|
|
61
|
-
$run(() => {
|
|
62
|
-
const ev = $props?.ontoggle;
|
|
66
|
+
// Dispatch the change event when the value of expanded changes
|
|
67
|
+
$handle((first) => {
|
|
63
68
|
const expanded = $state.expanded;
|
|
64
|
-
if (
|
|
65
|
-
firstToggle = false;
|
|
66
|
-
} else if (ev) {
|
|
67
|
-
ev(expanded);
|
|
68
|
-
}
|
|
69
|
+
if (!first) $props?.onchange?.(expanded);
|
|
69
70
|
});
|
|
70
71
|
|
|
71
72
|
@render {
|
|
@@ -74,7 +75,6 @@ export default function Disclosure($props: DisclosureProps | undefined) {
|
|
|
74
75
|
class={["torp-disclosure-item", $props?.class]}
|
|
75
76
|
{$props?.style}
|
|
76
77
|
data-state={$state.expanded ? "open" : "closed"}
|
|
77
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
78
78
|
>
|
|
79
79
|
<slot />
|
|
80
80
|
</div>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import getId from "../utils/getId";
|
|
3
|
-
import {
|
|
3
|
+
import { type DisclosureContext, DisclosureContextName } from "./DisclosureTypes";
|
|
4
4
|
|
|
5
5
|
interface DisclosureContentProps {
|
|
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
|
/** Whether this content should act as a region. Set this when the content contains heading elements or a nested Disclosure */
|
|
13
|
-
ariaRegion?: boolean
|
|
13
|
+
ariaRegion?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -23,7 +23,7 @@ export default function DisclosureContent($props: DisclosureContentProps | undef
|
|
|
23
23
|
if (!context) {
|
|
24
24
|
throw new Error("DisclosureContent must be contained within a Disclosure");
|
|
25
25
|
}
|
|
26
|
-
let $state = context.state
|
|
26
|
+
let $state = context.state;
|
|
27
27
|
|
|
28
28
|
// Set the content ID so that it can be used with aria-controls in DisclosureTrigger
|
|
29
29
|
$state.contentId = $props?.id ?? defaultId;
|
|
@@ -36,7 +36,6 @@ export default function DisclosureContent($props: DisclosureContentProps | undef
|
|
|
36
36
|
role={$props?.ariaRegion ? "region" : undefined}
|
|
37
37
|
aria-labelledby={$state.headerId}
|
|
38
38
|
data-state={$state.expanded ? "open" : "closed"}
|
|
39
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
40
39
|
>
|
|
41
40
|
@if ($state.expanded) {
|
|
42
41
|
<slot />
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
2
|
+
import { type DisclosureContext, DisclosureContextName } from "./DisclosureTypes";
|
|
3
3
|
|
|
4
4
|
interface DisclosureHeaderProps {
|
|
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
|
|
11
|
-
/** The type of HTML header to use */
|
|
12
|
-
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
10
|
+
style?: StyleValue;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* The header for a Disclosure, which contains the DisclosureTrigger.
|
|
17
15
|
*
|
|
18
16
|
* The structure of a DisclosureHeader is:
|
|
19
|
-
*
|
|
17
|
+
*
|
|
20
18
|
* ```
|
|
21
19
|
* <DisclosureHeader>
|
|
22
20
|
* <DisclosureTrigger />
|
|
@@ -28,18 +26,16 @@ export default function DisclosureHeader($props: DisclosureHeaderProps | undefin
|
|
|
28
26
|
if (!context) {
|
|
29
27
|
throw new Error("DisclosureHeader must be contained within a Disclosure");
|
|
30
28
|
}
|
|
31
|
-
let $state = context.state
|
|
29
|
+
let $state = context.state;
|
|
32
30
|
|
|
33
31
|
@render {
|
|
34
|
-
|
|
35
|
-
<h4
|
|
32
|
+
<div
|
|
36
33
|
{$props?.id}
|
|
37
34
|
class={["torp-disclosure-header", $props?.class]}
|
|
38
35
|
{$props?.style}
|
|
39
36
|
data-state={$state.expanded ? "open" : "closed"}
|
|
40
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
41
37
|
>
|
|
42
38
|
<slot />
|
|
43
|
-
</
|
|
39
|
+
</div>
|
|
44
40
|
}
|
|
45
41
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import getId from "../utils/getId";
|
|
3
|
-
import {
|
|
3
|
+
import { type DisclosureContext, DisclosureContextName } from "./DisclosureTypes";
|
|
4
4
|
|
|
5
5
|
interface DisclosureTriggerProps {
|
|
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,12 +33,11 @@ export default function DisclosureTrigger($props: DisclosureTriggerProps | undef
|
|
|
33
33
|
id={$props?.id ?? defaultId}
|
|
34
34
|
class={["torp-disclosure-trigger", $props?.class]}
|
|
35
35
|
{$props?.style}
|
|
36
|
-
|
|
36
|
+
{$state.disabled}
|
|
37
37
|
aria-expanded={$state.expanded.toString()}
|
|
38
38
|
aria-disabled={$state.disabled}
|
|
39
39
|
aria-controls={$state.contentId}
|
|
40
40
|
data-state={$state.expanded ? "open" : "closed"}
|
|
41
|
-
data-disabled={$state.disabled}
|
|
42
41
|
onclick={() => $state.expanded = !$state.expanded}
|
|
43
42
|
>
|
|
44
43
|
<slot />
|
|
@@ -5,15 +5,15 @@ interface DisclosureProps {
|
|
|
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 disclosure is expanded and its content visible */
|
|
12
|
-
expanded?: boolean
|
|
12
|
+
expanded?: boolean;
|
|
13
13
|
/** If set to true, the user cannot interact with this disclosure */
|
|
14
|
-
disabled?: boolean
|
|
14
|
+
disabled?: boolean;
|
|
15
15
|
/** Raised when the disclosure is opened or closed */
|
|
16
|
-
|
|
16
|
+
onchange?: (open: boolean) => void;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -46,11 +46,11 @@ interface DisclosureContentProps {
|
|
|
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 this content should act as a region. Set this when the content contains heading elements or a nested Disclosure */
|
|
53
|
-
ariaRegion?: boolean
|
|
53
|
+
ariaRegion?: boolean;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -70,18 +70,16 @@ interface DisclosureHeaderProps {
|
|
|
70
70
|
/** An ID for the root element */
|
|
71
71
|
id?: string;
|
|
72
72
|
/** Classes for the root element */
|
|
73
|
-
class?: ClassValue
|
|
73
|
+
class?: ClassValue;
|
|
74
74
|
/** Styles for the root element */
|
|
75
|
-
style?: StyleValue
|
|
76
|
-
/** The type of HTML header to use */
|
|
77
|
-
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
75
|
+
style?: StyleValue;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
79
|
* The header for a Disclosure, which contains the DisclosureTrigger.
|
|
82
80
|
*
|
|
83
81
|
* The structure of a DisclosureHeader is:
|
|
84
|
-
*
|
|
82
|
+
*
|
|
85
83
|
* ```
|
|
86
84
|
* <DisclosureHeader>
|
|
87
85
|
* <DisclosureTrigger />
|
|
@@ -102,9 +100,9 @@ interface DisclosureTriggerProps {
|
|
|
102
100
|
/** An ID for the root element */
|
|
103
101
|
id?: string;
|
|
104
102
|
/** Classes for the root element */
|
|
105
|
-
class?: ClassValue
|
|
103
|
+
class?: ClassValue;
|
|
106
104
|
/** Styles for the root element */
|
|
107
|
-
style?: StyleValue
|
|
105
|
+
style?: StyleValue;
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
/**
|
|
@@ -118,4 +116,4 @@ declare function DisclosureTrigger(
|
|
|
118
116
|
$slots?: Record<string, SlotRender>,
|
|
119
117
|
): void;
|
|
120
118
|
|
|
121
|
-
export { Disclosure, DisclosureContent, DisclosureHeader, DisclosureTrigger };
|
|
119
|
+
export { Disclosure, DisclosureContent, DisclosureHeader, DisclosureTrigger };
|
package/dist/Disclosure/index.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// src/Disclosure/DisclosureHeader.torp
|
|
8
|
-
import DisclosureHeader_default from "./DisclosureHeader.torp";
|
|
9
|
-
|
|
10
|
-
// src/Disclosure/DisclosureTrigger.torp
|
|
11
|
-
import DisclosureTrigger_default from "./DisclosureTrigger.torp";
|
|
12
|
-
export {
|
|
13
|
-
Disclosure_default as Disclosure,
|
|
14
|
-
DisclosureContent_default as DisclosureContent,
|
|
15
|
-
DisclosureHeader_default as DisclosureHeader,
|
|
16
|
-
DisclosureTrigger_default as DisclosureTrigger
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import Disclosure from "./Disclosure.torp";
|
|
2
|
+
import DisclosureContent from "./DisclosureContent.torp";
|
|
3
|
+
import DisclosureHeader from "./DisclosureHeader.torp";
|
|
4
|
+
import DisclosureTrigger from "./DisclosureTrigger.torp";
|
|
5
|
+
export { Disclosure, DisclosureContent, DisclosureHeader, DisclosureTrigger };
|
package/dist/Drawer/Drawer.torp
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
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 DrawerContext, DrawerContextName, type DrawerState } from "./DrawerTypes";
|
|
3
4
|
|
|
4
5
|
interface DrawerProps {
|
|
5
6
|
/** An ID for the root element */
|
|
6
7
|
id?: string;
|
|
7
8
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
9
|
+
class?: ClassValue;
|
|
9
10
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
11
|
+
style?: StyleValue;
|
|
11
12
|
/** Whether the drawer is modal. If true, an overlay should be supplied to obscure outside content, and only the drawer content will be visible to screen readers */
|
|
12
|
-
modal?: boolean
|
|
13
|
+
modal?: boolean;
|
|
13
14
|
/** Whether the drawer is visible */
|
|
14
|
-
visible
|
|
15
|
+
visible: Bindable<boolean | undefined>;
|
|
15
16
|
/** Which side of the window to show the drawer from */
|
|
16
|
-
position?: "left" | "right" | "top" | "bottom"
|
|
17
|
-
/** A function to be called when the user selects a response */
|
|
18
|
-
callback?: ((value: any) => void),
|
|
19
|
-
/** Raised when the drawer is opened or closed */
|
|
20
|
-
ontoggle?: (open: boolean) => void,
|
|
17
|
+
position?: "left" | "right" | "top" | "bottom";
|
|
21
18
|
/** Raised when the drawer has opened */
|
|
22
|
-
onopen?: () => void
|
|
19
|
+
onopen?: () => void;
|
|
23
20
|
/** Raised when the drawer has closed */
|
|
24
|
-
onclose?: (result: any) => void
|
|
21
|
+
onclose?: (result: any) => void;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* A drawer that can be used to show rich content or obtain information from a user.
|
|
29
26
|
*
|
|
30
|
-
* See [the WAI ARIA guidelines for Dialogs](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
|
|
31
|
-
*
|
|
32
27
|
* The structure of a Drawer is:
|
|
33
28
|
*
|
|
34
29
|
* ```
|
|
@@ -45,15 +40,7 @@ export default function Drawer($props: DrawerProps | undefined) {
|
|
|
45
40
|
position: $props?.position ?? "left",
|
|
46
41
|
});
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
$run(() => {
|
|
50
|
-
$state.visible = $props?.visible ?? false;
|
|
51
|
-
});
|
|
52
|
-
$run(() => {
|
|
53
|
-
if ($props !== undefined) {
|
|
54
|
-
$props.visible = $state.visible;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
43
|
+
$bind($state, $props, "visible");
|
|
57
44
|
|
|
58
45
|
let result: any;
|
|
59
46
|
|
|
@@ -65,22 +52,14 @@ export default function Drawer($props: DrawerProps | undefined) {
|
|
|
65
52
|
};
|
|
66
53
|
$context[DrawerContextName] = context;
|
|
67
54
|
|
|
68
|
-
// Dispatch the
|
|
69
|
-
|
|
70
|
-
$run(() => {
|
|
71
|
-
const ontoggle = $props?.ontoggle;
|
|
72
|
-
const onopen = $props?.onopen;
|
|
73
|
-
const onclose = $props?.onclose;
|
|
55
|
+
// Dispatch the open/close events when the drawer is opened or closed
|
|
56
|
+
$handle((first) => {
|
|
74
57
|
const visible = $state.visible;
|
|
75
|
-
if (
|
|
76
|
-
|
|
58
|
+
if (first) return;
|
|
59
|
+
if (visible) {
|
|
60
|
+
$props?.onopen?.();
|
|
77
61
|
} else {
|
|
78
|
-
|
|
79
|
-
if (visible) {
|
|
80
|
-
if (onopen) onopen()
|
|
81
|
-
} else {
|
|
82
|
-
if (onclose) onclose(result);
|
|
83
|
-
}
|
|
62
|
+
$props?.onclose?.(result);
|
|
84
63
|
}
|
|
85
64
|
});
|
|
86
65
|
|
|
@@ -88,11 +67,11 @@ export default function Drawer($props: DrawerProps | undefined) {
|
|
|
88
67
|
// Get the button's result
|
|
89
68
|
switch (type) {
|
|
90
69
|
case "confirm": {
|
|
91
|
-
result = value
|
|
70
|
+
result = value ?? true;
|
|
92
71
|
break;
|
|
93
72
|
}
|
|
94
73
|
case "cancel": {
|
|
95
|
-
result = value
|
|
74
|
+
result = value ?? false;
|
|
96
75
|
break;
|
|
97
76
|
}
|
|
98
77
|
default: {
|
|
@@ -103,11 +82,6 @@ export default function Drawer($props: DrawerProps | undefined) {
|
|
|
103
82
|
|
|
104
83
|
// Hide the drawer
|
|
105
84
|
$state.visible = false;
|
|
106
|
-
|
|
107
|
-
// Call the callback
|
|
108
|
-
if ($props?.callback) {
|
|
109
|
-
$props?.callback(result);
|
|
110
|
-
}
|
|
111
85
|
}
|
|
112
86
|
|
|
113
87
|
function handleClickOutside(e: MouseEvent) {
|
|
@@ -116,12 +90,8 @@ export default function Drawer($props: DrawerProps | undefined) {
|
|
|
116
90
|
}
|
|
117
91
|
|
|
118
92
|
@render {
|
|
119
|
-
<div
|
|
120
|
-
{$props?.id}
|
|
121
|
-
class={["torp-drawer", $props?.class]}
|
|
122
|
-
{$props?.style}
|
|
123
|
-
>
|
|
93
|
+
<div {$props?.id} class={["torp-drawer", $props?.class]} {$props?.style}>
|
|
124
94
|
<slot />
|
|
125
95
|
</div>
|
|
126
96
|
}
|
|
127
|
-
}
|
|
97
|
+
}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { slide } from "../motion";
|
|
3
2
|
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
4
|
-
import
|
|
3
|
+
import getId from "../utils/getId";
|
|
4
|
+
import { type DrawerContext, DrawerContextName } from "./DrawerTypes";
|
|
5
|
+
|
|
6
|
+
const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
5
7
|
|
|
6
8
|
interface DrawerContentProps {
|
|
7
9
|
/** An ID for the root element */
|
|
8
10
|
id?: string;
|
|
9
11
|
/** Classes for the root element */
|
|
10
|
-
class?: ClassValue
|
|
12
|
+
class?: ClassValue;
|
|
11
13
|
/** Styles for the root element */
|
|
12
|
-
style?: StyleValue
|
|
14
|
+
style?: StyleValue;
|
|
15
|
+
/** An ARIA label for describing the drawer to screen readers */
|
|
16
|
+
ariaLabel?: string;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* The content that is displayed for a Drawer when it is open.
|
|
17
21
|
*/
|
|
18
22
|
export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
23
|
+
const defaultId = getId();
|
|
24
|
+
|
|
19
25
|
let drawer: HTMLElement;
|
|
20
26
|
let shown = false;
|
|
21
27
|
let closeOnClick = false;
|
|
@@ -27,6 +33,8 @@ export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
|
27
33
|
}
|
|
28
34
|
let $state = context.state;
|
|
29
35
|
|
|
36
|
+
$state.contentId = $props?.id ?? defaultId;
|
|
37
|
+
|
|
30
38
|
$run(() => {
|
|
31
39
|
if (!$state.visible) {
|
|
32
40
|
hide();
|
|
@@ -36,11 +44,20 @@ export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
|
36
44
|
function show() {
|
|
37
45
|
shown = true;
|
|
38
46
|
|
|
47
|
+
// Focus the first focusable element in the drawer for accessibility
|
|
48
|
+
if (drawer) {
|
|
49
|
+
const firstFocusable = drawer.querySelector<HTMLElement>(FOCUSABLE_SELECTOR);
|
|
50
|
+
if (firstFocusable) {
|
|
51
|
+
firstFocusable.focus();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
// HACK: Because this Drawer could be shown with a click, we need to wait for another mousedown
|
|
40
56
|
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
41
57
|
closeOnClick = false;
|
|
42
58
|
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
43
59
|
addDocumentEvent("click", handleDocumentClick);
|
|
60
|
+
addDocumentEvent("keydown", handleDocumentKeyDown);
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
function hide() {
|
|
@@ -48,6 +65,10 @@ export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
|
48
65
|
|
|
49
66
|
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
50
67
|
removeDocumentEvent("click", handleDocumentClick);
|
|
68
|
+
removeDocumentEvent("keydown", handleDocumentKeyDown);
|
|
69
|
+
if (context.focusTrigger) {
|
|
70
|
+
context.focusTrigger();
|
|
71
|
+
}
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
function handleDocumentMouseDown() {
|
|
@@ -55,26 +76,59 @@ export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
|
55
76
|
}
|
|
56
77
|
|
|
57
78
|
function handleDocumentClick(e: MouseEvent) {
|
|
58
|
-
if (
|
|
59
|
-
closeOnClick &&
|
|
60
|
-
drawer &&
|
|
61
|
-
!drawer.contains(e.target as HTMLElement)
|
|
62
|
-
) {
|
|
79
|
+
if (closeOnClick && drawer && !drawer.contains(e.target as HTMLElement)) {
|
|
63
80
|
e.preventDefault();
|
|
64
81
|
context.handleClickOutside!(e);
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
|
|
85
|
+
function trapFocus(e: KeyboardEvent) {
|
|
86
|
+
if (e.key !== "Tab") return;
|
|
87
|
+
|
|
88
|
+
if (!drawer) return;
|
|
89
|
+
|
|
90
|
+
const focusableElements = drawer.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR);
|
|
91
|
+
if (focusableElements.length === 0) {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const firstElement = focusableElements[0];
|
|
97
|
+
const lastElement = focusableElements[focusableElements.length - 1];
|
|
98
|
+
|
|
99
|
+
if (e.shiftKey) {
|
|
100
|
+
if (document.activeElement === firstElement) {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
lastElement.focus();
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
if (document.activeElement === lastElement) {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
firstElement.focus();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function handleDocumentKeyDown(e: KeyboardEvent) {
|
|
113
|
+
if (e.key === "Escape") {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
$state.visible = false;
|
|
116
|
+
}
|
|
117
|
+
trapFocus(e);
|
|
118
|
+
}
|
|
119
|
+
|
|
68
120
|
@render {
|
|
69
121
|
@if ($state.visible) {
|
|
70
122
|
<div
|
|
71
|
-
{$props?.id}
|
|
123
|
+
id={$props?.id ?? defaultId}
|
|
72
124
|
class={["torp-drawer-content", $props?.class]}
|
|
73
125
|
{$props?.style}
|
|
74
|
-
style="position: fixed;"
|
|
75
|
-
transition={(e) => slide(e, { side: $state.position })}
|
|
76
126
|
&ref={drawer}
|
|
77
|
-
|
|
127
|
+
role="dialog"
|
|
128
|
+
aria-modal={$state.modal}
|
|
129
|
+
aria-label={$props?.ariaLabel}
|
|
130
|
+
aria-labelledby={$props?.ariaLabel ? undefined : $state.triggerId}
|
|
131
|
+
onmount={(_el) => show()}
|
|
78
132
|
>
|
|
79
133
|
<slot />
|
|
80
134
|
</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 DrawerContext, DrawerContextName } from "./DrawerTypes";
|
|
4
4
|
|
|
5
5
|
interface DrawerOverlayProps {
|
|
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 DrawerOverlay($props: DrawerOverlayProps | undefined) {
|
|
|
33
33
|
class={["torp-drawer-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,19 +1,22 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
2
|
+
import getId from "../utils/getId";
|
|
3
|
+
import { type DrawerContext, DrawerContextName } from "./DrawerTypes";
|
|
3
4
|
|
|
4
5
|
interface DrawerTriggerProps {
|
|
5
6
|
/** An ID for the root element */
|
|
6
7
|
id?: string;
|
|
7
8
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
9
|
+
class?: ClassValue;
|
|
9
10
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
11
|
+
style?: StyleValue;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* The button that causes a Drawer to appear or disappear.
|
|
15
16
|
*/
|
|
16
17
|
export default function DrawerTrigger($props: DrawerTriggerProps | undefined) {
|
|
18
|
+
const defaultId = getId();
|
|
19
|
+
|
|
17
20
|
// Get stuff out of the DrawerContext
|
|
18
21
|
const context = $context[DrawerContextName] as DrawerContext;
|
|
19
22
|
if (!context) {
|
|
@@ -21,6 +24,11 @@ export default function DrawerTrigger($props: DrawerTriggerProps | undefined) {
|
|
|
21
24
|
}
|
|
22
25
|
let $state = context.state;
|
|
23
26
|
|
|
27
|
+
let button: HTMLButtonElement;
|
|
28
|
+
|
|
29
|
+
$state.triggerId = $props?.id ?? defaultId;
|
|
30
|
+
context.focusTrigger = () => button.focus();
|
|
31
|
+
|
|
24
32
|
function handleClick() {
|
|
25
33
|
$state.visible = !$state.visible;
|
|
26
34
|
}
|
|
@@ -28,10 +36,14 @@ export default function DrawerTrigger($props: DrawerTriggerProps | undefined) {
|
|
|
28
36
|
@render {
|
|
29
37
|
<button
|
|
30
38
|
type="button"
|
|
31
|
-
{$props?.id}
|
|
39
|
+
id={$props?.id ?? defaultId}
|
|
32
40
|
class={["torp-drawer-trigger", $props?.class]}
|
|
33
41
|
{$props?.style}
|
|
34
42
|
onclick={handleClick}
|
|
43
|
+
aria-expanded={$state.visible ? "true" : "false"}
|
|
44
|
+
aria-haspopup="dialog"
|
|
45
|
+
aria-controls={$state.contentId}
|
|
46
|
+
&ref={button}
|
|
35
47
|
>
|
|
36
48
|
<slot />
|
|
37
49
|
</button>
|