@torpor/ui 0.2.1 → 0.3.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 +32 -0
- package/dist/Accordion/Accordion.torp +29 -22
- package/dist/Accordion/AccordionContent.torp +7 -8
- package/dist/Accordion/AccordionHeader.torp +4 -6
- package/dist/Accordion/AccordionItem.torp +15 -12
- package/dist/Accordion/AccordionTrigger.torp +6 -7
- package/dist/Accordion/AccordionTypes.ts +4 -3
- package/dist/Accordion/index.d.ts +5 -5
- package/dist/Breadcrumb/Breadcrumb.torp +9 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/dist/Breadcrumb/index.d.ts +8 -7
- package/dist/Calendar/Calendar.torp +12 -13
- package/dist/Calendar/CalendarDay.torp +3 -3
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/dist/Contextual/ContextualTrigger.torp +66 -0
- package/dist/Contextual/ContextualTypes.ts +30 -0
- package/dist/Contextual/index.d.ts +90 -0
- package/dist/Contextual/index.js +14 -0
- package/dist/Contextual/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +38 -72
- package/dist/Dialog/DialogBody.torp +6 -8
- package/dist/Dialog/DialogButton.torp +14 -12
- package/dist/Dialog/DialogFooter.torp +3 -5
- package/dist/Dialog/DialogHeader.torp +6 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +16 -11
- package/dist/Disclosure/Disclosure.torp +22 -23
- package/dist/Disclosure/DisclosureContent.torp +7 -8
- package/dist/Disclosure/DisclosureHeader.torp +5 -7
- package/dist/Disclosure/DisclosureTrigger.torp +7 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +12 -12
- package/dist/Drawer/Drawer.torp +101 -70
- package/dist/Drawer/DrawerContent.torp +80 -0
- package/dist/Drawer/DrawerOverlay.torp +38 -0
- package/dist/Drawer/DrawerTrigger.torp +35 -0
- package/dist/Drawer/DrawerTypes.ts +24 -0
- package/dist/Drawer/index.d.ts +90 -3
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/CheckBox.torp +91 -0
- package/dist/Form/Field.torp +2 -4
- package/dist/Form/File.torp +106 -0
- package/dist/Form/Form.torp +17 -10
- package/dist/Form/FormTypes.ts +5 -0
- package/dist/Form/Input.torp +28 -17
- package/dist/Form/Label.torp +1 -1
- package/dist/Form/Message.torp +1 -1
- package/dist/Form/Option.torp +24 -0
- package/dist/Form/Select.torp +97 -0
- package/dist/Form/TextArea.torp +101 -0
- package/dist/Form/index.d.ts +192 -5
- package/dist/Form/index.js +21 -1
- package/dist/Menu/Menu.torp +16 -15
- package/dist/Menu/MenuButton.torp +19 -13
- package/dist/Menu/MenuCheck.torp +18 -14
- package/dist/Menu/MenuGroup.torp +4 -6
- package/dist/Menu/MenuIndicator.torp +5 -7
- package/dist/Menu/MenuPopout.torp +12 -15
- package/dist/Menu/MenuPopoutContent.torp +6 -8
- package/dist/Menu/MenuPopoutTrigger.torp +12 -14
- package/dist/Menu/MenuRadio.torp +14 -14
- package/dist/Menu/MenuRadioGroup.torp +22 -14
- package/dist/Menu/MenuSeparator.torp +3 -5
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +28 -22
- package/dist/MenuBar/MenuBar.torp +13 -14
- package/dist/MenuBar/MenuBarItem.torp +13 -16
- package/dist/MenuBar/MenuBarItemContent.torp +7 -9
- package/dist/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/dist/MenuBar/index.d.ts +16 -16
- package/dist/Modal/Modal.torp +118 -0
- package/dist/Modal/ModalContent.torp +77 -0
- package/dist/Modal/ModalOverlay.torp +38 -0
- package/dist/Modal/ModalTrigger.torp +50 -0
- package/dist/Modal/ModalTypes.ts +22 -0
- package/dist/Modal/index.d.ts +108 -0
- package/dist/Modal/index.js +33 -0
- package/dist/Modal/index.js.map +1 -0
- package/dist/Modal/showModal.ts +19 -0
- package/dist/Modal/showPrompt.ts +23 -0
- package/dist/NavMenu/NavMenu.torp +7 -8
- package/dist/NavMenu/NavMenuButton.torp +6 -8
- package/dist/NavMenu/NavMenuElement.torp +8 -8
- package/dist/NavMenu/NavMenuGroup.torp +4 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/dist/NavMenu/NavMenuLink.torp +8 -11
- package/dist/NavMenu/NavMenuPopout.torp +25 -17
- package/dist/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/dist/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/dist/NavMenu/NavMenuSeparator.torp +3 -5
- package/dist/NavMenu/index.d.ts +17 -11
- package/dist/Notification/Notification.torp +22 -13
- package/dist/Notification/NotificationClose.torp +3 -5
- package/dist/Notification/NotificationContainer.torp +3 -5
- package/dist/Notification/NotificationContent.torp +3 -5
- package/dist/Notification/index.d.ts +4 -4
- package/dist/Popover/Popover.torp +31 -25
- package/dist/Popover/PopoverContent.torp +35 -10
- package/dist/Popover/PopoverTrigger.torp +24 -4
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +16 -124
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +12 -9
- package/dist/TabGroup/TabGroup.torp +41 -35
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +15 -8
- package/dist/TabGroup/TabList.torp +4 -6
- package/dist/TabGroup/TabTrigger.torp +8 -9
- package/dist/TabGroup/index.d.ts +14 -6
- package/dist/icons/ArrowDown.torp +3 -1
- package/dist/icons/ArrowLeft.torp +3 -1
- package/dist/icons/ArrowRight.torp +3 -1
- package/dist/icons/ArrowUp.torp +3 -1
- package/dist/icons/Bars.torp +3 -1
- package/dist/icons/Check.torp +3 -1
- package/dist/icons/ChevronDown.torp +3 -1
- package/dist/icons/ChevronLeft.torp +3 -1
- package/dist/icons/ChevronRight.torp +3 -1
- package/dist/icons/ChevronUp.torp +3 -1
- package/dist/icons/Cross.torp +3 -1
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +3 -1
- package/dist/icons/Minus.torp +3 -1
- package/dist/icons/Plus.torp +3 -1
- package/dist/icons/index.d.ts +271 -14
- package/dist/index.d.ts +17 -4
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +15 -6
- package/dist/motion/grow.ts +23 -0
- package/dist/motion/index.d.ts +19 -2
- package/dist/motion/index.js +93 -3
- package/dist/motion/index.js.map +1 -1
- package/dist/motion/measure.ts +28 -0
- package/dist/motion/slide.ts +45 -0
- package/dist/mount/clickPopover.ts +51 -0
- package/dist/mount/contextPopover.ts +51 -0
- package/dist/mount/hoverPopover.ts +58 -0
- package/package.json +21 -14
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +29 -22
- package/src/Accordion/AccordionContent.torp +7 -8
- package/src/Accordion/AccordionHeader.torp +4 -6
- package/src/Accordion/AccordionItem.torp +15 -12
- package/src/Accordion/AccordionTrigger.torp +6 -7
- package/src/Accordion/AccordionTypes.ts +4 -3
- package/src/Breadcrumb/Breadcrumb.torp +9 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/src/Calendar/Calendar.torp +12 -13
- package/src/Calendar/CalendarDay.torp +3 -3
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/src/Contextual/ContextualTrigger.torp +66 -0
- package/src/Contextual/ContextualTypes.ts +30 -0
- package/src/Contextual/index.ts +5 -0
- package/src/Dialog/Dialog.torp +38 -72
- package/src/Dialog/DialogBody.torp +6 -8
- package/src/Dialog/DialogButton.torp +14 -12
- package/src/Dialog/DialogFooter.torp +3 -5
- package/src/Dialog/DialogHeader.torp +6 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +22 -23
- package/src/Disclosure/DisclosureContent.torp +7 -8
- package/src/Disclosure/DisclosureHeader.torp +5 -7
- package/src/Disclosure/DisclosureTrigger.torp +7 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +101 -70
- package/src/Drawer/DrawerContent.torp +80 -0
- package/src/Drawer/DrawerOverlay.torp +38 -0
- package/src/Drawer/DrawerTrigger.torp +35 -0
- package/src/Drawer/DrawerTypes.ts +24 -0
- package/src/Drawer/index.ts +4 -1
- package/src/Form/CheckBox.torp +91 -0
- package/src/Form/Field.torp +2 -4
- package/src/Form/File.torp +106 -0
- package/src/Form/Form.torp +17 -10
- package/src/Form/FormTypes.ts +5 -0
- package/src/Form/Input.torp +28 -17
- package/src/Form/Label.torp +1 -1
- package/src/Form/Message.torp +1 -1
- package/src/Form/Option.torp +24 -0
- package/src/Form/Select.torp +97 -0
- package/src/Form/TextArea.torp +101 -0
- package/src/Form/index.ts +6 -1
- package/src/Menu/Menu.torp +16 -15
- package/src/Menu/MenuButton.torp +19 -13
- package/src/Menu/MenuCheck.torp +18 -14
- package/src/Menu/MenuGroup.torp +4 -6
- package/src/Menu/MenuIndicator.torp +5 -7
- package/src/Menu/MenuPopout.torp +12 -15
- package/src/Menu/MenuPopoutContent.torp +6 -8
- package/src/Menu/MenuPopoutTrigger.torp +12 -14
- package/src/Menu/MenuRadio.torp +14 -14
- package/src/Menu/MenuRadioGroup.torp +22 -14
- package/src/Menu/MenuSeparator.torp +3 -5
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +13 -14
- package/src/MenuBar/MenuBarItem.torp +13 -16
- package/src/MenuBar/MenuBarItemContent.torp +7 -9
- package/src/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/src/Modal/Modal.torp +118 -0
- package/src/Modal/ModalContent.torp +77 -0
- package/src/Modal/ModalOverlay.torp +38 -0
- package/src/Modal/ModalTrigger.torp +50 -0
- package/src/Modal/ModalTypes.ts +22 -0
- package/src/Modal/index.ts +10 -0
- package/src/Modal/showModal.ts +19 -0
- package/src/Modal/showPrompt.ts +23 -0
- package/src/NavMenu/NavMenu.torp +7 -8
- package/src/NavMenu/NavMenuButton.torp +6 -8
- package/src/NavMenu/NavMenuElement.torp +8 -8
- package/src/NavMenu/NavMenuGroup.torp +4 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/src/NavMenu/NavMenuLink.torp +8 -11
- package/src/NavMenu/NavMenuPopout.torp +25 -17
- package/src/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/src/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/src/NavMenu/NavMenuSeparator.torp +3 -5
- package/src/Notification/Notification.torp +22 -13
- package/src/Notification/NotificationClose.torp +3 -5
- package/src/Notification/NotificationContainer.torp +3 -5
- package/src/Notification/NotificationContent.torp +3 -5
- package/src/Popover/Popover.torp +31 -25
- package/src/Popover/PopoverContent.torp +35 -10
- package/src/Popover/PopoverTrigger.torp +24 -4
- package/src/Popover/PopoverTypes.ts +1 -1
- package/src/Popover/index.ts +1 -24
- package/src/Slider/Slider.torp +3 -3
- package/src/TabGroup/TabContent.torp +12 -9
- package/src/TabGroup/TabGroup.torp +41 -35
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +15 -8
- package/src/TabGroup/TabList.torp +4 -6
- package/src/TabGroup/TabTrigger.torp +8 -9
- package/src/icons/ArrowDown.torp +3 -1
- package/src/icons/ArrowLeft.torp +3 -1
- package/src/icons/ArrowRight.torp +3 -1
- package/src/icons/ArrowUp.torp +3 -1
- package/src/icons/Bars.torp +3 -1
- package/src/icons/Check.torp +3 -1
- package/src/icons/ChevronDown.torp +3 -1
- package/src/icons/ChevronLeft.torp +3 -1
- package/src/icons/ChevronRight.torp +3 -1
- package/src/icons/ChevronUp.torp +3 -1
- package/src/icons/Cross.torp +3 -1
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +3 -1
- package/src/icons/Minus.torp +3 -1
- package/src/icons/Plus.torp +3 -1
- package/src/motion/fade.ts +15 -6
- package/src/motion/grow.ts +23 -0
- package/src/motion/index.ts +4 -1
- package/src/motion/measure.ts +28 -0
- package/src/motion/slide.ts +45 -0
- package/src/mount/clickPopover.ts +51 -0
- package/src/mount/contextPopover.ts +51 -0
- package/src/mount/hoverPopover.ts +58 -0
- package/test/Accordion/components/AccordionAccessibility.torp +1 -3
- package/test/Accordion/components/AccordionKeyboard.torp +1 -3
- package/test/Accordion/components/AccordionList.torp +1 -3
- package/test/Accordion/components/AccordionMultiple.torp +2 -4
- package/test/Accordion/components/AccordionSingle.torp +2 -4
- package/test/Dialog/accessibility-modal.test.ts +2 -2
- package/test/Dialog/components/DialogAccessibility.torp +8 -14
- package/test/Dialog/components/DialogFunction.torp +20 -4
- package/test/Dialog/components/DialogModal.torp +30 -0
- package/test/Dialog/components/DialogVariable.torp +7 -7
- package/test/Disclosure/components/DisclosureTest.torp +1 -3
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/Notification/components/NotificationFunction.torp +0 -3
- package/test/Notification/components/NotificationVariable.torp +1 -1
- package/test/Popover/components/PopoverFunction.torp +37 -0
- package/test/Popover/components/PopoverTrigger.torp +36 -0
- package/test/Popover/components/{PromptVariable.torp → PopoverVariable.torp} +5 -3
- package/test/Popover/function.test.ts +2 -7
- package/test/Popover/trigger.test.ts +27 -0
- package/test/Popover/variable.test.ts +2 -2
- package/test/TabGroup/components/TabGroupAccessibility.torp +1 -3
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -3
- package/test/TabGroup/components/TabGroupList.torp +1 -3
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -3
- package/tsup.config.ts +2 -0
- package/dist/Popover/PopoverContentAnchored.torp +0 -113
- package/dist/Popover/PopoverOverlay.torp +0 -39
- package/dist/Popover/PopoverTriggerContextual.torp +0 -46
- package/dist/Popover/PopoverTriggerHover.torp +0 -47
- package/dist/Popover/mountClickPopover.ts +0 -50
- package/dist/Popover/mountContextPopover.ts +0 -50
- package/dist/Popover/mountHoverPopover.ts +0 -57
- package/dist/Popover/showPopoverPrompt.ts +0 -23
- package/src/Popover/PopoverContentAnchored.torp +0 -113
- package/src/Popover/PopoverOverlay.torp +0 -39
- package/src/Popover/PopoverTriggerContextual.torp +0 -46
- package/src/Popover/PopoverTriggerHover.torp +0 -47
- package/src/Popover/mountClickPopover.ts +0 -50
- package/src/Popover/mountContextPopover.ts +0 -50
- package/src/Popover/mountHoverPopover.ts +0 -57
- package/src/Popover/showPopoverPrompt.ts +0 -23
- package/test/Dialog/components/CustomDialog.torp +0 -20
- package/test/Popover/components/PromptFunction.torp +0 -19
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getByText, queryByText } from "@testing-library/dom";
|
|
2
|
+
import "@testing-library/jest-dom/vitest";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { mount } from "@torpor/view";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import PopoverTrigger from "./components/PopoverTrigger.torp";
|
|
7
|
+
|
|
8
|
+
describe("Prompt", () => {
|
|
9
|
+
it("Showing with a trigger", async () => {
|
|
10
|
+
const container = document.createElement("div");
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
mount(container, PopoverTrigger);
|
|
13
|
+
|
|
14
|
+
// By default, the prompt shouldn't be shown
|
|
15
|
+
expect(queryByText(container, "Which color do you prefer?")).not.toBeInTheDocument();
|
|
16
|
+
expect(queryByText(container, "Your favorite color is blue?!")).not.toBeInTheDocument();
|
|
17
|
+
|
|
18
|
+
// Clicking the button should show the prompt
|
|
19
|
+
await userEvent.click(getByText(container, "Show the prompt"));
|
|
20
|
+
expect(queryByText(container, "Which color do you prefer?")).toBeInTheDocument();
|
|
21
|
+
|
|
22
|
+
// Clicking the blue button should hide the prompt and set the value
|
|
23
|
+
await userEvent.click(getByText(container, "Blue"));
|
|
24
|
+
expect(queryByText(container, "Which color do you prefer?")).not.toBeInTheDocument();
|
|
25
|
+
expect(queryByText(container, "Your favorite color is blue?!")).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -3,13 +3,13 @@ import "@testing-library/jest-dom/vitest";
|
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import { mount } from "@torpor/view";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
6
|
-
import
|
|
6
|
+
import PopoverVariable from "./components/PopoverVariable.torp";
|
|
7
7
|
|
|
8
8
|
describe("Prompt", () => {
|
|
9
9
|
it("Showing with a variable", async () => {
|
|
10
10
|
const container = document.createElement("div");
|
|
11
11
|
document.body.appendChild(container);
|
|
12
|
-
mount(container,
|
|
12
|
+
mount(container, PopoverVariable);
|
|
13
13
|
|
|
14
14
|
// By default, the prompt shouldn't be shown
|
|
15
15
|
expect(queryByText(container, "Which color do you prefer?")).not.toBeInTheDocument();
|
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
} from "../../../src/TabGroup/index";
|
|
8
8
|
|
|
9
9
|
export default function TabGroupAccessibility() {
|
|
10
|
-
$props ??= $watch({});
|
|
11
|
-
|
|
12
10
|
@render {
|
|
13
|
-
<TabGroup value={$props
|
|
11
|
+
<TabGroup value={$props?.value}>
|
|
14
12
|
<TabList ariaLabel="Example tabs">
|
|
15
13
|
<TabHeader as="h4">
|
|
16
14
|
<TabTrigger>Header 1</TabTrigger>
|
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
} from "../../../src/TabGroup/index";
|
|
8
8
|
|
|
9
9
|
export default function TabGroupKeyboard() {
|
|
10
|
-
$props ??= $watch({});
|
|
11
|
-
|
|
12
10
|
@render {
|
|
13
|
-
<TabGroup value={$props
|
|
11
|
+
<TabGroup value={$props?.value}>
|
|
14
12
|
<TabList>
|
|
15
13
|
<TabHeader as="h4">
|
|
16
14
|
<TabTrigger>Header 1</TabTrigger>
|
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
} from "../../../src/TabGroup/index";
|
|
8
8
|
|
|
9
9
|
export default function TabGroupList() {
|
|
10
|
-
$props ??= $watch({});
|
|
11
|
-
|
|
12
10
|
@render {
|
|
13
|
-
<TabGroup value={$props
|
|
11
|
+
<TabGroup value={$props?.value}>
|
|
14
12
|
<TabList>
|
|
15
13
|
@for (let item of $props.items) {
|
|
16
14
|
@key = item.id
|
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
} from "../../../src/TabGroup/index";
|
|
8
8
|
|
|
9
9
|
export default function TabGroupTrigger() {
|
|
10
|
-
$props ??= $watch({});
|
|
11
|
-
|
|
12
10
|
@render {
|
|
13
|
-
<TabGroup value={$props
|
|
11
|
+
<TabGroup value={$props?.value}>
|
|
14
12
|
<TabList>
|
|
15
13
|
<TabHeader as="h4">
|
|
16
14
|
<TabTrigger>Header 1</TabTrigger>
|
package/tsup.config.ts
CHANGED
|
@@ -10,12 +10,14 @@ export default defineConfig({
|
|
|
10
10
|
"src/Accordion/index.ts",
|
|
11
11
|
"src/Breadcrumb/index.ts",
|
|
12
12
|
"src/Calendar/index.ts",
|
|
13
|
+
"src/Contextual/index.ts",
|
|
13
14
|
"src/Dialog/index.ts",
|
|
14
15
|
"src/Disclosure/index.ts",
|
|
15
16
|
"src/Drawer/index.ts",
|
|
16
17
|
"src/Form/index.ts",
|
|
17
18
|
"src/Menu/index.ts",
|
|
18
19
|
"src/MenuBar/index.ts",
|
|
20
|
+
"src/Modal/index.ts",
|
|
19
21
|
"src/NavMenu/index.ts",
|
|
20
22
|
"src/Notification/index.ts",
|
|
21
23
|
"src/Popover/index.ts",
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
2
|
-
import getScrollParent from "../utils/getScrollParent";
|
|
3
|
-
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
4
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
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
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The content that is displayed for a Popover when it is open, displayed
|
|
19
|
-
* alongside an element.
|
|
20
|
-
*/
|
|
21
|
-
export default function PopoverContentAnchored($props: PopoverContentAnchoredProps) {
|
|
22
|
-
$props ??= $watch({});
|
|
23
|
-
$props.side ??= "bottom";
|
|
24
|
-
$props.alignment ??= "center";
|
|
25
|
-
|
|
26
|
-
let div: HTMLDivElement;
|
|
27
|
-
let shown = false;
|
|
28
|
-
let closeOnClick = false;
|
|
29
|
-
|
|
30
|
-
// Get stuff out of the PopoverContext
|
|
31
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
32
|
-
if (!context) {
|
|
33
|
-
throw new Error("PopoverContentAnchored must be contained within a Popover");
|
|
34
|
-
}
|
|
35
|
-
let $state = context.state;
|
|
36
|
-
|
|
37
|
-
$run(() => {
|
|
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);
|
|
51
|
-
|
|
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();
|
|
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 scrollParent = getScrollParent(context.anchorElement)
|
|
70
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
71
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
72
|
-
if (context.anchorElement?.focus) {
|
|
73
|
-
context.anchorElement.focus();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function handleDocumentMouseDown() {
|
|
78
|
-
closeOnClick = true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function handleDocumentClick(e: MouseEvent) {
|
|
82
|
-
if (
|
|
83
|
-
closeOnClick &&
|
|
84
|
-
div &&
|
|
85
|
-
!div.contains(e.target as HTMLElement) &&
|
|
86
|
-
(!context.anchorElement || !context.anchorElement.contains(e.target as HTMLElement))
|
|
87
|
-
) {
|
|
88
|
-
e.preventDefault();
|
|
89
|
-
context.handleClickOutside!(e);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function setPosition() {
|
|
94
|
-
if (!context.anchorElement) {
|
|
95
|
-
throw new Error("PopoverContentAnchored must have an anchor element");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
setPopoverPosition(context.anchorElement, div, $props.side, $props.alignment);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@render {
|
|
102
|
-
@if ($state.visible) {
|
|
103
|
-
<div
|
|
104
|
-
{$props.id}
|
|
105
|
-
class={`torp-popover-content-anchored ${$props.class ?? ""}`.trim()}
|
|
106
|
-
&ref={div}
|
|
107
|
-
onmount={show}
|
|
108
|
-
>
|
|
109
|
-
<slot />
|
|
110
|
-
</div>
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { disableScroll } from "../mount/disableScroll";
|
|
2
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
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
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The background overlay for a Popover. Adding an overlay automatically sets the Popover to modal.
|
|
13
|
-
*/
|
|
14
|
-
export default function PopoverOverlay($props: PopoverOverlayProps) {
|
|
15
|
-
$props ??= $watch({});
|
|
16
|
-
|
|
17
|
-
// Get stuff out of the PopoverContext
|
|
18
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
19
|
-
if (!context) {
|
|
20
|
-
throw new Error("PopoverOverlay must be contained within a Popover");
|
|
21
|
-
}
|
|
22
|
-
let $state = context.state;
|
|
23
|
-
|
|
24
|
-
// Any Popover with an overlay is modal
|
|
25
|
-
context.modal = true;
|
|
26
|
-
|
|
27
|
-
@render {
|
|
28
|
-
@if ($state.visible) {
|
|
29
|
-
<div
|
|
30
|
-
{$props.id}
|
|
31
|
-
class={`torp-popover-overlay ${$props.class ?? ""}`.trim()}
|
|
32
|
-
tabindex="-1"
|
|
33
|
-
onmount={(el) => disableScroll(el)}
|
|
34
|
-
>
|
|
35
|
-
<slot />
|
|
36
|
-
</div>
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
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
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The element that causes a Popover to appear or disappear when right-clicked.
|
|
12
|
-
*/
|
|
13
|
-
export default function PopoverTriggerContextual($props: PopoverTriggerContextualProps) {
|
|
14
|
-
$props ??= $watch({});
|
|
15
|
-
|
|
16
|
-
// Get stuff out of the PopoverContext
|
|
17
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
18
|
-
if (!context) {
|
|
19
|
-
throw new Error("PopoverTriggerContextual must be contained within a Popover");
|
|
20
|
-
}
|
|
21
|
-
let $state = context.state;
|
|
22
|
-
|
|
23
|
-
function handleContextual(e: MouseEvent & { currentTarget: EventTarget & HTMLDivElement }) {
|
|
24
|
-
e.preventDefault();
|
|
25
|
-
if ($state.position) {
|
|
26
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
27
|
-
const rect = e.currentTarget.getBoundingClientRect();
|
|
28
|
-
const x = e.clientX - rect.left;
|
|
29
|
-
const y = e.clientY - rect.top;
|
|
30
|
-
$state.position = { x, y };
|
|
31
|
-
//$state.position = { x: window.scrollX + e.clientX, y: window.scrollY + e.clientY };
|
|
32
|
-
}
|
|
33
|
-
$state.visible = !$state.visible;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@render {
|
|
37
|
-
<div
|
|
38
|
-
{$props.id}
|
|
39
|
-
class={`torp-popover-trigger-contextual ${$props.class ?? ""}`.trim()}
|
|
40
|
-
oncontextmenu={handleContextual}
|
|
41
|
-
&ref={context.anchorElement}
|
|
42
|
-
>
|
|
43
|
-
<slot />
|
|
44
|
-
</div>
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
3
|
-
import hoverTrigger from "../mount/hoverTrigger";
|
|
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
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The div that causes a Popover to appear or disappear when hovered.
|
|
14
|
-
*/
|
|
15
|
-
export default function PopoverTriggerHover($props: PopoverTriggerHoverProps) {
|
|
16
|
-
$props ??= $watch({});
|
|
17
|
-
|
|
18
|
-
// Get stuff out of the PopoverContext
|
|
19
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
20
|
-
if (!context) {
|
|
21
|
-
throw new Error("PopoverTriggerHover must be contained within a Popover");
|
|
22
|
-
}
|
|
23
|
-
let $state = context.state;
|
|
24
|
-
|
|
25
|
-
function handleHover(node: HTMLElement, e: TouchEvent | MouseEvent) {
|
|
26
|
-
if ($state.position) {
|
|
27
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
28
|
-
const rect = node.getBoundingClientRect();
|
|
29
|
-
const x = e.clientX - rect.left;
|
|
30
|
-
const y = e.clientY - rect.top;
|
|
31
|
-
$state.position = { x, y };
|
|
32
|
-
//$state.position = { x: window.scrollX + e.clientX, y: window.scrollY + e.clientY };
|
|
33
|
-
}
|
|
34
|
-
$state.visible = !$state.visible
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@render {
|
|
38
|
-
<div
|
|
39
|
-
{$props.id}
|
|
40
|
-
class={`torp-popover-trigger-hover ${$props.class ?? ""}`.trim()}
|
|
41
|
-
onmount={(el) => hoverTrigger(el, { onHover: handleHover, onExit: handleHover })}
|
|
42
|
-
&ref={context.anchorElement}
|
|
43
|
-
>
|
|
44
|
-
<slot />
|
|
45
|
-
</div>
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Component } from "@torpor/view";
|
|
2
|
-
import showPopover from "./showPopover";
|
|
3
|
-
|
|
4
|
-
interface ClickPopoverOptions {
|
|
5
|
-
popover: Component;
|
|
6
|
-
props?: Record<PropertyKey, any>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A mount directive for showing a popover when an element is clicked.
|
|
11
|
-
* @param node The element to show the popover for
|
|
12
|
-
* @param options Options for showing the popover, consisting of the popover component and any props
|
|
13
|
-
*/
|
|
14
|
-
export default function clickPopover(node: HTMLElement, options: ClickPopoverOptions) {
|
|
15
|
-
const { popover, props } = options;
|
|
16
|
-
|
|
17
|
-
// Add a click event handler to the node
|
|
18
|
-
node.addEventListener("click", handleClick);
|
|
19
|
-
|
|
20
|
-
function handleClick(e: MouseEvent) {
|
|
21
|
-
e.preventDefault();
|
|
22
|
-
show();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let div: HTMLDivElement;
|
|
26
|
-
|
|
27
|
-
function show() {
|
|
28
|
-
// Show the popover in a div
|
|
29
|
-
if (div) {
|
|
30
|
-
document.body.removeChild(div);
|
|
31
|
-
}
|
|
32
|
-
div = document.createElement("div");
|
|
33
|
-
document.body.appendChild(div);
|
|
34
|
-
|
|
35
|
-
showPopover(popover, node, props, div);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
destroy(): void {
|
|
40
|
-
// Remove the event listener from the node on destroy
|
|
41
|
-
node.removeEventListener("click", handleClick);
|
|
42
|
-
|
|
43
|
-
// Remove the div we added
|
|
44
|
-
// TODO: Should we do this in more places?
|
|
45
|
-
if (div) {
|
|
46
|
-
document.body.removeChild(div);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Component } from "@torpor/view";
|
|
2
|
-
import showPopover from "./showPopover";
|
|
3
|
-
|
|
4
|
-
interface ContextPopoverOptions {
|
|
5
|
-
popover: Component;
|
|
6
|
-
props?: Record<PropertyKey, any>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A mount directive for showing a popover when the user opens an element's context menu.
|
|
11
|
-
* @param node The element to show the popover for
|
|
12
|
-
* @param options Options for showing the popover, consisting of the popover component and any props
|
|
13
|
-
*/
|
|
14
|
-
export default function contextPopover(node: HTMLElement, options: ContextPopoverOptions) {
|
|
15
|
-
const { popover, props } = options;
|
|
16
|
-
|
|
17
|
-
// Add a contextmenu event handler to the node
|
|
18
|
-
node.addEventListener("contextmenu", handleClick);
|
|
19
|
-
|
|
20
|
-
function handleClick(e: MouseEvent) {
|
|
21
|
-
e.preventDefault();
|
|
22
|
-
show();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let div: HTMLDivElement;
|
|
26
|
-
|
|
27
|
-
function show() {
|
|
28
|
-
// Show the popover in a div
|
|
29
|
-
if (div) {
|
|
30
|
-
document.body.removeChild(div);
|
|
31
|
-
}
|
|
32
|
-
div = document.createElement("div");
|
|
33
|
-
document.body.appendChild(div);
|
|
34
|
-
|
|
35
|
-
showPopover(popover, node, props, div);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
destroy(): void {
|
|
40
|
-
// Remove the event listener from the node on destroy
|
|
41
|
-
node.removeEventListener("contextmenu", handleClick);
|
|
42
|
-
|
|
43
|
-
// Remove the div we added
|
|
44
|
-
// TODO: Should we do this in more places?
|
|
45
|
-
if (div) {
|
|
46
|
-
document.body.removeChild(div);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Component } from "@torpor/view";
|
|
2
|
-
import hoverTrigger from "../mount/hoverTrigger";
|
|
3
|
-
import showPopover from "./showPopover";
|
|
4
|
-
|
|
5
|
-
interface HoverPopoverOptions {
|
|
6
|
-
popover: Component;
|
|
7
|
-
props?: Record<PropertyKey, any>;
|
|
8
|
-
hoverDelay?: number;
|
|
9
|
-
touchDelay?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A mount directive for showing a popover when an element is hovered.
|
|
14
|
-
* @param node The element to show the popover for
|
|
15
|
-
* @param options Options for showing the popover, consisting of the popover component, any props and delays for hover and touch
|
|
16
|
-
*/
|
|
17
|
-
export default function hoverPopover(node: HTMLElement, options: HoverPopoverOptions): () => void {
|
|
18
|
-
const { popover, props, hoverDelay, touchDelay } = options;
|
|
19
|
-
|
|
20
|
-
let div: HTMLDivElement | undefined;
|
|
21
|
-
|
|
22
|
-
function onHover(node: HTMLElement, e: MouseEvent | TouchEvent) {
|
|
23
|
-
// Show the popover in a div
|
|
24
|
-
if (div) {
|
|
25
|
-
document.body.removeChild(div);
|
|
26
|
-
}
|
|
27
|
-
div = document.createElement("div");
|
|
28
|
-
document.body.appendChild(div);
|
|
29
|
-
|
|
30
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
31
|
-
const rect = node.getBoundingClientRect();
|
|
32
|
-
let position: { x: number; y: number };
|
|
33
|
-
if (e.type.startsWith("mouse")) {
|
|
34
|
-
const me = e as MouseEvent;
|
|
35
|
-
position = { x: me.clientX - rect.left, y: me.clientY - rect.top };
|
|
36
|
-
} else {
|
|
37
|
-
const te = e as TouchEvent;
|
|
38
|
-
position = {
|
|
39
|
-
x: te.touches[0].clientX - rect.left,
|
|
40
|
-
y: te.touches[0].clientY - rect.top,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const allProps = Object.assign({}, props, { anchor: node, position });
|
|
44
|
-
|
|
45
|
-
showPopover(popover, node, allProps, div);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function onExit() {
|
|
49
|
-
// Remove the div
|
|
50
|
-
if (div) {
|
|
51
|
-
document.body.removeChild(div);
|
|
52
|
-
div = undefined;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });
|
|
57
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Component } from "@torpor/view";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shows a popover component in code, and asynchronously returns the value selected by the user.
|
|
5
|
-
* @param popover The popover component
|
|
6
|
-
* @param props The properties for the popover component
|
|
7
|
-
* @param target The target element to show the popover in
|
|
8
|
-
* @returns The value selected by the user
|
|
9
|
-
*/
|
|
10
|
-
export default function showPopoverPrompt(
|
|
11
|
-
popover: Component,
|
|
12
|
-
props?: Record<PropertyKey, any>,
|
|
13
|
-
target?: Element,
|
|
14
|
-
): Promise<void> {
|
|
15
|
-
return new Promise((resolve) => {
|
|
16
|
-
// Add the promise as the callback
|
|
17
|
-
const allProps = Object.assign({}, props, { callback: resolve });
|
|
18
|
-
|
|
19
|
-
// Create the popover
|
|
20
|
-
// TODO: This needs to clean up after itself, like the use methods do
|
|
21
|
-
popover(target || document.body, null, allProps);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
2
|
-
import getScrollParent from "../utils/getScrollParent";
|
|
3
|
-
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
4
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
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
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The content that is displayed for a Popover when it is open, displayed
|
|
19
|
-
* alongside an element.
|
|
20
|
-
*/
|
|
21
|
-
export default function PopoverContentAnchored($props: PopoverContentAnchoredProps) {
|
|
22
|
-
$props ??= $watch({});
|
|
23
|
-
$props.side ??= "bottom";
|
|
24
|
-
$props.alignment ??= "center";
|
|
25
|
-
|
|
26
|
-
let div: HTMLDivElement;
|
|
27
|
-
let shown = false;
|
|
28
|
-
let closeOnClick = false;
|
|
29
|
-
|
|
30
|
-
// Get stuff out of the PopoverContext
|
|
31
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
32
|
-
if (!context) {
|
|
33
|
-
throw new Error("PopoverContentAnchored must be contained within a Popover");
|
|
34
|
-
}
|
|
35
|
-
let $state = context.state;
|
|
36
|
-
|
|
37
|
-
$run(() => {
|
|
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);
|
|
51
|
-
|
|
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();
|
|
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 scrollParent = getScrollParent(context.anchorElement)
|
|
70
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
71
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
72
|
-
if (context.anchorElement?.focus) {
|
|
73
|
-
context.anchorElement.focus();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function handleDocumentMouseDown() {
|
|
78
|
-
closeOnClick = true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function handleDocumentClick(e: MouseEvent) {
|
|
82
|
-
if (
|
|
83
|
-
closeOnClick &&
|
|
84
|
-
div &&
|
|
85
|
-
!div.contains(e.target as HTMLElement) &&
|
|
86
|
-
(!context.anchorElement || !context.anchorElement.contains(e.target as HTMLElement))
|
|
87
|
-
) {
|
|
88
|
-
e.preventDefault();
|
|
89
|
-
context.handleClickOutside!(e);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function setPosition() {
|
|
94
|
-
if (!context.anchorElement) {
|
|
95
|
-
throw new Error("PopoverContentAnchored must have an anchor element");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
setPopoverPosition(context.anchorElement, div, $props.side, $props.alignment);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@render {
|
|
102
|
-
@if ($state.visible) {
|
|
103
|
-
<div
|
|
104
|
-
{$props.id}
|
|
105
|
-
class={`torp-popover-content-anchored ${$props.class ?? ""}`.trim()}
|
|
106
|
-
&ref={div}
|
|
107
|
-
onmount={show}
|
|
108
|
-
>
|
|
109
|
-
<slot />
|
|
110
|
-
</div>
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|