@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,250 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { TabGroupContextName, type TabGroupContext, type ItemState } from "./TabGroupTypes";
|
|
3
|
-
|
|
4
|
-
interface TabGroupProps {
|
|
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 orientation of the tab buttons, which affects keyboard navigation */
|
|
12
|
-
orientation?: "horizontal" | "vertical",
|
|
13
|
-
/** How tabs are activated; if automatic they are shown on focus, if manual they must be clicked */
|
|
14
|
-
activation?: "automatic" | "manual",
|
|
15
|
-
/** The value of the active TabContent */
|
|
16
|
-
value?: string,
|
|
17
|
-
/** If set to true, the user cannot interact with any items in the TabGroup */
|
|
18
|
-
disabled?: boolean,
|
|
19
|
-
/** Raised when the active item has changed */
|
|
20
|
-
onchange?: (value: string | string[]) => void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A list of interactive headings coupled with layered sections of content that
|
|
25
|
-
* enable users to reveal a single section of content at a time.
|
|
26
|
-
*
|
|
27
|
-
* See [the WAI ARIA guidelines for Tabs](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/).
|
|
28
|
-
*
|
|
29
|
-
* The structure of a TabGroup is:
|
|
30
|
-
*
|
|
31
|
-
* ```
|
|
32
|
-
* <TabGroup>
|
|
33
|
-
* <TabList>
|
|
34
|
-
* <TabHeader>
|
|
35
|
-
* <TabTrigger />
|
|
36
|
-
* </TabHeader>
|
|
37
|
-
* </TabList>
|
|
38
|
-
* <TabContent />
|
|
39
|
-
* </TabGroup>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export default function TabGroup($props: TabGroupProps | undefined) {
|
|
43
|
-
let orientation = $props?.orientation ?? "horizontal";
|
|
44
|
-
let activation = $props?.activation ?? "automatic";
|
|
45
|
-
|
|
46
|
-
let $state = $watch({
|
|
47
|
-
value: ""
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Sync props and state
|
|
51
|
-
$run(() => {
|
|
52
|
-
$state.value = $props?.value ?? "";
|
|
53
|
-
});
|
|
54
|
-
$run(() => {
|
|
55
|
-
if ($props !== undefined) {
|
|
56
|
-
$props.value = $state.value;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
let itemStates: ItemState[] = [];
|
|
61
|
-
|
|
62
|
-
// This is used to assign automatic indexes to items where needed
|
|
63
|
-
let nextHeaderIndex = 0;
|
|
64
|
-
let nextItemIndex = 0;
|
|
65
|
-
|
|
66
|
-
// Set the context to pass down to headers and content, with functions for each item to call
|
|
67
|
-
let context: TabGroupContext = {
|
|
68
|
-
registerHeader,
|
|
69
|
-
registerItem,
|
|
70
|
-
removeItem,
|
|
71
|
-
triggerItem,
|
|
72
|
-
handleHeaderKey,
|
|
73
|
-
orientation,
|
|
74
|
-
activation,
|
|
75
|
-
};
|
|
76
|
-
$context[TabGroupContextName] = context;
|
|
77
|
-
|
|
78
|
-
$run(() => {
|
|
79
|
-
// Ensure the value passed in was a string (in case e.g. the user has set values to ints)
|
|
80
|
-
$state.value = $state.value.toString();
|
|
81
|
-
for (let item of itemStates) {
|
|
82
|
-
item.active = item.value === $state.value;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
$run(() => {
|
|
87
|
-
itemStates.forEach((s) => s.parentDisabled = $props?.disabled === true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Dispatch the change event when the value changes
|
|
91
|
-
let firstChange = true;
|
|
92
|
-
$run(() => {
|
|
93
|
-
const ev = $props?.onchange;
|
|
94
|
-
const value = $props?.value;
|
|
95
|
-
if (firstChange) {
|
|
96
|
-
firstChange = false;
|
|
97
|
-
} else if (ev) {
|
|
98
|
-
ev(value!);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// On mount, if no value was set, show the first tab content
|
|
103
|
-
$mount(() => {
|
|
104
|
-
if ($state.value === "" && itemStates.length) {
|
|
105
|
-
$state.value = itemStates[0].value;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
function registerHeader(index: number | undefined, value: string | undefined, setFocused: () => void): ItemState {
|
|
110
|
-
// If an index wasn't set for the header, set it automatically
|
|
111
|
-
if (!index) {
|
|
112
|
-
index = nextHeaderIndex++;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Get or add the ItemState at this index
|
|
116
|
-
const itemState = getItemState(index, value);
|
|
117
|
-
|
|
118
|
-
itemState.setFocused = setFocused;
|
|
119
|
-
|
|
120
|
-
return itemState;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function registerItem(index: number | undefined, value: string | undefined): ItemState {
|
|
124
|
-
// If an index wasn't set for the item, set it automatically
|
|
125
|
-
if (index === undefined) {
|
|
126
|
-
index = nextItemIndex++;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Get or add the ItemState at this index
|
|
130
|
-
const itemState = getItemState(index, value);
|
|
131
|
-
|
|
132
|
-
return itemState;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function getItemState(index: number, value: string | undefined): ItemState {
|
|
136
|
-
// If we already have an item at this index, just return it
|
|
137
|
-
if (itemStates.length > index) {
|
|
138
|
-
return itemStates[index];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// If a value wasn't set for the item, set it to the index
|
|
142
|
-
if (value === undefined) {
|
|
143
|
-
value = index.toString();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Add the item's state to the array
|
|
147
|
-
const newItemState: ItemState = $watch({
|
|
148
|
-
index,
|
|
149
|
-
value,
|
|
150
|
-
// TODO: this would be better than using $mount, but it doesn't work with nested tabs
|
|
151
|
-
// active: value === $props?.value || ($props?.value === "" && index === 0),
|
|
152
|
-
active: value === $state.value,
|
|
153
|
-
headerId: "",
|
|
154
|
-
contentId: "",
|
|
155
|
-
disabled: false,
|
|
156
|
-
parentDisabled: false,
|
|
157
|
-
get dataState() {
|
|
158
|
-
return this.active ? "active" : "inactive";
|
|
159
|
-
},
|
|
160
|
-
setFocused: () => {},
|
|
161
|
-
orientation,
|
|
162
|
-
activation
|
|
163
|
-
});
|
|
164
|
-
itemStates.splice(index, 0, newItemState);
|
|
165
|
-
|
|
166
|
-
return newItemState;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// TODO: I think this should be done by value
|
|
170
|
-
function removeItem(itemIndex: number) {
|
|
171
|
-
// Remove the item and re-index
|
|
172
|
-
let index = itemStates.findIndex((item) => item.index === itemIndex);
|
|
173
|
-
if (index !== -1) {
|
|
174
|
-
itemStates.splice(itemIndex, 1);
|
|
175
|
-
}
|
|
176
|
-
itemStates.forEach((item, i) => (item.index = i));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function triggerItem(toggleValue: string) {
|
|
180
|
-
for (let item of itemStates) {
|
|
181
|
-
// The item is active if it has the supplied value
|
|
182
|
-
if (item.value === toggleValue) {
|
|
183
|
-
$state.value = item.value;
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function handleHeaderKey(headerIndex: number, e: KeyboardEvent) {
|
|
190
|
-
switch (e.key) {
|
|
191
|
-
case "Left":
|
|
192
|
-
case "ArrowLeft": {
|
|
193
|
-
if (orientation === "horizontal" && headerIndex > 0) {
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
itemStates[headerIndex - 1].setFocused();
|
|
196
|
-
}
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case "Up":
|
|
200
|
-
case "ArrowUp": {
|
|
201
|
-
if (orientation === "vertical" && headerIndex > 0) {
|
|
202
|
-
e.preventDefault();
|
|
203
|
-
itemStates[headerIndex - 1].setFocused();
|
|
204
|
-
}
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
case "Right":
|
|
208
|
-
case "ArrowRight": {
|
|
209
|
-
if (orientation === "horizontal" && headerIndex < itemStates.length - 1) {
|
|
210
|
-
e.preventDefault();
|
|
211
|
-
itemStates[headerIndex + 1].setFocused();
|
|
212
|
-
}
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
case "Down":
|
|
216
|
-
case "ArrowDown": {
|
|
217
|
-
if (orientation === "vertical" && headerIndex < itemStates.length - 1) {
|
|
218
|
-
e.preventDefault();
|
|
219
|
-
itemStates[headerIndex + 1].setFocused();
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case "Home": {
|
|
224
|
-
if (headerIndex > 0) {
|
|
225
|
-
e.preventDefault();
|
|
226
|
-
itemStates[0].setFocused();
|
|
227
|
-
}
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case "End": {
|
|
231
|
-
if (headerIndex < itemStates.length - 1) {
|
|
232
|
-
e.preventDefault();
|
|
233
|
-
itemStates[itemStates.length - 1].setFocused();
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
@render {
|
|
241
|
-
<div
|
|
242
|
-
{$props?.id}
|
|
243
|
-
class={["torp-tab-group", $props?.class]}
|
|
244
|
-
{$props?.style}
|
|
245
|
-
data-orientation={$props?.orientation}
|
|
246
|
-
>
|
|
247
|
-
<slot />
|
|
248
|
-
</div>
|
|
249
|
-
}
|
|
250
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export const TabGroupContextName = "TabGroup";
|
|
2
|
-
export const TabItemContextName = "TabItem";
|
|
3
|
-
|
|
4
|
-
export interface TabGroupContext {
|
|
5
|
-
/** Called from a header when it is added */
|
|
6
|
-
registerHeader: (
|
|
7
|
-
index: number | undefined,
|
|
8
|
-
value: string | undefined,
|
|
9
|
-
setFocused: () => void,
|
|
10
|
-
) => ItemState;
|
|
11
|
-
/** Called from an item when it is added */
|
|
12
|
-
registerItem: (index: number | undefined, value: string | undefined) => ItemState;
|
|
13
|
-
/** Called from an item when it is removed */
|
|
14
|
-
removeItem: (index: number) => void;
|
|
15
|
-
/** Called from an item when it is triggered */
|
|
16
|
-
triggerItem: (value: string) => void;
|
|
17
|
-
/** Called from a TabHeader when it receives a keyboard event */
|
|
18
|
-
handleHeaderKey: (index: number, e: KeyboardEvent) => void;
|
|
19
|
-
orientation: "horizontal" | "vertical";
|
|
20
|
-
activation: "automatic" | "manual";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface TabItemContext {
|
|
24
|
-
/** Raised when an item is triggered */
|
|
25
|
-
triggerItem: (value: string) => void;
|
|
26
|
-
/** Raised when a TabHeader receives a keyboard event */
|
|
27
|
-
handleHeaderKey: (index: number, e: KeyboardEvent) => void;
|
|
28
|
-
/** The reactive state for an item */
|
|
29
|
-
state: ItemState;
|
|
30
|
-
orientation: "horizontal" | "vertical";
|
|
31
|
-
activation: "automatic" | "manual";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ItemState {
|
|
35
|
-
index: number;
|
|
36
|
-
value: string;
|
|
37
|
-
active: boolean;
|
|
38
|
-
headerId: string;
|
|
39
|
-
contentId: string;
|
|
40
|
-
disabled: boolean;
|
|
41
|
-
parentDisabled: boolean;
|
|
42
|
-
/** Called in the TabGroup when a header needs to be focused */
|
|
43
|
-
setFocused: () => void;
|
|
44
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { TabGroupContextName, TabItemContextName, type TabGroupContext, type TabItemContext } from "./TabGroupTypes";
|
|
3
|
-
|
|
4
|
-
interface TabHeaderProps {
|
|
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
|
-
/** The index of this header's item */
|
|
14
|
-
index?: number,
|
|
15
|
-
/** The value for this header's item */
|
|
16
|
-
value?: string,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The header for a tab item, which contains the TabTrigger.
|
|
21
|
-
*
|
|
22
|
-
* The structure of a TabHeader is:
|
|
23
|
-
*
|
|
24
|
-
* ```
|
|
25
|
-
* <TabHeader>
|
|
26
|
-
* <TabTrigger />
|
|
27
|
-
* </TabHeader>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export default function TabHeader($props: TabHeaderProps | undefined) {
|
|
31
|
-
let button: HTMLButtonElement;
|
|
32
|
-
|
|
33
|
-
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
34
|
-
if (!context) {
|
|
35
|
-
throw new Error("TabHeader must be contained within a TabGroup");
|
|
36
|
-
}
|
|
37
|
-
let $state = context.registerHeader($props?.index, $props?.value);
|
|
38
|
-
|
|
39
|
-
const itemContext: TabItemContext = {
|
|
40
|
-
triggerItem: context.triggerItem,
|
|
41
|
-
handleHeaderKey: context.handleHeaderKey,
|
|
42
|
-
state: $state,
|
|
43
|
-
orientation: context.orientation,
|
|
44
|
-
activation: context.activation
|
|
45
|
-
};
|
|
46
|
-
$context[TabItemContextName] = itemContext;
|
|
47
|
-
|
|
48
|
-
// Remove the item from the parent TabGroup when this item is destroyed
|
|
49
|
-
$run(() => {
|
|
50
|
-
return () => {
|
|
51
|
-
context.removeItem($state.index);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
@render {
|
|
56
|
-
@// TODO: $props?.as
|
|
57
|
-
<h4
|
|
58
|
-
{$props?.id}
|
|
59
|
-
class={[
|
|
60
|
-
"torp-tab-header",
|
|
61
|
-
$props?.class,
|
|
62
|
-
context.orientation
|
|
63
|
-
]}
|
|
64
|
-
data-state={$state.active ? "active" : "inactive"}
|
|
65
|
-
data-disabled={$state.disabled ? "true" : undefined}
|
|
66
|
-
&ref={button}
|
|
67
|
-
>
|
|
68
|
-
<slot />
|
|
69
|
-
</h4>
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@style {
|
|
73
|
-
.torp-tab-header.horizontal {
|
|
74
|
-
display: inline-block;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.torp-tab-header.vertical {
|
|
78
|
-
display: block;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import { TabGroupContextName, type TabGroupContext } from "./TabGroupTypes";
|
|
3
|
-
|
|
4
|
-
interface TabListProps {
|
|
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
|
-
/** An ARIA label for describing the tab list to screen readers */
|
|
12
|
-
ariaLabel?: string,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A component that holds the TabHeaders of a TabGroup.
|
|
17
|
-
*
|
|
18
|
-
* The structure of a TabList is:
|
|
19
|
-
*
|
|
20
|
-
* ```
|
|
21
|
-
* <TabList>
|
|
22
|
-
* <TabHeader>
|
|
23
|
-
* <TabTrigger />
|
|
24
|
-
* </TabHeader>
|
|
25
|
-
* </TabList>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export default function TabList($props: TabListProps | undefined) {
|
|
29
|
-
// Get stuff out of the TabGroupContext
|
|
30
|
-
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error("TabList must be contained within a TabGroup");
|
|
33
|
-
}
|
|
34
|
-
// TODO: const { orientation } = context;
|
|
35
|
-
const orientation = context.orientation;
|
|
36
|
-
|
|
37
|
-
function handleFocus(e: FocusEvent & { currentTarget: EventTarget & HTMLElement }) {
|
|
38
|
-
// TODO: Should this be the first button?
|
|
39
|
-
const el = e.currentTarget.childNodes[0];
|
|
40
|
-
if (el instanceof HTMLElement) {
|
|
41
|
-
el.focus();
|
|
42
|
-
e.preventDefault();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@render {
|
|
47
|
-
<div
|
|
48
|
-
{$props?.id}
|
|
49
|
-
class={["torp-tab-list", $props?.class]}
|
|
50
|
-
{$props?.style}
|
|
51
|
-
role="tablist"
|
|
52
|
-
aria-label={$props?.ariaLabel}
|
|
53
|
-
aria-orientation={orientation}
|
|
54
|
-
data-orientation={orientation}
|
|
55
|
-
tabindex="0"
|
|
56
|
-
onfocus={handleFocus}
|
|
57
|
-
>
|
|
58
|
-
<slot />
|
|
59
|
-
</div>
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import getId from "../utils/getId";
|
|
3
|
-
import { TabItemContextName, type TabItemContext } from "./TabGroupTypes";
|
|
4
|
-
|
|
5
|
-
interface TabTriggerProps {
|
|
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 tab item, which can be used to reveal an associated TabContent.
|
|
16
|
-
*/
|
|
17
|
-
export default function TabTrigger($props: TabTriggerProps | undefined) {
|
|
18
|
-
let defaultId = getId();
|
|
19
|
-
|
|
20
|
-
let button: HTMLButtonElement;
|
|
21
|
-
|
|
22
|
-
// Get stuff out of the TabItemContext
|
|
23
|
-
const context = $context[TabItemContextName] as TabItemContext;
|
|
24
|
-
if (!context) {
|
|
25
|
-
throw new Error("TabTrigger must be contained within a TabHeader");
|
|
26
|
-
}
|
|
27
|
-
let $state = context.state;
|
|
28
|
-
|
|
29
|
-
// Set the header ID so that it can be used with aria-labelledby in TabContent
|
|
30
|
-
$state.headerId = $props?.id ?? defaultId;
|
|
31
|
-
|
|
32
|
-
// Let the item know how to set the button's focus
|
|
33
|
-
$state.setFocused = setFocused;
|
|
34
|
-
|
|
35
|
-
// This function is called by the parent TabGroup to focus this item's button
|
|
36
|
-
function setFocused() {
|
|
37
|
-
button.focus();
|
|
38
|
-
if (context.activation === "automatic") {
|
|
39
|
-
context.triggerItem($state.value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function handleClick() {
|
|
44
|
-
// Pass the value to the triggerItem method in the parent TabGroup which will handle toggling
|
|
45
|
-
// the value of active for all items (e.g. to close other items if necessary)
|
|
46
|
-
context.triggerItem($state.value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function handleKey(e: KeyboardEvent) {
|
|
50
|
-
// Pass the key press up to the parent TabGroup which will handle setting the focused button
|
|
51
|
-
context.handleHeaderKey($state.index, e);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@render {
|
|
55
|
-
<button
|
|
56
|
-
type="button"
|
|
57
|
-
id={$props?.id ?? defaultId}
|
|
58
|
-
class={["torp-tab-trigger", $props?.class]}
|
|
59
|
-
{$props?.style}
|
|
60
|
-
role="tab"
|
|
61
|
-
tabindex="-1"
|
|
62
|
-
disabled={$state.disabled || $state.parentDisabled}
|
|
63
|
-
aria-selected={$state.active.toString()}
|
|
64
|
-
aria-disabled={$state.disabled}
|
|
65
|
-
aria-controls={$state.contentId}
|
|
66
|
-
data-state={$state.active ? "active" : "inactive"}
|
|
67
|
-
data-disabled={$state.disabled}
|
|
68
|
-
data-orientation={context.orientation}
|
|
69
|
-
&ref={button}
|
|
70
|
-
onclick={handleClick}
|
|
71
|
-
onkeydown={handleKey}
|
|
72
|
-
>
|
|
73
|
-
<slot />
|
|
74
|
-
</button>
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/TabGroup/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import TabContent from "./TabContent.torp";
|
|
2
|
-
import TabGroup from "./TabGroup.torp";
|
|
3
|
-
import TabHeader from "./TabHeader.torp";
|
|
4
|
-
import TabList from "./TabList.torp";
|
|
5
|
-
import TabTrigger from "./TabTrigger.torp";
|
|
6
|
-
|
|
7
|
-
export { TabGroup, TabList, TabHeader, TabTrigger, TabContent };
|
package/src/ambient.d.ts
DELETED
package/src/icons/ArrowDown.torp
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ArrowDown($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<polygon points="25,40 50,70 75,40" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/icons/ArrowLeft.torp
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ArrowLeft($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<polygon points="60,25 30,50 60,75" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ArrowRight($props: IconProps | any) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<polygon points="40,25 70,50 40,75" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/icons/ArrowUp.torp
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ArrowUp($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<polygon points="25,60 50,30 75,60" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/icons/Bars.torp
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function Bars($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<path d="M10,25 L90,25" />
|
|
15
|
-
<path d="M10,50 L90,50" />
|
|
16
|
-
<path d="M10,75 L90,75" />
|
|
17
|
-
</g>
|
|
18
|
-
</svg>
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/icons/Check.torp
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function Check($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<path d="M10,55 L35,80 L90,25" fill="none" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ChevronDown($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<path d="M10,30 L50,70 L90,30" fill="none" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type IconProps } from "./IconTypes";
|
|
2
|
-
|
|
3
|
-
export default function ChevronLeft($props: IconProps | undefined) {
|
|
4
|
-
@render {
|
|
5
|
-
<svg
|
|
6
|
-
{$props?.id}
|
|
7
|
-
class={["torp-icon", $props?.class]}
|
|
8
|
-
{$props?.style}
|
|
9
|
-
viewBox="0 0 100 100"
|
|
10
|
-
stroke-linejoin="round"
|
|
11
|
-
stroke-width="12"
|
|
12
|
-
>
|
|
13
|
-
<g>
|
|
14
|
-
<path d="M70,10 L30,50 L70,90" fill="none" />
|
|
15
|
-
</g>
|
|
16
|
-
</svg>
|
|
17
|
-
}
|
|
18
|
-
}
|