@c9up/nebula 0.1.9 → 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/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/configure.d.ts +6 -0
- package/dist/configure.js +4 -22
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/id.d.ts +13 -29
- package/dist/lib/id.js +13 -39
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/dist/stubs.d.ts +13 -0
- package/dist/stubs.js +14 -0
- package/nebula.css +1 -1
- package/package.json +4 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/configure.ts +10 -23
- package/src/lib/children.ts +31 -0
- package/src/lib/id.ts +11 -39
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
- package/src/stubs.ts +16 -0
- package/stubs/config/nebula.stub +21 -0
|
@@ -29,7 +29,7 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
|
|
|
29
29
|
import { type Reactive, read } from "../lib/props.js";
|
|
30
30
|
import { controllable } from "../primitives/controllable.js";
|
|
31
31
|
import { modalSurface } from "../primitives/modalSurface.js";
|
|
32
|
-
import { Command, type
|
|
32
|
+
import { Command, type CommandProps } from "./Command.js";
|
|
33
33
|
import { dialogBackdropClasses } from "./Dialog.js";
|
|
34
34
|
|
|
35
35
|
export interface CommandDialogProps extends Omit<CommandProps, "class"> {
|
|
@@ -85,8 +85,8 @@ export const CommandDialog = component<CommandDialogProps>((props) => {
|
|
|
85
85
|
state.set(false);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function runAndClose(
|
|
89
|
-
props.onSelect?.(
|
|
88
|
+
function runAndClose(value: string): void {
|
|
89
|
+
props.onSelect?.(value);
|
|
90
90
|
// Closing after the action, not before: a handler that opens another
|
|
91
91
|
// surface should not have this one tearing down focus underneath it.
|
|
92
92
|
close();
|
|
@@ -132,11 +132,11 @@ export const CommandDialog = component<CommandDialogProps>((props) => {
|
|
|
132
132
|
: html`<p id="${descriptionId}" class="sr-only">${props.description}</p>`
|
|
133
133
|
}
|
|
134
134
|
${Command({
|
|
135
|
-
items: props.items,
|
|
136
|
-
placeholder: props.placeholder,
|
|
137
|
-
emptyMessage: props.emptyMessage,
|
|
138
135
|
filter: props.filter,
|
|
139
136
|
onSelect: runAndClose,
|
|
137
|
+
// Passed straight through: `Command` calls it inside its own
|
|
138
|
+
// setup, which is where the parts find its context.
|
|
139
|
+
children: props.children,
|
|
140
140
|
})}
|
|
141
141
|
</div>
|
|
142
142
|
</div>`,
|
|
@@ -1,46 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ContextMenu —
|
|
2
|
+
* ContextMenu — the menu a right-click opens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* ContextMenu({ children: () => html`
|
|
5
|
+
* ${ContextMenuTrigger({ children: "Right-click me" })}
|
|
6
|
+
* ${ContextMenuContent({ children: () => html`
|
|
7
|
+
* ${ContextMenuItem({ children: "Cut", onSelect: cut })}
|
|
8
|
+
* ` })}
|
|
9
|
+
* ` })
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* off screen.
|
|
11
|
+
* The rows come from `createMenuParts`, so a context menu and a dropdown menu
|
|
12
|
+
* cannot drift apart. What is specific here is the anchor: a context menu
|
|
13
|
+
* opens at the POINTER, not against a control, so a zero-size element is moved
|
|
14
|
+
* to the click coordinates and the surface is positioned against that.
|
|
13
15
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* Touch gets a long press, because there is no right button. It is cancelled
|
|
17
|
+
* by movement, so a scroll that starts on the region does not open a menu
|
|
18
|
+
* under the thumb.
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
+
import {
|
|
22
|
+
component,
|
|
23
|
+
createContext,
|
|
24
|
+
html,
|
|
25
|
+
inject,
|
|
26
|
+
onUnmount,
|
|
27
|
+
provide,
|
|
28
|
+
signal,
|
|
29
|
+
type TemplateResult,
|
|
30
|
+
} from "@c9up/aurora";
|
|
31
|
+
import type { Child, Parts, Slot } from "../lib/children.js";
|
|
32
|
+
import { slot } from "../lib/children.js";
|
|
21
33
|
import { cn } from "../lib/cn.js";
|
|
22
34
|
import { uid } from "../lib/id.js";
|
|
35
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
23
36
|
import { type Reactive, read } from "../lib/props.js";
|
|
24
37
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
25
|
-
import {
|
|
38
|
+
import { menuPanelClasses, wireMenu } from "../primitives/menu.js";
|
|
39
|
+
import { createMenuParts, type MenuOwner } from "../primitives/menuParts.js";
|
|
26
40
|
|
|
27
41
|
const LONG_PRESS_MS = 500;
|
|
28
42
|
|
|
43
|
+
interface RegisteredContent {
|
|
44
|
+
readonly body: Child;
|
|
45
|
+
readonly class?: Reactive<string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ContextMenuApi extends MenuOwner {
|
|
49
|
+
readonly anchorId: string;
|
|
50
|
+
readonly open: () => boolean;
|
|
51
|
+
openAt(x: number, y: number): void;
|
|
52
|
+
startLongPress(event: PointerEvent): void;
|
|
53
|
+
cancelLongPress(): void;
|
|
54
|
+
register(content: RegisteredContent): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ContextMenuContext = createContext<ContextMenuApi>("ContextMenu");
|
|
58
|
+
|
|
29
59
|
export interface ContextMenuProps {
|
|
30
|
-
/** The region that answers to right-click. */
|
|
31
|
-
children?: Slot;
|
|
32
|
-
entries: readonly MenuEntry[];
|
|
33
60
|
onOpenChange?: (open: boolean) => void;
|
|
34
|
-
|
|
35
|
-
contentClass?: Reactive<string>;
|
|
61
|
+
children?: Parts;
|
|
36
62
|
}
|
|
37
63
|
|
|
38
64
|
export const ContextMenu = component<ContextMenuProps>((props) => {
|
|
39
|
-
const regionId = uid("context-menu-region");
|
|
40
65
|
const anchorId = uid("context-menu-anchor");
|
|
41
66
|
const contentId = uid("context-menu-content");
|
|
42
67
|
const open = signal(false);
|
|
43
|
-
|
|
68
|
+
let content: RegisteredContent | undefined;
|
|
44
69
|
let unwire: (() => void) | null = null;
|
|
45
70
|
let pressTimer: ReturnType<typeof setTimeout> | undefined;
|
|
46
71
|
|
|
@@ -49,77 +74,154 @@ export const ContextMenu = component<ContextMenuProps>((props) => {
|
|
|
49
74
|
props.onOpenChange?.(next);
|
|
50
75
|
}
|
|
51
76
|
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
anchor.style.left = `${x}px`;
|
|
56
|
-
anchor.style.top = `${y}px`;
|
|
77
|
+
function cancelLongPress(): void {
|
|
78
|
+
if (pressTimer !== undefined) clearTimeout(pressTimer);
|
|
79
|
+
pressTimer = undefined;
|
|
57
80
|
}
|
|
58
81
|
|
|
59
82
|
function openAt(x: number, y: number): void {
|
|
60
|
-
|
|
83
|
+
const anchor = document.getElementById(anchorId);
|
|
84
|
+
if (anchor !== null) {
|
|
85
|
+
anchor.style.left = `${x}px`;
|
|
86
|
+
anchor.style.top = `${y}px`;
|
|
87
|
+
}
|
|
61
88
|
setOpen(true);
|
|
62
89
|
}
|
|
63
90
|
|
|
64
|
-
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
openAt(event.clientX, event.clientY);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function onPointerDown(event: PointerEvent): void {
|
|
70
|
-
if (event.pointerType !== "touch") return;
|
|
71
|
-
cancelPress();
|
|
72
|
-
pressTimer = setTimeout(
|
|
73
|
-
() => openAt(event.clientX, event.clientY),
|
|
74
|
-
LONG_PRESS_MS,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function cancelPress(): void {
|
|
79
|
-
if (pressTimer !== undefined) clearTimeout(pressTimer);
|
|
80
|
-
pressTimer = undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
onUnmount(cancelPress);
|
|
91
|
+
onUnmount(cancelLongPress);
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
provide<ContextMenuApi>(ContextMenuContext, {
|
|
94
|
+
anchorId,
|
|
87
95
|
open: () => open(),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class: read(props.contentClass),
|
|
97
|
-
}),
|
|
98
|
-
onOpened: (panel) => {
|
|
99
|
-
unwire = wireMenu(panel, { onCloseAll: () => setOpen(false) });
|
|
100
|
-
panel.focus({ preventScroll: true });
|
|
96
|
+
openAt,
|
|
97
|
+
startLongPress(event) {
|
|
98
|
+
if (event.pointerType !== "touch") return;
|
|
99
|
+
cancelLongPress();
|
|
100
|
+
pressTimer = setTimeout(
|
|
101
|
+
() => openAt(event.clientX, event.clientY),
|
|
102
|
+
LONG_PRESS_MS,
|
|
103
|
+
);
|
|
101
104
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
cancelLongPress,
|
|
106
|
+
closeAll: () => setOpen(false),
|
|
107
|
+
register(registered) {
|
|
108
|
+
content = registered;
|
|
105
109
|
},
|
|
106
110
|
});
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
const parts = props.children?.();
|
|
113
|
+
|
|
114
|
+
if (content !== undefined) {
|
|
115
|
+
const registered = content;
|
|
116
|
+
floatingSurface({
|
|
117
|
+
anchor: () => document.getElementById(anchorId),
|
|
118
|
+
open: () => open(),
|
|
119
|
+
onClose: () => setOpen(false),
|
|
120
|
+
placement: "bottom-start",
|
|
121
|
+
offset: 2,
|
|
122
|
+
content: () => renderPanel(registered, contentId),
|
|
123
|
+
onOpened: (panel) => {
|
|
124
|
+
unwire = wireMenu(panel, { onCloseAll: () => setOpen(false) });
|
|
125
|
+
panel.focus({ preventScroll: true });
|
|
126
|
+
},
|
|
127
|
+
onClosed: () => {
|
|
128
|
+
unwire?.();
|
|
129
|
+
unwire = null;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return html`${parts}`;
|
|
125
135
|
});
|
|
136
|
+
|
|
137
|
+
export interface ContextMenuTriggerProps {
|
|
138
|
+
children?: Slot;
|
|
139
|
+
class?: Reactive<string>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The region that answers to right-click, and the anchor the menu opens at. */
|
|
143
|
+
export const ContextMenuTrigger = component<ContextMenuTriggerProps>(
|
|
144
|
+
(props) => {
|
|
145
|
+
const menu = inject(ContextMenuContext);
|
|
146
|
+
function onContextMenu(event: MouseEvent): void {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
menu.openAt(event.clientX, event.clientY);
|
|
149
|
+
}
|
|
150
|
+
return html`<div
|
|
151
|
+
data-slot="context-menu-trigger"
|
|
152
|
+
data-state="${() => (menu.open() ? "open" : "closed")}"
|
|
153
|
+
class="${() => cn(read(props.class))}"
|
|
154
|
+
@contextmenu="${onContextMenu}"
|
|
155
|
+
@pointerdown="${(event: PointerEvent) => menu.startLongPress(event)}"
|
|
156
|
+
@pointerup="${() => menu.cancelLongPress()}"
|
|
157
|
+
@pointermove="${() => menu.cancelLongPress()}"
|
|
158
|
+
@pointercancel="${() => menu.cancelLongPress()}"
|
|
159
|
+
>${slot(props.children)}<span
|
|
160
|
+
id="${menu.anchorId}"
|
|
161
|
+
aria-hidden="true"
|
|
162
|
+
class="pointer-events-none fixed size-0"
|
|
163
|
+
></span></div>`;
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export interface ContextMenuContentProps {
|
|
168
|
+
children?: Parts;
|
|
169
|
+
class?: Reactive<string>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const ContextMenuContent = component<ContextMenuContentProps>(
|
|
173
|
+
(props) => {
|
|
174
|
+
const menu = inject(ContextMenuContext);
|
|
175
|
+
menu.register({ body: props.children?.(), class: props.class });
|
|
176
|
+
return html``;
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const parts = createMenuParts("context-menu", ContextMenuContext);
|
|
181
|
+
|
|
182
|
+
export const ContextMenuGroup = parts.Group;
|
|
183
|
+
export const ContextMenuItem = parts.Item;
|
|
184
|
+
export const ContextMenuCheckboxItem = parts.CheckboxItem;
|
|
185
|
+
export const ContextMenuRadioGroup = parts.RadioGroup;
|
|
186
|
+
export const ContextMenuRadioItem = parts.RadioItem;
|
|
187
|
+
export const ContextMenuLabel = parts.Label;
|
|
188
|
+
export const ContextMenuSeparator = parts.Separator;
|
|
189
|
+
export const ContextMenuShortcut = parts.Shortcut;
|
|
190
|
+
export const ContextMenuSub = parts.Sub;
|
|
191
|
+
export const ContextMenuSubTrigger = parts.SubTrigger;
|
|
192
|
+
export const ContextMenuSubContent = parts.SubContent;
|
|
193
|
+
export const ContextMenuPortal = parts.Portal;
|
|
194
|
+
|
|
195
|
+
export type {
|
|
196
|
+
MenuCheckboxItemProps as ContextMenuCheckboxItemProps,
|
|
197
|
+
MenuGroupProps as ContextMenuGroupProps,
|
|
198
|
+
MenuItemProps as ContextMenuItemProps,
|
|
199
|
+
MenuLabelProps as ContextMenuLabelProps,
|
|
200
|
+
MenuPortalProps as ContextMenuPortalProps,
|
|
201
|
+
MenuRadioGroupProps as ContextMenuRadioGroupProps,
|
|
202
|
+
MenuRadioItemProps as ContextMenuRadioItemProps,
|
|
203
|
+
MenuSeparatorProps as ContextMenuSeparatorProps,
|
|
204
|
+
MenuShortcutProps as ContextMenuShortcutProps,
|
|
205
|
+
MenuSubContentProps as ContextMenuSubContentProps,
|
|
206
|
+
MenuSubProps as ContextMenuSubProps,
|
|
207
|
+
MenuSubTriggerProps as ContextMenuSubTriggerProps,
|
|
208
|
+
} from "../primitives/menuParts.js";
|
|
209
|
+
|
|
210
|
+
function renderPanel(
|
|
211
|
+
registered: RegisteredContent,
|
|
212
|
+
contentId: string,
|
|
213
|
+
): TemplateResult {
|
|
214
|
+
return html`<div
|
|
215
|
+
data-slot="context-menu-content"
|
|
216
|
+
id="${contentId}"
|
|
217
|
+
role="menu"
|
|
218
|
+
aria-orientation="vertical"
|
|
219
|
+
tabindex="-1"
|
|
220
|
+
class="${cn(
|
|
221
|
+
menuPanelClasses,
|
|
222
|
+
zoomInOut,
|
|
223
|
+
slideInFromSide,
|
|
224
|
+
read(registered.class),
|
|
225
|
+
)}"
|
|
226
|
+
>${registered.body}</div>`;
|
|
227
|
+
}
|
|
@@ -30,7 +30,16 @@ import {
|
|
|
30
30
|
ChevronsUpDownIcon,
|
|
31
31
|
ChevronUpIcon,
|
|
32
32
|
} from "../lib/icons.js";
|
|
33
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
Pagination,
|
|
35
|
+
PaginationContent,
|
|
36
|
+
PaginationEllipsis,
|
|
37
|
+
PaginationItem,
|
|
38
|
+
PaginationLink,
|
|
39
|
+
PaginationNext,
|
|
40
|
+
PaginationPrevious,
|
|
41
|
+
pageWindow,
|
|
42
|
+
} from "../molecules/Pagination.js";
|
|
34
43
|
import {
|
|
35
44
|
Table,
|
|
36
45
|
TableBody,
|
|
@@ -271,17 +280,54 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
271
280
|
}),
|
|
272
281
|
],
|
|
273
282
|
})}
|
|
274
|
-
${
|
|
275
|
-
props.pageSize === undefined
|
|
276
|
-
? null
|
|
277
|
-
: Pagination({
|
|
278
|
-
page: () => Math.min(page(), pageCount()),
|
|
279
|
-
pageCount,
|
|
280
|
-
onPageChange: (next) => page(next),
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
+
${props.pageSize === undefined ? null : renderPagination()}
|
|
283
284
|
</div>`;
|
|
284
285
|
|
|
286
|
+
/**
|
|
287
|
+
* The page links.
|
|
288
|
+
*
|
|
289
|
+
* Composed from `Pagination`'s parts rather than described: `pageWindow`
|
|
290
|
+
* still decides WHICH pages are shown — first, last, a run around the
|
|
291
|
+
* current one and the gaps between — and the parts render that list.
|
|
292
|
+
*/
|
|
293
|
+
function renderPagination(): Child {
|
|
294
|
+
const current = (): number => Math.min(page(), pageCount());
|
|
295
|
+
const go = (target: number) => (): void => {
|
|
296
|
+
page(Math.min(Math.max(target, 1), pageCount()));
|
|
297
|
+
};
|
|
298
|
+
return Pagination({
|
|
299
|
+
children: () =>
|
|
300
|
+
PaginationContent({
|
|
301
|
+
children: [
|
|
302
|
+
PaginationItem({
|
|
303
|
+
children: PaginationPrevious({
|
|
304
|
+
disabled: () => current() <= 1,
|
|
305
|
+
onSelect: go(current() - 1),
|
|
306
|
+
}),
|
|
307
|
+
}),
|
|
308
|
+
...pageWindow(current(), pageCount()).map((entry) =>
|
|
309
|
+
PaginationItem({
|
|
310
|
+
children:
|
|
311
|
+
entry === null
|
|
312
|
+
? PaginationEllipsis({})
|
|
313
|
+
: PaginationLink({
|
|
314
|
+
children: String(entry),
|
|
315
|
+
isActive: () => current() === entry,
|
|
316
|
+
onSelect: go(entry),
|
|
317
|
+
}),
|
|
318
|
+
}),
|
|
319
|
+
),
|
|
320
|
+
PaginationItem({
|
|
321
|
+
children: PaginationNext({
|
|
322
|
+
disabled: () => current() >= pageCount(),
|
|
323
|
+
onSelect: go(current() + 1),
|
|
324
|
+
}),
|
|
325
|
+
}),
|
|
326
|
+
],
|
|
327
|
+
}),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
285
331
|
function renderRow(row: Row): Child {
|
|
286
332
|
const key = props.rowKey(row);
|
|
287
333
|
return TableRow({
|