@torpor/ui 0.1.7 → 0.2.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/CHANGELOG.md +47 -0
- package/dist/Accordion/Accordion.torp +25 -13
- package/dist/Accordion/AccordionContent.torp +15 -8
- package/dist/Accordion/AccordionHeader.torp +16 -7
- package/dist/Accordion/AccordionItem.torp +24 -10
- package/dist/Accordion/AccordionTrigger.torp +16 -8
- package/dist/Accordion/AccordionTypes.ts +2 -0
- package/dist/Accordion/index.d.ts +157 -0
- package/dist/Breadcrumb/Breadcrumb.torp +42 -0
- package/dist/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/dist/Breadcrumb/index.d.ts +84 -0
- package/dist/Breadcrumb/index.js +14 -0
- package/dist/Calendar/Calendar.torp +273 -0
- package/dist/Calendar/CalendarDay.torp +75 -0
- package/dist/Calendar/CalendarTypes.ts +22 -0
- package/dist/Calendar/index.d.ts +36 -0
- package/dist/Calendar/index.js +10 -0
- package/dist/Calendar/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +16 -6
- package/dist/Dialog/DialogBody.torp +13 -5
- package/dist/Dialog/DialogButton.torp +18 -6
- package/dist/Dialog/DialogFooter.torp +13 -3
- package/dist/Dialog/DialogHeader.torp +13 -4
- package/dist/Dialog/index.d.ts +135 -0
- package/dist/Disclosure/Disclosure.torp +79 -0
- package/dist/Disclosure/DisclosureContent.torp +43 -0
- package/dist/Disclosure/DisclosureHeader.torp +43 -0
- package/dist/Disclosure/DisclosureTrigger.torp +44 -0
- package/dist/Disclosure/DisclosureTypes.ts +14 -0
- package/dist/Disclosure/index.d.ts +113 -0
- package/dist/Disclosure/index.js +18 -0
- package/dist/Disclosure/index.js.map +1 -0
- package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +20 -19
- package/dist/Drawer/index.d.ts +21 -0
- package/dist/Drawer/index.js +6 -0
- package/dist/Drawer/index.js.map +1 -0
- package/dist/Form/Field.torp +93 -0
- package/dist/Form/Form.torp +131 -0
- package/dist/Form/FormTypes.ts +30 -0
- package/dist/Form/Input.torp +94 -0
- package/dist/Form/Label.torp +31 -0
- package/dist/Form/Message.torp +35 -0
- package/dist/Form/StandardSchemaV1.ts +70 -0
- package/dist/Form/index.d.ts +117 -0
- package/dist/Form/index.js +22 -0
- package/dist/Form/index.js.map +1 -0
- package/dist/Menu/Menu.torp +169 -0
- package/dist/Menu/MenuButton.torp +64 -0
- package/dist/Menu/MenuCheck.torp +81 -0
- package/dist/Menu/MenuGroup.torp +29 -0
- package/dist/Menu/MenuIndicator.torp +38 -0
- package/dist/Menu/MenuPopout.torp +82 -0
- package/dist/Menu/MenuPopoutContent.torp +83 -0
- package/dist/Menu/MenuPopoutTrigger.torp +126 -0
- package/dist/Menu/MenuRadio.torp +99 -0
- package/dist/Menu/MenuRadioGroup.torp +97 -0
- package/dist/Menu/MenuSeparator.torp +24 -0
- package/dist/Menu/MenuTypes.ts +58 -0
- package/dist/Menu/index.d.ts +293 -0
- package/dist/Menu/index.js +46 -0
- package/dist/Menu/index.js.map +1 -0
- package/dist/MenuBar/MenuBar.torp +159 -0
- package/dist/MenuBar/MenuBarItem.torp +115 -0
- package/dist/MenuBar/MenuBarItemContent.torp +117 -0
- package/dist/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/dist/MenuBar/MenuBarTypes.ts +36 -0
- package/dist/MenuBar/index.d.ts +125 -0
- package/dist/MenuBar/index.js +18 -0
- package/dist/MenuBar/index.js.map +1 -0
- package/dist/NavMenu/NavMenu.torp +15 -6
- package/dist/NavMenu/NavMenuButton.torp +14 -7
- package/dist/NavMenu/NavMenuElement.torp +16 -8
- package/dist/NavMenu/NavMenuGroup.torp +14 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/dist/NavMenu/NavMenuLink.torp +18 -10
- package/dist/NavMenu/NavMenuPopout.torp +13 -5
- package/dist/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/dist/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/dist/NavMenu/NavMenuSeparator.torp +12 -3
- package/dist/NavMenu/index.d.ts +259 -0
- package/dist/Notification/Notification.torp +58 -0
- package/dist/Notification/NotificationClose.torp +37 -0
- package/dist/Notification/NotificationContainer.torp +24 -0
- package/dist/Notification/NotificationContent.torp +23 -0
- package/dist/Notification/NotificationTypes.ts +5 -0
- package/dist/Notification/index.d.ts +92 -0
- package/dist/Notification/index.js +36 -0
- package/dist/Notification/index.js.map +1 -0
- package/dist/Notification/showNotification.ts +30 -0
- package/dist/Popover/Popover.torp +22 -8
- package/dist/Popover/PopoverContent.torp +41 -29
- package/dist/Popover/PopoverContentAnchored.torp +52 -44
- package/dist/Popover/PopoverContentContextual.torp +49 -37
- package/dist/Popover/PopoverOverlay.torp +13 -4
- package/dist/Popover/PopoverTrigger.torp +12 -3
- package/dist/Popover/PopoverTriggerContextual.torp +12 -3
- package/dist/Popover/PopoverTriggerHover.torp +14 -5
- package/dist/Popover/index.d.ts +191 -0
- package/dist/TabGroup/TabContent.torp +13 -7
- package/dist/TabGroup/TabGroup.torp +23 -11
- package/dist/TabGroup/TabHeader.torp +16 -7
- package/dist/TabGroup/TabList.torp +15 -6
- package/dist/TabGroup/TabTrigger.torp +14 -6
- package/dist/TabGroup/index.d.ts +150 -0
- package/dist/icons/ArrowDown.torp +15 -0
- package/dist/icons/ArrowLeft.torp +15 -0
- package/dist/icons/ArrowRight.torp +15 -0
- package/dist/icons/ArrowUp.torp +15 -0
- package/dist/icons/Bars.torp +17 -0
- package/dist/icons/Check.torp +15 -0
- package/dist/icons/ChevronDown.torp +15 -0
- package/dist/icons/ChevronLeft.torp +15 -0
- package/dist/icons/ChevronRight.torp +15 -0
- package/dist/icons/ChevronUp.torp +15 -0
- package/dist/icons/Cross.torp +16 -0
- package/dist/icons/Loading.torp +16 -0
- package/dist/icons/Minus.torp +15 -0
- package/dist/icons/Plus.torp +16 -0
- package/dist/icons/index.d.ts +142 -0
- package/dist/icons/index.js +58 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/{motion.d.cts → index.d.ts} +2 -2
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +7 -0
- package/dist/motion/index.d.ts +2 -0
- package/dist/{motion.js → motion/index.js} +1 -1
- package/dist/motion/index.js.map +1 -0
- package/dist/mount/index.d.ts +2 -0
- package/dist/utils/dateUtils.ts +244 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/setPopoverPosition.ts +4 -0
- package/package.json +60 -35
- package/scripts/postbuild.ts +42 -5
- package/src/Accordion/Accordion.torp +25 -13
- package/src/Accordion/AccordionContent.torp +15 -8
- package/src/Accordion/AccordionHeader.torp +16 -7
- package/src/Accordion/AccordionItem.torp +24 -10
- package/src/Accordion/AccordionTrigger.torp +16 -8
- package/src/Accordion/AccordionTypes.ts +2 -0
- package/src/Breadcrumb/Breadcrumb.torp +42 -0
- package/src/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/src/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/src/Breadcrumb/index.ts +5 -0
- package/src/Calendar/Calendar.torp +273 -0
- package/src/Calendar/CalendarDay.torp +75 -0
- package/src/Calendar/CalendarTypes.ts +22 -0
- package/src/Calendar/index.ts +4 -0
- package/src/Dialog/Dialog.torp +16 -6
- package/src/Dialog/DialogBody.torp +13 -5
- package/src/Dialog/DialogButton.torp +18 -6
- package/src/Dialog/DialogFooter.torp +13 -3
- package/src/Dialog/DialogHeader.torp +13 -4
- package/src/Disclosure/Disclosure.torp +79 -0
- package/src/Disclosure/DisclosureContent.torp +43 -0
- package/src/Disclosure/DisclosureHeader.torp +43 -0
- package/src/Disclosure/DisclosureTrigger.torp +44 -0
- package/src/Disclosure/DisclosureTypes.ts +14 -0
- package/src/Disclosure/index.ts +6 -0
- package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +20 -19
- package/src/Drawer/index.ts +3 -0
- package/src/Form/Field.torp +93 -0
- package/src/Form/Form.torp +131 -0
- package/src/Form/FormTypes.ts +30 -0
- package/src/Form/Input.torp +94 -0
- package/src/Form/Label.torp +31 -0
- package/src/Form/Message.torp +35 -0
- package/src/Form/StandardSchemaV1.ts +70 -0
- package/src/Form/index.ts +7 -0
- package/src/Menu/Menu.torp +169 -0
- package/src/Menu/MenuButton.torp +64 -0
- package/src/Menu/MenuCheck.torp +81 -0
- package/src/Menu/MenuGroup.torp +29 -0
- package/src/Menu/MenuIndicator.torp +38 -0
- package/src/Menu/MenuPopout.torp +82 -0
- package/src/Menu/MenuPopoutContent.torp +83 -0
- package/src/Menu/MenuPopoutTrigger.torp +126 -0
- package/src/Menu/MenuRadio.torp +99 -0
- package/src/Menu/MenuRadioGroup.torp +97 -0
- package/src/Menu/MenuSeparator.torp +24 -0
- package/src/Menu/MenuTypes.ts +58 -0
- package/src/Menu/index.ts +25 -0
- package/src/MenuBar/MenuBar.torp +159 -0
- package/src/MenuBar/MenuBarItem.torp +115 -0
- package/src/MenuBar/MenuBarItemContent.torp +117 -0
- package/src/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/src/MenuBar/MenuBarTypes.ts +36 -0
- package/src/MenuBar/index.ts +6 -0
- package/src/NavMenu/NavMenu.torp +15 -6
- package/src/NavMenu/NavMenuButton.torp +14 -7
- package/src/NavMenu/NavMenuElement.torp +16 -8
- package/src/NavMenu/NavMenuGroup.torp +14 -5
- package/src/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/src/NavMenu/NavMenuLink.torp +18 -10
- package/src/NavMenu/NavMenuPopout.torp +13 -5
- package/src/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/src/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/src/NavMenu/NavMenuSeparator.torp +12 -3
- package/src/Notification/Notification.torp +58 -0
- package/src/Notification/NotificationClose.torp +37 -0
- package/src/Notification/NotificationContainer.torp +24 -0
- package/src/Notification/NotificationContent.torp +23 -0
- package/src/Notification/NotificationTypes.ts +5 -0
- package/src/Notification/index.ts +13 -0
- package/src/Notification/showNotification.ts +30 -0
- package/src/Popover/Popover.torp +22 -8
- package/src/Popover/PopoverContent.torp +41 -29
- package/src/Popover/PopoverContentAnchored.torp +52 -44
- package/src/Popover/PopoverContentContextual.torp +49 -37
- package/src/Popover/PopoverOverlay.torp +13 -4
- package/src/Popover/PopoverTrigger.torp +12 -3
- package/src/Popover/PopoverTriggerContextual.torp +12 -3
- package/src/Popover/PopoverTriggerHover.torp +14 -5
- package/src/Slider/Slider.torp +83 -0
- package/src/Slider/index.ts +3 -0
- package/src/TabGroup/TabContent.torp +13 -7
- package/src/TabGroup/TabGroup.torp +23 -11
- package/src/TabGroup/TabHeader.torp +16 -7
- package/src/TabGroup/TabList.torp +15 -6
- package/src/TabGroup/TabTrigger.torp +14 -6
- package/src/icons/ArrowDown.torp +15 -0
- package/src/icons/ArrowLeft.torp +15 -0
- package/src/icons/ArrowRight.torp +15 -0
- package/src/icons/ArrowUp.torp +15 -0
- package/src/icons/Bars.torp +17 -0
- package/src/icons/Check.torp +15 -0
- package/src/icons/ChevronDown.torp +15 -0
- package/src/icons/ChevronLeft.torp +15 -0
- package/src/icons/ChevronRight.torp +15 -0
- package/src/icons/ChevronUp.torp +15 -0
- package/src/icons/Cross.torp +16 -0
- package/src/icons/Loading.torp +16 -0
- package/src/icons/Minus.torp +15 -0
- package/src/icons/Plus.torp +16 -0
- package/src/icons/index.ts +31 -0
- package/src/motion/fade.ts +2 -2
- package/src/motion/index.ts +3 -0
- package/src/utils/dateUtils.ts +244 -0
- package/src/utils/setPopoverPosition.ts +4 -0
- package/test/Accordion/components/AccordionAccessibility.torp +2 -0
- package/test/Accordion/components/AccordionKeyboard.torp +2 -0
- package/test/Accordion/components/AccordionList.torp +2 -0
- package/test/Accordion/components/AccordionMultiple.torp +2 -0
- package/test/Accordion/components/AccordionSingle.torp +2 -0
- package/test/Breadcrumb/accessibility.test.ts +29 -0
- package/test/Breadcrumb/basic.test.ts +17 -0
- package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
- package/test/Calendar/components/CalendarTest.torp +9 -0
- package/test/Calendar/default.test.ts +18 -0
- package/test/Dialog/components/DialogAccessibility.torp +5 -5
- package/test/Disclosure/accessibility.test.ts +31 -0
- package/test/Disclosure/components/DisclosureTest.torp +19 -0
- package/test/Disclosure/default.test.ts +15 -0
- package/test/Disclosure/toggle.test.ts +20 -0
- package/test/Form/components/FieldTest.torp +25 -0
- package/test/Form/components/FormTest.torp +31 -0
- package/test/Form/components/InputTest.torp +9 -0
- package/test/Form/field.test.ts +34 -0
- package/test/Form/form.test.ts +34 -0
- package/test/Form/input.test.ts +19 -0
- package/test/Menu/accessibility.test.ts +83 -0
- package/test/Menu/basic.test.ts +58 -0
- package/test/Menu/components/MenuAccessibility.torp +59 -0
- package/test/Menu/components/MenuBasic.torp +58 -0
- package/test/MenuBar/accessibility.test.ts +87 -0
- package/test/MenuBar/basic.test.ts +22 -0
- package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
- package/test/MenuBar/components/MenuBarBasic.torp +25 -0
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- package/test/Notification/accessibility.test.ts +21 -0
- package/test/Notification/components/CustomNotification.torp +14 -0
- package/test/Notification/components/NotificationAccessibility.torp +14 -0
- package/test/Notification/components/NotificationFunction.torp +20 -0
- package/test/Notification/components/NotificationVariable.torp +22 -0
- package/test/Notification/function.test.ts +25 -0
- package/test/Notification/variable.test.ts +25 -0
- package/test/Popover/components/CustomDialog.torp +25 -0
- package/test/Popover/components/PromptFunction.torp +19 -0
- package/test/Popover/components/PromptVariable.torp +38 -0
- package/test/Popover/function.test.ts +26 -0
- package/test/Popover/variable.test.ts +27 -0
- package/test/TabGroup/components/TabGroupAccessibility.torp +2 -0
- package/test/TabGroup/components/TabGroupKeyboard.torp +2 -0
- package/test/TabGroup/components/TabGroupList.torp +2 -0
- package/test/TabGroup/components/TabGroupTrigger.torp +2 -0
- package/tsup.config.ts +12 -4
- package/dist/Accordion/index.cjs +0 -53
- package/dist/Accordion/index.cjs.map +0 -1
- package/dist/Dialog/index.cjs +0 -53
- package/dist/Dialog/index.cjs.map +0 -1
- package/dist/NavMenu/index.cjs +0 -78
- package/dist/NavMenu/index.cjs.map +0 -1
- package/dist/Offscreen/index.cjs +0 -33
- package/dist/Offscreen/index.cjs.map +0 -1
- package/dist/Offscreen/index.js +0 -6
- package/dist/Popover/index.cjs +0 -222
- package/dist/Popover/index.cjs.map +0 -1
- package/dist/TabGroup/index.cjs +0 -53
- package/dist/TabGroup/index.cjs.map +0 -1
- package/dist/metafile-cjs.json +0 -1
- package/dist/motion.cjs +0 -34
- package/dist/motion.cjs.map +0 -1
- package/dist/motion.d.ts +0 -6
- package/dist/motion.js.map +0 -1
- package/src/Accordion.ts +0 -7
- package/src/Dialog.ts +0 -7
- package/src/NavMenu.ts +0 -23
- package/src/Offscreen/index.ts +0 -3
- package/src/Popover.ts +0 -29
- package/src/TabGroup.ts +0 -7
- package/src/motion.ts +0 -3
- /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
2
2
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
3
3
|
|
|
4
|
+
interface PopoverContentProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* The content that is displayed for a Popover when it is open, such as a Dialog
|
|
6
13
|
* in the middle of the screen or a div that slides in from the side.
|
|
7
14
|
*/
|
|
8
|
-
export default function PopoverContent($props:
|
|
15
|
+
export default function PopoverContent($props: PopoverContentProps) {
|
|
16
|
+
$props ??= $watch({});
|
|
17
|
+
|
|
9
18
|
let div: HTMLDivElement;
|
|
19
|
+
let shown = false;
|
|
20
|
+
let closeOnClick = false;
|
|
10
21
|
|
|
11
22
|
// Get stuff out of the PopoverContext
|
|
12
23
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
@@ -15,37 +26,37 @@ export default function PopoverContent($props: any) {
|
|
|
15
26
|
}
|
|
16
27
|
let $state = context.state;
|
|
17
28
|
|
|
18
|
-
let closeOnClick = false;
|
|
19
|
-
|
|
20
|
-
let first = true;
|
|
21
29
|
$run(() => {
|
|
22
|
-
|
|
30
|
+
if (!$state.visible) {
|
|
31
|
+
hide();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
function show() {
|
|
36
|
+
shown = true;
|
|
37
|
+
|
|
38
|
+
// HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
|
|
39
|
+
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
40
|
+
closeOnClick = false;
|
|
41
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
42
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
43
|
+
|
|
44
|
+
if (context.focusFirstElement) {
|
|
45
|
+
context.focusFirstElement();
|
|
27
46
|
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function hide() {
|
|
50
|
+
if (!shown) return;
|
|
28
51
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Wait for the content div to be shown, set its position, and listen for window resize to re-position
|
|
36
|
-
//await tick();
|
|
37
|
-
if (context.focusFirstElement) {
|
|
38
|
-
context.focusFirstElement();
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
42
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
43
|
-
// Focus the anchor element per WAI guidelines
|
|
44
|
-
if (context.anchorElement?.focus) {
|
|
45
|
-
context.anchorElement.focus();
|
|
46
|
-
}
|
|
52
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
53
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
54
|
+
|
|
55
|
+
// Focus the anchor element per WAI guidelines
|
|
56
|
+
if (context.anchorElement?.focus) {
|
|
57
|
+
context.anchorElement.focus();
|
|
47
58
|
}
|
|
48
|
-
}
|
|
59
|
+
}
|
|
49
60
|
|
|
50
61
|
function handleDocumentMouseDown() {
|
|
51
62
|
closeOnClick = true;
|
|
@@ -65,11 +76,12 @@ export default function PopoverContent($props: any) {
|
|
|
65
76
|
@render {
|
|
66
77
|
@if ($state.visible) {
|
|
67
78
|
<div
|
|
68
|
-
|
|
79
|
+
{$props.id}
|
|
69
80
|
class={`torp-popover-content ${$props.class ?? ""}`.trim()}
|
|
70
81
|
&ref={div}
|
|
82
|
+
onmount={show}
|
|
71
83
|
>
|
|
72
|
-
|
|
84
|
+
<slot />
|
|
73
85
|
</div>
|
|
74
86
|
}
|
|
75
87
|
}
|
|
@@ -3,21 +3,28 @@ import getScrollParent from "../utils/getScrollParent";
|
|
|
3
3
|
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
4
4
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
5
5
|
|
|
6
|
+
interface PopoverContentAnchoredProps {
|
|
7
|
+
/** An ID for the root element */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Class name(s) for the root element */
|
|
10
|
+
class?: string,
|
|
11
|
+
/** Where the popover will be shown, relative to the popover button */
|
|
12
|
+
side?: "top" | "right" | "bottom" | "left",
|
|
13
|
+
/** How the popover will be aligned, relative to the popover button */
|
|
14
|
+
alignment?: "start" | "center" | "end",
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
/**
|
|
7
18
|
* The content that is displayed for a Popover when it is open, displayed
|
|
8
19
|
* alongside an element.
|
|
9
|
-
*
|
|
10
|
-
* @prop {"top" | "right" | "bottom" | "left"} site -- Where the popover will be
|
|
11
|
-
* shown, relative to the popover button
|
|
12
|
-
* @prop {"start" | "center" | "end"} alignment -- How the popover will be
|
|
13
|
-
* aligned, relative to the popover button
|
|
14
20
|
*/
|
|
15
|
-
export default function PopoverContentAnchored($props:
|
|
21
|
+
export default function PopoverContentAnchored($props: PopoverContentAnchoredProps) {
|
|
22
|
+
$props ??= $watch({});
|
|
16
23
|
$props.side ??= "bottom";
|
|
17
24
|
$props.alignment ??= "center";
|
|
18
25
|
|
|
19
26
|
let div: HTMLDivElement;
|
|
20
|
-
|
|
27
|
+
let shown = false;
|
|
21
28
|
let closeOnClick = false;
|
|
22
29
|
|
|
23
30
|
// Get stuff out of the PopoverContext
|
|
@@ -27,42 +34,45 @@ export default function PopoverContentAnchored($props: any) {
|
|
|
27
34
|
}
|
|
28
35
|
let $state = context.state;
|
|
29
36
|
|
|
30
|
-
let first = true;
|
|
31
37
|
$run(() => {
|
|
32
|
-
|
|
38
|
+
if (!$state.visible) {
|
|
39
|
+
hide();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function show() {
|
|
44
|
+
shown = true;
|
|
45
|
+
|
|
46
|
+
// HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
|
|
47
|
+
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
48
|
+
closeOnClick = false;
|
|
49
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
50
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
33
51
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
// Set the position and listen for window resize and scroll to reset the position
|
|
53
|
+
setPosition();
|
|
54
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
55
|
+
scrollParent.addEventListener("resize", setPosition);
|
|
56
|
+
scrollParent.addEventListener("scroll", setPosition);
|
|
57
|
+
if (context.focusFirstElement) {
|
|
58
|
+
context.focusFirstElement();
|
|
37
59
|
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function hide() {
|
|
63
|
+
if (!shown) return;
|
|
64
|
+
|
|
65
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
66
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
38
67
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Wait for the content div to be shown, set its position, and listen for window resize to re-position
|
|
46
|
-
//await tick();
|
|
47
|
-
setPosition();
|
|
48
|
-
if (context.focusFirstElement) {
|
|
49
|
-
context.focusFirstElement();
|
|
50
|
-
}
|
|
51
|
-
const scrollParent = getScrollParent(context.anchorElement)
|
|
52
|
-
scrollParent.addEventListener("resize", setPosition);
|
|
53
|
-
scrollParent.addEventListener("scroll", setPosition);
|
|
54
|
-
} else {
|
|
55
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
56
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
57
|
-
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
58
|
-
const scrollParent = getScrollParent(context.anchorElement)
|
|
59
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
60
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
61
|
-
if (context.anchorElement?.focus) {
|
|
62
|
-
context.anchorElement.focus();
|
|
63
|
-
}
|
|
68
|
+
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
69
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
70
|
+
scrollParent.removeEventListener("resize", setPosition);
|
|
71
|
+
scrollParent.removeEventListener("scroll", setPosition);
|
|
72
|
+
if (context.anchorElement?.focus) {
|
|
73
|
+
context.anchorElement.focus();
|
|
64
74
|
}
|
|
65
|
-
}
|
|
75
|
+
}
|
|
66
76
|
|
|
67
77
|
function handleDocumentMouseDown() {
|
|
68
78
|
closeOnClick = true;
|
|
@@ -85,20 +95,18 @@ export default function PopoverContentAnchored($props: any) {
|
|
|
85
95
|
throw new Error("PopoverContentAnchored must have an anchor element");
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
|
|
89
|
-
setPopoverPosition(context.anchorElement, div, $props.side, $props.alignment);
|
|
90
|
-
}
|
|
98
|
+
setPopoverPosition(context.anchorElement, div, $props.side, $props.alignment);
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
@render {
|
|
94
102
|
@if ($state.visible) {
|
|
95
103
|
<div
|
|
96
|
-
|
|
104
|
+
{$props.id}
|
|
97
105
|
class={`torp-popover-content-anchored ${$props.class ?? ""}`.trim()}
|
|
98
106
|
&ref={div}
|
|
99
|
-
|
|
107
|
+
onmount={show}
|
|
100
108
|
>
|
|
101
|
-
|
|
109
|
+
<slot />
|
|
102
110
|
</div>
|
|
103
111
|
}
|
|
104
112
|
}
|
|
@@ -4,13 +4,22 @@ import getScrollParent from "../utils/getScrollParent";
|
|
|
4
4
|
import setContextPosition from "../utils/setContextPosition";
|
|
5
5
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
6
6
|
|
|
7
|
+
interface PopoverContentContextualProps {
|
|
8
|
+
/** An ID for the root element */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Class name(s) for the root element */
|
|
11
|
+
class?: string,
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
/**
|
|
8
15
|
* The content that is displayed for a Popover when it is open, displayed at the
|
|
9
16
|
* position that the user right-clicked.
|
|
10
17
|
*/
|
|
11
|
-
export default function PopoverContentContextual($props:
|
|
12
|
-
|
|
18
|
+
export default function PopoverContentContextual($props: PopoverContentContextualProps) {
|
|
19
|
+
$props ??= $watch({});
|
|
13
20
|
|
|
21
|
+
let div: HTMLDivElement;
|
|
22
|
+
let shown = false;
|
|
14
23
|
let closeOnClick = false;
|
|
15
24
|
|
|
16
25
|
// Get stuff out of the PopoverContext
|
|
@@ -20,42 +29,45 @@ export default function PopoverContentContextual($props: any) {
|
|
|
20
29
|
}
|
|
21
30
|
let $state = context.state;
|
|
22
31
|
|
|
23
|
-
let first = true;
|
|
24
32
|
$run(() => {
|
|
25
|
-
|
|
33
|
+
if (!$state.visible) {
|
|
34
|
+
hide();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function show() {
|
|
39
|
+
shown = true;
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
// HACK: Because this Contextual could be shown with a click, we need to wait for another mousedown
|
|
42
|
+
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
43
|
+
closeOnClick = false;
|
|
44
|
+
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
45
|
+
addDocumentEvent("click", handleDocumentClick);
|
|
46
|
+
|
|
47
|
+
// Set the position and listen for window resize and scroll to reset the position
|
|
48
|
+
setPosition();
|
|
49
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
50
|
+
scrollParent.addEventListener("resize", setPosition);
|
|
51
|
+
scrollParent.addEventListener("scroll", setPosition);
|
|
52
|
+
if (context.focusFirstElement) {
|
|
53
|
+
context.focusFirstElement();
|
|
30
54
|
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hide() {
|
|
58
|
+
if (!shown) return;
|
|
31
59
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (context.focusFirstElement) {
|
|
42
|
-
context.focusFirstElement();
|
|
43
|
-
}
|
|
44
|
-
const scrollParent = getScrollParent(context.anchorElement)
|
|
45
|
-
scrollParent.addEventListener("resize", setPosition);
|
|
46
|
-
scrollParent.addEventListener("scroll", setPosition);
|
|
47
|
-
} else {
|
|
48
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
49
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
50
|
-
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
51
|
-
const scrollParent = getScrollParent(context.anchorElement)
|
|
52
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
53
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
54
|
-
if (context.anchorElement?.focus) {
|
|
55
|
-
context.anchorElement.focus();
|
|
56
|
-
}
|
|
60
|
+
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
61
|
+
removeDocumentEvent("click", handleDocumentClick);
|
|
62
|
+
|
|
63
|
+
// Stop listening for window resize and focus the anchor element per WAI guidelines
|
|
64
|
+
const scrollParent = getScrollParent(context.anchorElement)
|
|
65
|
+
scrollParent.removeEventListener("resize", setPosition);
|
|
66
|
+
scrollParent.removeEventListener("scroll", setPosition);
|
|
67
|
+
if (context.anchorElement?.focus) {
|
|
68
|
+
context.anchorElement.focus();
|
|
57
69
|
}
|
|
58
|
-
}
|
|
70
|
+
}
|
|
59
71
|
|
|
60
72
|
function handleDocumentMouseDown() {
|
|
61
73
|
closeOnClick = true;
|
|
@@ -77,7 +89,7 @@ export default function PopoverContentContextual($props: any) {
|
|
|
77
89
|
throw new Error("ContextualContent must have an anchor element");
|
|
78
90
|
}
|
|
79
91
|
|
|
80
|
-
if (
|
|
92
|
+
if ($state.position) {
|
|
81
93
|
setContextPosition(context.anchorElement, div, $state.position);
|
|
82
94
|
}
|
|
83
95
|
}
|
|
@@ -85,12 +97,12 @@ export default function PopoverContentContextual($props: any) {
|
|
|
85
97
|
@render {
|
|
86
98
|
@if ($state.visible) {
|
|
87
99
|
<div
|
|
88
|
-
|
|
100
|
+
{$props.id}
|
|
89
101
|
class={`torp-popover-content-contextual ${$props.class ?? ""}`.trim()}
|
|
90
102
|
&ref={div}
|
|
91
|
-
|
|
103
|
+
onmount={show}
|
|
92
104
|
>
|
|
93
|
-
|
|
105
|
+
<slot />
|
|
94
106
|
</div>
|
|
95
107
|
}
|
|
96
108
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { disableScroll } from "../mount/disableScroll";
|
|
2
2
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
3
3
|
|
|
4
|
+
interface PopoverOverlayProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* The background overlay for a Popover. Adding an overlay automatically sets the Popover to modal.
|
|
6
13
|
*/
|
|
7
|
-
export default function PopoverOverlay($props:
|
|
14
|
+
export default function PopoverOverlay($props: PopoverOverlayProps) {
|
|
15
|
+
$props ??= $watch({});
|
|
16
|
+
|
|
8
17
|
// Get stuff out of the PopoverContext
|
|
9
18
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
10
19
|
if (!context) {
|
|
@@ -18,12 +27,12 @@ export default function PopoverOverlay($props: any) {
|
|
|
18
27
|
@render {
|
|
19
28
|
@if ($state.visible) {
|
|
20
29
|
<div
|
|
21
|
-
|
|
30
|
+
{$props.id}
|
|
22
31
|
class={`torp-popover-overlay ${$props.class ?? ""}`.trim()}
|
|
23
32
|
tabindex="-1"
|
|
24
|
-
|
|
33
|
+
onmount={(el) => disableScroll(el)}
|
|
25
34
|
>
|
|
26
|
-
|
|
35
|
+
<slot />
|
|
27
36
|
</div>
|
|
28
37
|
}
|
|
29
38
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
2
2
|
|
|
3
|
+
interface PopoverTriggerProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* The button that causes a Popover to appear or disappear.
|
|
5
12
|
*/
|
|
6
|
-
export default function PopoverTrigger($props:
|
|
13
|
+
export default function PopoverTrigger($props: PopoverTriggerProps) {
|
|
14
|
+
$props ??= $watch({});
|
|
15
|
+
|
|
7
16
|
// Get stuff out of the PopoverContext
|
|
8
17
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
9
18
|
if (!context) {
|
|
@@ -18,12 +27,12 @@ export default function PopoverTrigger($props: any) {
|
|
|
18
27
|
@render {
|
|
19
28
|
<button
|
|
20
29
|
type="button"
|
|
21
|
-
|
|
30
|
+
{$props.id}
|
|
22
31
|
class={`torp-popover-trigger ${$props.class ?? ""}`.trim()}
|
|
23
32
|
onclick={handleClick}
|
|
24
33
|
&ref={context.anchorElement}
|
|
25
34
|
>
|
|
26
|
-
|
|
35
|
+
<slot />
|
|
27
36
|
</button>
|
|
28
37
|
}
|
|
29
38
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
2
2
|
|
|
3
|
+
interface PopoverTriggerContextualProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* The element that causes a Popover to appear or disappear when right-clicked.
|
|
5
12
|
*/
|
|
6
|
-
export default function PopoverTriggerContextual($props:
|
|
13
|
+
export default function PopoverTriggerContextual($props: PopoverTriggerContextualProps) {
|
|
14
|
+
$props ??= $watch({});
|
|
15
|
+
|
|
7
16
|
// Get stuff out of the PopoverContext
|
|
8
17
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
9
18
|
if (!context) {
|
|
@@ -26,12 +35,12 @@ export default function PopoverTriggerContextual($props: any) {
|
|
|
26
35
|
|
|
27
36
|
@render {
|
|
28
37
|
<div
|
|
29
|
-
|
|
38
|
+
{$props.id}
|
|
30
39
|
class={`torp-popover-trigger-contextual ${$props.class ?? ""}`.trim()}
|
|
31
40
|
oncontextmenu={handleContextual}
|
|
32
41
|
&ref={context.anchorElement}
|
|
33
42
|
>
|
|
34
|
-
|
|
43
|
+
<slot />
|
|
35
44
|
</div>
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
3
3
|
import hoverTrigger from "../mount/hoverTrigger";
|
|
4
4
|
|
|
5
|
+
interface PopoverTriggerHoverProps {
|
|
6
|
+
/** An ID for the root element */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Class name(s) for the root element */
|
|
9
|
+
class?: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* The div that causes a Popover to appear or disappear when hovered.
|
|
7
14
|
*/
|
|
8
|
-
export default function PopoverTriggerHover($props:
|
|
15
|
+
export default function PopoverTriggerHover($props: PopoverTriggerHoverProps) {
|
|
16
|
+
$props ??= $watch({});
|
|
17
|
+
|
|
9
18
|
// Get stuff out of the PopoverContext
|
|
10
19
|
const context = $context[PopoverContextName] as PopoverContext;
|
|
11
20
|
if (!context) {
|
|
@@ -13,7 +22,7 @@ export default function PopoverTriggerHover($props: any) {
|
|
|
13
22
|
}
|
|
14
23
|
let $state = context.state;
|
|
15
24
|
|
|
16
|
-
function handleHover(node, e) {
|
|
25
|
+
function handleHover(node: HTMLElement, e: TouchEvent | MouseEvent) {
|
|
17
26
|
if ($state.position) {
|
|
18
27
|
// Get the position relative to the element, so we can reposition on scroll
|
|
19
28
|
const rect = node.getBoundingClientRect();
|
|
@@ -27,12 +36,12 @@ export default function PopoverTriggerHover($props: any) {
|
|
|
27
36
|
|
|
28
37
|
@render {
|
|
29
38
|
<div
|
|
30
|
-
|
|
39
|
+
{$props.id}
|
|
31
40
|
class={`torp-popover-trigger-hover ${$props.class ?? ""}`.trim()}
|
|
32
|
-
|
|
41
|
+
onmount={(el) => hoverTrigger(el, { onHover: handleHover, onExit: handleHover })}
|
|
33
42
|
&ref={context.anchorElement}
|
|
34
43
|
>
|
|
35
|
-
|
|
44
|
+
<slot />
|
|
36
45
|
</div>
|
|
37
46
|
}
|
|
38
47
|
}
|