@lenso/primitives 0.7.0 → 0.9.0
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/README.md +25 -8
- package/dist/list/list.d.ts +56 -0
- package/dist/list/list.js +163 -0
- package/dist/model-control/model-control.d.ts +50 -0
- package/dist/model-control/model-control.js +113 -0
- package/dist/section-index/index.d.ts +9 -0
- package/dist/section-index/index.js +8 -0
- package/dist/section-index/section-index.d.ts +42 -0
- package/dist/section-index/section-index.js +145 -0
- package/dist/sidebar/index.d.ts +31 -110
- package/dist/sidebar/index.js +29 -301
- package/dist/sidebar/sidebar.d.ts +41 -0
- package/dist/sidebar/sidebar.js +151 -0
- package/dist/swipe-actions/index.d.ts +12 -0
- package/dist/swipe-actions/index.js +11 -0
- package/dist/swipe-actions/swipe-actions.d.ts +40 -0
- package/dist/swipe-actions/swipe-actions.js +200 -0
- package/dist/wheel-picker/wheel-picker.d.ts +36 -0
- package/dist/wheel-picker/wheel-picker.js +68 -0
- package/package.json +49 -31
- package/dist/data-grid/index.d.ts +0 -117
- package/dist/data-grid/index.js +0 -179
- package/dist/resize-handle/index.d.ts +0 -44
- package/dist/resize-handle/index.js +0 -180
package/dist/sidebar/index.d.ts
CHANGED
|
@@ -1,111 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rootId: string;
|
|
17
|
-
side: SidebarSide;
|
|
18
|
-
triggerRef: React.RefObject<HTMLElement | null>;
|
|
19
|
-
}
|
|
20
|
-
type SidebarRenderProps<ElementType extends React.ElementType, State = {}> = Omit<useRender.ComponentProps<ElementType, State>, "ref"> & {
|
|
21
|
-
ref?: React.Ref<HTMLElement>;
|
|
1
|
+
import { type Parts } from "@ui-sdk/react/primitive";
|
|
2
|
+
import { sidebar } from "./sidebar.js";
|
|
3
|
+
declare const tags: {
|
|
4
|
+
readonly root: "div";
|
|
5
|
+
readonly trigger: "button";
|
|
6
|
+
readonly rail: "button";
|
|
7
|
+
readonly panel: "aside";
|
|
8
|
+
readonly item: "a";
|
|
9
|
+
readonly header: "div";
|
|
10
|
+
readonly content: "div";
|
|
11
|
+
readonly footer: "div";
|
|
12
|
+
readonly menu: "ul";
|
|
13
|
+
readonly "menu-item": "li";
|
|
14
|
+
readonly submenu: "ul";
|
|
15
|
+
readonly inset: "main";
|
|
22
16
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export declare
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export declare
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
export
|
|
39
|
-
defaultOpen?: boolean;
|
|
40
|
-
dir?: SidebarDirection;
|
|
41
|
-
onOpenChange?: (open: boolean) => void;
|
|
42
|
-
open?: boolean;
|
|
43
|
-
side?: SidebarSide;
|
|
44
|
-
}
|
|
45
|
-
export declare function SidebarRoot({ defaultOpen, dir, id, onOpenChange, open, ref, render, side, ...props }: SidebarRootProps): React.JSX.Element;
|
|
46
|
-
export interface SidebarTriggerProps extends Omit<Button.Props, "ref"> {
|
|
47
|
-
ref?: React.Ref<HTMLElement>;
|
|
48
|
-
targetId?: string;
|
|
49
|
-
}
|
|
50
|
-
export declare function SidebarTrigger({ onClick, ref, targetId, ...props }: SidebarTriggerProps): React.JSX.Element;
|
|
51
|
-
export type SidebarPanelState = {
|
|
52
|
-
open: boolean;
|
|
53
|
-
side: SidebarSide;
|
|
54
|
-
};
|
|
55
|
-
export interface SidebarPanelProps extends SidebarRenderProps<"aside", SidebarPanelState> {
|
|
56
|
-
}
|
|
57
|
-
export declare function SidebarPanel({ onKeyDown, ref, render, ...props }: SidebarPanelProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
58
|
-
export interface SidebarRailProps extends Omit<Button.Props, "ref"> {
|
|
59
|
-
closeLabel?: string;
|
|
60
|
-
openLabel?: string;
|
|
61
|
-
ref?: React.Ref<HTMLElement>;
|
|
62
|
-
targetId?: string;
|
|
63
|
-
}
|
|
64
|
-
export declare function SidebarRail({ "aria-label": ariaLabel, closeLabel, onClick, openLabel, ref, targetId, ...props }: SidebarRailProps): React.JSX.Element;
|
|
65
|
-
export interface SidebarHeaderProps extends SidebarRenderProps<"div"> {
|
|
66
|
-
}
|
|
67
|
-
export declare function SidebarHeader(props: SidebarHeaderProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
68
|
-
export interface SidebarContentProps extends SidebarRenderProps<"div"> {
|
|
69
|
-
}
|
|
70
|
-
export declare function SidebarContent(props: SidebarContentProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
71
|
-
export interface SidebarFooterProps extends SidebarRenderProps<"div"> {
|
|
72
|
-
}
|
|
73
|
-
export declare function SidebarFooter(props: SidebarFooterProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
74
|
-
export interface SidebarMenuProps extends SidebarRenderProps<"ul"> {
|
|
75
|
-
}
|
|
76
|
-
export declare function SidebarMenu(props: SidebarMenuProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
77
|
-
export interface SidebarSubmenuProps extends SidebarRenderProps<"ul"> {
|
|
78
|
-
}
|
|
79
|
-
export declare function SidebarSubmenu(props: SidebarSubmenuProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
80
|
-
export interface SidebarMenuItemProps extends SidebarRenderProps<"li"> {
|
|
81
|
-
}
|
|
82
|
-
export declare function SidebarMenuItem(props: SidebarMenuItemProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
83
|
-
export type SidebarItemState = {
|
|
84
|
-
nested: boolean;
|
|
85
|
-
selected: boolean;
|
|
86
|
-
};
|
|
87
|
-
export interface SidebarItemProps extends SidebarRenderProps<"button", SidebarItemState> {
|
|
88
|
-
nested?: boolean;
|
|
89
|
-
selected?: boolean;
|
|
90
|
-
}
|
|
91
|
-
export declare function SidebarItem({ nested, ref, render, selected, ...props }: SidebarItemProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
92
|
-
export interface SidebarInsetProps extends SidebarRenderProps<"main"> {
|
|
93
|
-
}
|
|
94
|
-
export declare function SidebarInset(props: SidebarInsetProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
95
|
-
export declare const Sidebar: {
|
|
96
|
-
readonly Content: typeof SidebarContent;
|
|
97
|
-
readonly Footer: typeof SidebarFooter;
|
|
98
|
-
readonly Group: typeof SidebarGroup;
|
|
99
|
-
readonly Header: typeof SidebarHeader;
|
|
100
|
-
readonly Inset: typeof SidebarInset;
|
|
101
|
-
readonly Item: typeof SidebarItem;
|
|
102
|
-
readonly Menu: typeof SidebarMenu;
|
|
103
|
-
readonly MenuItem: typeof SidebarMenuItem;
|
|
104
|
-
readonly Panel: typeof SidebarPanel;
|
|
105
|
-
readonly Provider: typeof SidebarProvider;
|
|
106
|
-
readonly Rail: typeof SidebarRail;
|
|
107
|
-
readonly Root: typeof SidebarRoot;
|
|
108
|
-
readonly Submenu: typeof SidebarSubmenu;
|
|
109
|
-
readonly Trigger: typeof SidebarTrigger;
|
|
110
|
-
};
|
|
111
|
-
export {};
|
|
17
|
+
type SidebarParts = Parts<typeof sidebar, typeof tags>;
|
|
18
|
+
export declare const Sidebar: SidebarParts;
|
|
19
|
+
export declare const SidebarRoot: SidebarParts["Root"];
|
|
20
|
+
export declare const SidebarTrigger: SidebarParts["Trigger"];
|
|
21
|
+
export declare const SidebarRail: SidebarParts["Rail"];
|
|
22
|
+
export declare const SidebarPanel: SidebarParts["Panel"];
|
|
23
|
+
export declare const SidebarItem: SidebarParts["Item"];
|
|
24
|
+
export declare const SidebarHeader: SidebarParts["Header"];
|
|
25
|
+
export declare const SidebarContent: SidebarParts["Content"];
|
|
26
|
+
export declare const SidebarFooter: SidebarParts["Footer"];
|
|
27
|
+
export declare const SidebarMenu: SidebarParts["Menu"];
|
|
28
|
+
export declare const SidebarMenuItem: SidebarParts["MenuItem"];
|
|
29
|
+
export declare const SidebarSubmenu: SidebarParts["Submenu"];
|
|
30
|
+
export declare const SidebarInset: SidebarParts["Inset"];
|
|
31
|
+
export { sidebar, createSidebarController } from "./sidebar.js";
|
|
32
|
+
export type { SidebarOptions, SidebarController, SidebarChangeReason, SidebarSide, SidebarState, SidebarItemState, } from "./sidebar.js";
|
package/dist/sidebar/index.js
CHANGED
|
@@ -1,302 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
])];
|
|
32
|
-
}
|
|
33
|
-
function composeRefs(...refs) {
|
|
34
|
-
return (node) => {
|
|
35
|
-
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
36
|
-
else if (ref) ref.current = node;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function SidebarGroup({ children, ref, render, ...props }) {
|
|
40
|
-
const store = React.useRef({
|
|
41
|
-
controllers: /* @__PURE__ */ new Map(),
|
|
42
|
-
listeners: /* @__PURE__ */ new Set()
|
|
43
|
-
});
|
|
44
|
-
const value = React.useMemo(() => ({
|
|
45
|
-
get: (rootId) => store.current.controllers.get(rootId) ?? null,
|
|
46
|
-
register: (controller) => {
|
|
47
|
-
store.current.controllers.set(controller.meta.rootId, controller);
|
|
48
|
-
for (const listener of store.current.listeners) listener();
|
|
49
|
-
return () => {
|
|
50
|
-
if (store.current.controllers.get(controller.meta.rootId) === controller) {
|
|
51
|
-
store.current.controllers.delete(controller.meta.rootId);
|
|
52
|
-
for (const listener of store.current.listeners) listener();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
subscribe: (listener) => {
|
|
57
|
-
store.current.listeners.add(listener);
|
|
58
|
-
return () => store.current.listeners.delete(listener);
|
|
59
|
-
}
|
|
60
|
-
}), []);
|
|
61
|
-
const element = useRender({
|
|
62
|
-
defaultTagName: "div",
|
|
63
|
-
ref,
|
|
64
|
-
render,
|
|
65
|
-
props: {
|
|
66
|
-
...mergeProps({ children }, props),
|
|
67
|
-
"data-slot": "sidebar-group"
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return /* @__PURE__ */ jsx(SidebarGroupContext.Provider, {
|
|
71
|
-
value,
|
|
72
|
-
children: element
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function SidebarProvider({ actions, children, meta, state }) {
|
|
76
|
-
const group = React.useContext(SidebarGroupContext);
|
|
77
|
-
const controller = React.useMemo(() => ({
|
|
78
|
-
actions,
|
|
79
|
-
meta,
|
|
80
|
-
state
|
|
81
|
-
}), [
|
|
82
|
-
actions,
|
|
83
|
-
meta,
|
|
84
|
-
state
|
|
85
|
-
]);
|
|
86
|
-
React.useEffect(() => group?.register(controller), [controller, group]);
|
|
87
|
-
return /* @__PURE__ */ jsx(SidebarContext.Provider, {
|
|
88
|
-
value: controller,
|
|
89
|
-
children
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function SidebarRoot({ defaultOpen = true, dir = "ltr", id, onOpenChange, open, ref, render, side = "left", ...props }) {
|
|
93
|
-
const generatedId = React.useId();
|
|
94
|
-
const rootId = id ?? `sidebar-${generatedId.replaceAll(":", "")}`;
|
|
95
|
-
const panelId = `${rootId}-panel`;
|
|
96
|
-
const [currentOpen, setOpen] = useControllableOpen({
|
|
97
|
-
defaultOpen,
|
|
98
|
-
onOpenChange,
|
|
99
|
-
open
|
|
100
|
-
});
|
|
101
|
-
const triggerRef = React.useRef(null);
|
|
102
|
-
const state = React.useMemo(() => ({ open: currentOpen }), [currentOpen]);
|
|
103
|
-
const actions = React.useMemo(() => ({
|
|
104
|
-
setOpen,
|
|
105
|
-
toggle: () => setOpen(!currentOpen)
|
|
106
|
-
}), [currentOpen, setOpen]);
|
|
107
|
-
const meta = React.useMemo(() => ({
|
|
108
|
-
dir,
|
|
109
|
-
panelId,
|
|
110
|
-
rootId,
|
|
111
|
-
side,
|
|
112
|
-
triggerRef
|
|
113
|
-
}), [
|
|
114
|
-
dir,
|
|
115
|
-
panelId,
|
|
116
|
-
rootId,
|
|
117
|
-
side
|
|
118
|
-
]);
|
|
119
|
-
const renderState = React.useMemo(() => ({
|
|
120
|
-
dir,
|
|
121
|
-
open: currentOpen,
|
|
122
|
-
side
|
|
123
|
-
}), [
|
|
124
|
-
currentOpen,
|
|
125
|
-
dir,
|
|
126
|
-
side
|
|
127
|
-
]);
|
|
128
|
-
const element = useRender({
|
|
129
|
-
defaultTagName: "div",
|
|
130
|
-
ref,
|
|
131
|
-
render,
|
|
132
|
-
state: renderState,
|
|
133
|
-
stateAttributesMapping: {
|
|
134
|
-
dir: () => null,
|
|
135
|
-
open: (value) => ({ "data-state": value ? "open" : "closed" }),
|
|
136
|
-
side: (value) => ({ "data-side": value })
|
|
137
|
-
},
|
|
138
|
-
props: {
|
|
139
|
-
...mergeProps({
|
|
140
|
-
dir,
|
|
141
|
-
id: rootId
|
|
142
|
-
}, props),
|
|
143
|
-
"data-slot": "sidebar-root"
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
return /* @__PURE__ */ jsx(SidebarProvider, {
|
|
147
|
-
actions,
|
|
148
|
-
meta,
|
|
149
|
-
state,
|
|
150
|
-
children: element
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function SidebarTrigger({ onClick, ref, targetId, ...props }) {
|
|
154
|
-
const nearest = React.useContext(SidebarContext);
|
|
155
|
-
const targeted = useTargetController(targetId);
|
|
156
|
-
const controller = targetId ? targeted : nearest;
|
|
157
|
-
if (!targetId && !controller) throw new Error("Sidebar.Trigger must be used within Sidebar.Root or specify targetId");
|
|
158
|
-
const panelId = controller?.meta.panelId ?? `${targetId}-panel`;
|
|
159
|
-
const open = controller?.state.open ?? false;
|
|
160
|
-
return /* @__PURE__ */ jsx(Button, {
|
|
161
|
-
...props,
|
|
162
|
-
"aria-controls": panelId,
|
|
163
|
-
"aria-expanded": open,
|
|
164
|
-
"data-side": controller?.meta.side,
|
|
165
|
-
"data-slot": "sidebar-trigger",
|
|
166
|
-
"data-state": open ? "open" : "closed",
|
|
167
|
-
disabled: props.disabled || !controller,
|
|
168
|
-
onClick: (event) => {
|
|
169
|
-
onClick?.(event);
|
|
170
|
-
if (!event.defaultPrevented && !event.baseUIHandlerPrevented) controller?.actions.toggle();
|
|
171
|
-
},
|
|
172
|
-
ref: controller ? composeRefs(controller.meta.triggerRef, ref) : ref
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function SidebarPanel({ onKeyDown, ref, render, ...props }) {
|
|
176
|
-
const controller = useSidebarController("Panel");
|
|
177
|
-
const state = React.useMemo(() => ({
|
|
178
|
-
open: controller.state.open,
|
|
179
|
-
side: controller.meta.side
|
|
180
|
-
}), [controller.meta.side, controller.state.open]);
|
|
181
|
-
return useRender({
|
|
182
|
-
defaultTagName: "aside",
|
|
183
|
-
ref,
|
|
184
|
-
render,
|
|
185
|
-
state,
|
|
186
|
-
stateAttributesMapping: {
|
|
187
|
-
open: (value) => ({ "data-state": value ? "open" : "closed" }),
|
|
188
|
-
side: (value) => ({ "data-side": value })
|
|
189
|
-
},
|
|
190
|
-
props: {
|
|
191
|
-
...mergeProps({
|
|
192
|
-
"aria-hidden": !controller.state.open,
|
|
193
|
-
hidden: !controller.state.open,
|
|
194
|
-
id: controller.meta.panelId,
|
|
195
|
-
onKeyDown(event) {
|
|
196
|
-
if (event.key === "Escape" && !event.defaultPrevented) {
|
|
197
|
-
event.preventDefault();
|
|
198
|
-
controller.actions.setOpen(false);
|
|
199
|
-
queueMicrotask(() => controller.meta.triggerRef.current?.focus());
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}, {
|
|
203
|
-
...props,
|
|
204
|
-
onKeyDown
|
|
205
|
-
}),
|
|
206
|
-
"data-slot": "sidebar-panel"
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
function SidebarRail({ "aria-label": ariaLabel, closeLabel = "Close sidebar", onClick, openLabel = "Open sidebar", ref, targetId, ...props }) {
|
|
211
|
-
const nearest = React.useContext(SidebarContext);
|
|
212
|
-
const targeted = useTargetController(targetId);
|
|
213
|
-
const controller = targetId ? targeted : nearest;
|
|
214
|
-
if (!targetId && !controller) throw new Error("Sidebar.Rail must be used within Sidebar.Root or specify targetId");
|
|
215
|
-
const panelId = controller?.meta.panelId ?? `${targetId}-panel`;
|
|
216
|
-
const open = controller?.state.open ?? false;
|
|
217
|
-
return /* @__PURE__ */ jsx(Button, {
|
|
218
|
-
...props,
|
|
219
|
-
"aria-controls": panelId,
|
|
220
|
-
"aria-expanded": open,
|
|
221
|
-
"aria-label": ariaLabel ?? (open ? closeLabel : openLabel),
|
|
222
|
-
"data-side": controller?.meta.side,
|
|
223
|
-
"data-slot": "sidebar-rail",
|
|
224
|
-
"data-state": open ? "open" : "closed",
|
|
225
|
-
disabled: props.disabled || !controller,
|
|
226
|
-
onClick: (event) => {
|
|
227
|
-
onClick?.(event);
|
|
228
|
-
if (!event.defaultPrevented && !event.baseUIHandlerPrevented) controller?.actions.toggle();
|
|
229
|
-
},
|
|
230
|
-
ref
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
function useSidebarPart(defaultTagName, slot, { ref, render, ...props }) {
|
|
234
|
-
return useRender({
|
|
235
|
-
defaultTagName,
|
|
236
|
-
ref,
|
|
237
|
-
render,
|
|
238
|
-
props: {
|
|
239
|
-
...props,
|
|
240
|
-
"data-slot": slot
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
function SidebarHeader(props) {
|
|
245
|
-
return useSidebarPart("div", "sidebar-header", props);
|
|
246
|
-
}
|
|
247
|
-
function SidebarContent(props) {
|
|
248
|
-
return useSidebarPart("div", "sidebar-content", props);
|
|
249
|
-
}
|
|
250
|
-
function SidebarFooter(props) {
|
|
251
|
-
return useSidebarPart("div", "sidebar-footer", props);
|
|
252
|
-
}
|
|
253
|
-
function SidebarMenu(props) {
|
|
254
|
-
return useSidebarPart("ul", "sidebar-menu", props);
|
|
255
|
-
}
|
|
256
|
-
function SidebarSubmenu(props) {
|
|
257
|
-
return useSidebarPart("ul", "sidebar-submenu", props);
|
|
258
|
-
}
|
|
259
|
-
function SidebarMenuItem(props) {
|
|
260
|
-
return useSidebarPart("li", "sidebar-menu-item", props);
|
|
261
|
-
}
|
|
262
|
-
function SidebarItem({ nested = false, ref, render, selected = false, ...props }) {
|
|
263
|
-
const state = React.useMemo(() => ({
|
|
264
|
-
nested,
|
|
265
|
-
selected
|
|
266
|
-
}), [nested, selected]);
|
|
267
|
-
return useRender({
|
|
268
|
-
defaultTagName: "button",
|
|
269
|
-
ref,
|
|
270
|
-
render,
|
|
271
|
-
state,
|
|
272
|
-
stateAttributesMapping: {
|
|
273
|
-
nested: (value) => ({ "data-level": value ? "nested" : "root" }),
|
|
274
|
-
selected: (value) => ({ "data-state": value ? "selected" : "default" })
|
|
275
|
-
},
|
|
276
|
-
props: {
|
|
277
|
-
...mergeProps({ "aria-current": selected ? "page" : void 0 }, props),
|
|
278
|
-
"data-slot": "sidebar-item"
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
function SidebarInset(props) {
|
|
283
|
-
return useSidebarPart("main", "sidebar-inset", props);
|
|
284
|
-
}
|
|
285
|
-
const Sidebar = {
|
|
286
|
-
Content: SidebarContent,
|
|
287
|
-
Footer: SidebarFooter,
|
|
288
|
-
Group: SidebarGroup,
|
|
289
|
-
Header: SidebarHeader,
|
|
290
|
-
Inset: SidebarInset,
|
|
291
|
-
Item: SidebarItem,
|
|
292
|
-
Menu: SidebarMenu,
|
|
293
|
-
MenuItem: SidebarMenuItem,
|
|
294
|
-
Panel: SidebarPanel,
|
|
295
|
-
Provider: SidebarProvider,
|
|
296
|
-
Rail: SidebarRail,
|
|
297
|
-
Root: SidebarRoot,
|
|
298
|
-
Submenu: SidebarSubmenu,
|
|
299
|
-
Trigger: SidebarTrigger
|
|
300
|
-
};
|
|
301
|
-
//#endregion
|
|
302
|
-
export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader, SidebarInset, SidebarItem, SidebarMenu, SidebarMenuItem, SidebarPanel, SidebarProvider, SidebarRail, SidebarRoot, SidebarSubmenu, SidebarTrigger };
|
|
2
|
+
import { createSidebarController, sidebar } from "./sidebar.js";
|
|
3
|
+
import { createParts } from "@ui-sdk/react/primitive";
|
|
4
|
+
const Sidebar = createParts(sidebar, {
|
|
5
|
+
root: "div",
|
|
6
|
+
trigger: "button",
|
|
7
|
+
rail: "button",
|
|
8
|
+
panel: "aside",
|
|
9
|
+
item: "a",
|
|
10
|
+
header: "div",
|
|
11
|
+
content: "div",
|
|
12
|
+
footer: "div",
|
|
13
|
+
menu: "ul",
|
|
14
|
+
"menu-item": "li",
|
|
15
|
+
submenu: "ul",
|
|
16
|
+
inset: "main"
|
|
17
|
+
});
|
|
18
|
+
const SidebarRoot = Sidebar.Root;
|
|
19
|
+
const SidebarTrigger = Sidebar.Trigger;
|
|
20
|
+
const SidebarRail = Sidebar.Rail;
|
|
21
|
+
const SidebarPanel = Sidebar.Panel;
|
|
22
|
+
const SidebarItem = Sidebar.Item;
|
|
23
|
+
const SidebarHeader = Sidebar.Header;
|
|
24
|
+
const SidebarContent = Sidebar.Content;
|
|
25
|
+
const SidebarFooter = Sidebar.Footer;
|
|
26
|
+
const SidebarMenu = Sidebar.Menu;
|
|
27
|
+
const SidebarMenuItem = Sidebar.MenuItem;
|
|
28
|
+
const SidebarSubmenu = Sidebar.Submenu;
|
|
29
|
+
const SidebarInset = Sidebar.Inset;
|
|
30
|
+
export { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarInset, SidebarItem, SidebarMenu, SidebarMenuItem, SidebarPanel, SidebarRail, SidebarRoot, SidebarSubmenu, SidebarTrigger, createSidebarController, sidebar };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type FocusRecovery, definePrimitive, type ChangeDetails, type ChangeOptions, type SlotDefinition } from "@ui-sdk/core";
|
|
2
|
+
export type SidebarSide = "left" | "right";
|
|
3
|
+
export type SidebarChangeReason = "trigger-press" | "escape-key" | "controller";
|
|
4
|
+
export type SidebarController = {
|
|
5
|
+
isOpen: () => boolean;
|
|
6
|
+
setOpen: (open: boolean, options?: ChangeOptions<SidebarChangeReason>) => boolean;
|
|
7
|
+
toggle: (options?: ChangeOptions<SidebarChangeReason>) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export type SidebarOptions = {
|
|
10
|
+
open?: boolean;
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
onOpenChange?: (open: boolean, details: ChangeDetails<SidebarChangeReason>) => void;
|
|
13
|
+
side?: SidebarSide;
|
|
14
|
+
controller?: SidebarController;
|
|
15
|
+
};
|
|
16
|
+
export type SidebarState = {
|
|
17
|
+
open: boolean;
|
|
18
|
+
side: SidebarSide;
|
|
19
|
+
};
|
|
20
|
+
export type SidebarItemState = {
|
|
21
|
+
selected: boolean;
|
|
22
|
+
nested: boolean;
|
|
23
|
+
};
|
|
24
|
+
type SidebarItemOptions = {
|
|
25
|
+
selected?: boolean;
|
|
26
|
+
nested?: boolean;
|
|
27
|
+
};
|
|
28
|
+
type SidebarApi = SidebarController & {
|
|
29
|
+
trigger: () => HTMLElement | undefined;
|
|
30
|
+
recovery: FocusRecovery;
|
|
31
|
+
};
|
|
32
|
+
type SidebarSlots = {
|
|
33
|
+
[Name in "root" | "trigger" | "rail" | "panel"]: SlotDefinition<SidebarState, SidebarApi, {}, SidebarState>;
|
|
34
|
+
} & {
|
|
35
|
+
item: SlotDefinition<SidebarState, SidebarApi, SidebarItemOptions, SidebarItemState>;
|
|
36
|
+
} & {
|
|
37
|
+
[Name in "header" | "content" | "footer" | "menu" | "menu-item" | "submenu" | "inset"]: SlotDefinition<SidebarState, SidebarApi, {}>;
|
|
38
|
+
};
|
|
39
|
+
export declare function createSidebarController(): SidebarController;
|
|
40
|
+
export declare const sidebar: ReturnType<typeof definePrimitive<SidebarOptions, SidebarState, SidebarApi, SidebarSlots>>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { bindPanel, createChange, createController, createFocusRecovery, definePrimitive, elements } from "@ui-sdk/core";
|
|
2
|
+
// src/sidebar/sidebar.ts
|
|
3
|
+
function createSidebarController() {
|
|
4
|
+
return createController();
|
|
5
|
+
}
|
|
6
|
+
const sidebar = definePrimitive({
|
|
7
|
+
name: "sidebar",
|
|
8
|
+
options: {
|
|
9
|
+
open: "boolean",
|
|
10
|
+
defaultOpen: "boolean",
|
|
11
|
+
onOpenChange: "callback",
|
|
12
|
+
side: "string",
|
|
13
|
+
controller: "value"
|
|
14
|
+
},
|
|
15
|
+
controlled: ["open"],
|
|
16
|
+
state: (options) => ({
|
|
17
|
+
open: options.open ?? options.defaultOpen ?? true,
|
|
18
|
+
side: options.side ?? "left"
|
|
19
|
+
}),
|
|
20
|
+
sync: (options) => ({
|
|
21
|
+
...options.open === void 0 ? {} : { open: options.open },
|
|
22
|
+
side: options.side ?? "left"
|
|
23
|
+
}),
|
|
24
|
+
api: (context) => {
|
|
25
|
+
const change = createChange(context);
|
|
26
|
+
const setOpen = (open, options = {}) => change("open", open, {
|
|
27
|
+
...options,
|
|
28
|
+
reason: options.reason ?? "controller"
|
|
29
|
+
});
|
|
30
|
+
const trigger = () => elements(context, "trigger")[0]?.el ?? elements(context, "rail")[0]?.el;
|
|
31
|
+
return {
|
|
32
|
+
recovery: createFocusRecovery({ fallback: trigger }),
|
|
33
|
+
isOpen: () => context.store.get().open,
|
|
34
|
+
setOpen,
|
|
35
|
+
toggle: (options) => setOpen(!context.store.get().open, options),
|
|
36
|
+
trigger
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
slots: (slot) => {
|
|
40
|
+
const toggle = slot({
|
|
41
|
+
role: "button",
|
|
42
|
+
focus: "native",
|
|
43
|
+
state: (state) => ({
|
|
44
|
+
open: state.open,
|
|
45
|
+
side: state.side
|
|
46
|
+
}),
|
|
47
|
+
attrs: (state, part) => ({
|
|
48
|
+
type: "button",
|
|
49
|
+
"aria-controls": `${part.id}-panel`,
|
|
50
|
+
"aria-expanded": String(state.open),
|
|
51
|
+
"data-open": state.open ? "" : void 0,
|
|
52
|
+
"data-closed": state.open ? void 0 : "",
|
|
53
|
+
"data-side": state.side
|
|
54
|
+
}),
|
|
55
|
+
press: ({ api }, event) => api.toggle({
|
|
56
|
+
reason: "trigger-press",
|
|
57
|
+
...event ? { event } : {}
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
root: slot({
|
|
62
|
+
state: (state) => ({
|
|
63
|
+
open: state.open,
|
|
64
|
+
side: state.side
|
|
65
|
+
}),
|
|
66
|
+
attrs: (state) => ({
|
|
67
|
+
"data-open": state.open ? "" : void 0,
|
|
68
|
+
"data-closed": state.open ? void 0 : "",
|
|
69
|
+
"data-side": state.side
|
|
70
|
+
})
|
|
71
|
+
}),
|
|
72
|
+
trigger: toggle,
|
|
73
|
+
rail: toggle,
|
|
74
|
+
panel: slot({
|
|
75
|
+
role: "complementary",
|
|
76
|
+
state: (state) => ({
|
|
77
|
+
open: state.open,
|
|
78
|
+
side: state.side
|
|
79
|
+
}),
|
|
80
|
+
attrs: (state, part) => ({
|
|
81
|
+
id: `${part.id}-panel`,
|
|
82
|
+
hidden: state.open ? void 0 : "",
|
|
83
|
+
"aria-hidden": String(!state.open),
|
|
84
|
+
"data-open": state.open ? "" : void 0,
|
|
85
|
+
"data-closed": state.open ? void 0 : "",
|
|
86
|
+
"data-side": state.side
|
|
87
|
+
}),
|
|
88
|
+
on: { keydown: (event, { api, store }) => {
|
|
89
|
+
if (event.key !== "Escape" || !store.get().open) return;
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
api.setOpen(false, {
|
|
92
|
+
reason: "escape-key",
|
|
93
|
+
event
|
|
94
|
+
});
|
|
95
|
+
} },
|
|
96
|
+
bind: (el, part) => {
|
|
97
|
+
const { api, store } = part;
|
|
98
|
+
const recover = api.recovery.bind(el, part);
|
|
99
|
+
const unbind = bindPanel(el, {
|
|
100
|
+
size: (element, height, width) => {
|
|
101
|
+
element.style.setProperty("--sidebar-panel-height", height);
|
|
102
|
+
element.style.setProperty("--sidebar-panel-width", width);
|
|
103
|
+
},
|
|
104
|
+
isOpen: () => store.get().open,
|
|
105
|
+
isExiting: () => false,
|
|
106
|
+
isFindable: () => false,
|
|
107
|
+
opening: () => "instant",
|
|
108
|
+
reveal: (event) => {
|
|
109
|
+
api.setOpen(true, {
|
|
110
|
+
reason: "controller",
|
|
111
|
+
event
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
trigger: api.trigger,
|
|
115
|
+
subscribe: store.subscribe,
|
|
116
|
+
settled: () => {},
|
|
117
|
+
exited: () => {}
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
unbind();
|
|
121
|
+
recover();
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
item: slot({
|
|
126
|
+
props: {
|
|
127
|
+
selected: "boolean",
|
|
128
|
+
nested: "boolean"
|
|
129
|
+
},
|
|
130
|
+
state: (_, { props }) => ({
|
|
131
|
+
selected: props.selected ?? false,
|
|
132
|
+
nested: props.nested ?? false
|
|
133
|
+
}),
|
|
134
|
+
attrs: (_, { props }) => ({
|
|
135
|
+
"aria-current": props.selected ? "page" : void 0,
|
|
136
|
+
"data-selected": props.selected ? "" : void 0,
|
|
137
|
+
"data-nested": props.nested ? "" : void 0
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
header: slot({}),
|
|
141
|
+
content: slot({}),
|
|
142
|
+
footer: slot({}),
|
|
143
|
+
menu: slot({}),
|
|
144
|
+
"menu-item": slot({}),
|
|
145
|
+
submenu: slot({}),
|
|
146
|
+
inset: slot({})
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
agent: { actions: ["setOpen", "toggle"] }
|
|
150
|
+
});
|
|
151
|
+
export { createSidebarController, sidebar };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Parts } from "@ui-sdk/react/primitive";
|
|
2
|
+
import { swipeActions } from "./swipe-actions.js";
|
|
3
|
+
declare const tags: {
|
|
4
|
+
readonly root: "div";
|
|
5
|
+
readonly content: "div";
|
|
6
|
+
readonly body: "div";
|
|
7
|
+
readonly actions: "div";
|
|
8
|
+
readonly trigger: "button";
|
|
9
|
+
};
|
|
10
|
+
export declare const SwipeActions: Parts<typeof swipeActions, typeof tags>;
|
|
11
|
+
export { swipeActions, createSwipeActionsController } from "./swipe-actions.js";
|
|
12
|
+
export type { SwipeActionsOptions, SwipeActionsController, SwipeActionsReason, } from "./swipe-actions.js";
|