@torpor/ui 0.3.5 → 0.3.7
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/dist/Chart/BarChart.torp +159 -0
- package/dist/Chart/DataSeries.ts +5 -0
- package/dist/Chart/GridLines.torp +62 -0
- package/dist/Chart/LineChart.torp +196 -0
- package/dist/Chart/PieChart.torp +145 -0
- package/dist/Chart/ScatterChart.torp +215 -0
- package/dist/Chart/SparkLine.torp +71 -0
- package/dist/Chart/XAxis.torp +60 -0
- package/dist/Chart/YAxis.torp +41 -0
- package/dist/Chart/index.d.ts +220 -0
- package/dist/Chart/index.js +34 -0
- package/dist/Chart/index.js.map +1 -0
- package/dist/Form/TextArea.torp +3 -0
- package/dist/Form/index.d.ts +2 -0
- package/dist/metafile-esm.json +1 -1
- package/dist/utils/chartColors.ts +17 -0
- package/dist/utils/chartUtils.ts +71 -0
- package/package.json +10 -3
- package/CHANGELOG.md +0 -344
- package/scripts/postbuild.ts +0 -127
- package/src/Accordion/Accordion.torp +0 -230
- package/src/Accordion/AccordionContent.torp +0 -46
- package/src/Accordion/AccordionHeader.torp +0 -45
- package/src/Accordion/AccordionItem.torp +0 -101
- package/src/Accordion/AccordionTrigger.torp +0 -70
- package/src/Accordion/AccordionTypes.ts +0 -36
- package/src/Accordion/index.ts +0 -7
- package/src/Breadcrumb/Breadcrumb.torp +0 -45
- package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
- package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
- package/src/Breadcrumb/index.ts +0 -5
- package/src/Calendar/Calendar.torp +0 -277
- package/src/Calendar/CalendarDay.torp +0 -78
- package/src/Calendar/CalendarTypes.ts +0 -22
- package/src/Calendar/index.ts +0 -4
- package/src/Contextual/Contextual.torp +0 -129
- package/src/Contextual/ContextualContent.torp +0 -112
- package/src/Contextual/ContextualTrigger.torp +0 -70
- package/src/Contextual/ContextualTypes.ts +0 -30
- package/src/Contextual/index.ts +0 -5
- package/src/Dialog/Dialog.torp +0 -136
- package/src/Dialog/DialogBody.torp +0 -44
- package/src/Dialog/DialogButton.torp +0 -66
- package/src/Dialog/DialogFooter.torp +0 -25
- package/src/Dialog/DialogHeader.torp +0 -45
- package/src/Dialog/DialogTypes.ts +0 -17
- package/src/Dialog/index.ts +0 -7
- package/src/Disclosure/Disclosure.torp +0 -82
- package/src/Disclosure/DisclosureContent.torp +0 -46
- package/src/Disclosure/DisclosureHeader.torp +0 -45
- package/src/Disclosure/DisclosureTrigger.torp +0 -47
- package/src/Disclosure/DisclosureTypes.ts +0 -13
- package/src/Disclosure/index.ts +0 -6
- package/src/Drawer/Drawer.torp +0 -127
- package/src/Drawer/DrawerContent.torp +0 -83
- package/src/Drawer/DrawerOverlay.torp +0 -42
- package/src/Drawer/DrawerTrigger.torp +0 -39
- package/src/Drawer/DrawerTypes.ts +0 -24
- package/src/Drawer/index.ts +0 -6
- package/src/Form/CheckBox.torp +0 -94
- package/src/Form/Field.torp +0 -95
- package/src/Form/File.torp +0 -102
- package/src/Form/Form.torp +0 -147
- package/src/Form/FormTypes.ts +0 -35
- package/src/Form/Hidden.torp +0 -25
- package/src/Form/Input.torp +0 -112
- package/src/Form/Label.torp +0 -35
- package/src/Form/Message.torp +0 -39
- package/src/Form/Option.torp +0 -28
- package/src/Form/Select.torp +0 -101
- package/src/Form/StandardSchemaV1.ts +0 -70
- package/src/Form/TextArea.torp +0 -105
- package/src/Form/index.ts +0 -13
- package/src/Menu/Menu.torp +0 -174
- package/src/Menu/MenuButton.torp +0 -74
- package/src/Menu/MenuCheck.torp +0 -89
- package/src/Menu/MenuGroup.torp +0 -31
- package/src/Menu/MenuIndicator.torp +0 -40
- package/src/Menu/MenuPopout.torp +0 -83
- package/src/Menu/MenuPopoutContent.torp +0 -84
- package/src/Menu/MenuPopoutTrigger.torp +0 -128
- package/src/Menu/MenuRadio.torp +0 -103
- package/src/Menu/MenuRadioGroup.torp +0 -109
- package/src/Menu/MenuSeparator.torp +0 -26
- package/src/Menu/MenuTypes.ts +0 -60
- package/src/Menu/index.ts +0 -25
- package/src/MenuBar/MenuBar.torp +0 -162
- package/src/MenuBar/MenuBarItem.torp +0 -116
- package/src/MenuBar/MenuBarItemContent.torp +0 -119
- package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
- package/src/MenuBar/MenuBarTypes.ts +0 -36
- package/src/MenuBar/index.ts +0 -6
- package/src/Modal/Modal.torp +0 -122
- package/src/Modal/ModalContent.torp +0 -81
- package/src/Modal/ModalOverlay.torp +0 -42
- package/src/Modal/ModalTrigger.torp +0 -54
- package/src/Modal/ModalTypes.ts +0 -22
- package/src/Modal/index.ts +0 -10
- package/src/Modal/showModal.ts +0 -19
- package/src/Modal/showPrompt.ts +0 -23
- package/src/NavMenu/NavMenu.torp +0 -190
- package/src/NavMenu/NavMenuButton.torp +0 -55
- package/src/NavMenu/NavMenuElement.torp +0 -55
- package/src/NavMenu/NavMenuGroup.torp +0 -41
- package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
- package/src/NavMenu/NavMenuLink.torp +0 -60
- package/src/NavMenu/NavMenuPopout.torp +0 -89
- package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
- package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
- package/src/NavMenu/NavMenuSeparator.torp +0 -24
- package/src/NavMenu/NavMenuTypes.ts +0 -32
- package/src/NavMenu/index.ts +0 -23
- package/src/Notification/Notification.torp +0 -71
- package/src/Notification/NotificationClose.torp +0 -39
- package/src/Notification/NotificationContainer.torp +0 -26
- package/src/Notification/NotificationContent.torp +0 -25
- package/src/Notification/NotificationTypes.ts +0 -5
- package/src/Notification/index.ts +0 -13
- package/src/Notification/showNotification.ts +0 -30
- package/src/Popover/Popover.torp +0 -129
- package/src/Popover/PopoverContent.torp +0 -117
- package/src/Popover/PopoverTrigger.torp +0 -62
- package/src/Popover/PopoverTypes.ts +0 -30
- package/src/Popover/index.ts +0 -6
- package/src/Popover/showPopover.ts +0 -24
- package/src/Slider/Slider.torp +0 -84
- package/src/Slider/index.ts +0 -3
- package/src/TabGroup/TabContent.torp +0 -49
- package/src/TabGroup/TabGroup.torp +0 -250
- package/src/TabGroup/TabGroupTypes.ts +0 -44
- package/src/TabGroup/TabHeader.torp +0 -81
- package/src/TabGroup/TabList.torp +0 -61
- package/src/TabGroup/TabTrigger.torp +0 -76
- package/src/TabGroup/index.ts +0 -7
- package/src/ambient.d.ts +0 -7
- package/src/icons/ArrowDown.torp +0 -18
- package/src/icons/ArrowLeft.torp +0 -18
- package/src/icons/ArrowRight.torp +0 -18
- package/src/icons/ArrowUp.torp +0 -18
- package/src/icons/Bars.torp +0 -20
- package/src/icons/Check.torp +0 -18
- package/src/icons/ChevronDown.torp +0 -18
- package/src/icons/ChevronLeft.torp +0 -18
- package/src/icons/ChevronRight.torp +0 -18
- package/src/icons/ChevronUp.torp +0 -18
- package/src/icons/Cross.torp +0 -19
- package/src/icons/IconTypes.ts +0 -10
- package/src/icons/Loading.torp +0 -19
- package/src/icons/Minus.torp +0 -18
- package/src/icons/Plus.torp +0 -19
- package/src/icons/index.ts +0 -31
- package/src/motion/fade.ts +0 -16
- package/src/motion/grow.ts +0 -23
- package/src/motion/index.ts +0 -6
- package/src/motion/measure.ts +0 -28
- package/src/motion/slide.ts +0 -45
- package/src/mount/clickPopover.ts +0 -51
- package/src/mount/contextPopover.ts +0 -51
- package/src/mount/disableScroll.ts +0 -28
- package/src/mount/hoverPopover.ts +0 -58
- package/src/mount/hoverTrigger.ts +0 -59
- package/src/mount/trapFocus.ts +0 -58
- package/src/utils/dateUtils.ts +0 -244
- package/src/utils/documentEvents.ts +0 -17
- package/src/utils/getId.ts +0 -6
- package/src/utils/getScrollParent.ts +0 -22
- package/src/utils/setContextPosition.ts +0 -31
- package/src/utils/setPopoverPosition.ts +0 -142
- package/test/Accordion/accessibility.test.ts +0 -59
- package/test/Accordion/components/AccordionAccessibility.torp +0 -44
- package/test/Accordion/components/AccordionKeyboard.torp +0 -32
- package/test/Accordion/components/AccordionList.torp +0 -23
- package/test/Accordion/components/AccordionMultiple.torp +0 -32
- package/test/Accordion/components/AccordionSingle.torp +0 -32
- package/test/Accordion/for-items.test.ts +0 -52
- package/test/Accordion/keyboard.test.ts +0 -64
- package/test/Accordion/multiple-item-toggle.test.ts +0 -32
- package/test/Accordion/multiple-item-value.test.ts +0 -17
- package/test/Accordion/single-item-toggle.test.ts +0 -31
- package/test/Accordion/single-item-value.test.ts +0 -17
- package/test/Breadcrumb/accessibility.test.ts +0 -29
- package/test/Breadcrumb/basic.test.ts +0 -17
- package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
- package/test/Calendar/components/CalendarTest.torp +0 -9
- package/test/Calendar/default.test.ts +0 -18
- package/test/Dialog/accessibility-alert.test.ts +0 -40
- package/test/Dialog/accessibility-modal.test.ts +0 -52
- package/test/Dialog/components/DialogAccessibility.torp +0 -25
- package/test/Dialog/components/DialogFunction.torp +0 -36
- package/test/Dialog/components/DialogModal.torp +0 -30
- package/test/Dialog/components/DialogVariable.torp +0 -33
- package/test/Dialog/function.test.ts +0 -26
- package/test/Dialog/variable.test.ts +0 -27
- package/test/Disclosure/accessibility.test.ts +0 -31
- package/test/Disclosure/components/DisclosureTest.torp +0 -17
- package/test/Disclosure/default.test.ts +0 -15
- package/test/Disclosure/toggle.test.ts +0 -20
- package/test/Form/components/FieldTest.torp +0 -25
- package/test/Form/components/FormTest.torp +0 -31
- package/test/Form/components/InputTest.torp +0 -9
- package/test/Form/field.test.ts +0 -34
- package/test/Form/form.test.ts +0 -34
- package/test/Form/input.test.ts +0 -19
- package/test/Menu/accessibility.test.ts +0 -83
- package/test/Menu/basic.test.ts +0 -58
- package/test/Menu/components/MenuAccessibility.torp +0 -59
- package/test/Menu/components/MenuBasic.torp +0 -58
- package/test/MenuBar/accessibility.test.ts +0 -87
- package/test/MenuBar/basic.test.ts +0 -22
- package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
- package/test/MenuBar/components/MenuBarBasic.torp +0 -25
- package/test/NavMenu/accessibility.test.ts +0 -97
- package/test/NavMenu/basic.test.ts +0 -22
- package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
- package/test/NavMenu/components/NavMenuBasic.torp +0 -28
- package/test/Notification/accessibility.test.ts +0 -21
- package/test/Notification/components/CustomNotification.torp +0 -14
- package/test/Notification/components/NotificationAccessibility.torp +0 -14
- package/test/Notification/components/NotificationFunction.torp +0 -17
- package/test/Notification/components/NotificationVariable.torp +0 -22
- package/test/Notification/function.test.ts +0 -25
- package/test/Notification/variable.test.ts +0 -25
- package/test/Popover/components/CustomDialog.torp +0 -25
- package/test/Popover/components/PopoverFunction.torp +0 -37
- package/test/Popover/components/PopoverTrigger.torp +0 -36
- package/test/Popover/components/PopoverVariable.torp +0 -40
- package/test/Popover/function.test.ts +0 -21
- package/test/Popover/trigger.test.ts +0 -27
- package/test/Popover/variable.test.ts +0 -27
- package/test/TabGroup/accessibility.test.ts +0 -67
- package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
- package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
- package/test/TabGroup/components/TabGroupList.torp +0 -26
- package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
- package/test/TabGroup/for-items.test.ts +0 -52
- package/test/TabGroup/item-trigger.test.ts +0 -33
- package/test/TabGroup/item-value.test.ts +0 -17
- package/test/TabGroup/keyboard.test.ts +0 -72
- package/tsconfig.json +0 -4
- package/tsup.config.ts +0 -37
- package/vitest.config.ts +0 -12
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Notification from "./Notification.torp";
|
|
2
|
-
import NotificationClose from "./NotificationClose.torp";
|
|
3
|
-
import NotificationContainer from "./NotificationContainer.torp";
|
|
4
|
-
import NotificationContent from "./NotificationContent.torp";
|
|
5
|
-
import showNotification from "./showNotification";
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
Notification,
|
|
9
|
-
NotificationContainer,
|
|
10
|
-
NotificationContent,
|
|
11
|
-
NotificationClose,
|
|
12
|
-
showNotification,
|
|
13
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mount } from "@torpor/view";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shows a notification component in code.
|
|
5
|
-
* @param notification The notification component
|
|
6
|
-
* @param props The properties for the notification component
|
|
7
|
-
* @param target The target element to show the notification in
|
|
8
|
-
*/
|
|
9
|
-
export default function showNotification(notification: any, props: any, target?: Element): void {
|
|
10
|
-
if (!target) {
|
|
11
|
-
// Put the notification in the first NotificationContainer, or the
|
|
12
|
-
// document body if there are no NotificationContainers
|
|
13
|
-
target = document.getElementsByClassName("torp-notification-container")[0];
|
|
14
|
-
if (!target) {
|
|
15
|
-
throw new Error("No notification container found");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// HACK: Should allow mounting in a non-empty container
|
|
20
|
-
// Move existing nodes into a fragment, and add them back after mounting
|
|
21
|
-
var fragment = document.createDocumentFragment();
|
|
22
|
-
while (target.firstChild) {
|
|
23
|
-
fragment.append(target.firstChild);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Create the notification
|
|
27
|
-
mount(target, notification, props);
|
|
28
|
-
|
|
29
|
-
target.prepend(fragment);
|
|
30
|
-
}
|
package/src/Popover/Popover.torp
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { PopoverContextName, type Point, type PopoverContext, type PopoverState } from "./PopoverTypes";
|
|
3
|
-
|
|
4
|
-
interface PopoverProps {
|
|
5
|
-
/** An ID for the root element */
|
|
6
|
-
id?: string;
|
|
7
|
-
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue,
|
|
9
|
-
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue,
|
|
11
|
-
/** Whether the popover is modal. If true, an overlay should be supplied to obscure outside content, and only the popover content will be visible to screen readers */
|
|
12
|
-
modal?: boolean,
|
|
13
|
-
/** Whether the popover is visible */
|
|
14
|
-
visible?: boolean,
|
|
15
|
-
/** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
|
|
16
|
-
anchor?: HTMLElement,
|
|
17
|
-
/** The position to display this popover at if it's contextual, as an alternative to supplying a PopoverTriggerContextual */
|
|
18
|
-
position?: Point,
|
|
19
|
-
/** A function to be called when the user selects a response */
|
|
20
|
-
callback?: ((value: any) => void),
|
|
21
|
-
/** Raised when the popover is opened or closed */
|
|
22
|
-
ontoggle?: (open: boolean) => void,
|
|
23
|
-
/** Raised when the popover has opened */
|
|
24
|
-
onopen?: () => void,
|
|
25
|
-
/** Raised when the popover has closed */
|
|
26
|
-
onclose?: (result: any) => void,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A popover window that is shown to the user relative to an anchor element.
|
|
31
|
-
*
|
|
32
|
-
* The structure of a Popover is:
|
|
33
|
-
*
|
|
34
|
-
* ```
|
|
35
|
-
* <Popover>
|
|
36
|
-
* <PopoverTrigger /> (optional)
|
|
37
|
-
* <PopoverContent />
|
|
38
|
-
* </Popover>
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export default function Popover($props: PopoverProps | undefined) {
|
|
42
|
-
let $state: PopoverState = $watch({
|
|
43
|
-
visible: false,
|
|
44
|
-
position: { x: 0, y: 0 }
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// Sync props and state
|
|
48
|
-
$run(() => {
|
|
49
|
-
$state.visible = $props?.visible ?? false;
|
|
50
|
-
$state.position = $props?.position ?? { x: 0, y: 0 };
|
|
51
|
-
});
|
|
52
|
-
$run(() => {
|
|
53
|
-
if ($props !== undefined) {
|
|
54
|
-
$props.visible = $state.visible;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
let result: any;
|
|
59
|
-
|
|
60
|
-
// Set the context to pass down to items
|
|
61
|
-
let context: PopoverContext = {
|
|
62
|
-
handleButton,
|
|
63
|
-
handleClickOutside,
|
|
64
|
-
state: $state,
|
|
65
|
-
modal: $props?.modal,
|
|
66
|
-
anchorElement: $props?.anchor ? $unwrap($props.anchor) : undefined,
|
|
67
|
-
};
|
|
68
|
-
$context[PopoverContextName] = context;
|
|
69
|
-
|
|
70
|
-
// Dispatch the toggle event when the popover is opened or closed
|
|
71
|
-
let firstToggle = true;
|
|
72
|
-
$run(() => {
|
|
73
|
-
const ontoggle = $props?.ontoggle;
|
|
74
|
-
const onopen = $props?.onopen;
|
|
75
|
-
const onclose = $props?.onclose;
|
|
76
|
-
const visible = $state.visible;
|
|
77
|
-
if (firstToggle) {
|
|
78
|
-
firstToggle = false;
|
|
79
|
-
} else {
|
|
80
|
-
if (ontoggle) ontoggle(visible);
|
|
81
|
-
if (visible) {
|
|
82
|
-
if (onopen) onopen()
|
|
83
|
-
} else {
|
|
84
|
-
if (onclose) onclose(result);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
90
|
-
// Get the button's result
|
|
91
|
-
switch (type) {
|
|
92
|
-
case "confirm": {
|
|
93
|
-
result = value || true;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case "cancel": {
|
|
97
|
-
result = value || false;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
default: {
|
|
101
|
-
result = value;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Hide the popover
|
|
107
|
-
$state.visible = false;
|
|
108
|
-
|
|
109
|
-
// Call the callback
|
|
110
|
-
if ($props?.callback) {
|
|
111
|
-
$props?.callback(result);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function handleClickOutside(e: MouseEvent) {
|
|
116
|
-
e.preventDefault();
|
|
117
|
-
$state.visible = false;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@render {
|
|
121
|
-
<div
|
|
122
|
-
{$props?.id}
|
|
123
|
-
class={["torp-popover", $props?.class]}
|
|
124
|
-
{$props?.style}
|
|
125
|
-
>
|
|
126
|
-
<slot />
|
|
127
|
-
</div>
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
3
|
-
import getScrollParent from "../utils/getScrollParent";
|
|
4
|
-
import setPopoverPosition from "../utils/setPopoverPosition";
|
|
5
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
6
|
-
|
|
7
|
-
interface PopoverContentProps {
|
|
8
|
-
/** An ID for the root element */
|
|
9
|
-
id?: string;
|
|
10
|
-
/** Classes for the root element */
|
|
11
|
-
class?: ClassValue,
|
|
12
|
-
/** Styles for the root element */
|
|
13
|
-
style?: StyleValue,
|
|
14
|
-
/** Where the popover will be shown, relative to the popover trigger */
|
|
15
|
-
side?: "top" | "right" | "bottom" | "left",
|
|
16
|
-
/** How the popover will be aligned, relative to the popover trigger */
|
|
17
|
-
alignment?: "start" | "center" | "end",
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The content that is displayed for a Popover when it is open, displayed
|
|
22
|
-
* alongside an element.
|
|
23
|
-
*/
|
|
24
|
-
export default function PopoverContent($props?: PopoverContentProps | undefined) {
|
|
25
|
-
let div: HTMLDivElement;
|
|
26
|
-
let shown = false;
|
|
27
|
-
let closeOnClick = false;
|
|
28
|
-
|
|
29
|
-
// Get stuff out of the PopoverContext
|
|
30
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error("PopoverContent must be contained within a Popover");
|
|
33
|
-
}
|
|
34
|
-
let $state = context.state;
|
|
35
|
-
|
|
36
|
-
$run(() => {
|
|
37
|
-
if (!$state.visible) {
|
|
38
|
-
hide();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function show() {
|
|
43
|
-
shown = true;
|
|
44
|
-
|
|
45
|
-
// HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
|
|
46
|
-
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
47
|
-
closeOnClick = false;
|
|
48
|
-
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
49
|
-
addDocumentEvent("click", handleDocumentClick);
|
|
50
|
-
|
|
51
|
-
// Set the position and listen for window resize and scroll to reset the position
|
|
52
|
-
setPosition();
|
|
53
|
-
const anchorElement = context.anchorElement!
|
|
54
|
-
const scrollParent = getScrollParent(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 anchorElement = context.anchorElement!
|
|
70
|
-
const scrollParent = getScrollParent(anchorElement)
|
|
71
|
-
scrollParent.removeEventListener("resize", setPosition);
|
|
72
|
-
scrollParent.removeEventListener("scroll", setPosition);
|
|
73
|
-
if (anchorElement.focus) {
|
|
74
|
-
anchorElement.focus();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function handleDocumentMouseDown() {
|
|
79
|
-
closeOnClick = true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function handleDocumentClick(e: MouseEvent) {
|
|
83
|
-
if (
|
|
84
|
-
closeOnClick &&
|
|
85
|
-
div &&
|
|
86
|
-
!div.contains(e.target as HTMLElement) &&
|
|
87
|
-
(!context.anchorElement || !context.anchorElement.contains(e.target as HTMLElement))
|
|
88
|
-
) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
context.handleClickOutside!(e);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function setPosition() {
|
|
95
|
-
if (!context.anchorElement) {
|
|
96
|
-
throw new Error("Popover must have an anchor element");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let side = $props?.side ?? "bottom";
|
|
100
|
-
let alignment = $props?.alignment ?? "center";
|
|
101
|
-
setPopoverPosition(context.anchorElement, div, side, alignment);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@render {
|
|
105
|
-
@if ($state.visible) {
|
|
106
|
-
<div
|
|
107
|
-
{$props?.id}
|
|
108
|
-
class={["torp-popover-content", $props?.class]}
|
|
109
|
-
{$props?.style}
|
|
110
|
-
&ref={div}
|
|
111
|
-
onmount={show}
|
|
112
|
-
>
|
|
113
|
-
<slot />
|
|
114
|
-
</div>
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
|
|
3
|
-
import hoverTrigger from "../mount/hoverTrigger";
|
|
4
|
-
|
|
5
|
-
interface PopoverTriggerProps {
|
|
6
|
-
/** An ID for the root element */
|
|
7
|
-
id?: string;
|
|
8
|
-
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue,
|
|
10
|
-
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue,
|
|
12
|
-
/** Whether the popover is activated by click/press or by hover **/
|
|
13
|
-
activation?: "press" | "hover"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The button that causes a Popover to appear or disappear.
|
|
18
|
-
*/
|
|
19
|
-
export default function PopoverTrigger($props: PopoverTriggerProps | undefined) {
|
|
20
|
-
let activation = $props?.activation ?? "press";
|
|
21
|
-
|
|
22
|
-
// Get stuff out of the PopoverContext
|
|
23
|
-
const context = $context[PopoverContextName] as PopoverContext;
|
|
24
|
-
if (!context) {
|
|
25
|
-
throw new Error("PopoverTrigger must be contained within a Popover");
|
|
26
|
-
}
|
|
27
|
-
let $state = context.state;
|
|
28
|
-
|
|
29
|
-
function handleClick() {
|
|
30
|
-
if (activation !== "press") return;
|
|
31
|
-
|
|
32
|
-
$state.visible = !$state.visible;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function handleHover(node: HTMLElement, e: MouseEvent) {
|
|
36
|
-
if (activation !== "hover") return;
|
|
37
|
-
|
|
38
|
-
if ($state.position) {
|
|
39
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
40
|
-
const rect = node.getBoundingClientRect();
|
|
41
|
-
const x = e.clientX - rect.left;
|
|
42
|
-
const y = e.clientY - rect.top;
|
|
43
|
-
$state.position = { x, y };
|
|
44
|
-
//$state.position = { x: window.scrollX + e.clientX, y: window.scrollY + e.clientY };
|
|
45
|
-
}
|
|
46
|
-
$state.visible = !$state.visible
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@render {
|
|
50
|
-
<button
|
|
51
|
-
type="button"
|
|
52
|
-
{$props?.id}
|
|
53
|
-
class={["torp-popover-trigger", $props?.class]}
|
|
54
|
-
{$props?.style}
|
|
55
|
-
onclick={handleClick}
|
|
56
|
-
onmount={(el) => hoverTrigger(el, { onHover: handleHover, onExit: handleHover })}
|
|
57
|
-
&ref={context.anchorElement}
|
|
58
|
-
>
|
|
59
|
-
<slot />
|
|
60
|
-
</button>
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const PopoverContextName = "Popover";
|
|
2
|
-
|
|
3
|
-
/** The shared context for popover components (Contextual, Prompt and Popover) */
|
|
4
|
-
export interface PopoverContext {
|
|
5
|
-
handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
|
|
6
|
-
// HACK: We need to be able to let children (i.e. Dialogs) override the click outside functionality
|
|
7
|
-
// There may be a more elegant way to accomplish this too
|
|
8
|
-
handleClickOutside?: (e: MouseEvent) => void;
|
|
9
|
-
state: PopoverState;
|
|
10
|
-
//modal: boolean;
|
|
11
|
-
anchorElement?: HTMLElement;
|
|
12
|
-
// HACK: focusFirstElement is necessary because if we focus the first element e.g. in a Dialog's
|
|
13
|
-
// onMount, it will scroll the page to the focused element and mess up our careful positioning
|
|
14
|
-
// We need to be able to manually set the order to
|
|
15
|
-
// 1. set visible (so we have an element with content)
|
|
16
|
-
// 2. set position (so the element is in the right place)
|
|
17
|
-
// 3. set focus (for accessibility)
|
|
18
|
-
// There may be a more elegant way to accomplish this!
|
|
19
|
-
focusFirstElement?: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface PopoverState {
|
|
23
|
-
visible: boolean;
|
|
24
|
-
position: Point;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface Point {
|
|
28
|
-
x: number;
|
|
29
|
-
y: number;
|
|
30
|
-
}
|
package/src/Popover/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// TODO: Allow passing in a variable -- so that you can show an inline popover
|
|
2
|
-
import type { Component } from "@torpor/view";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Shows a popover component in code.
|
|
6
|
-
* @param popover The popover component
|
|
7
|
-
* @param anchor The element to use as an anchor for the popover component
|
|
8
|
-
* @param props The properties for the popover component
|
|
9
|
-
* @param target The target element to show the popover in
|
|
10
|
-
* @returns The value selected by the user
|
|
11
|
-
*/
|
|
12
|
-
export default function showPopover(
|
|
13
|
-
popover: Component,
|
|
14
|
-
anchor: HTMLElement,
|
|
15
|
-
props?: Record<PropertyKey, any>,
|
|
16
|
-
target?: Element,
|
|
17
|
-
): void {
|
|
18
|
-
// Add the anchor element to the properties
|
|
19
|
-
const allProps = Object.assign({}, props, { anchor });
|
|
20
|
-
|
|
21
|
-
// Create the popover
|
|
22
|
-
// TODO: This needs to clean up after itself, like the mount methods do
|
|
23
|
-
popover(target || anchor.parentElement || document.body, null, allProps);
|
|
24
|
-
}
|
package/src/Slider/Slider.torp
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export default function Slider($props: any | undefined) {
|
|
2
|
-
//export let value = 0;
|
|
3
|
-
//export let total = 0;
|
|
4
|
-
|
|
5
|
-
let position = 0;
|
|
6
|
-
let dragging = false;
|
|
7
|
-
let background: HTMLElement;
|
|
8
|
-
let handle: HTMLElement;
|
|
9
|
-
let skipRecalc = false;
|
|
10
|
-
|
|
11
|
-
$mount(() => {
|
|
12
|
-
calculatePosition();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
beforeUpdate(() => {
|
|
16
|
-
if (background && handle) {
|
|
17
|
-
if (skipRecalc) {
|
|
18
|
-
skipRecalc = false;
|
|
19
|
-
} else {
|
|
20
|
-
calculatePosition();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function calculatePosition() {
|
|
26
|
-
// Calculate the initial handle position
|
|
27
|
-
const handleRect = handle.getBoundingClientRect();
|
|
28
|
-
const backgroundRect = background.getBoundingClientRect();
|
|
29
|
-
const offsetX = (value / total) * backgroundRect.width;
|
|
30
|
-
position = offsetX - handleRect.width / 2;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function handleMouseDown() {
|
|
34
|
-
dragging = true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function handleMouseUp() {
|
|
38
|
-
dragging = false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function handleMouseMove(e: MouseEvent) {
|
|
42
|
-
if (!e.buttons) {
|
|
43
|
-
dragging = false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (dragging) {
|
|
47
|
-
const handleRect = handle.getBoundingClientRect();
|
|
48
|
-
const backgroundRect = background.getBoundingClientRect();
|
|
49
|
-
let offsetX = e.clientX - backgroundRect.left;
|
|
50
|
-
|
|
51
|
-
const minWidth = handleRect.width / 2;
|
|
52
|
-
const maxWidth = backgroundRect.width - handleRect.width / 2;
|
|
53
|
-
|
|
54
|
-
if (offsetX < minWidth) {
|
|
55
|
-
offsetX = minWidth;
|
|
56
|
-
value = 0;
|
|
57
|
-
} else if (offsetX > maxWidth) {
|
|
58
|
-
offsetX = maxWidth;
|
|
59
|
-
value = total;
|
|
60
|
-
} else {
|
|
61
|
-
const width = backgroundRect.width - handleRect.width;
|
|
62
|
-
value = Math.floor((total / width) * offsetX);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
position = offsetX - handleRect.width / 2;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Don't recalc with the value change - we know where everything should be
|
|
69
|
-
skipRecalc = true;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@render {
|
|
73
|
-
<div
|
|
74
|
-
{$props?.id}
|
|
75
|
-
class={["torp-slider", $props?.class]}
|
|
76
|
-
{$props?.style}
|
|
77
|
-
onmousemove={handleMouseMove}
|
|
78
|
-
onmouseup={handleMouseUp}
|
|
79
|
-
>
|
|
80
|
-
<div &ref={background} />
|
|
81
|
-
<div &ref={handle} style={`left: ${position}px;`} onmousedown={handleMouseDown} />
|
|
82
|
-
</div>
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/Slider/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import getId from "../utils/getId";
|
|
3
|
-
import { TabGroupContextName, type TabGroupContext } from "./TabGroupTypes";
|
|
4
|
-
|
|
5
|
-
interface TabContentProps {
|
|
6
|
-
/** An ID for the root element */
|
|
7
|
-
id?: string;
|
|
8
|
-
/** Classes for the root element */
|
|
9
|
-
class?: ClassValue,
|
|
10
|
-
/** Styles for the root element */
|
|
11
|
-
style?: StyleValue,
|
|
12
|
-
/** The index of this item */
|
|
13
|
-
index?: number,
|
|
14
|
-
/** The value for this item */
|
|
15
|
-
value?: string,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Content for a TabGroup, which can be revealed or hidden by an associated TabTrigger.
|
|
20
|
-
*/
|
|
21
|
-
export default function TabContent($props: TabContentProps | undefined) {
|
|
22
|
-
let defaultId = getId();
|
|
23
|
-
|
|
24
|
-
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
25
|
-
if (!context) {
|
|
26
|
-
throw new Error("TabContent must be contained within a TabGroup");
|
|
27
|
-
}
|
|
28
|
-
let $state = context.registerItem($props?.index, $props?.value);
|
|
29
|
-
|
|
30
|
-
// Set the content ID so that it can be used with aria-controls in TabTrigger
|
|
31
|
-
$state.contentId = $props?.id ?? defaultId;
|
|
32
|
-
|
|
33
|
-
@render {
|
|
34
|
-
<div
|
|
35
|
-
id={$props?.id ?? defaultId}
|
|
36
|
-
class={["torp-tab-content", $props?.class]}
|
|
37
|
-
{$props?.style}
|
|
38
|
-
role="tabpanel"
|
|
39
|
-
aria-labelledby={$state.headerId}
|
|
40
|
-
data-orientation={context.orientation}
|
|
41
|
-
data-state={$state.active ? "active" : "inactive"}
|
|
42
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
43
|
-
>
|
|
44
|
-
@if ($state.active) {
|
|
45
|
-
<slot />
|
|
46
|
-
}
|
|
47
|
-
</div>
|
|
48
|
-
}
|
|
49
|
-
}
|