@torpor/ui 0.3.5 → 0.3.6
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/metafile-esm.json +1 -1
- package/package.json +5 -2
- 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,66 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { DialogContextName, type DialogContext } from "./DialogTypes";
|
|
3
|
-
|
|
4
|
-
interface DialogButtonProps {
|
|
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
|
-
/** The value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover */
|
|
12
|
-
value?: any,
|
|
13
|
-
/** "confirm" if the button should respond to the Enter key or "cancel" if the button should respond to the Escape key */
|
|
14
|
-
type?: "confirm" | "cancel",
|
|
15
|
-
/** Whether this button is disabled */
|
|
16
|
-
disabled?: boolean,
|
|
17
|
-
/** Raised when the button is clicked */
|
|
18
|
-
onclick?: (e: MouseEvent) => void,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A button that is placed in a DialogFooter and signals a response by a user.
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export default function DialogButton($props: DialogButtonProps | undefined) {
|
|
26
|
-
let button: HTMLButtonElement;
|
|
27
|
-
|
|
28
|
-
// Get stuff out of the DialogContext
|
|
29
|
-
const context = $context[DialogContextName] as DialogContext;
|
|
30
|
-
if (!context) {
|
|
31
|
-
throw new Error("DialogButton must be contained within a Dialog");
|
|
32
|
-
}
|
|
33
|
-
const handleButton = context.handleButton;
|
|
34
|
-
|
|
35
|
-
$mount(() => {
|
|
36
|
-
// Store the confirm or cancel button in the DialogContext
|
|
37
|
-
if ($props?.type === "confirm") {
|
|
38
|
-
context.confirmButton = button;
|
|
39
|
-
} else if ($props?.type === "cancel") {
|
|
40
|
-
context.cancelButton = button;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
function handleClick(e: MouseEvent) {
|
|
45
|
-
if ($props?.onclick) {
|
|
46
|
-
$props?.onclick(e)
|
|
47
|
-
}
|
|
48
|
-
if (handleButton) {
|
|
49
|
-
handleButton($props?.type, $props?.value);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@render {
|
|
54
|
-
<button
|
|
55
|
-
type="button"
|
|
56
|
-
{$props?.id}
|
|
57
|
-
class={["torp-dialog-button", $props?.class]}
|
|
58
|
-
{$props?.style}
|
|
59
|
-
disabled={$props?.disabled}
|
|
60
|
-
onclick={handleClick}
|
|
61
|
-
&ref={button}
|
|
62
|
-
>
|
|
63
|
-
<slot />
|
|
64
|
-
</button>
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
|
|
3
|
-
interface DialogFooterProps {
|
|
4
|
-
/** An ID for the root element */
|
|
5
|
-
id?: string;
|
|
6
|
-
/** Classes for the root element */
|
|
7
|
-
class?: ClassValue,
|
|
8
|
-
/** Styles for the root element */
|
|
9
|
-
style?: StyleValue,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The footer for a Dialog, which may contain one or more DialogButtons.
|
|
14
|
-
*/
|
|
15
|
-
export default function DialogFooter($props: DialogFooterProps | undefined) {
|
|
16
|
-
@render {
|
|
17
|
-
<div
|
|
18
|
-
{$props?.id}
|
|
19
|
-
class={["torp-dialog-footer", $props?.class]}
|
|
20
|
-
{$props?.style}
|
|
21
|
-
>
|
|
22
|
-
<slot />
|
|
23
|
-
</div>
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import getId from "../utils/getId";
|
|
3
|
-
import { DialogContextName, type DialogContext } from "./DialogTypes";
|
|
4
|
-
|
|
5
|
-
interface DialogHeaderProps {
|
|
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 header will be announced by screen readers when the Dialog is opened */
|
|
13
|
-
ariaAnnounce?: boolean,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The header for a Dialog. Content in the header will be announced by screen
|
|
18
|
-
* readers when the Dialog is opened, unless ariaAnnounce is false.
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export default function DialogHeader($props: DialogHeaderProps | undefined) {
|
|
22
|
-
let defaultId = getId();
|
|
23
|
-
|
|
24
|
-
// Get stuff out of the DialogContext
|
|
25
|
-
const context = $context[DialogContextName] as DialogContext;
|
|
26
|
-
if (!context) {
|
|
27
|
-
throw new Error("DialogHeader must be contained within a Dialog");
|
|
28
|
-
}
|
|
29
|
-
let $state = context.state;
|
|
30
|
-
|
|
31
|
-
// Set the header id for using in the Dialog's ARIA attributes
|
|
32
|
-
if ($props?.ariaAnnounce !== false) {
|
|
33
|
-
$state.headerId = $props?.id ?? defaultId;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@render {
|
|
37
|
-
<div
|
|
38
|
-
id={$props?.id ?? defaultId}
|
|
39
|
-
class={["torp-dialog-footer", $props?.class]}
|
|
40
|
-
{$props?.style}
|
|
41
|
-
>
|
|
42
|
-
<slot />
|
|
43
|
-
</div>
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const DialogContextName = "Dialog";
|
|
2
|
-
|
|
3
|
-
export type HandleButtonPress = (type: "confirm" | "cancel" | undefined, value?: any) => void;
|
|
4
|
-
|
|
5
|
-
export interface DialogContext {
|
|
6
|
-
handleButton?: HandleButtonPress;
|
|
7
|
-
state: DialogState;
|
|
8
|
-
anchorElement?: HTMLElement;
|
|
9
|
-
confirmButton?: HTMLButtonElement;
|
|
10
|
-
cancelButton?: HTMLButtonElement;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface DialogState {
|
|
14
|
-
dialogId: string;
|
|
15
|
-
headerId: string;
|
|
16
|
-
bodyId: string;
|
|
17
|
-
}
|
package/src/Dialog/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Dialog from "./Dialog.torp";
|
|
2
|
-
import DialogBody from "./DialogBody.torp";
|
|
3
|
-
import DialogButton from "./DialogButton.torp";
|
|
4
|
-
import DialogFooter from "./DialogFooter.torp";
|
|
5
|
-
import DialogHeader from "./DialogHeader.torp";
|
|
6
|
-
|
|
7
|
-
export { Dialog, DialogHeader, DialogBody, DialogFooter, DialogButton };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { DisclosureContextName, type DisclosureContext, type DisclosureState } from "./DisclosureTypes";
|
|
3
|
-
|
|
4
|
-
interface DisclosureProps {
|
|
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 disclosure is expanded and its content visible */
|
|
12
|
-
expanded?: boolean,
|
|
13
|
-
/** If set to true, the user cannot interact with this disclosure */
|
|
14
|
-
disabled?: boolean,
|
|
15
|
-
/** Raised when the disclosure is opened or closed */
|
|
16
|
-
ontoggle?: (open: boolean) => void,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* An interactive header that enables users to reveal or hide an associated section of content.
|
|
21
|
-
*
|
|
22
|
-
* See [the WAI ARIA guidelines for Disclosures](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/).
|
|
23
|
-
*
|
|
24
|
-
* The structure of a Disclosure is:
|
|
25
|
-
*
|
|
26
|
-
* ```
|
|
27
|
-
* <Disclosure>
|
|
28
|
-
* <DisclosureHeader>
|
|
29
|
-
* <DisclosureTrigger />
|
|
30
|
-
* </DisclosureHeader>
|
|
31
|
-
* <DisclosureContent />
|
|
32
|
-
* </Disclosure>
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export default function Disclosure($props: DisclosureProps | undefined) {
|
|
36
|
-
let $state: DisclosureState = $watch({
|
|
37
|
-
expanded: false,
|
|
38
|
-
disabled: false,
|
|
39
|
-
headerId: "",
|
|
40
|
-
contentId: "",
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Update $state with $props
|
|
44
|
-
$run(() => {
|
|
45
|
-
$state.expanded = $props?.expanded === true ||
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
$props?.expanded === "true";
|
|
48
|
-
$state.disabled = $props?.disabled === true ||
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
$props?.disabled === "true";
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Put stuff into a DisclosureContext
|
|
54
|
-
const itemContext: DisclosureContext = {
|
|
55
|
-
state: $state,
|
|
56
|
-
};
|
|
57
|
-
$context[DisclosureContextName] = itemContext;
|
|
58
|
-
|
|
59
|
-
// Dispatch the toggle event when the value of expanded changes
|
|
60
|
-
let firstToggle = true;
|
|
61
|
-
$run(() => {
|
|
62
|
-
const ev = $props?.ontoggle;
|
|
63
|
-
const expanded = $state.expanded;
|
|
64
|
-
if (firstToggle) {
|
|
65
|
-
firstToggle = false;
|
|
66
|
-
} else if (ev) {
|
|
67
|
-
ev(expanded);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
@render {
|
|
72
|
-
<div
|
|
73
|
-
{$props?.id}
|
|
74
|
-
class={["torp-disclosure-item", $props?.class]}
|
|
75
|
-
{$props?.style}
|
|
76
|
-
data-state={$state.expanded ? "open" : "closed"}
|
|
77
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
78
|
-
>
|
|
79
|
-
<slot />
|
|
80
|
-
</div>
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import getId from "../utils/getId";
|
|
3
|
-
import { DisclosureContextName, type DisclosureContext } from "./DisclosureTypes";
|
|
4
|
-
|
|
5
|
-
interface DisclosureContentProps {
|
|
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 this content should act as a region. Set this when the content contains heading elements or a nested Disclosure */
|
|
13
|
-
ariaRegion?: boolean,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Content for a Disclosure, which can be revealed or hidden by an associated DisclosureTrigger.
|
|
18
|
-
*/
|
|
19
|
-
export default function DisclosureContent($props: DisclosureContentProps | undefined) {
|
|
20
|
-
let defaultId = getId();
|
|
21
|
-
|
|
22
|
-
const context = $context[DisclosureContextName] as DisclosureContext;
|
|
23
|
-
if (!context) {
|
|
24
|
-
throw new Error("DisclosureContent must be contained within a Disclosure");
|
|
25
|
-
}
|
|
26
|
-
let $state = context.state
|
|
27
|
-
|
|
28
|
-
// Set the content ID so that it can be used with aria-controls in DisclosureTrigger
|
|
29
|
-
$state.contentId = $props?.id ?? defaultId;
|
|
30
|
-
|
|
31
|
-
@render {
|
|
32
|
-
<div
|
|
33
|
-
id={$props?.id ?? defaultId}
|
|
34
|
-
class={["torp-disclosure-content", $props?.class]}
|
|
35
|
-
{$props?.style}
|
|
36
|
-
role={$props?.ariaRegion ? "region" : undefined}
|
|
37
|
-
aria-labelledby={$state.headerId}
|
|
38
|
-
data-state={$state.expanded ? "open" : "closed"}
|
|
39
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
40
|
-
>
|
|
41
|
-
@if ($state.expanded) {
|
|
42
|
-
<slot />
|
|
43
|
-
}
|
|
44
|
-
</div>
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { DisclosureContextName, type DisclosureContext } from "./DisclosureTypes";
|
|
3
|
-
|
|
4
|
-
interface DisclosureHeaderProps {
|
|
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
|
-
/** The type of HTML header to use */
|
|
12
|
-
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The header for a Disclosure, which contains the DisclosureTrigger.
|
|
17
|
-
*
|
|
18
|
-
* The structure of a DisclosureHeader is:
|
|
19
|
-
*
|
|
20
|
-
* ```
|
|
21
|
-
* <DisclosureHeader>
|
|
22
|
-
* <DisclosureTrigger />
|
|
23
|
-
* </DisclosureHeader>
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export default function DisclosureHeader($props: DisclosureHeaderProps | undefined) {
|
|
27
|
-
const context = $context[DisclosureContextName] as DisclosureContext;
|
|
28
|
-
if (!context) {
|
|
29
|
-
throw new Error("DisclosureHeader must be contained within a Disclosure");
|
|
30
|
-
}
|
|
31
|
-
let $state = context.state
|
|
32
|
-
|
|
33
|
-
@render {
|
|
34
|
-
@// TODO: $props.as
|
|
35
|
-
<h4
|
|
36
|
-
{$props?.id}
|
|
37
|
-
class={["torp-disclosure-header", $props?.class]}
|
|
38
|
-
{$props?.style}
|
|
39
|
-
data-state={$state.expanded ? "open" : "closed"}
|
|
40
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
41
|
-
>
|
|
42
|
-
<slot />
|
|
43
|
-
</h4>
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import getId from "../utils/getId";
|
|
3
|
-
import { DisclosureContextName, type DisclosureContext } from "./DisclosureTypes";
|
|
4
|
-
|
|
5
|
-
interface DisclosureTriggerProps {
|
|
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
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A header button for a Disclosure, which can be used to reveal or hide an associated DisclosureContent.
|
|
16
|
-
*/
|
|
17
|
-
export default function DisclosureTrigger($props: DisclosureTriggerProps | undefined) {
|
|
18
|
-
let defaultId = getId();
|
|
19
|
-
|
|
20
|
-
// Get stuff out of the DisclosureContext
|
|
21
|
-
const context = $context[DisclosureContextName] as DisclosureContext;
|
|
22
|
-
if (!context) {
|
|
23
|
-
throw new Error("DisclosureTrigger must be contained within a Disclosure");
|
|
24
|
-
}
|
|
25
|
-
let $state = context.state;
|
|
26
|
-
|
|
27
|
-
// Set the header ID so that it can be used with aria-labelledby in DisclosureContent
|
|
28
|
-
$state.headerId = $props?.id ?? defaultId;
|
|
29
|
-
|
|
30
|
-
@render {
|
|
31
|
-
<button
|
|
32
|
-
type="button"
|
|
33
|
-
id={$props?.id ?? defaultId}
|
|
34
|
-
class={["torp-disclosure-trigger", $props?.class]}
|
|
35
|
-
{$props?.style}
|
|
36
|
-
disabled={$state.disabled}
|
|
37
|
-
aria-expanded={$state.expanded.toString()}
|
|
38
|
-
aria-disabled={$state.disabled}
|
|
39
|
-
aria-controls={$state.contentId}
|
|
40
|
-
data-state={$state.expanded ? "open" : "closed"}
|
|
41
|
-
data-disabled={$state.disabled}
|
|
42
|
-
onclick={() => $state.expanded = !$state.expanded}
|
|
43
|
-
>
|
|
44
|
-
<slot />
|
|
45
|
-
</button>
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const DisclosureContextName = "Disclosure";
|
|
2
|
-
|
|
3
|
-
export interface DisclosureContext {
|
|
4
|
-
/** The reactive state for a Disclosure */
|
|
5
|
-
state: DisclosureState;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface DisclosureState {
|
|
9
|
-
headerId: string;
|
|
10
|
-
contentId: string;
|
|
11
|
-
expanded: boolean;
|
|
12
|
-
disabled: boolean;
|
|
13
|
-
}
|
package/src/Disclosure/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import Disclosure from "./Disclosure.torp";
|
|
2
|
-
import DisclosureContent from "./DisclosureContent.torp";
|
|
3
|
-
import DisclosureHeader from "./DisclosureHeader.torp";
|
|
4
|
-
import DisclosureTrigger from "./DisclosureTrigger.torp";
|
|
5
|
-
|
|
6
|
-
export { Disclosure, DisclosureHeader, DisclosureTrigger, DisclosureContent };
|
package/src/Drawer/Drawer.torp
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { DrawerContextName, type DrawerContext, type DrawerState } from "./DrawerTypes";
|
|
3
|
-
|
|
4
|
-
interface DrawerProps {
|
|
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 drawer is modal. If true, an overlay should be supplied to obscure outside content, and only the drawer content will be visible to screen readers */
|
|
12
|
-
modal?: boolean,
|
|
13
|
-
/** Whether the drawer is visible */
|
|
14
|
-
visible?: boolean,
|
|
15
|
-
/** Which side of the window to show the drawer from */
|
|
16
|
-
position?: "left" | "right" | "top" | "bottom",
|
|
17
|
-
/** A function to be called when the user selects a response */
|
|
18
|
-
callback?: ((value: any) => void),
|
|
19
|
-
/** Raised when the drawer is opened or closed */
|
|
20
|
-
ontoggle?: (open: boolean) => void,
|
|
21
|
-
/** Raised when the drawer has opened */
|
|
22
|
-
onopen?: () => void,
|
|
23
|
-
/** Raised when the drawer has closed */
|
|
24
|
-
onclose?: (result: any) => void,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A drawer that can be used to show rich content or obtain information from a user.
|
|
29
|
-
*
|
|
30
|
-
* See [the WAI ARIA guidelines for Dialogs](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
|
|
31
|
-
*
|
|
32
|
-
* The structure of a Drawer is:
|
|
33
|
-
*
|
|
34
|
-
* ```
|
|
35
|
-
* <Drawer>
|
|
36
|
-
* <DrawerTrigger /> (optional)
|
|
37
|
-
* <DrawerContent />
|
|
38
|
-
* </Drawer>
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export default function Drawer($props: DrawerProps | undefined) {
|
|
42
|
-
let $state: DrawerState = $watch({
|
|
43
|
-
visible: false,
|
|
44
|
-
modal: $props?.modal ?? false,
|
|
45
|
-
position: $props?.position ?? "left",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Sync props and state
|
|
49
|
-
$run(() => {
|
|
50
|
-
$state.visible = $props?.visible ?? false;
|
|
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: DrawerContext = {
|
|
62
|
-
handleButton,
|
|
63
|
-
handleClickOutside,
|
|
64
|
-
state: $state,
|
|
65
|
-
};
|
|
66
|
-
$context[DrawerContextName] = context;
|
|
67
|
-
|
|
68
|
-
// Dispatch the toggle event when the drawer is opened or closed
|
|
69
|
-
let firstToggle = true;
|
|
70
|
-
$run(() => {
|
|
71
|
-
const ontoggle = $props?.ontoggle;
|
|
72
|
-
const onopen = $props?.onopen;
|
|
73
|
-
const onclose = $props?.onclose;
|
|
74
|
-
const visible = $state.visible;
|
|
75
|
-
if (firstToggle) {
|
|
76
|
-
firstToggle = false;
|
|
77
|
-
} else {
|
|
78
|
-
if (ontoggle) ontoggle(visible);
|
|
79
|
-
if (visible) {
|
|
80
|
-
if (onopen) onopen()
|
|
81
|
-
} else {
|
|
82
|
-
if (onclose) onclose(result);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
88
|
-
// Get the button's result
|
|
89
|
-
switch (type) {
|
|
90
|
-
case "confirm": {
|
|
91
|
-
result = value || true;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case "cancel": {
|
|
95
|
-
result = value || false;
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
default: {
|
|
99
|
-
result = value;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Hide the drawer
|
|
105
|
-
$state.visible = false;
|
|
106
|
-
|
|
107
|
-
// Call the callback
|
|
108
|
-
if ($props?.callback) {
|
|
109
|
-
$props?.callback(result);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function handleClickOutside(e: MouseEvent) {
|
|
114
|
-
e.preventDefault();
|
|
115
|
-
$state.visible = false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@render {
|
|
119
|
-
<div
|
|
120
|
-
{$props?.id}
|
|
121
|
-
class={["torp-drawer", $props?.class]}
|
|
122
|
-
{$props?.style}
|
|
123
|
-
>
|
|
124
|
-
<slot />
|
|
125
|
-
</div>
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { slide } from "../motion";
|
|
3
|
-
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
4
|
-
import { DrawerContextName, type DrawerContext } from "./DrawerTypes";
|
|
5
|
-
|
|
6
|
-
interface DrawerContentProps {
|
|
7
|
-
/** An ID for the root element */
|
|
8
|
-
id?: string;
|
|
9
|
-
/** Classes for the root element */
|
|
10
|
-
class?: ClassValue,
|
|
11
|
-
/** Styles for the root element */
|
|
12
|
-
style?: StyleValue,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The content that is displayed for a Drawer when it is open.
|
|
17
|
-
*/
|
|
18
|
-
export default function DrawerContent($props: DrawerContentProps | undefined) {
|
|
19
|
-
let drawer: HTMLElement;
|
|
20
|
-
let shown = false;
|
|
21
|
-
let closeOnClick = false;
|
|
22
|
-
|
|
23
|
-
// Get stuff out of the DrawerContext
|
|
24
|
-
const context = $context[DrawerContextName] as DrawerContext;
|
|
25
|
-
if (!context) {
|
|
26
|
-
throw new Error("DrawerContent must be contained within a Drawer");
|
|
27
|
-
}
|
|
28
|
-
let $state = context.state;
|
|
29
|
-
|
|
30
|
-
$run(() => {
|
|
31
|
-
if (!$state.visible) {
|
|
32
|
-
hide();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
function show() {
|
|
37
|
-
shown = true;
|
|
38
|
-
|
|
39
|
-
// HACK: Because this Drawer could be shown with a click, we need to wait for another mousedown
|
|
40
|
-
// before we close on click. Otherwise the click immediately bubbles to the document
|
|
41
|
-
closeOnClick = false;
|
|
42
|
-
addDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
43
|
-
addDocumentEvent("click", handleDocumentClick);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function hide() {
|
|
47
|
-
if (!shown) return;
|
|
48
|
-
|
|
49
|
-
removeDocumentEvent("mousedown", handleDocumentMouseDown);
|
|
50
|
-
removeDocumentEvent("click", handleDocumentClick);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function handleDocumentMouseDown() {
|
|
54
|
-
closeOnClick = true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function handleDocumentClick(e: MouseEvent) {
|
|
58
|
-
if (
|
|
59
|
-
closeOnClick &&
|
|
60
|
-
drawer &&
|
|
61
|
-
!drawer.contains(e.target as HTMLElement)
|
|
62
|
-
) {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
context.handleClickOutside!(e);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@render {
|
|
69
|
-
@if ($state.visible) {
|
|
70
|
-
<div
|
|
71
|
-
{$props?.id}
|
|
72
|
-
class={["torp-drawer-content", $props?.class]}
|
|
73
|
-
{$props?.style}
|
|
74
|
-
style="position: fixed;"
|
|
75
|
-
transition={(e) => slide(e, { side: $state.position })}
|
|
76
|
-
&ref={drawer}
|
|
77
|
-
onmount={show}
|
|
78
|
-
>
|
|
79
|
-
<slot />
|
|
80
|
-
</div>
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { disableScroll } from "../mount/disableScroll";
|
|
3
|
-
import { DrawerContextName, type DrawerContext } from "./DrawerTypes";
|
|
4
|
-
|
|
5
|
-
interface DrawerOverlayProps {
|
|
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
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The background overlay for a Drawer component.
|
|
16
|
-
* Adding an overlay automatically sets the component's `modal` value to true.
|
|
17
|
-
*/
|
|
18
|
-
export default function DrawerOverlay($props: DrawerOverlayProps | undefined) {
|
|
19
|
-
// Get stuff out of the DrawerContext
|
|
20
|
-
const context = $context[DrawerContextName] as DrawerContext;
|
|
21
|
-
if (!context) {
|
|
22
|
-
throw new Error("DrawerOverlay must be contained within a Drawer");
|
|
23
|
-
}
|
|
24
|
-
let $state = context.state;
|
|
25
|
-
|
|
26
|
-
// Any drawer with an overlay is modal
|
|
27
|
-
$state.modal = true;
|
|
28
|
-
|
|
29
|
-
@render {
|
|
30
|
-
@if ($state.visible) {
|
|
31
|
-
<div
|
|
32
|
-
{$props?.id}
|
|
33
|
-
class={["torp-drawer-overlay", $props?.class]}
|
|
34
|
-
{$props?.style}
|
|
35
|
-
tabindex="-1"
|
|
36
|
-
onmount={(el) => disableScroll(el)}
|
|
37
|
-
>
|
|
38
|
-
<slot />
|
|
39
|
-
</div>
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|