@torpor/ui 0.4.0 → 1.0.1
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 +42 -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 +1 -1
- 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 +24 -3
- 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 +55 -144
- 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 +85 -0
- package/dist/Charts/ChartYAxis.torp +107 -0
- package/dist/Charts/ColumnChart.torp +70 -0
- package/dist/Charts/GridLines.torp +4 -4
- package/dist/Charts/LineChart.torp +55 -178
- package/dist/Charts/PieChart.torp +14 -20
- package/dist/Charts/ScatterChart.torp +45 -38
- package/dist/Charts/SparkLine.torp +16 -19
- package/dist/Charts/XAxis.torp +14 -11
- package/dist/Charts/YAxis.torp +10 -8
- package/dist/Charts/index.d.ts +328 -79
- package/dist/Charts/index.js +17 -34
- 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 +120 -0
- package/dist/ComboBox/ComboBoxInput.torp +161 -0
- package/dist/ComboBox/ComboBoxTrigger.torp +49 -0
- package/dist/ComboBox/ComboBoxTypes.ts +39 -0
- package/dist/ComboBox/index.d.ts +154 -0
- package/dist/ComboBox/index.js +6 -0
- package/dist/CommandPalette/CommandPalette.torp +223 -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 +32 -50
- 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 +4 -17
- 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 +315 -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 +24 -17
- package/dist/Dialog/DialogBody.torp +5 -9
- package/dist/Dialog/DialogButton.torp +12 -12
- package/dist/Dialog/DialogFooter.torp +3 -7
- package/dist/Dialog/DialogHeader.torp +6 -10
- package/dist/Dialog/index.d.ts +27 -27
- 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/index.d.ts +14 -16
- package/dist/Disclosure/index.js +5 -18
- package/dist/Drawer/Drawer.torp +19 -49
- package/dist/Drawer/DrawerContent.torp +70 -13
- package/dist/Drawer/DrawerOverlay.torp +4 -4
- package/dist/Drawer/DrawerTrigger.torp +16 -4
- package/dist/Drawer/DrawerTypes.ts +3 -0
- 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 +27 -18
- 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 +5 -4
- 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 +178 -79
- package/dist/Form/index.js +16 -50
- package/dist/ListBox/ListBox.torp +253 -150
- package/dist/ListBox/ListBoxItem.torp +54 -30
- package/dist/ListBox/ListBoxSeparator.torp +5 -2
- package/dist/ListBox/ListBoxTypes.ts +23 -5
- package/dist/ListBox/LoadedListBoxItems.torp +41 -0
- package/dist/ListBox/index.d.ts +56 -17
- package/dist/ListBox/index.js +4 -14
- 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 +86 -71
- 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 +9 -19
- 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 +33 -51
- package/dist/MenuBar/MenuBarItemContent.torp +15 -101
- package/dist/MenuBar/MenuBarItemTrigger.torp +20 -55
- package/dist/MenuBar/MenuBarTypes.ts +11 -10
- package/dist/MenuBar/index.d.ts +17 -19
- package/dist/MenuBar/index.js +5 -18
- package/dist/Modal/Modal.torp +22 -47
- 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 +5 -16
- 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 -111
- package/dist/NavMenu/NavMenuButton.torp +7 -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 +15 -60
- package/dist/NavMenu/NavMenuPopoutContent.torp +14 -73
- package/dist/NavMenu/NavMenuPopoutTrigger.torp +17 -99
- package/dist/NavMenu/NavMenuSeparator.torp +3 -7
- package/dist/NavMenu/NavMenuTypes.ts +4 -14
- package/dist/NavMenu/index.d.ts +40 -44
- 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 +41 -34
- package/dist/Pagination/PaginationItem.torp +50 -13
- package/dist/Pagination/PaginationTypes.ts +3 -6
- package/dist/Pagination/buildPages.ts +9 -5
- package/dist/Pagination/index.d.ts +19 -9
- package/dist/Pagination/index.js +3 -40
- package/dist/Popover/Popover.torp +32 -50
- 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 +4 -17
- 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 +107 -53
- package/dist/SelectBox/SelectBoxContent.torp +49 -19
- package/dist/SelectBox/SelectBoxTrigger.torp +108 -8
- package/dist/SelectBox/SelectBoxTypes.ts +26 -11
- package/dist/SelectBox/index.d.ts +39 -54
- package/dist/SelectBox/index.js +5 -18
- package/dist/Slider/Slider.torp +245 -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 +1 -1
- 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 +29 -110
- package/dist/ToolBar/ToolBarButton.torp +7 -8
- package/dist/ToolBar/ToolBarElement.torp +7 -11
- package/dist/ToolBar/ToolBarPopout.torp +16 -68
- package/dist/ToolBar/ToolBarPopoutContent.torp +15 -73
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +19 -110
- package/dist/ToolBar/ToolBarSeparator.torp +3 -7
- package/dist/ToolBar/ToolBarTypes.ts +7 -14
- package/dist/ToolBar/index.d.ts +30 -32
- package/dist/ToolBar/index.js +8 -30
- 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 +70 -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 +59 -12
- 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/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 +97 -22
- 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/Charts/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/ListBox/index.js.map +0 -1
- package/dist/Menu/index.js.map +0 -1
- package/dist/MenuBar/index.js.map +0 -1
- package/dist/NavMenu/index.js.map +0 -1
- package/dist/Pagination/index.js.map +0 -1
- package/dist/SelectBox/SelectBoxInput.torp +0 -95
- package/dist/SelectBox/index.js.map +0 -1
- package/dist/TabGroup/index.js.map +0 -1
- package/dist/ToolBar/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/Pagination/index.js
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
// src/Pagination/PaginationItem.torp
|
|
5
|
-
import PaginationItem_default from "./PaginationItem.torp";
|
|
6
|
-
|
|
7
|
-
// src/Pagination/buildPages.ts
|
|
8
|
-
function buildPages(count, number, pageSize = 1, maxPages = 9) {
|
|
9
|
-
const pageCount = Math.ceil(count / pageSize);
|
|
10
|
-
if (pageCount <= maxPages) {
|
|
11
|
-
return Array.from({ length: pageCount }).fill(0).map((_, i) => i + 1);
|
|
12
|
-
} else {
|
|
13
|
-
let start = number - Math.floor((maxPages - 1) / 2);
|
|
14
|
-
let end = number + Math.ceil((maxPages - 1) / 2);
|
|
15
|
-
if (start < 1) {
|
|
16
|
-
end += Math.abs(start) + 1;
|
|
17
|
-
start = 1;
|
|
18
|
-
} else if (end > pageCount) {
|
|
19
|
-
start -= end - pageCount;
|
|
20
|
-
end = pageCount;
|
|
21
|
-
}
|
|
22
|
-
const numbers = Array.from({ length: end - start + 1 }).fill(0).map((_, i) => start + i);
|
|
23
|
-
if (numbers[0] !== 1) {
|
|
24
|
-
numbers[0] = 1;
|
|
25
|
-
numbers[1] = "startgap";
|
|
26
|
-
}
|
|
27
|
-
const l = numbers.length;
|
|
28
|
-
if (numbers[l - 1] !== pageCount) {
|
|
29
|
-
numbers[l - 1] = pageCount;
|
|
30
|
-
numbers[l - 2] = "endgap";
|
|
31
|
-
}
|
|
32
|
-
return numbers;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
Pagination_default as Pagination,
|
|
37
|
-
PaginationItem_default as PaginationItem,
|
|
38
|
-
buildPages
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import Pagination from "./Pagination.torp";
|
|
2
|
+
import PaginationItem from "./PaginationItem.torp";
|
|
3
|
+
export { Pagination, PaginationItem };
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
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 {
|
|
5
|
+
type Point,
|
|
6
|
+
type PopoverContext,
|
|
7
|
+
PopoverContextName,
|
|
8
|
+
type PopoverState,
|
|
9
|
+
} from "./PopoverTypes";
|
|
4
10
|
|
|
5
11
|
interface PopoverProps {
|
|
6
12
|
/** An ID for the root element */
|
|
7
13
|
id?: string;
|
|
8
14
|
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue
|
|
15
|
+
class?: ClassValue;
|
|
10
16
|
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue
|
|
17
|
+
style?: StyleValue;
|
|
12
18
|
/** Whether the popover is modal. If true, an overlay should be supplied to obscure outside content, and only the popover content will be visible to screen readers */
|
|
13
|
-
modal?: boolean
|
|
19
|
+
modal?: boolean;
|
|
14
20
|
/** Whether the popover is visible */
|
|
15
|
-
visible
|
|
21
|
+
visible: Bindable<boolean | undefined>;
|
|
16
22
|
/** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
|
|
17
|
-
anchor?: HTMLElement
|
|
23
|
+
anchor?: HTMLElement;
|
|
18
24
|
/** The position to display this popover at if it's contextual, as an alternative to supplying a PopoverTriggerContextual */
|
|
19
|
-
position?: Point
|
|
20
|
-
/** A function to be called when the user selects a response */
|
|
21
|
-
callback?: ((value: any) => void),
|
|
22
|
-
/** Raised when the popover is opened or closed */
|
|
23
|
-
ontoggle?: (open: boolean) => void,
|
|
25
|
+
position?: Point;
|
|
24
26
|
/** Raised when the popover has opened */
|
|
25
|
-
onopen?: () => void
|
|
27
|
+
onopen?: () => void;
|
|
26
28
|
/** Raised when the popover has closed */
|
|
27
|
-
onclose?: (result: any) => void
|
|
29
|
+
onclose?: (result: any) => void;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -42,19 +44,16 @@ interface PopoverProps {
|
|
|
42
44
|
export default function Popover($props: PopoverProps | undefined) {
|
|
43
45
|
let $state: PopoverState = $watch({
|
|
44
46
|
visible: false,
|
|
45
|
-
position: { x: 0, y: 0 }
|
|
46
|
-
|
|
47
|
+
position: { x: 0, y: 0 },
|
|
48
|
+
contentId: undefined,
|
|
49
|
+
triggerId: undefined,
|
|
50
|
+
contentRole: undefined,
|
|
51
|
+
});
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
$bind($state, $props, "visible");
|
|
49
54
|
$run(() => {
|
|
50
|
-
$state.visible = $props?.visible ?? false;
|
|
51
55
|
$state.position = $props?.position ?? { x: 0, y: 0 };
|
|
52
56
|
});
|
|
53
|
-
$run(() => {
|
|
54
|
-
if ($props !== undefined) {
|
|
55
|
-
$props.visible = $state.visible;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
57
|
|
|
59
58
|
let result: any;
|
|
60
59
|
|
|
@@ -72,22 +71,14 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
72
71
|
let popoutContext: PopoutContext = context;
|
|
73
72
|
$context[PopoutContextName] = popoutContext;
|
|
74
73
|
|
|
75
|
-
// Dispatch the
|
|
76
|
-
|
|
77
|
-
$run(() => {
|
|
78
|
-
const ontoggle = $props?.ontoggle;
|
|
79
|
-
const onopen = $props?.onopen;
|
|
80
|
-
const onclose = $props?.onclose;
|
|
74
|
+
// Dispatch the open/close events when the popover is opened or closed
|
|
75
|
+
$handle((first) => {
|
|
81
76
|
const visible = $state.visible;
|
|
82
|
-
if (
|
|
83
|
-
|
|
77
|
+
if (first) return;
|
|
78
|
+
if (visible) {
|
|
79
|
+
$props?.onopen?.();
|
|
84
80
|
} else {
|
|
85
|
-
|
|
86
|
-
if (visible) {
|
|
87
|
-
if (onopen) onopen()
|
|
88
|
-
} else {
|
|
89
|
-
if (onclose) onclose(result);
|
|
90
|
-
}
|
|
81
|
+
$props?.onclose?.(result);
|
|
91
82
|
}
|
|
92
83
|
});
|
|
93
84
|
|
|
@@ -110,25 +101,16 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
110
101
|
|
|
111
102
|
// Hide the popover
|
|
112
103
|
$state.visible = false;
|
|
113
|
-
|
|
114
|
-
// Call the callback
|
|
115
|
-
if ($props?.callback) {
|
|
116
|
-
$props?.callback(result);
|
|
117
|
-
}
|
|
118
104
|
}
|
|
119
105
|
|
|
120
|
-
function handleClickOutside(e: MouseEvent) {
|
|
106
|
+
function handleClickOutside(e: MouseEvent | KeyboardEvent) {
|
|
121
107
|
e.preventDefault();
|
|
122
108
|
$state.visible = false;
|
|
123
109
|
}
|
|
124
110
|
|
|
125
111
|
@render {
|
|
126
|
-
<div
|
|
127
|
-
{$props?.id}
|
|
128
|
-
class={["torp-popover", $props?.class]}
|
|
129
|
-
{$props?.style}
|
|
130
|
-
>
|
|
112
|
+
<div {$props?.id} class={["torp-popover", $props?.class]} {$props?.style}>
|
|
131
113
|
<slot />
|
|
132
114
|
</div>
|
|
133
115
|
}
|
|
134
|
-
}
|
|
116
|
+
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
2
|
+
import getId from "../utils/getId";
|
|
3
|
+
import { createPopoutContent } from "../utils/popoutContent";
|
|
4
|
+
import { type PopoverContext, PopoverContextName } from "./PopoverTypes";
|
|
6
5
|
|
|
7
6
|
interface PopoverContentProps {
|
|
8
7
|
/** An ID for the root element */
|
|
9
8
|
id?: string;
|
|
10
9
|
/** Classes for the root element */
|
|
11
|
-
class?: ClassValue
|
|
10
|
+
class?: ClassValue;
|
|
12
11
|
/** Styles for the root element */
|
|
13
|
-
style?: StyleValue
|
|
12
|
+
style?: StyleValue;
|
|
14
13
|
/** Where the popover will be shown, relative to the popover trigger */
|
|
15
|
-
side?: "top" | "right" | "bottom" | "left"
|
|
14
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
16
15
|
/** How the popover will be aligned, relative to the popover trigger */
|
|
17
|
-
alignment?: "start" | "center" | "end"
|
|
16
|
+
alignment?: "start" | "center" | "end";
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -22,9 +21,7 @@ interface PopoverContentProps {
|
|
|
22
21
|
* alongside an element.
|
|
23
22
|
*/
|
|
24
23
|
export default function PopoverContent($props?: PopoverContentProps | undefined) {
|
|
25
|
-
let
|
|
26
|
-
let shown = false;
|
|
27
|
-
let closeOnClick = false;
|
|
24
|
+
let defaultId = getId();
|
|
28
25
|
|
|
29
26
|
// Get stuff out of the PopoverContext
|
|
30
27
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
@@ -33,82 +30,36 @@ export default function PopoverContent($props?: PopoverContentProps | undefined)
|
|
|
33
30
|
}
|
|
34
31
|
let $state = context.state;
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
hide();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function show() {
|
|
43
|
-
shown = true;
|
|
44
|
-
|
|
45
|
-
// HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
|
|
46
|
-
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
47
|
-
closeOnClick = false;
|
|
48
|
-
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
49
|
-
addDocumentEvent("click", handleDocumentClick);
|
|
33
|
+
// Set the content ID so that the trigger can use it with aria-controls
|
|
34
|
+
$state.contentId = $props?.id ?? defaultId;
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function hide() {
|
|
63
|
-
if (!shown) return;
|
|
64
|
-
|
|
65
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
66
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
67
|
-
|
|
68
|
-
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
69
|
-
const anchorElement = context.anchorElement!
|
|
70
|
-
const scrollParent = getScrollParent(anchorElement)
|
|
71
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
72
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
73
|
-
if (anchorElement.focus) {
|
|
74
|
-
anchorElement.focus();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function handleDocumentMouseDown() {
|
|
79
|
-
closeOnClick = true;
|
|
80
|
-
}
|
|
36
|
+
const popout = createPopoutContent({
|
|
37
|
+
getAnchor: () => context.anchorElement,
|
|
38
|
+
getContent: () => div,
|
|
39
|
+
close: (e) => context.handleClickOutside?.(e),
|
|
40
|
+
side: $props?.side ?? "bottom",
|
|
41
|
+
alignment: $props?.alignment ?? "center",
|
|
42
|
+
ignoreAnchorClicks: true,
|
|
43
|
+
focusFirstElement: () => context.focusFirstElement?.(),
|
|
44
|
+
refocusAnchorOnHide: true,
|
|
45
|
+
});
|
|
81
46
|
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
closeOnClick &&
|
|
85
|
-
div &&
|
|
86
|
-
!div.contains(e.target as HTMLElement) &&
|
|
87
|
-
(!context.anchorElement || !context.anchorElement.contains(e.target as HTMLElement))
|
|
88
|
-
) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
context.handleClickOutside!(e);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
47
|
+
let div: HTMLDivElement;
|
|
93
48
|
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
49
|
+
$run(() => {
|
|
50
|
+
if (!$state.visible) {
|
|
51
|
+
popout.hide();
|
|
97
52
|
}
|
|
98
|
-
|
|
99
|
-
let side = $props?.side ?? "bottom";
|
|
100
|
-
let alignment = $props?.alignment ?? "center";
|
|
101
|
-
setPopoverPosition(context.anchorElement, div, side, alignment);
|
|
102
|
-
}
|
|
53
|
+
});
|
|
103
54
|
|
|
104
55
|
@render {
|
|
105
56
|
@if ($state.visible) {
|
|
106
57
|
<div
|
|
107
|
-
{$props?.id}
|
|
58
|
+
id={$props?.id ?? defaultId}
|
|
108
59
|
class={["torp-popover-content", $props?.class]}
|
|
109
60
|
{$props?.style}
|
|
110
61
|
&ref={div}
|
|
111
|
-
onmount={show}
|
|
62
|
+
onmount={(_el) => popout.show()}
|
|
112
63
|
>
|
|
113
64
|
<slot />
|
|
114
65
|
</div>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import { createHoverReveal } from "../utils/hoverReveal";
|
|
3
|
+
import getId from "../utils/getId";
|
|
4
|
+
import { type PopoverContext, PopoverContextName } from "./PopoverTypes";
|
|
5
|
+
|
|
6
|
+
interface PopoverHoverProps {
|
|
7
|
+
/** An ID for the root element */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Classes for the root element */
|
|
10
|
+
class?: ClassValue;
|
|
11
|
+
/** Styles for the root element */
|
|
12
|
+
style?: StyleValue;
|
|
13
|
+
/** Milliseconds to wait before opening (default 500; 0 opens immediately) */
|
|
14
|
+
hoverDelay?: number;
|
|
15
|
+
/** Milliseconds to wait after the pointer or focus leaves before closing (default 300) */
|
|
16
|
+
exitGrace?: number;
|
|
17
|
+
/** Whether hovering and focusing are ignored */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An element that shows a Popover while hovered, with proper hover
|
|
23
|
+
* semantics: an intent delay before opening (so passing over the element
|
|
24
|
+
* doesn't flash a popover), and an exit grace period after leaving (so
|
|
25
|
+
* moving into the popover content doesn't close it).
|
|
26
|
+
*
|
|
27
|
+
* Focusing the element opens it immediately; blurring closes it. Use this
|
|
28
|
+
* in place of PopoverTrigger:
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* <Popover>
|
|
32
|
+
* <PopoverHover>Anything can go here</PopoverHover>
|
|
33
|
+
* <PopoverContent />
|
|
34
|
+
* </Popover>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export default function PopoverHover($props?: PopoverHoverProps) {
|
|
38
|
+
let defaultId = getId();
|
|
39
|
+
|
|
40
|
+
// Get stuff out of the PopoverContext
|
|
41
|
+
const context = $context[PopoverContextName] as PopoverContext;
|
|
42
|
+
if (!context) {
|
|
43
|
+
throw new Error("PopoverHover must be contained within a Popover");
|
|
44
|
+
}
|
|
45
|
+
const $state = context.state;
|
|
46
|
+
|
|
47
|
+
// Set the trigger ID so that it can be used with aria-labelledby
|
|
48
|
+
$state.triggerId = $props?.id ?? defaultId;
|
|
49
|
+
|
|
50
|
+
function setVisible(visible: boolean) {
|
|
51
|
+
$state.visible = visible;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const hover = createHoverReveal({
|
|
55
|
+
show: () => setVisible(true),
|
|
56
|
+
hide: () => setVisible(false),
|
|
57
|
+
isVisible: () => $state.visible,
|
|
58
|
+
disabled: () => $props?.disabled === true,
|
|
59
|
+
getContent: () => ($state.contentId ? document.getElementById($state.contentId) : undefined),
|
|
60
|
+
hoverDelay: $props?.hoverDelay,
|
|
61
|
+
exitGrace: $props?.exitGrace,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
$run(() => {
|
|
65
|
+
return () => hover.dispose();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function anchor(node: HTMLElement) {
|
|
69
|
+
context.anchorElement = node;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@render {
|
|
73
|
+
<div
|
|
74
|
+
id={$props?.id ?? defaultId}
|
|
75
|
+
class={["torp-popover-hover", $props?.class]}
|
|
76
|
+
{$props?.style}
|
|
77
|
+
tabindex="0"
|
|
78
|
+
aria-haspopup={$state.contentRole ?? "true"}
|
|
79
|
+
aria-expanded={$state.visible ? "true" : "false"}
|
|
80
|
+
aria-controls={$state.contentId}
|
|
81
|
+
onmouseenter={() => hover.handleEnter()}
|
|
82
|
+
onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
|
|
83
|
+
onfocus={() => hover.handleFocus()}
|
|
84
|
+
onblur={(e: FocusEvent) => hover.handleBlur(e)}
|
|
85
|
+
onmount={anchor}
|
|
86
|
+
>
|
|
87
|
+
<slot />
|
|
88
|
+
</div>
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,62 +1,39 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import PopoutClickTrigger from "../utils/PopoutClickTrigger.torp";
|
|
3
|
+
import { type PopoverContext, PopoverContextName } from "./PopoverTypes";
|
|
4
4
|
|
|
5
5
|
interface PopoverTriggerProps {
|
|
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 popover 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 causes a Popover to appear or disappear.
|
|
15
|
+
* The button that causes a Popover to appear or disappear when pressed.
|
|
16
|
+
*
|
|
17
|
+
* For hover activation, use PopoverHover instead -- hover surfaces need an
|
|
18
|
+
* intent delay and an exit grace period that a press button doesn't.
|
|
18
19
|
*/
|
|
19
|
-
export default function PopoverTrigger($props
|
|
20
|
-
let activation = $props?.activation ?? "press";
|
|
21
|
-
|
|
20
|
+
export default function PopoverTrigger($props?: PopoverTriggerProps) {
|
|
22
21
|
// Get stuff out of the PopoverContext
|
|
23
22
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
24
23
|
if (!context) {
|
|
25
24
|
throw new Error("PopoverTrigger must be contained within a Popover");
|
|
26
25
|
}
|
|
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(node: HTMLElement, e: MouseEvent) {
|
|
36
|
-
if (activation !== "hover") return;
|
|
37
|
-
|
|
38
|
-
if ($state.position) {
|
|
39
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
40
|
-
const rect = node.getBoundingClientRect();
|
|
41
|
-
const x = e.clientX - rect.left;
|
|
42
|
-
const y = e.clientY - rect.top;
|
|
43
|
-
$state.position = { x, y };
|
|
44
|
-
//$state.position = { x: window.scrollX + e.clientX, y: window.scrollY + e.clientY };
|
|
45
|
-
}
|
|
46
|
-
$state.visible = !$state.visible
|
|
47
|
-
}
|
|
48
26
|
|
|
49
27
|
@render {
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
{$props?.
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
&ref={context.anchorElement}
|
|
28
|
+
<PopoutClickTrigger
|
|
29
|
+
id={$props?.id}
|
|
30
|
+
class={$props?.class ?? "torp-popover-trigger"}
|
|
31
|
+
style={$props?.style}
|
|
32
|
+
context={context}
|
|
33
|
+
tag="button"
|
|
34
|
+
event="click"
|
|
58
35
|
>
|
|
59
36
|
<slot />
|
|
60
|
-
</
|
|
37
|
+
</PopoutClickTrigger>
|
|
61
38
|
}
|
|
62
39
|
}
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
+
import { type PopoutContext, type PopoutState } from "../utils/PopoutTypes";
|
|
2
|
+
|
|
1
3
|
export const PopoverContextName: unique symbol = Symbol.for("torp.Popover");
|
|
2
4
|
|
|
3
5
|
/** The shared context for popover components (Contextual, Prompt and Popover) */
|
|
4
|
-
export interface PopoverContext {
|
|
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 PopoverContext extends PopoutContext {
|
|
9
7
|
state: PopoverState;
|
|
10
|
-
//modal: boolean;
|
|
11
|
-
anchorElement?: HTMLElement;
|
|
12
|
-
// HACK: focusFirstElement is necessary because if we focus the first element e.g. in a Dialog's
|
|
13
|
-
// onMount, it will scroll the page to the focused element and mess up our careful positioning
|
|
14
|
-
// We need to be able to manually set the order to
|
|
15
|
-
// 1. set visible (so we have an element with content)
|
|
16
|
-
// 2. set position (so the element is in the right place)
|
|
17
|
-
// 3. set focus (for accessibility)
|
|
18
|
-
// There may be a more elegant way to accomplish this!
|
|
19
|
-
focusFirstElement?: () => void;
|
|
20
8
|
}
|
|
21
9
|
|
|
22
|
-
export interface PopoverState {
|
|
23
|
-
visible: boolean;
|
|
10
|
+
export interface PopoverState extends PopoutState {
|
|
24
11
|
position: Point;
|
|
25
12
|
}
|
|
26
13
|
|
package/dist/Popover/index.d.ts
CHANGED
|
@@ -5,25 +5,21 @@ interface PopoverProps {
|
|
|
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 popover is modal. If true, an overlay should be supplied to obscure outside content, and only the popover content will be visible to screen readers */
|
|
12
|
-
modal?: boolean
|
|
12
|
+
modal?: boolean;
|
|
13
13
|
/** Whether the popover is visible */
|
|
14
|
-
visible
|
|
14
|
+
visible: Bindable<boolean | undefined>;
|
|
15
15
|
/** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
|
|
16
|
-
anchor?: HTMLElement
|
|
16
|
+
anchor?: HTMLElement;
|
|
17
17
|
/** The position to display this popover at if it's contextual, as an alternative to supplying a PopoverTriggerContextual */
|
|
18
|
-
position?: Point
|
|
19
|
-
/** A function to be called when the user selects a response */
|
|
20
|
-
callback?: ((value: any) => void),
|
|
21
|
-
/** Raised when the popover is opened or closed */
|
|
22
|
-
ontoggle?: (open: boolean) => void,
|
|
18
|
+
position?: Point;
|
|
23
19
|
/** Raised when the popover has opened */
|
|
24
|
-
onopen?: () => void
|
|
20
|
+
onopen?: () => void;
|
|
25
21
|
/** Raised when the popover has closed */
|
|
26
|
-
onclose?: (result: any) => void
|
|
22
|
+
onclose?: (result: any) => void;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
/**
|
|
@@ -62,26 +58,45 @@ declare function PopoverContent(
|
|
|
62
58
|
|
|
63
59
|
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
/**
|
|
62
|
+
* An element that shows a Popover while hovered, with proper hover
|
|
63
|
+
* semantics: an intent delay before opening (so passing over the element
|
|
64
|
+
* doesn't flash a popover), and an exit grace period after leaving (so
|
|
65
|
+
* moving into the popover content doesn't close it).
|
|
66
|
+
*
|
|
67
|
+
* Focusing the element opens it immediately; blurring closes it. Use this
|
|
68
|
+
* in place of PopoverTrigger:
|
|
69
|
+
*
|
|
70
|
+
* ```
|
|
71
|
+
* <Popover>
|
|
72
|
+
* <PopoverHover>Anything can go here</PopoverHover>
|
|
73
|
+
* <PopoverContent />
|
|
74
|
+
* </Popover>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function PopoverHover(
|
|
78
|
+
$parent: ParentNode,
|
|
79
|
+
$anchor: Node | null,
|
|
80
|
+
$props?: PopoverHoverProps,
|
|
81
|
+
$context?: Record<PropertyKey, any>,
|
|
82
|
+
$slots?: Record<string, SlotRender>,
|
|
83
|
+
): void;
|
|
84
|
+
|
|
85
|
+
|
|
75
86
|
|
|
76
87
|
/**
|
|
77
|
-
* The button that causes a Popover to appear or disappear.
|
|
88
|
+
* The button that causes a Popover to appear or disappear when pressed.
|
|
89
|
+
*
|
|
90
|
+
* For hover activation, use PopoverHover instead -- hover surfaces need an
|
|
91
|
+
* intent delay and an exit grace period that a press button doesn't.
|
|
78
92
|
*/
|
|
79
93
|
declare function PopoverTrigger(
|
|
80
94
|
$parent: ParentNode,
|
|
81
95
|
$anchor: Node | null,
|
|
82
|
-
$props
|
|
96
|
+
$props?: PopoverTriggerProps,
|
|
83
97
|
$context?: Record<PropertyKey, any>,
|
|
84
98
|
$slots?: Record<string, SlotRender>,
|
|
85
99
|
): void;
|
|
86
100
|
|
|
87
|
-
export { Popover, PopoverContent, PopoverTrigger };
|
|
101
|
+
export { Popover, PopoverContent, PopoverHover, PopoverTrigger };
|
|
102
|
+
export { default as showPopover } from "./showPopover";
|
package/dist/Popover/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import Popover from "./Popover.torp";
|
|
2
|
+
import PopoverContent from "./PopoverContent.torp";
|
|
3
|
+
import PopoverHover from "./PopoverHover.torp";
|
|
4
|
+
import PopoverTrigger from "./PopoverTrigger.torp";
|
|
5
|
+
//#region src/Popover/showPopover.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shows a popover component in code.
|
|
8
|
+
* @param popover The popover component
|
|
9
|
+
* @param anchor The element to use as an anchor for the popover component
|
|
10
|
+
* @param props The properties for the popover component
|
|
11
|
+
* @param target The target element to show the popover in
|
|
12
|
+
* @returns The value selected by the user
|
|
13
|
+
*/
|
|
11
14
|
function showPopover(popover, anchor, props, target) {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const allProps = Object.assign({}, props, { anchor });
|
|
16
|
+
popover(target || anchor.parentElement || document.body, null, allProps);
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
PopoverTrigger_default as PopoverTrigger,
|
|
19
|
-
showPopover
|
|
20
|
-
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Popover, PopoverContent, PopoverHover, PopoverTrigger, showPopover };
|
|
20
|
+
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Popover/showPopover.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline popover\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code.\n * @param popover The popover component\n * @param anchor The element to use as an anchor for the popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopover(\n\tpopover: Component,\n\tanchor: HTMLElement,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Add the anchor element to the properties\n\tconst allProps = Object.assign({}, props, { anchor });\n\n\t// Create the popover\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tpopover(target || anchor.parentElement || document.body, null, allProps);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/Popover/showPopover.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline popover\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code.\n * @param popover The popover component\n * @param anchor The element to use as an anchor for the popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopover(\n\tpopover: Component,\n\tanchor: HTMLElement,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Add the anchor element to the properties\n\tconst allProps = Object.assign({}, props, { anchor });\n\n\t// Create the popover\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tpopover(target || anchor.parentElement || document.body, null, allProps);\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAwB,YACvB,SACA,QACA,OACA,QACO;CAEP,MAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC;CAIpD,QAAQ,UAAU,OAAO,iBAAiB,SAAS,MAAM,MAAM,QAAQ;AACxE"}
|