@torpor/ui 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/dist/Accordion/Accordion.torp +25 -13
- package/dist/Accordion/AccordionContent.torp +15 -8
- package/dist/Accordion/AccordionHeader.torp +16 -7
- package/dist/Accordion/AccordionItem.torp +24 -10
- package/dist/Accordion/AccordionTrigger.torp +16 -8
- package/dist/Accordion/AccordionTypes.ts +2 -0
- package/dist/Accordion/index.d.ts +157 -0
- package/dist/Breadcrumb/Breadcrumb.torp +42 -0
- package/dist/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/dist/Breadcrumb/index.d.ts +84 -0
- package/dist/Breadcrumb/index.js +14 -0
- package/dist/Calendar/Calendar.torp +273 -0
- package/dist/Calendar/CalendarDay.torp +75 -0
- package/dist/Calendar/CalendarTypes.ts +22 -0
- package/dist/Calendar/index.d.ts +36 -0
- package/dist/Calendar/index.js +10 -0
- package/dist/Calendar/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +16 -6
- package/dist/Dialog/DialogBody.torp +13 -5
- package/dist/Dialog/DialogButton.torp +18 -6
- package/dist/Dialog/DialogFooter.torp +13 -3
- package/dist/Dialog/DialogHeader.torp +13 -4
- package/dist/Dialog/index.d.ts +135 -0
- package/dist/Disclosure/Disclosure.torp +79 -0
- package/dist/Disclosure/DisclosureContent.torp +43 -0
- package/dist/Disclosure/DisclosureHeader.torp +43 -0
- package/dist/Disclosure/DisclosureTrigger.torp +44 -0
- package/dist/Disclosure/DisclosureTypes.ts +14 -0
- package/dist/Disclosure/index.d.ts +113 -0
- package/dist/Disclosure/index.js +18 -0
- package/dist/Disclosure/index.js.map +1 -0
- package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +20 -19
- package/dist/Drawer/index.d.ts +21 -0
- package/dist/Drawer/index.js +6 -0
- package/dist/Drawer/index.js.map +1 -0
- package/dist/Form/Field.torp +93 -0
- package/dist/Form/Form.torp +131 -0
- package/dist/Form/FormTypes.ts +30 -0
- package/dist/Form/Input.torp +94 -0
- package/dist/Form/Label.torp +31 -0
- package/dist/Form/Message.torp +35 -0
- package/dist/Form/StandardSchemaV1.ts +70 -0
- package/dist/Form/index.d.ts +117 -0
- package/dist/Form/index.js +22 -0
- package/dist/Form/index.js.map +1 -0
- package/dist/Menu/Menu.torp +169 -0
- package/dist/Menu/MenuButton.torp +64 -0
- package/dist/Menu/MenuCheck.torp +81 -0
- package/dist/Menu/MenuGroup.torp +29 -0
- package/dist/Menu/MenuIndicator.torp +38 -0
- package/dist/Menu/MenuPopout.torp +82 -0
- package/dist/Menu/MenuPopoutContent.torp +83 -0
- package/dist/Menu/MenuPopoutTrigger.torp +126 -0
- package/dist/Menu/MenuRadio.torp +99 -0
- package/dist/Menu/MenuRadioGroup.torp +97 -0
- package/dist/Menu/MenuSeparator.torp +24 -0
- package/dist/Menu/MenuTypes.ts +58 -0
- package/dist/Menu/index.d.ts +293 -0
- package/dist/Menu/index.js +46 -0
- package/dist/Menu/index.js.map +1 -0
- package/dist/MenuBar/MenuBar.torp +159 -0
- package/dist/MenuBar/MenuBarItem.torp +115 -0
- package/dist/MenuBar/MenuBarItemContent.torp +117 -0
- package/dist/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/dist/MenuBar/MenuBarTypes.ts +36 -0
- package/dist/MenuBar/index.d.ts +125 -0
- package/dist/MenuBar/index.js +18 -0
- package/dist/MenuBar/index.js.map +1 -0
- package/dist/NavMenu/NavMenu.torp +15 -6
- package/dist/NavMenu/NavMenuButton.torp +14 -7
- package/dist/NavMenu/NavMenuElement.torp +16 -8
- package/dist/NavMenu/NavMenuGroup.torp +14 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/dist/NavMenu/NavMenuLink.torp +18 -10
- package/dist/NavMenu/NavMenuPopout.torp +13 -5
- package/dist/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/dist/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/dist/NavMenu/NavMenuSeparator.torp +12 -3
- package/dist/NavMenu/index.d.ts +259 -0
- package/dist/Notification/Notification.torp +58 -0
- package/dist/Notification/NotificationClose.torp +37 -0
- package/dist/Notification/NotificationContainer.torp +24 -0
- package/dist/Notification/NotificationContent.torp +23 -0
- package/dist/Notification/NotificationTypes.ts +5 -0
- package/dist/Notification/index.d.ts +92 -0
- package/dist/Notification/index.js +36 -0
- package/dist/Notification/index.js.map +1 -0
- package/dist/Notification/showNotification.ts +30 -0
- package/dist/Popover/Popover.torp +22 -8
- package/dist/Popover/PopoverContent.torp +41 -29
- package/dist/Popover/PopoverContentAnchored.torp +52 -44
- package/dist/Popover/PopoverContentContextual.torp +49 -37
- package/dist/Popover/PopoverOverlay.torp +13 -4
- package/dist/Popover/PopoverTrigger.torp +12 -3
- package/dist/Popover/PopoverTriggerContextual.torp +12 -3
- package/dist/Popover/PopoverTriggerHover.torp +14 -5
- package/dist/Popover/index.d.ts +191 -0
- package/dist/TabGroup/TabContent.torp +13 -7
- package/dist/TabGroup/TabGroup.torp +23 -11
- package/dist/TabGroup/TabHeader.torp +16 -7
- package/dist/TabGroup/TabList.torp +15 -6
- package/dist/TabGroup/TabTrigger.torp +14 -6
- package/dist/TabGroup/index.d.ts +150 -0
- package/dist/icons/ArrowDown.torp +15 -0
- package/dist/icons/ArrowLeft.torp +15 -0
- package/dist/icons/ArrowRight.torp +15 -0
- package/dist/icons/ArrowUp.torp +15 -0
- package/dist/icons/Bars.torp +17 -0
- package/dist/icons/Check.torp +15 -0
- package/dist/icons/ChevronDown.torp +15 -0
- package/dist/icons/ChevronLeft.torp +15 -0
- package/dist/icons/ChevronRight.torp +15 -0
- package/dist/icons/ChevronUp.torp +15 -0
- package/dist/icons/Cross.torp +16 -0
- package/dist/icons/Loading.torp +16 -0
- package/dist/icons/Minus.torp +15 -0
- package/dist/icons/Plus.torp +16 -0
- package/dist/icons/index.d.ts +142 -0
- package/dist/icons/index.js +58 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/{motion.d.cts → index.d.ts} +2 -2
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +7 -0
- package/dist/motion/index.d.ts +2 -0
- package/dist/{motion.js → motion/index.js} +1 -1
- package/dist/motion/index.js.map +1 -0
- package/dist/mount/index.d.ts +2 -0
- package/dist/utils/dateUtils.ts +244 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/setPopoverPosition.ts +4 -0
- package/package.json +60 -35
- package/scripts/postbuild.ts +42 -5
- package/src/Accordion/Accordion.torp +25 -13
- package/src/Accordion/AccordionContent.torp +15 -8
- package/src/Accordion/AccordionHeader.torp +16 -7
- package/src/Accordion/AccordionItem.torp +24 -10
- package/src/Accordion/AccordionTrigger.torp +16 -8
- package/src/Accordion/AccordionTypes.ts +2 -0
- package/src/Breadcrumb/Breadcrumb.torp +42 -0
- package/src/Breadcrumb/BreadcrumbItem.torp +28 -0
- package/src/Breadcrumb/BreadcrumbSeparator.torp +25 -0
- package/src/Breadcrumb/index.ts +5 -0
- package/src/Calendar/Calendar.torp +273 -0
- package/src/Calendar/CalendarDay.torp +75 -0
- package/src/Calendar/CalendarTypes.ts +22 -0
- package/src/Calendar/index.ts +4 -0
- package/src/Dialog/Dialog.torp +16 -6
- package/src/Dialog/DialogBody.torp +13 -5
- package/src/Dialog/DialogButton.torp +18 -6
- package/src/Dialog/DialogFooter.torp +13 -3
- package/src/Dialog/DialogHeader.torp +13 -4
- package/src/Disclosure/Disclosure.torp +79 -0
- package/src/Disclosure/DisclosureContent.torp +43 -0
- package/src/Disclosure/DisclosureHeader.torp +43 -0
- package/src/Disclosure/DisclosureTrigger.torp +44 -0
- package/src/Disclosure/DisclosureTypes.ts +14 -0
- package/src/Disclosure/index.ts +6 -0
- package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +20 -19
- package/src/Drawer/index.ts +3 -0
- package/src/Form/Field.torp +93 -0
- package/src/Form/Form.torp +131 -0
- package/src/Form/FormTypes.ts +30 -0
- package/src/Form/Input.torp +94 -0
- package/src/Form/Label.torp +31 -0
- package/src/Form/Message.torp +35 -0
- package/src/Form/StandardSchemaV1.ts +70 -0
- package/src/Form/index.ts +7 -0
- package/src/Menu/Menu.torp +169 -0
- package/src/Menu/MenuButton.torp +64 -0
- package/src/Menu/MenuCheck.torp +81 -0
- package/src/Menu/MenuGroup.torp +29 -0
- package/src/Menu/MenuIndicator.torp +38 -0
- package/src/Menu/MenuPopout.torp +82 -0
- package/src/Menu/MenuPopoutContent.torp +83 -0
- package/src/Menu/MenuPopoutTrigger.torp +126 -0
- package/src/Menu/MenuRadio.torp +99 -0
- package/src/Menu/MenuRadioGroup.torp +97 -0
- package/src/Menu/MenuSeparator.torp +24 -0
- package/src/Menu/MenuTypes.ts +58 -0
- package/src/Menu/index.ts +25 -0
- package/src/MenuBar/MenuBar.torp +159 -0
- package/src/MenuBar/MenuBarItem.torp +115 -0
- package/src/MenuBar/MenuBarItemContent.torp +117 -0
- package/src/MenuBar/MenuBarItemTrigger.torp +98 -0
- package/src/MenuBar/MenuBarTypes.ts +36 -0
- package/src/MenuBar/index.ts +6 -0
- package/src/NavMenu/NavMenu.torp +15 -6
- package/src/NavMenu/NavMenuButton.torp +14 -7
- package/src/NavMenu/NavMenuElement.torp +16 -8
- package/src/NavMenu/NavMenuGroup.torp +14 -5
- package/src/NavMenu/NavMenuGroupHeader.torp +14 -6
- package/src/NavMenu/NavMenuLink.torp +18 -10
- package/src/NavMenu/NavMenuPopout.torp +13 -5
- package/src/NavMenu/NavMenuPopoutButton.torp +17 -11
- package/src/NavMenu/NavMenuPopoutContent.torp +42 -30
- package/src/NavMenu/NavMenuSeparator.torp +12 -3
- package/src/Notification/Notification.torp +58 -0
- package/src/Notification/NotificationClose.torp +37 -0
- package/src/Notification/NotificationContainer.torp +24 -0
- package/src/Notification/NotificationContent.torp +23 -0
- package/src/Notification/NotificationTypes.ts +5 -0
- package/src/Notification/index.ts +13 -0
- package/src/Notification/showNotification.ts +30 -0
- package/src/Popover/Popover.torp +22 -8
- package/src/Popover/PopoverContent.torp +41 -29
- package/src/Popover/PopoverContentAnchored.torp +52 -44
- package/src/Popover/PopoverContentContextual.torp +49 -37
- package/src/Popover/PopoverOverlay.torp +13 -4
- package/src/Popover/PopoverTrigger.torp +12 -3
- package/src/Popover/PopoverTriggerContextual.torp +12 -3
- package/src/Popover/PopoverTriggerHover.torp +14 -5
- package/src/Slider/Slider.torp +83 -0
- package/src/Slider/index.ts +3 -0
- package/src/TabGroup/TabContent.torp +13 -7
- package/src/TabGroup/TabGroup.torp +23 -11
- package/src/TabGroup/TabHeader.torp +16 -7
- package/src/TabGroup/TabList.torp +15 -6
- package/src/TabGroup/TabTrigger.torp +14 -6
- package/src/icons/ArrowDown.torp +15 -0
- package/src/icons/ArrowLeft.torp +15 -0
- package/src/icons/ArrowRight.torp +15 -0
- package/src/icons/ArrowUp.torp +15 -0
- package/src/icons/Bars.torp +17 -0
- package/src/icons/Check.torp +15 -0
- package/src/icons/ChevronDown.torp +15 -0
- package/src/icons/ChevronLeft.torp +15 -0
- package/src/icons/ChevronRight.torp +15 -0
- package/src/icons/ChevronUp.torp +15 -0
- package/src/icons/Cross.torp +16 -0
- package/src/icons/Loading.torp +16 -0
- package/src/icons/Minus.torp +15 -0
- package/src/icons/Plus.torp +16 -0
- package/src/icons/index.ts +31 -0
- package/src/motion/fade.ts +2 -2
- package/src/motion/index.ts +3 -0
- package/src/utils/dateUtils.ts +244 -0
- package/src/utils/setPopoverPosition.ts +4 -0
- package/test/Accordion/components/AccordionAccessibility.torp +2 -0
- package/test/Accordion/components/AccordionKeyboard.torp +2 -0
- package/test/Accordion/components/AccordionList.torp +2 -0
- package/test/Accordion/components/AccordionMultiple.torp +2 -0
- package/test/Accordion/components/AccordionSingle.torp +2 -0
- package/test/Breadcrumb/accessibility.test.ts +29 -0
- package/test/Breadcrumb/basic.test.ts +17 -0
- package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
- package/test/Calendar/components/CalendarTest.torp +9 -0
- package/test/Calendar/default.test.ts +18 -0
- package/test/Dialog/components/DialogAccessibility.torp +5 -5
- package/test/Disclosure/accessibility.test.ts +31 -0
- package/test/Disclosure/components/DisclosureTest.torp +19 -0
- package/test/Disclosure/default.test.ts +15 -0
- package/test/Disclosure/toggle.test.ts +20 -0
- package/test/Form/components/FieldTest.torp +25 -0
- package/test/Form/components/FormTest.torp +31 -0
- package/test/Form/components/InputTest.torp +9 -0
- package/test/Form/field.test.ts +34 -0
- package/test/Form/form.test.ts +34 -0
- package/test/Form/input.test.ts +19 -0
- package/test/Menu/accessibility.test.ts +83 -0
- package/test/Menu/basic.test.ts +58 -0
- package/test/Menu/components/MenuAccessibility.torp +59 -0
- package/test/Menu/components/MenuBasic.torp +58 -0
- package/test/MenuBar/accessibility.test.ts +87 -0
- package/test/MenuBar/basic.test.ts +22 -0
- package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
- package/test/MenuBar/components/MenuBarBasic.torp +25 -0
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- package/test/Notification/accessibility.test.ts +21 -0
- package/test/Notification/components/CustomNotification.torp +14 -0
- package/test/Notification/components/NotificationAccessibility.torp +14 -0
- package/test/Notification/components/NotificationFunction.torp +20 -0
- package/test/Notification/components/NotificationVariable.torp +22 -0
- package/test/Notification/function.test.ts +25 -0
- package/test/Notification/variable.test.ts +25 -0
- package/test/Popover/components/CustomDialog.torp +25 -0
- package/test/Popover/components/PromptFunction.torp +19 -0
- package/test/Popover/components/PromptVariable.torp +38 -0
- package/test/Popover/function.test.ts +26 -0
- package/test/Popover/variable.test.ts +27 -0
- package/test/TabGroup/components/TabGroupAccessibility.torp +2 -0
- package/test/TabGroup/components/TabGroupKeyboard.torp +2 -0
- package/test/TabGroup/components/TabGroupList.torp +2 -0
- package/test/TabGroup/components/TabGroupTrigger.torp +2 -0
- package/tsup.config.ts +12 -4
- package/dist/Accordion/index.cjs +0 -53
- package/dist/Accordion/index.cjs.map +0 -1
- package/dist/Dialog/index.cjs +0 -53
- package/dist/Dialog/index.cjs.map +0 -1
- package/dist/NavMenu/index.cjs +0 -78
- package/dist/NavMenu/index.cjs.map +0 -1
- package/dist/Offscreen/index.cjs +0 -33
- package/dist/Offscreen/index.cjs.map +0 -1
- package/dist/Offscreen/index.js +0 -6
- package/dist/Popover/index.cjs +0 -222
- package/dist/Popover/index.cjs.map +0 -1
- package/dist/TabGroup/index.cjs +0 -53
- package/dist/TabGroup/index.cjs.map +0 -1
- package/dist/metafile-cjs.json +0 -1
- package/dist/motion.cjs +0 -34
- package/dist/motion.cjs.map +0 -1
- package/dist/motion.d.ts +0 -6
- package/dist/motion.js.map +0 -1
- package/src/Accordion.ts +0 -7
- package/src/Dialog.ts +0 -7
- package/src/NavMenu.ts +0 -23
- package/src/Offscreen/index.ts +0 -3
- package/src/Popover.ts +0 -29
- package/src/TabGroup.ts +0 -7
- package/src/motion.ts +0 -3
- /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface BreadcrumbProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** An ARIA label for describing the popover to screen readers */
|
|
10
|
+
ariaLabel?: string | undefined,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* A list of links to the parent pages of the current page in hierarchical order.
|
|
16
|
+
*
|
|
17
|
+
* See [the WAI ARIA guidelines for Breadcrumbs](https://www.w3.org/WAI/ARIA/apg/patterns/breadcrumb/).
|
|
18
|
+
*
|
|
19
|
+
* The structure of a Breadcrumb is:
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* <Breadcrumb>
|
|
23
|
+
* <BreadcrumbItem />
|
|
24
|
+
* <BreadcrumbSeparator /> (optional)
|
|
25
|
+
* <BreadcrumbItem />
|
|
26
|
+
* ...
|
|
27
|
+
* </Breadcrumb>
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* You can separate BreadcrumbItems using BreadcrumbSeparators or by using CSS.
|
|
31
|
+
*/
|
|
32
|
+
declare function Breadcrumb(
|
|
33
|
+
$parent: ParentNode,
|
|
34
|
+
$anchor: Node | null,
|
|
35
|
+
$props: BreadcrumbProps,
|
|
36
|
+
$context?: Record<PropertyKey, any>,
|
|
37
|
+
$slots?: Record<string, SlotRender>,
|
|
38
|
+
): void;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
interface BreadcrumbItemProps {
|
|
43
|
+
/** An ID for the root element */
|
|
44
|
+
id?: string;
|
|
45
|
+
/** Class name(s) for the root element */
|
|
46
|
+
class?: string,
|
|
47
|
+
/** Whether this is the current page */
|
|
48
|
+
current?: boolean,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An item in a breadcrumb, containing a link to one of the parent pages of the
|
|
53
|
+
* current page (or the current page).
|
|
54
|
+
*/
|
|
55
|
+
declare function BreadcrumbItem(
|
|
56
|
+
$parent: ParentNode,
|
|
57
|
+
$anchor: Node | null,
|
|
58
|
+
$props: BreadcrumbItemProps,
|
|
59
|
+
$context?: Record<PropertyKey, any>,
|
|
60
|
+
$slots?: Record<string, SlotRender>,
|
|
61
|
+
): void;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
interface BreadcrumbSeparatorProps {
|
|
66
|
+
/** An ID for the root element */
|
|
67
|
+
id?: string;
|
|
68
|
+
/** Class name(s) for the root element */
|
|
69
|
+
class?: string,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A separator between links in a Breadcrumb component. It is hidden from
|
|
74
|
+
* screen readers.
|
|
75
|
+
*/
|
|
76
|
+
declare function BreadcrumbSeparator(
|
|
77
|
+
$parent: ParentNode,
|
|
78
|
+
$anchor: Node | null,
|
|
79
|
+
$props: BreadcrumbSeparatorProps,
|
|
80
|
+
$context?: Record<PropertyKey, any>,
|
|
81
|
+
$slots?: Record<string, SlotRender>,
|
|
82
|
+
): void;
|
|
83
|
+
|
|
84
|
+
export { Breadcrumb, BreadcrumbItem, BreadcrumbSeparator };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/Breadcrumb/Breadcrumb.torp
|
|
2
|
+
import Breadcrumb_default from "./Breadcrumb.torp";
|
|
3
|
+
|
|
4
|
+
// src/Breadcrumb/BreadcrumbItem.torp
|
|
5
|
+
import BreadcrumbItem_default from "./BreadcrumbItem.torp";
|
|
6
|
+
|
|
7
|
+
// src/Breadcrumb/BreadcrumbSeparator.torp
|
|
8
|
+
import BreadcrumbSeparator_default from "./BreadcrumbSeparator.torp";
|
|
9
|
+
export {
|
|
10
|
+
Breadcrumb_default as Breadcrumb,
|
|
11
|
+
BreadcrumbItem_default as BreadcrumbItem,
|
|
12
|
+
BreadcrumbSeparator_default as BreadcrumbSeparator
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { ReactiveDate } from "@torpor/view";
|
|
2
|
+
import { areDatesEqual, dayNames, monthNames } from "../utils/dateUtils";
|
|
3
|
+
import CalendarDay from "./CalendarDay.torp";
|
|
4
|
+
import { type CalendarContext, type DayState, type CalendarEvent, CalendarContextName } from "./CalendarTypes";
|
|
5
|
+
import ChevronLeft from "../icons/ChevronLeft.torp";
|
|
6
|
+
import ChevronRight from "../icons/ChevronRight.torp";
|
|
7
|
+
|
|
8
|
+
// TODO: Split this out into Calendar, CalendarHeader, CalendarPreviousTrigger, CalendarGrid etc
|
|
9
|
+
|
|
10
|
+
interface CalendarProps {
|
|
11
|
+
/** An ID for the root element */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Class name(s) for the root element */
|
|
14
|
+
class?: string,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function Calendar($props: CalendarProps) {
|
|
18
|
+
$props ??= $watch({});
|
|
19
|
+
$props.startOfWeek ??= 1;
|
|
20
|
+
$props.selectable ??= false;
|
|
21
|
+
$props.value ??= new Date();
|
|
22
|
+
$props.events ??= [];
|
|
23
|
+
|
|
24
|
+
// Ensure the value is a reactive date
|
|
25
|
+
$props.value = new ReactiveDate($unwrap($props.value));
|
|
26
|
+
|
|
27
|
+
// A note on dates:
|
|
28
|
+
// * value is the selected value
|
|
29
|
+
// * activeDate is the date that is active when the user is navigating via keyboard
|
|
30
|
+
// * visibleDate is the date that is currently being displayed in the calendar (really only the month part is important here)
|
|
31
|
+
|
|
32
|
+
let $state = $watch({
|
|
33
|
+
activeDate: $props.value,
|
|
34
|
+
visibleDate: $props.value,
|
|
35
|
+
//get days() {
|
|
36
|
+
// // TODO: $cache
|
|
37
|
+
// return buildDays($state.visibleDate, $props.startOfWeek)
|
|
38
|
+
//},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let visibleStartDate = $props.value;
|
|
42
|
+
let visibleEndDate = $props.value;
|
|
43
|
+
let container: HTMLElement;
|
|
44
|
+
let refocus = false;
|
|
45
|
+
|
|
46
|
+
const context: CalendarContext = {
|
|
47
|
+
registerDay
|
|
48
|
+
};
|
|
49
|
+
$context[CalendarContextName] = context;
|
|
50
|
+
|
|
51
|
+
$run(() => {
|
|
52
|
+
$state.days = buildDays($state.visibleDate, $props.startOfWeek)
|
|
53
|
+
|
|
54
|
+
// HACK: Shouldn't need this
|
|
55
|
+
if (refocus) {
|
|
56
|
+
refocus = false;
|
|
57
|
+
const el = container.getElementsByClassName("active")[0];
|
|
58
|
+
if (el && el.children[0] instanceof HTMLElement) {
|
|
59
|
+
el.children[0].focus();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function registerDay(date: ReactiveDate, setActive: (value: boolean) => void) {
|
|
65
|
+
const day = $state.days.find((day) => areDatesEqual(day.date, date));
|
|
66
|
+
if (day) {
|
|
67
|
+
day.setActive = setActive;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildDays(date: ReactiveDate, start: number): DayState[] {
|
|
72
|
+
const newDays = [];
|
|
73
|
+
|
|
74
|
+
// Set the first day to the start of the week before the first day of
|
|
75
|
+
// the month (e.g. Monday the 28th of the previous month)
|
|
76
|
+
visibleStartDate = new Date();
|
|
77
|
+
visibleStartDate.setFullYear(date.getFullYear(), date.getMonth(), 1);
|
|
78
|
+
visibleStartDate.setDate(
|
|
79
|
+
visibleStartDate.getDate() - ((visibleStartDate.getDay() + 7 - start) % 7)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Set the last day to the end of the week after the last day of the
|
|
83
|
+
// month (e.g. Sunday the 6th of the next month)
|
|
84
|
+
visibleEndDate = new Date();
|
|
85
|
+
visibleEndDate.setFullYear(date.getFullYear(), date.getMonth() + 1, 0);
|
|
86
|
+
visibleEndDate.setDate(
|
|
87
|
+
visibleEndDate.getDate() + ((start - 1 - visibleEndDate.getDay() + 7) % 7)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const dayDiff =
|
|
91
|
+
Math.round((visibleEndDate.getTime() - visibleStartDate.getTime()) / (1000 * 60 * 60 * 24)) +
|
|
92
|
+
1;
|
|
93
|
+
|
|
94
|
+
for (let i = 0; i < dayDiff; i++) {
|
|
95
|
+
const dayDate = new ReactiveDate();
|
|
96
|
+
dayDate.setFullYear(
|
|
97
|
+
visibleStartDate.getFullYear(),
|
|
98
|
+
visibleStartDate.getMonth(),
|
|
99
|
+
visibleStartDate.getDate() + i
|
|
100
|
+
);
|
|
101
|
+
dayDate.setHours(0);
|
|
102
|
+
dayDate.setMinutes(0);
|
|
103
|
+
dayDate.setSeconds(0);
|
|
104
|
+
dayDate.setMilliseconds(0);
|
|
105
|
+
const newDay: DayState = {
|
|
106
|
+
date: dayDate,
|
|
107
|
+
muted: dayDate.getMonth() !== date.getMonth(),
|
|
108
|
+
active: areDatesEqual(dayDate, $state.activeDate)
|
|
109
|
+
};
|
|
110
|
+
newDays.push(newDay);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return newDays;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function setValue(date: Date) {
|
|
117
|
+
$state.value = new ReactiveDate(date);
|
|
118
|
+
|
|
119
|
+
// Also set the active date so that the user knows where they are
|
|
120
|
+
setActiveDate(date);
|
|
121
|
+
|
|
122
|
+
if ($props.onchange) $props.onchange(value);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function setActiveDate(date: Date) {
|
|
126
|
+
$state.activeDate = new ReactiveDate(date);
|
|
127
|
+
|
|
128
|
+
// If the selected date is outside the visible date range, move the date range
|
|
129
|
+
if (date < visibleStartDate || date > visibleEndDate) {
|
|
130
|
+
refocus = true;
|
|
131
|
+
$state.visibleDate = new ReactiveDate(date);
|
|
132
|
+
if ($props.onchangedate) $props.onchangedate(date);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
$state.days.forEach((day) => {
|
|
136
|
+
const active = areDatesEqual(day.date, new Date(date));
|
|
137
|
+
if (day.setActive) {
|
|
138
|
+
day.setActive(active);
|
|
139
|
+
}
|
|
140
|
+
day.active = active;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function handleFocus(e: FocusEvent & { currentTarget: EventTarget & HTMLElement }) {
|
|
145
|
+
const el = e.currentTarget.getElementsByClassName("active")[0];
|
|
146
|
+
if (el && el.children[0] instanceof HTMLElement) {
|
|
147
|
+
el.children[0].focus();
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function handlePrevMonth(e: Event) {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
$state.visibleDate.setMonth($state.visibleDate.getMonth() - 1);
|
|
155
|
+
if ($props.onchangedate) $props.onchangedate(visibleDate);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function handleNextMonth(e: Event) {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
$state.visibleDate.setMonth($state.visibleDate.getMonth() + 1);
|
|
161
|
+
if ($props.onchangedate) $props.onchangedate(visibleDate);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function handleDayClick(date: ReactiveDate) {
|
|
165
|
+
if (!$props.selectable) return;
|
|
166
|
+
|
|
167
|
+
setValue(date);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function handleKey(e: KeyboardEvent) {
|
|
171
|
+
if (!$props.selectable) return;
|
|
172
|
+
|
|
173
|
+
switch (e.key) {
|
|
174
|
+
case "Enter": {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
setValue($state.activeDate);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case "Esc":
|
|
180
|
+
case "Escape": {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
if ($props.onclose) $props.onclose();
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "Left":
|
|
186
|
+
case "ArrowLeft": {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
// Move to the date one day before
|
|
189
|
+
const newDate = new Date($state.activeDate.getTime() - 1 * 86400000)
|
|
190
|
+
setActiveDate(newDate);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case "Up":
|
|
194
|
+
case "ArrowUp": {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
// Move to the date seven days before
|
|
197
|
+
const newDate = new Date($state.activeDate.getTime() - 7 * 86400000)
|
|
198
|
+
setActiveDate(newDate);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case "Right":
|
|
202
|
+
case "ArrowRight": {
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
// Move to the date one day after
|
|
205
|
+
const newDate = new Date($state.activeDate.getTime() + 1 * 86400000)
|
|
206
|
+
setActiveDate(newDate);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case "Down":
|
|
210
|
+
case "ArrowDown": {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
// Move to the date seven days after
|
|
213
|
+
const newDate = new Date($state.activeDate.getTime() + 7 * 86400000)
|
|
214
|
+
setActiveDate(newDate);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@render {
|
|
221
|
+
<div
|
|
222
|
+
{$props.id}
|
|
223
|
+
class={`torp-calendar ${$props.class ?? ""}`.trim()}
|
|
224
|
+
&ref={container}
|
|
225
|
+
>
|
|
226
|
+
<div class={`torp-calendar-header ${$props.class ?? ""}`.trim()}>
|
|
227
|
+
<button class={`torp-calendar-previous-trigger ${$props.class ?? ""}`.trim()} onclick={handlePrevMonth}>
|
|
228
|
+
<slot name="prev-button">
|
|
229
|
+
<ChevronLeft />
|
|
230
|
+
</slot>
|
|
231
|
+
</button>
|
|
232
|
+
<span class={`torp-calendar-month-name ${$props.class ?? ""}`.trim()}>
|
|
233
|
+
{monthNames[$state.visibleDate.getMonth()] + " " + $state.visibleDate.getFullYear()}
|
|
234
|
+
</span>
|
|
235
|
+
<button class={`torp-calendar-next-trigger ${$props.class ?? ""}`.trim()} onclick={handleNextMonth}>
|
|
236
|
+
<slot name="next-button">
|
|
237
|
+
<ChevronRight />
|
|
238
|
+
</slot>
|
|
239
|
+
</button>
|
|
240
|
+
</div>
|
|
241
|
+
<div
|
|
242
|
+
class={`torp-calendar-grid ${$props.class ?? ""}`.trim()}
|
|
243
|
+
tabindex={$props.selectable ? 0 : -1}
|
|
244
|
+
onfocus={handleFocus}
|
|
245
|
+
onkeydown={handleKey}
|
|
246
|
+
>
|
|
247
|
+
@for (let index of [0, 1, 2, 3, 4, 5, 6]) {
|
|
248
|
+
<span>
|
|
249
|
+
{dayNames[(Math.abs($props.startOfWeek) + index) % 7].substring(0, 2)}
|
|
250
|
+
</span>
|
|
251
|
+
}
|
|
252
|
+
@for (let day of $state.days) {
|
|
253
|
+
@key = day.date;
|
|
254
|
+
<CalendarDay
|
|
255
|
+
{day.date}
|
|
256
|
+
{day.muted}
|
|
257
|
+
{day.active}
|
|
258
|
+
{$props.selectable}
|
|
259
|
+
events={$props.events.filter((ev) => areDatesEqual(new Date(ev.date), day.date))}
|
|
260
|
+
onclick={handleDayClick}
|
|
261
|
+
/>
|
|
262
|
+
}
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@style {
|
|
268
|
+
.torp-calendar-grid {
|
|
269
|
+
display: grid;
|
|
270
|
+
grid-template-columns: repeat(7, 1fr);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { areDatesEqual } from "../utils/dateUtils";
|
|
2
|
+
import { type CalendarContext, type CalendarEvent, CalendarContextName } from "./CalendarTypes";
|
|
3
|
+
|
|
4
|
+
interface CalendarDayProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function CalendarDay($props: CalendarDayProps) {
|
|
12
|
+
$props ??= $watch({});
|
|
13
|
+
$props.date ??= new Date();
|
|
14
|
+
$props.selectable ??= false;
|
|
15
|
+
$props.muted ??= false;
|
|
16
|
+
$props.active ??= false;
|
|
17
|
+
$props.events ??= [];
|
|
18
|
+
|
|
19
|
+
// HACK: can't unwrap in @render
|
|
20
|
+
let date = $unwrap($props.date);
|
|
21
|
+
|
|
22
|
+
// Register this item with the parent Calendar, which will handle toggling active for all days
|
|
23
|
+
const { registerDay } = $context[CalendarContextName] as CalendarContext;
|
|
24
|
+
registerDay($props.date, setActive);
|
|
25
|
+
|
|
26
|
+
// This function is called by the parent Calendar to set this item's active value
|
|
27
|
+
function setActive(value: boolean) {
|
|
28
|
+
//if (active !== value) {
|
|
29
|
+
// active = value;
|
|
30
|
+
// dispatch("activeChange", value);
|
|
31
|
+
//}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isToday() {
|
|
35
|
+
const today = new Date();
|
|
36
|
+
return areDatesEqual(date, today);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function handleClick() {
|
|
40
|
+
//dispatch("click", date);
|
|
41
|
+
if ($props.onclick) $props.onclick($props.date);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function handleKey() {
|
|
45
|
+
//dispatch("click", date);
|
|
46
|
+
if ($props.onkeydown) $props.onkeydown();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@render {
|
|
50
|
+
<div
|
|
51
|
+
{$props.id}
|
|
52
|
+
class={[
|
|
53
|
+
`torp-calendar-day ${$props.class ?? ""}`.trim(),
|
|
54
|
+
{
|
|
55
|
+
muted: $props.muted,
|
|
56
|
+
today: isToday(),
|
|
57
|
+
active: $props.selectable && $props.active
|
|
58
|
+
}
|
|
59
|
+
]}
|
|
60
|
+
>
|
|
61
|
+
@if ($props.selectable) {
|
|
62
|
+
<button type="button" tabindex="-1" onclick={handleClick} onkeydown={handleKey}>
|
|
63
|
+
<span>{date.getDate()}</span>
|
|
64
|
+
</button>
|
|
65
|
+
} else {
|
|
66
|
+
<span>{date.getDate()}</span>
|
|
67
|
+
}
|
|
68
|
+
<ul class={`torp-calendar-day-events ${$props.class ?? ""}`.trim()}>
|
|
69
|
+
@for (ev of $props.events) {
|
|
70
|
+
<li title={ev.content} />
|
|
71
|
+
}
|
|
72
|
+
</ul>
|
|
73
|
+
</div>
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const CalendarContextName = "Calendar";
|
|
2
|
+
|
|
3
|
+
export interface CalendarContext {
|
|
4
|
+
// The registerDay function is called from each CalendarDay to register itself with this
|
|
5
|
+
// Calendar. They pass us a setActive method that we can call
|
|
6
|
+
registerDay: (date: Date, setActive: (value: boolean) => void) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DayState {
|
|
10
|
+
date: Date;
|
|
11
|
+
muted: boolean;
|
|
12
|
+
state: {
|
|
13
|
+
active: boolean;
|
|
14
|
+
};
|
|
15
|
+
setActive?: (value: boolean) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CalendarEvent {
|
|
19
|
+
date: Date;
|
|
20
|
+
content: string;
|
|
21
|
+
color: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface CalendarProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare function Calendar(
|
|
12
|
+
$parent: ParentNode,
|
|
13
|
+
$anchor: Node | null,
|
|
14
|
+
$props: CalendarProps,
|
|
15
|
+
$context?: Record<PropertyKey, any>,
|
|
16
|
+
$slots?: Record<string, SlotRender>,
|
|
17
|
+
): void;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
interface CalendarDayProps {
|
|
22
|
+
/** An ID for the root element */
|
|
23
|
+
id?: string;
|
|
24
|
+
/** Class name(s) for the root element */
|
|
25
|
+
class?: string,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare function CalendarDay(
|
|
29
|
+
$parent: ParentNode,
|
|
30
|
+
$anchor: Node | null,
|
|
31
|
+
$props: CalendarDayProps,
|
|
32
|
+
$context?: Record<PropertyKey, any>,
|
|
33
|
+
$slots?: Record<string, SlotRender>,
|
|
34
|
+
): void;
|
|
35
|
+
|
|
36
|
+
export { Calendar, CalendarDay };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/Calendar/Calendar.torp
|
|
2
|
+
import Calendar_default from "./Calendar.torp";
|
|
3
|
+
|
|
4
|
+
// src/Calendar/CalendarDay.torp
|
|
5
|
+
import CalendarDay_default from "./CalendarDay.torp";
|
|
6
|
+
export {
|
|
7
|
+
Calendar_default as Calendar,
|
|
8
|
+
CalendarDay_default as CalendarDay
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/Dialog/Dialog.torp
CHANGED
|
@@ -4,6 +4,17 @@ import { trapFocus, type TrapFocusOptions } from "../mount/trapFocus";
|
|
|
4
4
|
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
5
5
|
import { DialogContextName, type DialogContext, type DialogState } from "./DialogTypes";
|
|
6
6
|
|
|
7
|
+
interface DialogProps {
|
|
8
|
+
/** An ID for the root element */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Class name(s) for the root element */
|
|
11
|
+
class?: string,
|
|
12
|
+
/** An ARIA label for describing the popover to screen readers */
|
|
13
|
+
ariaLabel?: string,
|
|
14
|
+
/** Whether the dialog should alert the user via the screen reader */
|
|
15
|
+
alert?: boolean,
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
/**
|
|
8
19
|
* Content for a window displayed in a Popover.
|
|
9
20
|
*
|
|
@@ -21,10 +32,9 @@ import { DialogContextName, type DialogContext, type DialogState } from "./Dialo
|
|
|
21
32
|
* </Dialog>
|
|
22
33
|
* ```
|
|
23
34
|
*
|
|
24
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the popover to screen readers
|
|
25
|
-
* @prop {boolean} alert -- Whether the dialog should alert the user via the screen reader
|
|
26
35
|
*/
|
|
27
|
-
export default function Dialog($props:
|
|
36
|
+
export default function Dialog($props: DialogProps) {
|
|
37
|
+
$props ??= $watch({});
|
|
28
38
|
$props.id ??= getId();
|
|
29
39
|
$props.dialog ??= false;
|
|
30
40
|
|
|
@@ -138,7 +148,7 @@ export default function Dialog($props: any) {
|
|
|
138
148
|
|
|
139
149
|
@render {
|
|
140
150
|
<div
|
|
141
|
-
|
|
151
|
+
{$props.id}
|
|
142
152
|
class={`torp-dialog ${$props.class ?? ""}`.trim()}
|
|
143
153
|
tabindex="0"
|
|
144
154
|
role={$props.alert ? "alertdialog" : "dialog"}
|
|
@@ -147,10 +157,10 @@ export default function Dialog($props: any) {
|
|
|
147
157
|
aria-labelledby={!$props.ariaLabel && $state.headerId ? $state.headerId : undefined}
|
|
148
158
|
aria-describedby={$state.bodyId ? $state.bodyId : undefined}
|
|
149
159
|
onkeydown={handleKey}
|
|
150
|
-
|
|
160
|
+
onmount={(el) => trapFocus(el, trapFocusOptions)}
|
|
151
161
|
&ref={div}
|
|
152
162
|
>
|
|
153
|
-
|
|
163
|
+
<slot />
|
|
154
164
|
</div>
|
|
155
165
|
}
|
|
156
166
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { DialogContextName, type DialogContext } from "./DialogTypes";
|
|
3
3
|
|
|
4
|
+
interface DialogBodyProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** Whether the body content will be announced by screen readers when the Dialog is opened */
|
|
10
|
+
ariaAnnounce?: boolean,
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* The body information for a Dialog. Content in the body will be announced by
|
|
6
15
|
* screen readers when the Dialog is opened, unless ariaAnnounce is false.
|
|
7
|
-
*
|
|
8
|
-
* @prop {boolean} ariaAnnounce -- Whether the body content will be announced by screen readers when the Dialog is opened
|
|
9
16
|
*/
|
|
10
|
-
export default function DialogBody($props:
|
|
17
|
+
export default function DialogBody($props: DialogBodyProps) {
|
|
18
|
+
$props ??= $watch({});
|
|
11
19
|
$props.id ??= getId();
|
|
12
20
|
$props.ariaAnnounce ??= true;
|
|
13
21
|
|
|
@@ -25,10 +33,10 @@ export default function DialogBody($props: any) {
|
|
|
25
33
|
|
|
26
34
|
@render {
|
|
27
35
|
<div
|
|
28
|
-
|
|
36
|
+
{$props.id}
|
|
29
37
|
class={`torp-dialog-body ${$props.class ?? ""}`.trim()}
|
|
30
38
|
>
|
|
31
|
-
|
|
39
|
+
<slot />
|
|
32
40
|
</div>
|
|
33
41
|
}
|
|
34
42
|
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { DialogContextName, type DialogContext } from "./DialogTypes";
|
|
2
2
|
|
|
3
|
+
interface DialogButtonProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover */
|
|
9
|
+
value?: any,
|
|
10
|
+
/** "confirm" if the button should respond to the Enter key or "cancel" if the button should respond to the Escape key */
|
|
11
|
+
type?: "confirm" | "cancel",
|
|
12
|
+
/** Whether this button is disabled */
|
|
13
|
+
disabled?: boolean,
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
/**
|
|
4
17
|
* A button that is placed in a DialogFooter and signals a response by a user.
|
|
5
18
|
*
|
|
6
|
-
* @prop {any | undefined} value -- The value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover
|
|
7
|
-
* @prop {"confirm" | "cancel" | undefined} type -- "confirm" if the button should respond to the Enter key or "cancel" if the button should respond to the Escape key
|
|
8
|
-
* @prop {boolean} disabled -- Whether this button is disabled
|
|
9
19
|
*/
|
|
10
|
-
export default function DialogButton($props:
|
|
20
|
+
export default function DialogButton($props: DialogButtonProps) {
|
|
21
|
+
$props ??= $watch({});
|
|
22
|
+
|
|
11
23
|
let button: HTMLButtonElement;
|
|
12
24
|
|
|
13
25
|
// Get stuff out of the DialogContext
|
|
@@ -36,13 +48,13 @@ export default function DialogButton($props: any) {
|
|
|
36
48
|
@render {
|
|
37
49
|
<button
|
|
38
50
|
type="button"
|
|
39
|
-
|
|
51
|
+
{$props.id}
|
|
40
52
|
class={`torp-dialog-button ${$props.class ?? ""}`.trim()}
|
|
41
53
|
disabled={$props.disabled}
|
|
42
54
|
onclick={handleClick}
|
|
43
55
|
&ref={button}
|
|
44
56
|
>
|
|
45
|
-
|
|
57
|
+
<slot />
|
|
46
58
|
</button>
|
|
47
59
|
}
|
|
48
60
|
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
interface DialogFooterProps {
|
|
3
|
+
/** An ID for the root element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Class name(s) for the root element */
|
|
6
|
+
class?: string,
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* The footer for a Dialog, which may contain one or more DialogButtons.
|
|
3
11
|
*/
|
|
4
|
-
export default function DialogFooter($props:
|
|
12
|
+
export default function DialogFooter($props: DialogFooterProps) {
|
|
13
|
+
$props ??= $watch({});
|
|
14
|
+
|
|
5
15
|
@render {
|
|
6
16
|
<div
|
|
7
|
-
|
|
17
|
+
{$props.id}
|
|
8
18
|
class={`torp-dialog-footer ${$props.class ?? ""}`.trim()}
|
|
9
19
|
>
|
|
10
|
-
|
|
20
|
+
<slot />
|
|
11
21
|
</div>
|
|
12
22
|
}
|
|
13
23
|
}
|