@torpor/ui 0.2.0 → 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 +12 -0
- package/dist/Accordion/Accordion.torp +23 -11
- package/dist/Accordion/AccordionContent.torp +13 -6
- package/dist/Accordion/AccordionHeader.torp +14 -5
- package/dist/Accordion/AccordionItem.torp +22 -8
- package/dist/Accordion/AccordionTrigger.torp +14 -6
- package/dist/Accordion/AccordionTypes.ts +2 -0
- package/dist/Accordion/index.d.ts +100 -35
- package/dist/Breadcrumb/Breadcrumb.torp +12 -3
- package/dist/Breadcrumb/BreadcrumbItem.torp +12 -3
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +10 -1
- package/dist/Breadcrumb/index.d.ts +49 -21
- package/dist/Calendar/Calendar.torp +9 -1
- package/dist/Calendar/CalendarDay.torp +9 -1
- package/dist/Calendar/index.d.ts +16 -18
- package/dist/Dialog/Dialog.torp +13 -3
- package/dist/Dialog/DialogBody.torp +11 -3
- package/dist/Dialog/DialogButton.torp +16 -4
- package/dist/Dialog/DialogFooter.torp +11 -1
- package/dist/Dialog/DialogHeader.torp +11 -2
- package/dist/Dialog/index.d.ts +78 -35
- package/dist/Disclosure/Disclosure.torp +17 -7
- package/dist/Disclosure/DisclosureContent.torp +13 -6
- package/dist/Disclosure/DisclosureHeader.torp +14 -5
- package/dist/Disclosure/DisclosureTrigger.torp +10 -2
- package/dist/Disclosure/index.d.ts +67 -28
- package/dist/Drawer/Drawer.torp +11 -1
- package/dist/Drawer/index.d.ts +10 -9
- 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 +12 -3
- package/dist/Menu/MenuButton.torp +14 -3
- package/dist/Menu/MenuCheck.torp +14 -3
- package/dist/Menu/MenuGroup.torp +13 -3
- package/dist/Menu/MenuIndicator.torp +12 -3
- package/dist/Menu/MenuPopout.torp +17 -6
- package/dist/Menu/MenuPopoutContent.torp +13 -4
- package/dist/Menu/MenuPopoutTrigger.torp +13 -4
- package/dist/Menu/MenuRadio.torp +16 -5
- package/dist/Menu/MenuRadioGroup.torp +16 -5
- package/dist/Menu/MenuSeparator.torp +11 -1
- package/dist/Menu/index.d.ts +170 -77
- package/dist/MenuBar/MenuBar.torp +13 -4
- package/dist/MenuBar/MenuBarItem.torp +17 -6
- package/dist/MenuBar/MenuBarItemContent.torp +13 -4
- package/dist/MenuBar/MenuBarItemTrigger.torp +11 -2
- package/dist/MenuBar/index.d.ts +79 -28
- package/dist/NavMenu/NavMenu.torp +13 -4
- package/dist/NavMenu/NavMenuButton.torp +12 -5
- package/dist/NavMenu/NavMenuElement.torp +14 -6
- package/dist/NavMenu/NavMenuGroup.torp +12 -3
- package/dist/NavMenu/NavMenuGroupHeader.torp +12 -4
- package/dist/NavMenu/NavMenuLink.torp +16 -8
- package/dist/NavMenu/NavMenuPopout.torp +11 -3
- package/dist/NavMenu/NavMenuPopoutButton.torp +14 -8
- package/dist/NavMenu/NavMenuPopoutContent.torp +13 -3
- package/dist/NavMenu/NavMenuSeparator.torp +10 -1
- package/dist/NavMenu/index.d.ts +147 -70
- package/dist/Notification/Notification.torp +15 -5
- package/dist/Notification/NotificationClose.torp +10 -1
- package/dist/Notification/NotificationContainer.torp +11 -1
- package/dist/Notification/NotificationContent.torp +11 -1
- package/dist/Notification/index.d.ts +46 -28
- package/dist/Popover/Popover.torp +20 -6
- package/dist/Popover/PopoverContent.torp +10 -1
- package/dist/Popover/PopoverContentAnchored.torp +13 -6
- package/dist/Popover/PopoverContentContextual.torp +10 -1
- package/dist/Popover/PopoverOverlay.torp +10 -1
- package/dist/Popover/PopoverTrigger.torp +10 -1
- package/dist/Popover/PopoverTriggerContextual.torp +10 -1
- package/dist/Popover/PopoverTriggerHover.torp +11 -2
- package/dist/Popover/index.d.ts +101 -56
- package/dist/TabGroup/TabContent.torp +11 -5
- package/dist/TabGroup/TabGroup.torp +21 -9
- package/dist/TabGroup/TabHeader.torp +14 -5
- package/dist/TabGroup/TabList.torp +13 -4
- package/dist/TabGroup/TabTrigger.torp +12 -4
- package/dist/TabGroup/index.d.ts +93 -35
- package/dist/icons/ArrowDown.torp +3 -3
- package/dist/icons/ArrowLeft.torp +3 -3
- package/dist/icons/ArrowRight.torp +3 -3
- package/dist/icons/ArrowUp.torp +3 -3
- package/dist/icons/Bars.torp +3 -3
- package/dist/icons/Check.torp +3 -3
- package/dist/icons/ChevronDown.torp +3 -3
- package/dist/icons/ChevronLeft.torp +3 -3
- package/dist/icons/ChevronRight.torp +3 -3
- package/dist/icons/ChevronUp.torp +3 -3
- package/dist/icons/Cross.torp +3 -3
- package/dist/icons/Loading.torp +3 -3
- package/dist/icons/Minus.torp +3 -3
- package/dist/icons/Plus.torp +3 -3
- package/dist/icons/index.d.ts +14 -126
- package/dist/metafile-esm.json +1 -1
- package/package.json +13 -4
- package/src/Accordion/Accordion.torp +23 -11
- package/src/Accordion/AccordionContent.torp +13 -6
- package/src/Accordion/AccordionHeader.torp +14 -5
- package/src/Accordion/AccordionItem.torp +22 -8
- package/src/Accordion/AccordionTrigger.torp +14 -6
- package/src/Accordion/AccordionTypes.ts +2 -0
- package/src/Breadcrumb/Breadcrumb.torp +12 -3
- package/src/Breadcrumb/BreadcrumbItem.torp +12 -3
- package/src/Breadcrumb/BreadcrumbSeparator.torp +10 -1
- package/src/Calendar/Calendar.torp +9 -1
- package/src/Calendar/CalendarDay.torp +9 -1
- package/src/Dialog/Dialog.torp +13 -3
- package/src/Dialog/DialogBody.torp +11 -3
- package/src/Dialog/DialogButton.torp +16 -4
- package/src/Dialog/DialogFooter.torp +11 -1
- package/src/Dialog/DialogHeader.torp +11 -2
- package/src/Disclosure/Disclosure.torp +17 -7
- package/src/Disclosure/DisclosureContent.torp +13 -6
- package/src/Disclosure/DisclosureHeader.torp +14 -5
- package/src/Disclosure/DisclosureTrigger.torp +10 -2
- package/src/Drawer/Drawer.torp +11 -1
- 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 +12 -3
- package/src/Menu/MenuButton.torp +14 -3
- package/src/Menu/MenuCheck.torp +14 -3
- package/src/Menu/MenuGroup.torp +13 -3
- package/src/Menu/MenuIndicator.torp +12 -3
- package/src/Menu/MenuPopout.torp +17 -6
- package/src/Menu/MenuPopoutContent.torp +13 -4
- package/src/Menu/MenuPopoutTrigger.torp +13 -4
- package/src/Menu/MenuRadio.torp +16 -5
- package/src/Menu/MenuRadioGroup.torp +16 -5
- package/src/Menu/MenuSeparator.torp +11 -1
- package/src/MenuBar/MenuBar.torp +13 -4
- package/src/MenuBar/MenuBarItem.torp +17 -6
- package/src/MenuBar/MenuBarItemContent.torp +13 -4
- package/src/MenuBar/MenuBarItemTrigger.torp +11 -2
- package/src/NavMenu/NavMenu.torp +13 -4
- package/src/NavMenu/NavMenuButton.torp +12 -5
- package/src/NavMenu/NavMenuElement.torp +14 -6
- package/src/NavMenu/NavMenuGroup.torp +12 -3
- package/src/NavMenu/NavMenuGroupHeader.torp +12 -4
- package/src/NavMenu/NavMenuLink.torp +16 -8
- package/src/NavMenu/NavMenuPopout.torp +11 -3
- package/src/NavMenu/NavMenuPopoutButton.torp +14 -8
- package/src/NavMenu/NavMenuPopoutContent.torp +13 -3
- package/src/NavMenu/NavMenuSeparator.torp +10 -1
- package/src/Notification/Notification.torp +15 -5
- package/src/Notification/NotificationClose.torp +10 -1
- package/src/Notification/NotificationContainer.torp +11 -1
- package/src/Notification/NotificationContent.torp +11 -1
- package/src/Popover/Popover.torp +20 -6
- package/src/Popover/PopoverContent.torp +10 -1
- package/src/Popover/PopoverContentAnchored.torp +13 -6
- package/src/Popover/PopoverContentContextual.torp +10 -1
- package/src/Popover/PopoverOverlay.torp +10 -1
- package/src/Popover/PopoverTrigger.torp +10 -1
- package/src/Popover/PopoverTriggerContextual.torp +10 -1
- package/src/Popover/PopoverTriggerHover.torp +11 -2
- package/src/TabGroup/TabContent.torp +11 -5
- package/src/TabGroup/TabGroup.torp +21 -9
- package/src/TabGroup/TabHeader.torp +14 -5
- package/src/TabGroup/TabList.torp +13 -4
- package/src/TabGroup/TabTrigger.torp +12 -4
- package/src/icons/ArrowDown.torp +3 -3
- package/src/icons/ArrowLeft.torp +3 -3
- package/src/icons/ArrowRight.torp +3 -3
- package/src/icons/ArrowUp.torp +3 -3
- package/src/icons/Bars.torp +3 -3
- package/src/icons/Check.torp +3 -3
- package/src/icons/ChevronDown.torp +3 -3
- package/src/icons/ChevronLeft.torp +3 -3
- package/src/icons/ChevronRight.torp +3 -3
- package/src/icons/ChevronUp.torp +3 -3
- package/src/icons/Cross.torp +3 -3
- package/src/icons/Loading.torp +3 -3
- package/src/icons/Minus.torp +3 -3
- package/src/icons/Plus.torp +3 -3
- 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/Disclosure/accessibility.test.ts +3 -2
- package/test/Disclosure/components/DisclosureTest.torp +2 -0
- package/test/Disclosure/toggle.test.ts +3 -2
- package/test/Form/components/FieldTest.torp +25 -0
- package/test/Form/components/FormTest.torp +31 -0
- package/test/Form/components/InputTest.torp +9 -0
- package/test/Form/field.test.ts +34 -0
- package/test/Form/form.test.ts +34 -0
- package/test/Form/input.test.ts +19 -0
- package/test/Menu/accessibility.test.ts +3 -2
- package/test/Menu/basic.test.ts +11 -10
- package/test/MenuBar/accessibility.test.ts +3 -2
- package/test/MenuBar/basic.test.ts +3 -2
- package/test/NavMenu/basic.test.ts +1 -1
- package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
- package/test/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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @torpor/ui
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 84f7d87: Fix: prop types
|
|
8
|
+
- 34d17f7: Feat: UI Form component and client-side submit
|
|
9
|
+
- Updated dependencies [f4716c5]
|
|
10
|
+
- Updated dependencies [1253f7a]
|
|
11
|
+
- Updated dependencies [6268e00]
|
|
12
|
+
- Updated dependencies [f2fb547]
|
|
13
|
+
- @torpor/view@0.3.2
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { AccordionContextName, type AccordionContext, type ItemState } from "./AccordionTypes";
|
|
2
2
|
|
|
3
|
+
interface AccordionProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** Whether a single AccordionItem or multiple AccordionItems can be expanded at the same time */
|
|
9
|
+
type?: "single" | "multiple",
|
|
10
|
+
/** The value of the expanded AccordionItem, or an array of values if the type is "multiple" */
|
|
11
|
+
value?: string | string[],
|
|
12
|
+
/** If set to true, the user cannot interact with any items in the Accordion */
|
|
13
|
+
disabled?: boolean,
|
|
14
|
+
/** Raised when the expanded item(s) have changed */
|
|
15
|
+
onchange?: (value: string | string[]) => void,
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* A vertically stacked set of interactive headings that enable users to reveal
|
|
5
20
|
* or hide associated sections of content.
|
|
@@ -18,13 +33,10 @@ import { AccordionContextName, type AccordionContext, type ItemState } from "./A
|
|
|
18
33
|
* </AccordionItem>
|
|
19
34
|
* </Accordion>
|
|
20
35
|
* ```
|
|
21
|
-
*
|
|
22
|
-
* @prop {"single" | "multiple"} type -- Whether a single AccordionItem or multiple AccordionItems can be expanded at the same time
|
|
23
|
-
* @prop {string | string[]} value -- The value of the expanded AccordionItem, or an array of values if the type is "multiple"
|
|
24
|
-
* @prop {boolean} disabled -- If set to true, the user cannot interact with any items in the Accordion
|
|
25
|
-
* @prop {(value: string | string[]) => void} [onchange] -- Raised when the expanded item(s) have changed
|
|
26
36
|
*/
|
|
27
|
-
export default function Accordion($props:
|
|
37
|
+
export default function Accordion($props: AccordionProps) {
|
|
38
|
+
$props ??= $watch({ type: "single", value: "" });
|
|
39
|
+
|
|
28
40
|
$props.type ||= "single";
|
|
29
41
|
$props.value ||= $props.type === "single" ? "" : [];
|
|
30
42
|
|
|
@@ -44,10 +56,10 @@ export default function Accordion($props: any) {
|
|
|
44
56
|
|
|
45
57
|
$run(() => {
|
|
46
58
|
// HACK: This should probably be done with setters?
|
|
47
|
-
let newValue = $props.value
|
|
59
|
+
let newValue = $props.value!;
|
|
48
60
|
|
|
49
61
|
// Get the value
|
|
50
|
-
switch ($props
|
|
62
|
+
switch ($props!.type) {
|
|
51
63
|
case "single": {
|
|
52
64
|
// Ensure the value passed in was a string (in case e.g. the user has set values to ints)
|
|
53
65
|
newValue = newValue?.toString();
|
|
@@ -73,7 +85,7 @@ export default function Accordion($props: any) {
|
|
|
73
85
|
})
|
|
74
86
|
|
|
75
87
|
$run(() => {
|
|
76
|
-
itemStates.forEach((s) => s.parentDisabled = $props.disabled);
|
|
88
|
+
itemStates.forEach((s) => s.parentDisabled = $props.disabled === true);
|
|
77
89
|
});
|
|
78
90
|
|
|
79
91
|
// Dispatch the change event when the value changes
|
|
@@ -84,7 +96,7 @@ export default function Accordion($props: any) {
|
|
|
84
96
|
if (firstChange) {
|
|
85
97
|
firstChange = false;
|
|
86
98
|
} else if (ev) {
|
|
87
|
-
ev(value);
|
|
99
|
+
ev(value!);
|
|
88
100
|
}
|
|
89
101
|
});
|
|
90
102
|
|
|
@@ -114,7 +126,7 @@ export default function Accordion($props: any) {
|
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
// Set whether the Accordion itself is disabled
|
|
117
|
-
itemState.parentDisabled = $props.disabled
|
|
129
|
+
itemState.parentDisabled = $props.disabled === true
|
|
118
130
|
|
|
119
131
|
// Add the item's state to the array
|
|
120
132
|
itemStates.splice(itemState.index, 0, itemState);
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { AccordionItemContextName, type AccordionItemContext } from "./AccordionTypes";
|
|
3
3
|
|
|
4
|
+
interface AccordionContentProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** Whether this content should act as a region. Set this when the content contains heading elements or a nested Accordion */
|
|
10
|
+
ariaRegion?: boolean,
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* Content for an AccordionItem, which can be revealed or hidden by an associated AccordionTrigger.
|
|
6
|
-
*
|
|
7
|
-
* @prop {string} [id] -- An ID for the AccordionContent's div container
|
|
8
|
-
* @prop {boolean} [ariaRegion] -- Whether this content should act as a region. Set this when the content contains heading elements or a nested Accordion
|
|
9
15
|
*/
|
|
10
|
-
export default function AccordionContent($props:
|
|
16
|
+
export default function AccordionContent($props: AccordionContentProps) {
|
|
17
|
+
$props ??= $watch({});
|
|
11
18
|
$props.id ||= getId();
|
|
12
19
|
|
|
13
20
|
const context = $context[AccordionItemContextName] as AccordionItemContext;
|
|
14
21
|
if (!context) {
|
|
15
22
|
throw new Error("AccordionContent must be contained within an AccordionItem");
|
|
16
23
|
}
|
|
17
|
-
let $state =
|
|
24
|
+
let $state = context.state
|
|
18
25
|
|
|
19
26
|
// Set the content ID so that it can be used with aria-controls in AccordionTrigger
|
|
20
27
|
$state.contentId = $props.id;
|
|
@@ -26,7 +33,7 @@ export default function AccordionContent($props: any) {
|
|
|
26
33
|
role={$props.ariaRegion ? "region" : undefined}
|
|
27
34
|
aria-labelledby={$state.headerId}
|
|
28
35
|
data-state={$state.dataState}
|
|
29
|
-
data-disabled={$state.
|
|
36
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
30
37
|
>
|
|
31
38
|
@if ($state.expanded) {
|
|
32
39
|
<slot />
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { AccordionItemContextName, type AccordionItemContext } from "./AccordionTypes";
|
|
2
2
|
|
|
3
|
+
interface AccordionHeaderProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The type of HTML header to use */
|
|
9
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* The header for an AccordionItem, which contains the AccordionTrigger.
|
|
5
14
|
*
|
|
@@ -10,15 +19,15 @@ import { AccordionItemContextName, type AccordionItemContext } from "./Accordion
|
|
|
10
19
|
* <AccordionTrigger />
|
|
11
20
|
* </AccordionHeader>
|
|
12
21
|
* ```
|
|
13
|
-
*
|
|
14
|
-
* @prop {"h1" | "h2" | "h3" | "h4" | "h5" | "h6"} as -- The type of HTML header to use
|
|
15
22
|
*/
|
|
16
|
-
export default function AccordionHeader($props:
|
|
23
|
+
export default function AccordionHeader($props: AccordionHeaderProps) {
|
|
24
|
+
$props ??= $watch({});
|
|
25
|
+
|
|
17
26
|
const context = $context[AccordionItemContextName] as AccordionItemContext;
|
|
18
27
|
if (!context) {
|
|
19
28
|
throw new Error("AccordionHeader must be contained within an AccordionItem");
|
|
20
29
|
}
|
|
21
|
-
let $state =
|
|
30
|
+
let $state = context.state
|
|
22
31
|
|
|
23
32
|
@render {
|
|
24
33
|
@// TODO: $props.as
|
|
@@ -26,7 +35,7 @@ export default function AccordionHeader($props: any) {
|
|
|
26
35
|
{$props.id}
|
|
27
36
|
class={`torp-accordion-header ${$props.class ?? ""}`.trim()}
|
|
28
37
|
data-state={$state.dataState}
|
|
29
|
-
data-disabled={$state.
|
|
38
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
30
39
|
>
|
|
31
40
|
<slot />
|
|
32
41
|
</h4>
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import { AccordionContextName, AccordionItemContextName, type AccordionContext, type AccordionItemContext } from "./AccordionTypes";
|
|
1
|
+
import { AccordionContextName, AccordionItemContextName, type ItemState, type AccordionContext, type AccordionItemContext } from "./AccordionTypes";
|
|
2
|
+
|
|
3
|
+
interface AccordionItemProps {
|
|
4
|
+
/** An ID for the root element */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Class name(s) for the root element */
|
|
7
|
+
class?: string,
|
|
8
|
+
/** The index of this item in the Accordion. Set this if you will be inserting, removing or sorting items. If you don't set this, it will be set automatically */
|
|
9
|
+
index?: number,
|
|
10
|
+
/** A value for the item. Set this if you need more control over which item(s) are expanded. If you don't set this, the value will be set to the item's initial index */
|
|
11
|
+
value?: string,
|
|
12
|
+
/** If set to true, the user cannot interact with this AccordionItem */
|
|
13
|
+
disabled?: boolean,
|
|
14
|
+
/** Raised when this item is opened or closed */
|
|
15
|
+
ontoggle?: (open: boolean) => void,
|
|
16
|
+
}
|
|
2
17
|
|
|
3
18
|
/**
|
|
4
19
|
* An item in an Accordion, which must consist of an AccordionTrigger and an AccordionContent.
|
|
@@ -13,17 +28,16 @@ import { AccordionContextName, AccordionItemContextName, type AccordionContext,
|
|
|
13
28
|
* <AccordionContent />
|
|
14
29
|
* </AccordionItem>
|
|
15
30
|
* ```
|
|
16
|
-
*
|
|
17
|
-
* @prop {number} [index] -- The index of this item in the Accordion. Set this if you will be inserting, removing or sorting items. If you don't set this, it will be set automatically
|
|
18
|
-
* @prop {string} [value] -- A value for the item. Set this if you need more control over which item(s) are expanded. If you don't set this, the value will be set to the item's initial index
|
|
19
|
-
* @prop {boolean} [disabled] -- If set to true, the user cannot interact with this AccordionItem
|
|
20
|
-
* @prop {(boolean) => void} [ontoggle] -- Raised when this item is opened or closed
|
|
21
31
|
*/
|
|
22
|
-
export default function AccordionItem($props:
|
|
32
|
+
export default function AccordionItem($props: AccordionItemProps) {
|
|
33
|
+
$props ??= $watch({});
|
|
34
|
+
|
|
23
35
|
let $state: ItemState = $watch({
|
|
24
36
|
index: -1,
|
|
25
37
|
value: "",
|
|
26
38
|
expanded: false,
|
|
39
|
+
headerId: "",
|
|
40
|
+
contentId: "",
|
|
27
41
|
disabled: $props.disabled,
|
|
28
42
|
parentDisabled: false,
|
|
29
43
|
get dataState() {
|
|
@@ -72,7 +86,7 @@ export default function AccordionItem($props: any) {
|
|
|
72
86
|
{$props.id}
|
|
73
87
|
class={`torp-accordion-item ${$props.class ?? ""}`.trim()}
|
|
74
88
|
data-state={$state.dataState}
|
|
75
|
-
data-disabled={$state.
|
|
89
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
76
90
|
>
|
|
77
91
|
<slot />
|
|
78
92
|
</div>
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import getId from "../utils/getId";
|
|
2
2
|
import { AccordionItemContextName, type AccordionItemContext } from "./AccordionTypes";
|
|
3
3
|
|
|
4
|
+
interface AccordionTriggerProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* A header button for an AccordionItem, which can be used to reveal or hide an associated AccordionContent.
|
|
6
13
|
*/
|
|
7
|
-
export default function AccordionTrigger() {
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
export default function AccordionTrigger($props: AccordionTriggerProps) {
|
|
15
|
+
$props ??= $watch({});
|
|
10
16
|
$props.id ||= getId();
|
|
11
17
|
|
|
18
|
+
let button: HTMLButtonElement;
|
|
19
|
+
|
|
12
20
|
// Get stuff out of the AccordionItemContext
|
|
13
21
|
const context = $context[AccordionItemContextName] as AccordionItemContext;
|
|
14
22
|
if (!context) {
|
|
15
23
|
throw new Error("AccordionTrigger must be contained within an AccordionItem");
|
|
16
24
|
}
|
|
17
|
-
let $state =
|
|
25
|
+
let $state = context.state;
|
|
18
26
|
|
|
19
27
|
// Set the header ID so that it can be used with aria-labelledby in AccordionContent
|
|
20
28
|
$state.headerId = $props.id;
|
|
@@ -45,10 +53,10 @@ export default function AccordionTrigger() {
|
|
|
45
53
|
class={`torp-accordion-trigger ${$props.class ?? ""}`.trim()}
|
|
46
54
|
disabled={$state.disabled || $state.parentDisabled}
|
|
47
55
|
aria-expanded={$state.expanded.toString()}
|
|
48
|
-
aria-disabled={$state.disabled}
|
|
56
|
+
aria-disabled={$state.disabled ? "true" : undefined}
|
|
49
57
|
aria-controls={$state.contentId}
|
|
50
58
|
data-state={$state.dataState}
|
|
51
|
-
data-disabled={$state.disabled}
|
|
59
|
+
data-disabled={$state.disabled ? "true" : undefined}
|
|
52
60
|
&ref={button}
|
|
53
61
|
onclick={handleClick}
|
|
54
62
|
onkeydown={handleKey}
|
|
@@ -1,90 +1,155 @@
|
|
|
1
1
|
import { type SlotRender } from "@torpor/view";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
interface AccordionProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** Whether a single AccordionItem or multiple AccordionItems can be expanded at the same time */
|
|
10
|
+
type?: "single" | "multiple",
|
|
11
|
+
/** The value of the expanded AccordionItem, or an array of values if the type is "multiple" */
|
|
12
|
+
value?: string | string[],
|
|
13
|
+
/** If set to true, the user cannot interact with any items in the Accordion */
|
|
14
|
+
disabled?: boolean,
|
|
15
|
+
/** Raised when the expanded item(s) have changed */
|
|
16
|
+
onchange?: (value: string | string[]) => void,
|
|
17
|
+
}
|
|
18
|
+
|
|
4
19
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
20
|
+
* A vertically stacked set of interactive headings that enable users to reveal
|
|
21
|
+
* or hide associated sections of content.
|
|
22
|
+
*
|
|
23
|
+
* See [the WAI ARIA guidelines for Accordions](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/).
|
|
24
|
+
*
|
|
25
|
+
* The structure of an Accordion is:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* <Accordion>
|
|
29
|
+
* <AccordionItem>
|
|
30
|
+
* <AccordionHeader>
|
|
31
|
+
* <AccordionTrigger />
|
|
32
|
+
* </AccordionHeader>
|
|
33
|
+
* <AccordionContent />
|
|
34
|
+
* </AccordionItem>
|
|
35
|
+
* </Accordion>
|
|
36
|
+
* ```
|
|
11
37
|
*/
|
|
12
38
|
declare function Accordion(
|
|
13
39
|
$parent: ParentNode,
|
|
14
40
|
$anchor: Node | null,
|
|
15
|
-
$props:
|
|
41
|
+
$props: AccordionProps,
|
|
16
42
|
$context?: Record<PropertyKey, any>,
|
|
17
43
|
$slots?: Record<string, SlotRender>,
|
|
18
44
|
): void;
|
|
19
45
|
|
|
20
46
|
|
|
21
47
|
|
|
48
|
+
interface AccordionContentProps {
|
|
49
|
+
/** An ID for the root element */
|
|
50
|
+
id?: string;
|
|
51
|
+
/** Class name(s) for the root element */
|
|
52
|
+
class?: string,
|
|
53
|
+
/** Whether this content should act as a region. Set this when the content contains heading elements or a nested Accordion */
|
|
54
|
+
ariaRegion?: boolean,
|
|
55
|
+
}
|
|
56
|
+
|
|
22
57
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param $parent -- The parent node.
|
|
25
|
-
* @param $anchor -- The node to mount the component before.
|
|
26
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
27
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
28
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
58
|
+
* Content for an AccordionItem, which can be revealed or hidden by an associated AccordionTrigger.
|
|
29
59
|
*/
|
|
30
60
|
declare function AccordionContent(
|
|
31
61
|
$parent: ParentNode,
|
|
32
62
|
$anchor: Node | null,
|
|
33
|
-
$props:
|
|
63
|
+
$props: AccordionContentProps,
|
|
34
64
|
$context?: Record<PropertyKey, any>,
|
|
35
65
|
$slots?: Record<string, SlotRender>,
|
|
36
66
|
): void;
|
|
37
67
|
|
|
38
68
|
|
|
39
69
|
|
|
70
|
+
interface AccordionHeaderProps {
|
|
71
|
+
/** An ID for the root element */
|
|
72
|
+
id?: string;
|
|
73
|
+
/** Class name(s) for the root element */
|
|
74
|
+
class?: string,
|
|
75
|
+
/** The type of HTML header to use */
|
|
76
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
|
|
77
|
+
}
|
|
78
|
+
|
|
40
79
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
80
|
+
* The header for an AccordionItem, which contains the AccordionTrigger.
|
|
81
|
+
*
|
|
82
|
+
* The structure of an AccordionHeader is:
|
|
83
|
+
*
|
|
84
|
+
* ```
|
|
85
|
+
* <AccordionHeader>
|
|
86
|
+
* <AccordionTrigger />
|
|
87
|
+
* </AccordionHeader>
|
|
88
|
+
* ```
|
|
47
89
|
*/
|
|
48
90
|
declare function AccordionHeader(
|
|
49
91
|
$parent: ParentNode,
|
|
50
92
|
$anchor: Node | null,
|
|
51
|
-
$props:
|
|
93
|
+
$props: AccordionHeaderProps,
|
|
52
94
|
$context?: Record<PropertyKey, any>,
|
|
53
95
|
$slots?: Record<string, SlotRender>,
|
|
54
96
|
): void;
|
|
55
97
|
|
|
56
98
|
|
|
57
99
|
|
|
100
|
+
interface AccordionItemProps {
|
|
101
|
+
/** An ID for the root element */
|
|
102
|
+
id?: string;
|
|
103
|
+
/** Class name(s) for the root element */
|
|
104
|
+
class?: string,
|
|
105
|
+
/** The index of this item in the Accordion. Set this if you will be inserting, removing or sorting items. If you don't set this, it will be set automatically */
|
|
106
|
+
index?: number,
|
|
107
|
+
/** A value for the item. Set this if you need more control over which item(s) are expanded. If you don't set this, the value will be set to the item's initial index */
|
|
108
|
+
value?: string,
|
|
109
|
+
/** If set to true, the user cannot interact with this AccordionItem */
|
|
110
|
+
disabled?: boolean,
|
|
111
|
+
/** Raised when this item is opened or closed */
|
|
112
|
+
ontoggle?: (open: boolean) => void,
|
|
113
|
+
}
|
|
114
|
+
|
|
58
115
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
116
|
+
* An item in an Accordion, which must consist of an AccordionTrigger and an AccordionContent.
|
|
117
|
+
*
|
|
118
|
+
* The structure of an AccordionItem is:
|
|
119
|
+
*
|
|
120
|
+
* ```
|
|
121
|
+
* <AccordionItem>
|
|
122
|
+
* <AccordionHeader>
|
|
123
|
+
* <AccordionTrigger />
|
|
124
|
+
* </AccordionHeader>
|
|
125
|
+
* <AccordionContent />
|
|
126
|
+
* </AccordionItem>
|
|
127
|
+
* ```
|
|
65
128
|
*/
|
|
66
129
|
declare function AccordionItem(
|
|
67
130
|
$parent: ParentNode,
|
|
68
131
|
$anchor: Node | null,
|
|
69
|
-
$props:
|
|
132
|
+
$props: AccordionItemProps,
|
|
70
133
|
$context?: Record<PropertyKey, any>,
|
|
71
134
|
$slots?: Record<string, SlotRender>,
|
|
72
135
|
): void;
|
|
73
136
|
|
|
74
137
|
|
|
75
138
|
|
|
139
|
+
interface AccordionTriggerProps {
|
|
140
|
+
/** An ID for the root element */
|
|
141
|
+
id?: string;
|
|
142
|
+
/** Class name(s) for the root element */
|
|
143
|
+
class?: string,
|
|
144
|
+
}
|
|
145
|
+
|
|
76
146
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param $parent -- The parent node.
|
|
79
|
-
* @param $anchor -- The node to mount the component before.
|
|
80
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
81
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
82
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
147
|
+
* A header button for an AccordionItem, which can be used to reveal or hide an associated AccordionContent.
|
|
83
148
|
*/
|
|
84
149
|
declare function AccordionTrigger(
|
|
85
150
|
$parent: ParentNode,
|
|
86
151
|
$anchor: Node | null,
|
|
87
|
-
$props
|
|
152
|
+
$props: AccordionTriggerProps,
|
|
88
153
|
$context?: Record<PropertyKey, any>,
|
|
89
154
|
$slots?: Record<string, SlotRender>,
|
|
90
155
|
): void;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
interface BreadcrumbProps {
|
|
3
|
+
/** An ID for the root element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Class name(s) for the root element */
|
|
6
|
+
class?: string,
|
|
7
|
+
/** An ARIA label for describing the popover to screen readers */
|
|
8
|
+
ariaLabel?: string | undefined,
|
|
9
|
+
}
|
|
10
|
+
|
|
2
11
|
/**
|
|
3
12
|
*
|
|
4
13
|
* A list of links to the parent pages of the current page in hierarchical order.
|
|
@@ -17,10 +26,10 @@
|
|
|
17
26
|
* ```
|
|
18
27
|
*
|
|
19
28
|
* You can separate BreadcrumbItems using BreadcrumbSeparators or by using CSS.
|
|
20
|
-
*
|
|
21
|
-
* @prop {string | undefined} ariaLabel -- An ARIA label for describing the popover to screen readers
|
|
22
29
|
*/
|
|
23
|
-
export default function Breadcrumb($props:
|
|
30
|
+
export default function Breadcrumb($props: BreadcrumbProps) {
|
|
31
|
+
$props ??= $watch({});
|
|
32
|
+
|
|
24
33
|
@render {
|
|
25
34
|
<nav
|
|
26
35
|
{$props.id}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
|
|
2
|
+
interface BreadcrumbItemProps {
|
|
3
|
+
/** An ID for the root element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Class name(s) for the root element */
|
|
6
|
+
class?: string,
|
|
7
|
+
/** Whether this is the current page */
|
|
8
|
+
current?: boolean,
|
|
9
|
+
}
|
|
10
|
+
|
|
2
11
|
/**
|
|
3
12
|
* An item in a breadcrumb, containing a link to one of the parent pages of the
|
|
4
13
|
* current page (or the current page).
|
|
5
|
-
*
|
|
6
|
-
* @prop {boolean | undefined} current -- Whether this is the current page
|
|
7
14
|
*/
|
|
8
|
-
export default function BreadcrumbItem($props:
|
|
15
|
+
export default function BreadcrumbItem($props: BreadcrumbItemProps) {
|
|
16
|
+
$props ??= $watch({});
|
|
17
|
+
|
|
9
18
|
@render {
|
|
10
19
|
<div
|
|
11
20
|
{$props.id}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
interface BreadcrumbSeparatorProps {
|
|
3
|
+
/** An ID for the root element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Class name(s) for the root element */
|
|
6
|
+
class?: string,
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
/**
|
|
3
10
|
* A separator between links in a Breadcrumb component. It is hidden from
|
|
4
11
|
* screen readers.
|
|
5
12
|
*/
|
|
6
|
-
export default function BreadcrumbSeparator($props:
|
|
13
|
+
export default function BreadcrumbSeparator($props: BreadcrumbSeparatorProps) {
|
|
14
|
+
$props ??= $watch({});
|
|
15
|
+
|
|
7
16
|
@render {
|
|
8
17
|
<div
|
|
9
18
|
{$props.id}
|
|
@@ -1,54 +1,82 @@
|
|
|
1
1
|
import { type SlotRender } from "@torpor/view";
|
|
2
2
|
|
|
3
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
|
+
|
|
4
13
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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.
|
|
11
31
|
*/
|
|
12
32
|
declare function Breadcrumb(
|
|
13
33
|
$parent: ParentNode,
|
|
14
34
|
$anchor: Node | null,
|
|
15
|
-
$props:
|
|
35
|
+
$props: BreadcrumbProps,
|
|
16
36
|
$context?: Record<PropertyKey, any>,
|
|
17
37
|
$slots?: Record<string, SlotRender>,
|
|
18
38
|
): void;
|
|
19
39
|
|
|
20
40
|
|
|
21
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
|
+
|
|
22
51
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param $anchor -- The node to mount the component before.
|
|
26
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
27
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
28
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
52
|
+
* An item in a breadcrumb, containing a link to one of the parent pages of the
|
|
53
|
+
* current page (or the current page).
|
|
29
54
|
*/
|
|
30
55
|
declare function BreadcrumbItem(
|
|
31
56
|
$parent: ParentNode,
|
|
32
57
|
$anchor: Node | null,
|
|
33
|
-
$props:
|
|
58
|
+
$props: BreadcrumbItemProps,
|
|
34
59
|
$context?: Record<PropertyKey, any>,
|
|
35
60
|
$slots?: Record<string, SlotRender>,
|
|
36
61
|
): void;
|
|
37
62
|
|
|
38
63
|
|
|
39
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
|
+
|
|
40
72
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @param $anchor -- The node to mount the component before.
|
|
44
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
45
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
46
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
73
|
+
* A separator between links in a Breadcrumb component. It is hidden from
|
|
74
|
+
* screen readers.
|
|
47
75
|
*/
|
|
48
76
|
declare function BreadcrumbSeparator(
|
|
49
77
|
$parent: ParentNode,
|
|
50
78
|
$anchor: Node | null,
|
|
51
|
-
$props:
|
|
79
|
+
$props: BreadcrumbSeparatorProps,
|
|
52
80
|
$context?: Record<PropertyKey, any>,
|
|
53
81
|
$slots?: Record<string, SlotRender>,
|
|
54
82
|
): void;
|
|
@@ -7,7 +7,15 @@ import ChevronRight from "../icons/ChevronRight.torp";
|
|
|
7
7
|
|
|
8
8
|
// TODO: Split this out into Calendar, CalendarHeader, CalendarPreviousTrigger, CalendarGrid etc
|
|
9
9
|
|
|
10
|
-
|
|
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({});
|
|
11
19
|
$props.startOfWeek ??= 1;
|
|
12
20
|
$props.selectable ??= false;
|
|
13
21
|
$props.value ??= new Date();
|