@torpor/ui 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/Accordion/Accordion.torp +44 -25
- package/dist/Accordion/AccordionContent.torp +18 -12
- package/dist/Accordion/AccordionHeader.torp +15 -8
- package/dist/Accordion/AccordionItem.torp +34 -17
- package/dist/Accordion/AccordionTrigger.torp +17 -10
- package/dist/Accordion/AccordionTypes.ts +6 -3
- package/dist/Accordion/index.d.ts +100 -35
- package/dist/Breadcrumb/Breadcrumb.torp +18 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +14 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +10 -3
- package/dist/Breadcrumb/index.d.ts +50 -21
- package/dist/Calendar/Calendar.torp +21 -14
- package/dist/Calendar/CalendarDay.torp +12 -4
- package/dist/Calendar/index.d.ts +16 -18
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +21 -12
- 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 +49 -73
- package/dist/Dialog/DialogBody.torp +15 -9
- package/dist/Dialog/DialogButton.torp +27 -13
- package/dist/Dialog/DialogFooter.torp +11 -3
- package/dist/Dialog/DialogHeader.torp +15 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +83 -35
- package/dist/Disclosure/Disclosure.torp +34 -25
- package/dist/Disclosure/DisclosureContent.torp +18 -12
- package/dist/Disclosure/DisclosureHeader.torp +16 -9
- package/dist/Disclosure/DisclosureTrigger.torp +15 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +67 -28
- package/dist/Drawer/Drawer.torp +109 -68
- 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 +96 -8
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/Field.torp +91 -0
- package/dist/Form/Form.torp +129 -0
- package/dist/Form/FormTypes.ts +30 -0
- package/dist/Form/Input.torp +97 -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 +131 -0
- package/dist/Form/index.js +22 -0
- package/dist/Form/index.js.map +1 -0
- package/dist/Menu/Menu.torp +25 -15
- package/dist/Menu/MenuButton.torp +30 -13
- package/dist/Menu/MenuCheck.torp +29 -14
- package/dist/Menu/MenuGroup.torp +14 -6
- package/dist/Menu/MenuIndicator.torp +14 -7
- package/dist/Menu/MenuPopout.torp +23 -15
- package/dist/Menu/MenuPopoutContent.torp +17 -10
- package/dist/Menu/MenuPopoutTrigger.torp +23 -16
- package/dist/Menu/MenuRadio.torp +27 -16
- package/dist/Menu/MenuRadioGroup.torp +34 -15
- package/dist/Menu/MenuSeparator.torp +11 -3
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +176 -77
- package/dist/MenuBar/MenuBar.torp +24 -16
- package/dist/MenuBar/MenuBarItem.torp +24 -16
- package/dist/MenuBar/MenuBarItemContent.torp +18 -11
- package/dist/MenuBar/MenuBarItemTrigger.torp +15 -9
- package/dist/MenuBar/index.d.ts +79 -28
- 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 +18 -10
- package/dist/NavMenu/NavMenuButton.torp +15 -10
- package/dist/NavMenu/NavMenuElement.torp +19 -11
- package/dist/NavMenu/NavMenuGroup.torp +13 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +15 -8
- package/dist/NavMenu/NavMenuLink.torp +21 -16
- package/dist/NavMenu/NavMenuPopout.torp +34 -18
- package/dist/NavMenu/NavMenuPopoutButton.torp +23 -18
- package/dist/NavMenu/NavMenuPopoutContent.torp +23 -13
- package/dist/NavMenu/NavMenuSeparator.torp +10 -3
- package/dist/NavMenu/index.d.ts +153 -70
- package/dist/Notification/Notification.torp +35 -16
- package/dist/Notification/NotificationClose.torp +10 -3
- package/dist/Notification/NotificationContainer.torp +11 -3
- package/dist/Notification/NotificationContent.torp +11 -3
- package/dist/Notification/index.d.ts +46 -28
- package/dist/Popover/Popover.torp +48 -28
- package/dist/Popover/PopoverContent.torp +42 -8
- package/dist/Popover/PopoverTrigger.torp +32 -3
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +48 -111
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +20 -11
- package/dist/TabGroup/TabGroup.torp +58 -40
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +26 -10
- package/dist/TabGroup/TabList.torp +14 -7
- package/dist/TabGroup/TabTrigger.torp +17 -10
- package/dist/TabGroup/index.d.ts +101 -35
- package/dist/icons/ArrowDown.torp +5 -3
- package/dist/icons/ArrowLeft.torp +5 -3
- package/dist/icons/ArrowRight.torp +5 -3
- package/dist/icons/ArrowUp.torp +5 -3
- package/dist/icons/Bars.torp +5 -3
- package/dist/icons/Check.torp +5 -3
- package/dist/icons/ChevronDown.torp +5 -3
- package/dist/icons/ChevronLeft.torp +5 -3
- package/dist/icons/ChevronRight.torp +5 -3
- package/dist/icons/ChevronUp.torp +5 -3
- package/dist/icons/Cross.torp +5 -3
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +5 -3
- package/dist/icons/Minus.torp +5 -3
- package/dist/icons/Plus.torp +5 -3
- package/dist/icons/index.d.ts +271 -126
- 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 +28 -12
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +44 -25
- package/src/Accordion/AccordionContent.torp +18 -12
- package/src/Accordion/AccordionHeader.torp +15 -8
- package/src/Accordion/AccordionItem.torp +34 -17
- package/src/Accordion/AccordionTrigger.torp +17 -10
- package/src/Accordion/AccordionTypes.ts +6 -3
- package/src/Breadcrumb/Breadcrumb.torp +18 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +14 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +10 -3
- package/src/Calendar/Calendar.torp +21 -14
- package/src/Calendar/CalendarDay.torp +12 -4
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +21 -12
- 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 +49 -73
- package/src/Dialog/DialogBody.torp +15 -9
- package/src/Dialog/DialogButton.torp +27 -13
- package/src/Dialog/DialogFooter.torp +11 -3
- package/src/Dialog/DialogHeader.torp +15 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +34 -25
- package/src/Disclosure/DisclosureContent.torp +18 -12
- package/src/Disclosure/DisclosureHeader.torp +16 -9
- package/src/Disclosure/DisclosureTrigger.torp +15 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +109 -68
- 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/Field.torp +91 -0
- package/src/Form/Form.torp +129 -0
- package/src/Form/FormTypes.ts +30 -0
- package/src/Form/Input.torp +97 -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 +25 -15
- package/src/Menu/MenuButton.torp +30 -13
- package/src/Menu/MenuCheck.torp +29 -14
- package/src/Menu/MenuGroup.torp +14 -6
- package/src/Menu/MenuIndicator.torp +14 -7
- package/src/Menu/MenuPopout.torp +23 -15
- package/src/Menu/MenuPopoutContent.torp +17 -10
- package/src/Menu/MenuPopoutTrigger.torp +23 -16
- package/src/Menu/MenuRadio.torp +27 -16
- package/src/Menu/MenuRadioGroup.torp +34 -15
- package/src/Menu/MenuSeparator.torp +11 -3
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +24 -16
- package/src/MenuBar/MenuBarItem.torp +24 -16
- package/src/MenuBar/MenuBarItemContent.torp +18 -11
- package/src/MenuBar/MenuBarItemTrigger.torp +15 -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 +18 -10
- package/src/NavMenu/NavMenuButton.torp +15 -10
- package/src/NavMenu/NavMenuElement.torp +19 -11
- package/src/NavMenu/NavMenuGroup.torp +13 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +15 -8
- package/src/NavMenu/NavMenuLink.torp +21 -16
- package/src/NavMenu/NavMenuPopout.torp +34 -18
- package/src/NavMenu/NavMenuPopoutButton.torp +23 -18
- package/src/NavMenu/NavMenuPopoutContent.torp +23 -13
- package/src/NavMenu/NavMenuSeparator.torp +10 -3
- package/src/Notification/Notification.torp +35 -16
- package/src/Notification/NotificationClose.torp +10 -3
- package/src/Notification/NotificationContainer.torp +11 -3
- package/src/Notification/NotificationContent.torp +11 -3
- package/src/Popover/Popover.torp +48 -28
- package/src/Popover/PopoverContent.torp +42 -8
- package/src/Popover/PopoverTrigger.torp +32 -3
- 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 +20 -11
- package/src/TabGroup/TabGroup.torp +58 -40
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +26 -10
- package/src/TabGroup/TabList.torp +14 -7
- package/src/TabGroup/TabTrigger.torp +17 -10
- package/src/icons/ArrowDown.torp +5 -3
- package/src/icons/ArrowLeft.torp +5 -3
- package/src/icons/ArrowRight.torp +5 -3
- package/src/icons/ArrowUp.torp +5 -3
- package/src/icons/Bars.torp +5 -3
- package/src/icons/Check.torp +5 -3
- package/src/icons/ChevronDown.torp +5 -3
- package/src/icons/ChevronLeft.torp +5 -3
- package/src/icons/ChevronRight.torp +5 -3
- package/src/icons/ChevronUp.torp +5 -3
- package/src/icons/Cross.torp +5 -3
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +5 -3
- package/src/icons/Minus.torp +5 -3
- package/src/icons/Plus.torp +5 -3
- 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 -1
- package/test/Accordion/components/AccordionKeyboard.torp +1 -1
- package/test/Accordion/components/AccordionList.torp +1 -1
- package/test/Accordion/components/AccordionMultiple.torp +2 -2
- package/test/Accordion/components/AccordionSingle.torp +2 -2
- 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/accessibility.test.ts +3 -2
- package/test/Disclosure/components/DisclosureTest.torp +1 -1
- package/test/Disclosure/toggle.test.ts +3 -2
- 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 +3 -2
- package/test/Menu/basic.test.ts +11 -10
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/MenuBar/accessibility.test.ts +3 -2
- package/test/MenuBar/basic.test.ts +3 -2
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- 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 -1
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -1
- package/test/TabGroup/components/TabGroupList.torp +1 -1
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -1
- package/tsup.config.ts +3 -1
- package/dist/Popover/PopoverContentAnchored.torp +0 -106
- package/dist/Popover/PopoverOverlay.torp +0 -30
- package/dist/Popover/PopoverTriggerContextual.torp +0 -37
- package/dist/Popover/PopoverTriggerHover.torp +0 -38
- 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 -106
- package/src/Popover/PopoverOverlay.torp +0 -30
- package/src/Popover/PopoverTriggerContextual.torp +0 -37
- package/src/Popover/PopoverTriggerHover.torp +0 -38
- 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
package/dist/Popover/index.js
CHANGED
|
@@ -4,180 +4,18 @@ import Popover_default from "./Popover.torp";
|
|
|
4
4
|
// src/Popover/PopoverContent.torp
|
|
5
5
|
import PopoverContent_default from "./PopoverContent.torp";
|
|
6
6
|
|
|
7
|
-
// src/Popover/PopoverContentAnchored.torp
|
|
8
|
-
import PopoverContentAnchored_default from "./PopoverContentAnchored.torp";
|
|
9
|
-
|
|
10
|
-
// src/Popover/PopoverContentContextual.torp
|
|
11
|
-
import PopoverContentContextual_default from "./PopoverContentContextual.torp";
|
|
12
|
-
|
|
13
|
-
// src/Popover/PopoverOverlay.torp
|
|
14
|
-
import PopoverOverlay_default from "./PopoverOverlay.torp";
|
|
15
|
-
|
|
16
7
|
// src/Popover/PopoverTrigger.torp
|
|
17
8
|
import PopoverTrigger_default from "./PopoverTrigger.torp";
|
|
18
9
|
|
|
19
|
-
// src/Popover/PopoverTriggerContextual.torp
|
|
20
|
-
import PopoverTriggerContextual_default from "./PopoverTriggerContextual.torp";
|
|
21
|
-
|
|
22
|
-
// src/Popover/PopoverTriggerHover.torp
|
|
23
|
-
import PopoverTriggerHover_default from "./PopoverTriggerHover.torp";
|
|
24
|
-
|
|
25
10
|
// src/Popover/showPopover.ts
|
|
26
11
|
function showPopover(popover, anchor, props, target) {
|
|
27
12
|
const allProps = Object.assign({}, props, { anchor });
|
|
28
13
|
popover(target || anchor.parentElement || document.body, null, allProps);
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
// src/Popover/mountClickPopover.ts
|
|
32
|
-
function clickPopover(node, options) {
|
|
33
|
-
const { popover, props } = options;
|
|
34
|
-
node.addEventListener("click", handleClick);
|
|
35
|
-
function handleClick(e) {
|
|
36
|
-
e.preventDefault();
|
|
37
|
-
show();
|
|
38
|
-
}
|
|
39
|
-
let div;
|
|
40
|
-
function show() {
|
|
41
|
-
if (div) {
|
|
42
|
-
document.body.removeChild(div);
|
|
43
|
-
}
|
|
44
|
-
div = document.createElement("div");
|
|
45
|
-
document.body.appendChild(div);
|
|
46
|
-
showPopover(popover, node, props, div);
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
destroy() {
|
|
50
|
-
node.removeEventListener("click", handleClick);
|
|
51
|
-
if (div) {
|
|
52
|
-
document.body.removeChild(div);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/Popover/mountContextPopover.ts
|
|
59
|
-
function contextPopover(node, options) {
|
|
60
|
-
const { popover, props } = options;
|
|
61
|
-
node.addEventListener("contextmenu", handleClick);
|
|
62
|
-
function handleClick(e) {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
show();
|
|
65
|
-
}
|
|
66
|
-
let div;
|
|
67
|
-
function show() {
|
|
68
|
-
if (div) {
|
|
69
|
-
document.body.removeChild(div);
|
|
70
|
-
}
|
|
71
|
-
div = document.createElement("div");
|
|
72
|
-
document.body.appendChild(div);
|
|
73
|
-
showPopover(popover, node, props, div);
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
destroy() {
|
|
77
|
-
node.removeEventListener("contextmenu", handleClick);
|
|
78
|
-
if (div) {
|
|
79
|
-
document.body.removeChild(div);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/mount/hoverTrigger.ts
|
|
86
|
-
function hoverTrigger(node, options) {
|
|
87
|
-
const { onHover, onExit } = options;
|
|
88
|
-
const hoverDelay = options.hoverDelay || 1e3;
|
|
89
|
-
const touchDelay = options.touchDelay || 1e3;
|
|
90
|
-
let interval;
|
|
91
|
-
node.addEventListener("mouseenter", handleMouseEnter);
|
|
92
|
-
node.addEventListener("mouseleave", handleMouseLeave);
|
|
93
|
-
node.addEventListener("mousemove", handleMouseMove);
|
|
94
|
-
node.addEventListener("touchstart", handleMouseEnter);
|
|
95
|
-
node.addEventListener("touchend", handleMouseLeave);
|
|
96
|
-
function handleMouseEnter(e) {
|
|
97
|
-
e.preventDefault();
|
|
98
|
-
if (!interval) {
|
|
99
|
-
const delay = e.type.startsWith("mouse") ? hoverDelay : touchDelay;
|
|
100
|
-
interval = setTimeout(() => onHover(node, e), delay);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function handleMouseLeave(e) {
|
|
104
|
-
if (interval) {
|
|
105
|
-
clearTimeout(interval);
|
|
106
|
-
interval = void 0;
|
|
107
|
-
}
|
|
108
|
-
if (onExit) {
|
|
109
|
-
onExit(node, e);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function handleMouseMove(e) {
|
|
113
|
-
if (interval) {
|
|
114
|
-
clearTimeout(interval);
|
|
115
|
-
interval = setTimeout(() => onHover(node, e), hoverDelay);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return () => {
|
|
119
|
-
node.removeEventListener("mouseenter", handleMouseEnter);
|
|
120
|
-
node.removeEventListener("mouseleave", handleMouseLeave);
|
|
121
|
-
node.removeEventListener("mousemove", handleMouseMove);
|
|
122
|
-
node.removeEventListener("touchstart", handleMouseEnter);
|
|
123
|
-
node.removeEventListener("touchend", handleMouseLeave);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/Popover/mountHoverPopover.ts
|
|
128
|
-
function hoverPopover(node, options) {
|
|
129
|
-
const { popover, props, hoverDelay, touchDelay } = options;
|
|
130
|
-
let div;
|
|
131
|
-
function onHover(node2, e) {
|
|
132
|
-
if (div) {
|
|
133
|
-
document.body.removeChild(div);
|
|
134
|
-
}
|
|
135
|
-
div = document.createElement("div");
|
|
136
|
-
document.body.appendChild(div);
|
|
137
|
-
const rect = node2.getBoundingClientRect();
|
|
138
|
-
let position;
|
|
139
|
-
if (e.type.startsWith("mouse")) {
|
|
140
|
-
const me = e;
|
|
141
|
-
position = { x: me.clientX - rect.left, y: me.clientY - rect.top };
|
|
142
|
-
} else {
|
|
143
|
-
const te = e;
|
|
144
|
-
position = {
|
|
145
|
-
x: te.touches[0].clientX - rect.left,
|
|
146
|
-
y: te.touches[0].clientY - rect.top
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const allProps = Object.assign({}, props, { anchor: node2, position });
|
|
150
|
-
showPopover(popover, node2, allProps, div);
|
|
151
|
-
}
|
|
152
|
-
function onExit() {
|
|
153
|
-
if (div) {
|
|
154
|
-
document.body.removeChild(div);
|
|
155
|
-
div = void 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/Popover/showPopoverPrompt.ts
|
|
162
|
-
function showPopoverPrompt(popover, props, target) {
|
|
163
|
-
return new Promise((resolve) => {
|
|
164
|
-
const allProps = Object.assign({}, props, { callback: resolve });
|
|
165
|
-
popover(target || document.body, null, allProps);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
15
|
export {
|
|
169
16
|
Popover_default as Popover,
|
|
170
17
|
PopoverContent_default as PopoverContent,
|
|
171
|
-
PopoverContentAnchored_default as PopoverContentAnchored,
|
|
172
|
-
PopoverContentContextual_default as PopoverContentContextual,
|
|
173
|
-
PopoverOverlay_default as PopoverOverlay,
|
|
174
18
|
PopoverTrigger_default as PopoverTrigger,
|
|
175
|
-
|
|
176
|
-
PopoverTriggerHover_default as PopoverTriggerHover,
|
|
177
|
-
clickPopover,
|
|
178
|
-
contextPopover,
|
|
179
|
-
hoverPopover,
|
|
180
|
-
showPopover,
|
|
181
|
-
showPopoverPrompt
|
|
19
|
+
showPopover
|
|
182
20
|
};
|
|
183
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Popover/showPopover.ts","../../src/Popover/mountClickPopover.ts","../../src/Popover/mountContextPopover.ts","../../src/mount/hoverTrigger.ts","../../src/Popover/mountHoverPopover.ts","../../src/Popover/showPopoverPrompt.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","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ClickPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when an element is clicked.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function clickPopover(node: HTMLElement, options: ClickPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a click event handler to the node\n\tnode.addEventListener(\"click\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"click\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ContextPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when the user opens an element's context menu.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function contextPopover(node: HTMLElement, options: ContextPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a contextmenu event handler to the node\n\tnode.addEventListener(\"contextmenu\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"contextmenu\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","interface HoverTriggerOptions {\n\tonHover: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\tonExit?: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\nexport default function hoverTrigger(node: HTMLElement, options: HoverTriggerOptions): () => void {\n\tconst { onHover, onExit } = options;\n\tconst hoverDelay = options.hoverDelay || 1000;\n\tconst touchDelay = options.touchDelay || 1000;\n\n\tlet interval: NodeJS.Timeout | undefined;\n\n\t// Add click event handlers to the node\n\tnode.addEventListener(\"mouseenter\", handleMouseEnter);\n\tnode.addEventListener(\"mouseleave\", handleMouseLeave);\n\tnode.addEventListener(\"mousemove\", handleMouseMove);\n\tnode.addEventListener(\"touchstart\", handleMouseEnter);\n\tnode.addEventListener(\"touchend\", handleMouseLeave);\n\n\tfunction handleMouseEnter(e: MouseEvent | TouchEvent) {\n\t\t// Handle the hover after a delay\n\t\te.preventDefault();\n\t\tif (!interval) {\n\t\t\tconst delay = e.type.startsWith(\"mouse\") ? hoverDelay : touchDelay;\n\t\t\tinterval = setTimeout(() => onHover(node, e), delay);\n\t\t}\n\t}\n\n\tfunction handleMouseLeave(e: MouseEvent | TouchEvent) {\n\t\t// Prevent short hovers or touches from firing the event\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = undefined;\n\t\t}\n\n\t\tif (onExit) {\n\t\t\tonExit(node, e);\n\t\t}\n\t}\n\n\tfunction handleMouseMove(e: MouseEvent) {\n\t\t// Reset the interval on mouse move\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = setTimeout(() => onHover(node, e), hoverDelay);\n\t\t}\n\t}\n\n\t// Remove the event listeners from the node on destroy\n\treturn () => {\n\t\tnode.removeEventListener(\"mouseenter\", handleMouseEnter);\n\t\tnode.removeEventListener(\"mouseleave\", handleMouseLeave);\n\t\tnode.removeEventListener(\"mousemove\", handleMouseMove);\n\t\tnode.removeEventListener(\"touchstart\", handleMouseEnter);\n\t\tnode.removeEventListener(\"touchend\", handleMouseLeave);\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport hoverTrigger from \"../mount/hoverTrigger\";\nimport showPopover from \"./showPopover\";\n\ninterface HoverPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\n/**\n * A mount directive for showing a popover when an element is hovered.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component, any props and delays for hover and touch\n */\nexport default function hoverPopover(node: HTMLElement, options: HoverPopoverOptions): () => void {\n\tconst { popover, props, hoverDelay, touchDelay } = options;\n\n\tlet div: HTMLDivElement | undefined;\n\n\tfunction onHover(node: HTMLElement, e: MouseEvent | TouchEvent) {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\t// Get the position relative to the element, so we can reposition on scroll\n\t\tconst rect = node.getBoundingClientRect();\n\t\tlet position: { x: number; y: number };\n\t\tif (e.type.startsWith(\"mouse\")) {\n\t\t\tconst me = e as MouseEvent;\n\t\t\tposition = { x: me.clientX - rect.left, y: me.clientY - rect.top };\n\t\t} else {\n\t\t\tconst te = e as TouchEvent;\n\t\t\tposition = {\n\t\t\t\tx: te.touches[0].clientX - rect.left,\n\t\t\t\ty: te.touches[0].clientY - rect.top,\n\t\t\t};\n\t\t}\n\t\tconst allProps = Object.assign({}, props, { anchor: node, position });\n\n\t\tshowPopover(popover, node, allProps, div);\n\t}\n\n\tfunction onExit() {\n\t\t// Remove the div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t\tdiv = undefined;\n\t\t}\n\t}\n\n\treturn hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code, and asynchronously returns the value selected by the user.\n * @param popover 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 showPopoverPrompt(\n\tpopover: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the callback\n\t\tconst allProps = Object.assign({}, props, { callback: resolve });\n\n\t\t// Create the popover\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tpopover(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":"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","names":["node"]}
|
|
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":";;;;;;;;;;AAWe,SAAR,YACN,SACA,QACA,OACA,QACO;AAEP,QAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC;AAIpD,UAAQ,UAAU,OAAO,iBAAiB,SAAS,MAAM,MAAM,QAAQ;AACxE;","names":[]}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { TabGroupContextName, type TabGroupContext } from "./TabGroupTypes";
|
|
3
3
|
|
|
4
|
+
interface TabContentProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The index of this item */
|
|
10
|
+
index?: number,
|
|
11
|
+
/** The value for this item */
|
|
12
|
+
value?: string,
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
/**
|
|
5
16
|
* Content for a TabGroup, which can be revealed or hidden by an associated TabTrigger.
|
|
6
|
-
*
|
|
7
|
-
* @prop {string} [id] -- An ID for the TabContent's div container
|
|
8
17
|
*/
|
|
9
|
-
export default function TabContent($props:
|
|
10
|
-
|
|
18
|
+
export default function TabContent($props: TabContentProps | undefined) {
|
|
19
|
+
let defaultId = getId();
|
|
11
20
|
|
|
12
21
|
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
13
22
|
if (!context) {
|
|
14
23
|
throw new Error("TabContent must be contained within a TabGroup");
|
|
15
24
|
}
|
|
16
|
-
let $state =
|
|
25
|
+
let $state = context.registerItem($props?.index, $props?.value);
|
|
17
26
|
|
|
18
27
|
// Set the content ID so that it can be used with aria-controls in TabTrigger
|
|
19
|
-
$state.contentId = $props
|
|
28
|
+
$state.contentId = $props?.id ?? defaultId;
|
|
20
29
|
|
|
21
30
|
@render {
|
|
22
31
|
<div
|
|
23
|
-
{$props
|
|
24
|
-
class={`torp-tab-content ${$props
|
|
32
|
+
id={$props?.id ?? defaultId}
|
|
33
|
+
class={`torp-tab-content ${$props?.class ?? ""}`.trim()}
|
|
25
34
|
role="tabpanel"
|
|
26
35
|
aria-labelledby={$state.headerId}
|
|
27
|
-
data-orientation={
|
|
28
|
-
data-state={$state.
|
|
29
|
-
data-disabled={$state.
|
|
36
|
+
data-orientation={context.orientation}
|
|
37
|
+
data-state={$state.active ? "active" : "inactive"}
|
|
38
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
30
39
|
>
|
|
31
40
|
@if ($state.active) {
|
|
32
41
|
<slot />
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { TabGroupContextName, type TabGroupContext, type ItemState } from "./TabGroupTypes";
|
|
2
2
|
|
|
3
|
+
interface TabGroupProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The orientation of the tab buttons, which affects keyboard navigation */
|
|
9
|
+
orientation?: "horizontal" | "vertical",
|
|
10
|
+
/** How tabs are activated; if automatic they are shown on focus, if manual they must be clicked */
|
|
11
|
+
activation?: "automatic" | "manual",
|
|
12
|
+
/** The value of the active TabContent */
|
|
13
|
+
value?: string,
|
|
14
|
+
/** If set to true, the user cannot interact with any items in the TabGroup */
|
|
15
|
+
disabled?: boolean,
|
|
16
|
+
/** Raised when the active item has changed */
|
|
17
|
+
onchange?: (value: string | string[]) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
/**
|
|
4
21
|
* A list of interactive headings coupled with layered sections of content that
|
|
5
22
|
* enable users to reveal a single section of content at a time.
|
|
@@ -18,17 +35,24 @@ import { TabGroupContextName, type TabGroupContext, type ItemState } from "./Tab
|
|
|
18
35
|
* <TabContent />
|
|
19
36
|
* </TabGroup>
|
|
20
37
|
* ```
|
|
21
|
-
*
|
|
22
|
-
* @prop {"horizontal" | "vertical"} orientation -- The orientation of the tab buttons, which affects keyboard navigation
|
|
23
|
-
* @prop {"automatic" | "manual"} activation -- How tabs are activated; if automatic they are shown on focus, if manual they must be clicked
|
|
24
|
-
* @prop {string | string[]} value -- The value of the active TabContent
|
|
25
|
-
* @prop {boolean} disabled -- If set to true, the user cannot interact with any items in the TabGroup
|
|
26
|
-
* @prop {(value: string | string[]) => void} [onchange] -- Raised when the active item has changed
|
|
27
38
|
*/
|
|
28
|
-
export default function TabGroup($props:
|
|
29
|
-
$props
|
|
30
|
-
$props
|
|
31
|
-
|
|
39
|
+
export default function TabGroup($props: TabGroupProps | undefined) {
|
|
40
|
+
let orientation = $props?.orientation ?? "horizontal";
|
|
41
|
+
let activation = $props?.activation ?? "automatic";
|
|
42
|
+
|
|
43
|
+
let $state = $watch({
|
|
44
|
+
value: ""
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Sync props and state
|
|
48
|
+
$run(() => {
|
|
49
|
+
$state.value = $props?.value ?? "";
|
|
50
|
+
});
|
|
51
|
+
$run(() => {
|
|
52
|
+
if ($props !== undefined) {
|
|
53
|
+
$props.value = $state.value;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
32
56
|
|
|
33
57
|
let itemStates: ItemState[] = [];
|
|
34
58
|
|
|
@@ -43,45 +67,39 @@ export default function TabGroup($props: any) {
|
|
|
43
67
|
removeItem,
|
|
44
68
|
triggerItem,
|
|
45
69
|
handleHeaderKey,
|
|
46
|
-
orientation
|
|
47
|
-
activation
|
|
70
|
+
orientation,
|
|
71
|
+
activation,
|
|
48
72
|
};
|
|
49
73
|
$context[TabGroupContextName] = context;
|
|
50
74
|
|
|
51
75
|
$run(() => {
|
|
52
|
-
// HACK: This should probably be done with setters?
|
|
53
|
-
let newValue = $props.value;
|
|
54
|
-
|
|
55
76
|
// Ensure the value passed in was a string (in case e.g. the user has set values to ints)
|
|
56
|
-
|
|
77
|
+
$state.value = $state.value.toString();
|
|
57
78
|
for (let item of itemStates) {
|
|
58
|
-
item.active = item.value ===
|
|
79
|
+
item.active = item.value === $state.value;
|
|
59
80
|
}
|
|
60
|
-
|
|
61
|
-
// Set the value
|
|
62
|
-
$props.value = newValue;
|
|
63
81
|
});
|
|
64
82
|
|
|
65
83
|
$run(() => {
|
|
66
|
-
itemStates.forEach((s) => s.parentDisabled = $props
|
|
84
|
+
itemStates.forEach((s) => s.parentDisabled = $props?.disabled === true);
|
|
67
85
|
});
|
|
68
86
|
|
|
69
87
|
// Dispatch the change event when the value changes
|
|
70
88
|
let firstChange = true;
|
|
71
89
|
$run(() => {
|
|
72
|
-
const ev = $props
|
|
73
|
-
const value = $props
|
|
90
|
+
const ev = $props?.onchange;
|
|
91
|
+
const value = $props?.value;
|
|
74
92
|
if (firstChange) {
|
|
75
93
|
firstChange = false;
|
|
76
94
|
} else if (ev) {
|
|
77
|
-
ev(value);
|
|
95
|
+
ev(value!);
|
|
78
96
|
}
|
|
79
97
|
});
|
|
80
98
|
|
|
81
99
|
// On mount, if no value was set, show the first tab content
|
|
82
100
|
$mount(() => {
|
|
83
|
-
if ($
|
|
84
|
-
$
|
|
101
|
+
if ($state.value === "" && itemStates.length) {
|
|
102
|
+
$state.value = itemStates[0].value;
|
|
85
103
|
}
|
|
86
104
|
});
|
|
87
105
|
|
|
@@ -101,7 +119,7 @@ export default function TabGroup($props: any) {
|
|
|
101
119
|
|
|
102
120
|
function registerItem(index: number | undefined, value: string | undefined): ItemState {
|
|
103
121
|
// If an index wasn't set for the item, set it automatically
|
|
104
|
-
if (
|
|
122
|
+
if (index === undefined) {
|
|
105
123
|
index = nextItemIndex++;
|
|
106
124
|
}
|
|
107
125
|
|
|
@@ -118,7 +136,7 @@ export default function TabGroup($props: any) {
|
|
|
118
136
|
}
|
|
119
137
|
|
|
120
138
|
// If a value wasn't set for the item, set it to the index
|
|
121
|
-
if (
|
|
139
|
+
if (value === undefined) {
|
|
122
140
|
value = index.toString();
|
|
123
141
|
}
|
|
124
142
|
|
|
@@ -127,8 +145,8 @@ export default function TabGroup($props: any) {
|
|
|
127
145
|
index,
|
|
128
146
|
value,
|
|
129
147
|
// TODO: this would be better than using $mount, but it doesn't work with nested tabs
|
|
130
|
-
// active: value === $props
|
|
131
|
-
active: value === $
|
|
148
|
+
// active: value === $props?.value || ($props?.value === "" && index === 0),
|
|
149
|
+
active: value === $state.value,
|
|
132
150
|
headerId: "",
|
|
133
151
|
contentId: "",
|
|
134
152
|
disabled: false,
|
|
@@ -137,8 +155,8 @@ export default function TabGroup($props: any) {
|
|
|
137
155
|
return this.active ? "active" : "inactive";
|
|
138
156
|
},
|
|
139
157
|
setFocused: () => {},
|
|
140
|
-
orientation
|
|
141
|
-
activation
|
|
158
|
+
orientation,
|
|
159
|
+
activation
|
|
142
160
|
});
|
|
143
161
|
itemStates.splice(index, 0, newItemState);
|
|
144
162
|
|
|
@@ -159,7 +177,7 @@ export default function TabGroup($props: any) {
|
|
|
159
177
|
for (let item of itemStates) {
|
|
160
178
|
// The item is active if it has the supplied value
|
|
161
179
|
if (item.value === toggleValue) {
|
|
162
|
-
$
|
|
180
|
+
$state.value = item.value;
|
|
163
181
|
break;
|
|
164
182
|
}
|
|
165
183
|
}
|
|
@@ -169,7 +187,7 @@ export default function TabGroup($props: any) {
|
|
|
169
187
|
switch (e.key) {
|
|
170
188
|
case "Left":
|
|
171
189
|
case "ArrowLeft": {
|
|
172
|
-
if (
|
|
190
|
+
if (orientation === "horizontal" && headerIndex > 0) {
|
|
173
191
|
e.preventDefault();
|
|
174
192
|
itemStates[headerIndex - 1].setFocused();
|
|
175
193
|
}
|
|
@@ -177,7 +195,7 @@ export default function TabGroup($props: any) {
|
|
|
177
195
|
}
|
|
178
196
|
case "Up":
|
|
179
197
|
case "ArrowUp": {
|
|
180
|
-
if (
|
|
198
|
+
if (orientation === "vertical" && headerIndex > 0) {
|
|
181
199
|
e.preventDefault();
|
|
182
200
|
itemStates[headerIndex - 1].setFocused();
|
|
183
201
|
}
|
|
@@ -185,7 +203,7 @@ export default function TabGroup($props: any) {
|
|
|
185
203
|
}
|
|
186
204
|
case "Right":
|
|
187
205
|
case "ArrowRight": {
|
|
188
|
-
if (
|
|
206
|
+
if (orientation === "horizontal" && headerIndex < itemStates.length - 1) {
|
|
189
207
|
e.preventDefault();
|
|
190
208
|
itemStates[headerIndex + 1].setFocused();
|
|
191
209
|
}
|
|
@@ -193,7 +211,7 @@ export default function TabGroup($props: any) {
|
|
|
193
211
|
}
|
|
194
212
|
case "Down":
|
|
195
213
|
case "ArrowDown": {
|
|
196
|
-
if (
|
|
214
|
+
if (orientation === "vertical" && headerIndex < itemStates.length - 1) {
|
|
197
215
|
e.preventDefault();
|
|
198
216
|
itemStates[headerIndex + 1].setFocused();
|
|
199
217
|
}
|
|
@@ -218,9 +236,9 @@ export default function TabGroup($props: any) {
|
|
|
218
236
|
|
|
219
237
|
@render {
|
|
220
238
|
<div
|
|
221
|
-
{$props
|
|
222
|
-
class={`torp-tab-group ${$props
|
|
223
|
-
data-orientation={$props
|
|
239
|
+
{$props?.id}
|
|
240
|
+
class={`torp-tab-group ${$props?.class ?? ""}`.trim()}
|
|
241
|
+
data-orientation={$props?.orientation}
|
|
224
242
|
>
|
|
225
243
|
<slot />
|
|
226
244
|
</div>
|
|
@@ -3,9 +3,13 @@ export const TabItemContextName = "TabItem";
|
|
|
3
3
|
|
|
4
4
|
export interface TabGroupContext {
|
|
5
5
|
/** Called from a header when it is added */
|
|
6
|
-
registerHeader: (
|
|
6
|
+
registerHeader: (
|
|
7
|
+
index: number | undefined,
|
|
8
|
+
value: string | undefined,
|
|
9
|
+
setFocused: () => void,
|
|
10
|
+
) => ItemState;
|
|
7
11
|
/** Called from an item when it is added */
|
|
8
|
-
registerItem: (index: number, value: string) => ItemState;
|
|
12
|
+
registerItem: (index: number | undefined, value: string | undefined) => ItemState;
|
|
9
13
|
/** Called from an item when it is removed */
|
|
10
14
|
removeItem: (index: number) => void;
|
|
11
15
|
/** Called from an item when it is triggered */
|
|
@@ -17,12 +21,14 @@ export interface TabGroupContext {
|
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export interface TabItemContext {
|
|
20
|
-
/**
|
|
24
|
+
/** Raised when an item is triggered */
|
|
21
25
|
triggerItem: (value: string) => void;
|
|
22
|
-
/**
|
|
26
|
+
/** Raised when a TabHeader receives a keyboard event */
|
|
23
27
|
handleHeaderKey: (index: number, e: KeyboardEvent) => void;
|
|
24
28
|
/** The reactive state for an item */
|
|
25
29
|
state: ItemState;
|
|
30
|
+
orientation: "horizontal" | "vertical";
|
|
31
|
+
activation: "automatic" | "manual";
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export interface ItemState {
|
|
@@ -33,7 +39,6 @@ export interface ItemState {
|
|
|
33
39
|
contentId: string;
|
|
34
40
|
disabled: boolean;
|
|
35
41
|
parentDisabled: boolean;
|
|
36
|
-
dataState: "active" | "inactive";
|
|
37
42
|
/** Called in the TabGroup when a header needs to be focused */
|
|
38
43
|
setFocused: () => void;
|
|
39
44
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { TabGroupContextName, TabItemContextName, type TabGroupContext, type TabItemContext } from "./TabGroupTypes";
|
|
2
2
|
|
|
3
|
+
interface TabHeaderProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The type of HTML header to use */
|
|
9
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"
|
|
10
|
+
/** The index of this header's item */
|
|
11
|
+
index?: number,
|
|
12
|
+
/** The value for this header's item */
|
|
13
|
+
value?: string,
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
/**
|
|
4
17
|
* The header for a tab item, which contains the TabTrigger.
|
|
5
18
|
*
|
|
@@ -10,20 +23,22 @@ import { TabGroupContextName, TabItemContextName, type TabGroupContext, type Tab
|
|
|
10
23
|
* <TabTrigger />
|
|
11
24
|
* </TabHeader>
|
|
12
25
|
* ```
|
|
13
|
-
*
|
|
14
|
-
* @prop {"h1" | "h2" | "h3" | "h4" | "h5" | "h6"} as -- The type of HTML header to use
|
|
15
26
|
*/
|
|
16
|
-
export default function TabHeader($props:
|
|
27
|
+
export default function TabHeader($props: TabHeaderProps | undefined) {
|
|
28
|
+
let button: HTMLButtonElement;
|
|
29
|
+
|
|
17
30
|
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
18
31
|
if (!context) {
|
|
19
32
|
throw new Error("TabHeader must be contained within a TabGroup");
|
|
20
33
|
}
|
|
21
|
-
let $state =
|
|
34
|
+
let $state = context.registerHeader($props?.index, $props?.value);
|
|
22
35
|
|
|
23
36
|
const itemContext: TabItemContext = {
|
|
24
37
|
triggerItem: context.triggerItem,
|
|
25
38
|
handleHeaderKey: context.handleHeaderKey,
|
|
26
39
|
state: $state,
|
|
40
|
+
orientation: context.orientation,
|
|
41
|
+
activation: context.activation
|
|
27
42
|
};
|
|
28
43
|
$context[TabItemContextName] = itemContext;
|
|
29
44
|
|
|
@@ -35,16 +50,17 @@ export default function TabHeader($props: any) {
|
|
|
35
50
|
});
|
|
36
51
|
|
|
37
52
|
@render {
|
|
38
|
-
@// TODO: $props
|
|
53
|
+
@// TODO: $props?.as
|
|
39
54
|
<h4
|
|
40
|
-
{$props
|
|
55
|
+
{$props?.id}
|
|
41
56
|
class={[
|
|
42
57
|
"torp-tab-header",
|
|
43
|
-
$props
|
|
44
|
-
|
|
58
|
+
$props?.class,
|
|
59
|
+
context.orientation
|
|
45
60
|
]}
|
|
46
|
-
data-state={$state.
|
|
47
|
-
data-disabled={$state.
|
|
61
|
+
data-state={$state.active ? "active" : "inactive"}
|
|
62
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
63
|
+
&ref={button}
|
|
48
64
|
>
|
|
49
65
|
<slot />
|
|
50
66
|
</h4>
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { TabGroupContextName,
|
|
1
|
+
import { TabGroupContextName, type TabGroupContext } from "./TabGroupTypes";
|
|
2
|
+
|
|
3
|
+
interface TabListProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** An ARIA label for describing the tab list to screen readers */
|
|
9
|
+
ariaLabel?: string,
|
|
10
|
+
}
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* A component that holds the TabHeaders of a TabGroup.
|
|
@@ -12,10 +21,8 @@ import { TabGroupContextName, TabItemContextName, type TabGroupContext, type Tab
|
|
|
12
21
|
* </TabHeader>
|
|
13
22
|
* </TabList>
|
|
14
23
|
* ```
|
|
15
|
-
*
|
|
16
|
-
* @prop {string} ariaLabel -- An ARIA label for describing the tab list to screen readers
|
|
17
24
|
*/
|
|
18
|
-
export default function TabList($props:
|
|
25
|
+
export default function TabList($props: TabListProps | undefined) {
|
|
19
26
|
// Get stuff out of the TabGroupContext
|
|
20
27
|
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
21
28
|
if (!context) {
|
|
@@ -35,10 +42,10 @@ export default function TabList($props: any) {
|
|
|
35
42
|
|
|
36
43
|
@render {
|
|
37
44
|
<div
|
|
38
|
-
{$props
|
|
39
|
-
class={`torp-tab-list ${$props
|
|
45
|
+
{$props?.id}
|
|
46
|
+
class={`torp-tab-list ${$props?.class ?? ""}`.trim()}
|
|
40
47
|
role="tablist"
|
|
41
|
-
aria-label={$props
|
|
48
|
+
aria-label={$props?.ariaLabel}
|
|
42
49
|
aria-orientation={orientation}
|
|
43
50
|
data-orientation={orientation}
|
|
44
51
|
tabindex="0"
|