@exegia/corpora-ui 0.17.0 → 0.18.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/dist-lib/components/blocks/nav/sidebar-block.d.ts +1 -1
- package/dist-lib/components/blocks/scaffold/__tests__/scaffold.test.d.ts +1 -0
- package/dist-lib/components/blocks/scaffold/constants.d.ts +20 -0
- package/dist-lib/components/blocks/scaffold/index.d.ts +25 -0
- package/dist-lib/components/blocks/scaffold/panel-close-button.d.ts +4 -0
- package/dist-lib/components/blocks/scaffold/panel-menu-button.d.ts +7 -0
- package/dist-lib/components/blocks/scaffold/scaffold-actions.d.ts +9 -0
- package/dist-lib/components/blocks/scaffold/scaffold-canvas.d.ts +7 -0
- package/dist-lib/components/blocks/scaffold/scaffold-context.d.ts +5 -0
- package/dist-lib/components/blocks/scaffold/scaffold-inspector.d.ts +9 -0
- package/dist-lib/components/blocks/scaffold/scaffold-main.d.ts +8 -0
- package/dist-lib/components/blocks/scaffold/scaffold-panel.d.ts +10 -0
- package/dist-lib/components/blocks/scaffold/scaffold-root.d.ts +8 -0
- package/dist-lib/components/blocks/scaffold/scaffold-sidebar.d.ts +7 -0
- package/dist-lib/components/blocks/scaffold/scaffold-sub-panel.d.ts +3 -0
- package/dist-lib/components/blocks/scaffold/type.d.ts +133 -0
- package/dist-lib/components/blocks/scaffold/use-scaffold.d.ts +8 -0
- package/dist-lib/components/blocks/scaffold/utils.d.ts +15 -0
- package/dist-lib/components/blocks/shell/animated-panel-inset.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-panel-provider.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-panel-trigger.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-panel.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-content.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-footer.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-group-content.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-group-label.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-group.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-header.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu-button.d.ts +3 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu-item.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu-sub-button.d.ts +3 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu-sub-item.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu-sub.d.ts +2 -0
- package/dist-lib/components/blocks/shell/animated-sidebar-menu.d.ts +2 -0
- package/dist-lib/components/blocks/shell/index.d.ts +16 -0
- package/dist-lib/components/blocks/shell/type.d.ts +90 -4
- package/dist-lib/components/blocks/shell/utils.d.ts +37 -0
- package/dist-lib/components/motion/index.d.ts +1 -0
- package/dist-lib/components/motion/overflow-actions.d.ts +35 -0
- package/dist-lib/components/ui/button-group.d.ts +11 -0
- package/dist-lib/components/ui/glasscn/glass-button-group.d.ts +5 -0
- package/dist-lib/components/ui/glasscn/glass-container.d.ts +7 -0
- package/dist-lib/components/ui/glasscn/glass-separator.d.ts +5 -0
- package/dist-lib/components/ui/group.d.ts +17 -0
- package/dist-lib/components/ui/separator.d.ts +2 -3
- package/dist-lib/components/ui/sheet.d.ts +14 -0
- package/dist-lib/components/ui/tooltip.d.ts +6 -0
- package/dist-lib/index.d.ts +2 -1
- package/dist-lib/index.js +1592 -1084
- package/dist-lib/index.js.map +1 -1
- package/dist-lib/lib/ease.d.ts +3 -0
- package/dist-lib/lib/hooks/use-hover-capable.d.ts +6 -0
- package/package.json +2 -1
- package/src/components/beste/piece/browser-frame.tsx +2 -2
- package/src/components/blocks/nav/sidebar-block.tsx +5 -5
- package/src/components/blocks/nav/sidebar-nav-row.tsx +4 -5
- package/src/components/blocks/scaffold/__tests__/scaffold.test.tsx +203 -0
- package/src/components/blocks/scaffold/constants.ts +28 -0
- package/src/components/blocks/scaffold/index.ts +38 -0
- package/src/components/blocks/scaffold/panel-close-button.tsx +36 -0
- package/src/components/blocks/scaffold/panel-menu-button.tsx +240 -0
- package/src/components/blocks/scaffold/scaffold-actions.tsx +97 -0
- package/src/components/blocks/scaffold/scaffold-canvas.tsx +29 -0
- package/src/components/blocks/scaffold/scaffold-context.ts +18 -0
- package/src/components/blocks/scaffold/scaffold-inspector.tsx +57 -0
- package/src/components/blocks/scaffold/scaffold-main.tsx +28 -0
- package/src/components/blocks/scaffold/scaffold-panel.tsx +98 -0
- package/src/components/blocks/scaffold/scaffold-root.tsx +68 -0
- package/src/components/blocks/scaffold/scaffold-sidebar.tsx +31 -0
- package/src/components/blocks/scaffold/scaffold-sub-panel.tsx +51 -0
- package/src/components/blocks/scaffold/type.ts +171 -0
- package/src/components/blocks/scaffold/use-scaffold.ts +48 -0
- package/src/components/blocks/scaffold/utils.ts +30 -0
- package/src/components/blocks/shell/animated-panel-inset.tsx +23 -0
- package/src/components/blocks/shell/animated-panel-provider.tsx +155 -0
- package/src/components/blocks/shell/animated-panel-trigger.tsx +42 -0
- package/src/components/blocks/shell/animated-panel.tsx +135 -0
- package/src/components/blocks/shell/animated-sidebar-content.tsx +19 -0
- package/src/components/blocks/shell/animated-sidebar-footer.tsx +19 -0
- package/src/components/blocks/shell/animated-sidebar-group-content.tsx +16 -0
- package/src/components/blocks/shell/animated-sidebar-group-label.tsx +29 -0
- package/src/components/blocks/shell/animated-sidebar-group.tsx +16 -0
- package/src/components/blocks/shell/animated-sidebar-header.tsx +16 -0
- package/src/components/blocks/shell/animated-sidebar-menu-button.tsx +151 -0
- package/src/components/blocks/shell/animated-sidebar-menu-item.tsx +20 -0
- package/src/components/blocks/shell/animated-sidebar-menu-sub-button.tsx +85 -0
- package/src/components/blocks/shell/animated-sidebar-menu-sub-item.tsx +19 -0
- package/src/components/blocks/shell/animated-sidebar-menu-sub.tsx +44 -0
- package/src/components/blocks/shell/animated-sidebar-menu.tsx +26 -0
- package/src/components/blocks/shell/index.ts +18 -0
- package/src/components/blocks/shell/shell-layout.tsx +28 -36
- package/src/components/blocks/shell/type.ts +112 -6
- package/src/components/blocks/shell/use-shell-panels.ts +1 -1
- package/src/components/blocks/shell/utils.ts +142 -1
- package/src/components/docs/demo-controls.tsx +1 -1
- package/src/components/motion/index.ts +0 -0
- package/src/components/motion/overflow-actions.tsx +376 -0
- package/src/components/ui/button-group.tsx +88 -0
- package/src/components/ui/glasscn/glass-button-group.tsx +48 -0
- package/src/components/ui/glasscn/glass-container.tsx +125 -0
- package/src/components/ui/glasscn/glass-separator.tsx +39 -0
- package/src/components/ui/glasscn/liquid-glass.tsx +250 -210
- package/src/components/ui/group.tsx +92 -0
- package/src/components/ui/separator.tsx +11 -11
- package/src/components/ui/sheet.tsx +135 -0
- package/src/components/ui/tooltip.tsx +66 -0
- package/src/index.css +1 -1
- package/src/index.ts +13 -1
- package/src/lib/ease.ts +26 -0
- package/src/lib/hooks/use-hover-capable.ts +23 -0
- package/dist-lib/components/motion/animated-sidebar.d.ts +0 -106
- package/src/components/motion/animated-sidebar.tsx +0 -1171
package/dist-lib/lib/ease.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Transition, Variants } from 'motion/react';
|
|
1
2
|
export declare const EASE_OUT: readonly [0.16, 1, 0.3, 1];
|
|
2
3
|
export declare const EASE_IN_OUT: readonly [0.77, 0, 0.175, 1];
|
|
3
4
|
export declare const EASE_DRAWER: readonly [0.32, 0.72, 0, 1];
|
|
@@ -44,3 +45,5 @@ export declare const SPRING_GLIDE: {
|
|
|
44
45
|
readonly damping: 50;
|
|
45
46
|
readonly mass: 0.5;
|
|
46
47
|
};
|
|
48
|
+
export declare const SHELL_TRANSITION: Transition;
|
|
49
|
+
export declare const ICON_VARIANTS: Variants;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true only on devices that have a true hover (mouse / trackpad).
|
|
3
|
+
* Touch devices fire phantom `:hover` on tap that sticks until tap-elsewhere
|
|
4
|
+
* — gate hover-only effects (scale lifts, magnetic pulls) behind this.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useHoverCapable(): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exegia/corpora-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "shadcn-ready React UI library for the corpora manuscript-research apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"class-variance-authority": "^0.7.1",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
48
48
|
"cuelume": "^0.2.1",
|
|
49
|
+
"iconsax-reactjs": "^0.0.8",
|
|
49
50
|
"lucide-react": "^1.31.0",
|
|
50
51
|
"motion": "^12.43.0",
|
|
51
52
|
"motion-icons-react": "^1.1.0",
|
|
@@ -22,7 +22,7 @@ export function BrowserFrame({
|
|
|
22
22
|
className
|
|
23
23
|
)}
|
|
24
24
|
>
|
|
25
|
-
<div className="flex min-h-
|
|
25
|
+
<div className="flex min-h-32 w-full max-h-[500px] flex-col overflow-hidden rounded-lg border border-border bg-neutral-50 shadow-lg dark:bg-neutral-900 relative">
|
|
26
26
|
<div id="title-bar" className={cn("flex flex-1 w-full items-center gap-2 px-4 py-3 z-20", titleBarStyle(titleStyle, 'title'))}>
|
|
27
27
|
<div className="flex items-center gap-2" aria-hidden="true">
|
|
28
28
|
<span className="size-3 cursor-pointer rounded-full bg-rose-500 shadow-md outline outline-rose-800" />
|
|
@@ -46,7 +46,7 @@ export function BrowserFrame({
|
|
|
46
46
|
</div>
|
|
47
47
|
)}
|
|
48
48
|
</div>
|
|
49
|
-
<div className={cn("flex flex-1
|
|
49
|
+
<div className={cn("flex flex-1", titleBarStyle(titleStyle, "frame"))}>
|
|
50
50
|
{children}
|
|
51
51
|
</div>
|
|
52
52
|
</div>
|
|
@@ -4,7 +4,9 @@ import { PanelLeftIcon } from "lucide-react"
|
|
|
4
4
|
import * as React from "react"
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
AnimatedSidebar,
|
|
7
|
+
AnimatedPanel as AnimatedSidebar,
|
|
8
|
+
AnimatedPanelProvider as AnimatedSidebarProvider,
|
|
9
|
+
AnimatedPanelTrigger as AnimatedSidebarTrigger,
|
|
8
10
|
AnimatedSidebarContent,
|
|
9
11
|
AnimatedSidebarFooter,
|
|
10
12
|
AnimatedSidebarGroup,
|
|
@@ -12,9 +14,7 @@ import {
|
|
|
12
14
|
AnimatedSidebarGroupLabel,
|
|
13
15
|
AnimatedSidebarHeader,
|
|
14
16
|
AnimatedSidebarMenu,
|
|
15
|
-
|
|
16
|
-
AnimatedSidebarTrigger,
|
|
17
|
-
} from "@/components/motion/animated-sidebar"
|
|
17
|
+
} from "@/components/blocks/shell"
|
|
18
18
|
import { cn } from "@/lib/utils"
|
|
19
19
|
import { SidebarNavRow } from "@/components/blocks/nav/sidebar-nav-row"
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ export type {
|
|
|
34
34
|
* beside your own content. It owns its own sidebar context (⌘B toggles it);
|
|
35
35
|
* pass `open`/`onOpenChange` to drive the rail, and `openMobile`/
|
|
36
36
|
* `onOpenMobileChange` to open the drawer from a header button of your own.
|
|
37
|
-
* Compose the underlying `
|
|
37
|
+
* Compose the underlying `AnimatedPanel*` parts directly when a screen
|
|
38
38
|
* needs something this API does not cover.
|
|
39
39
|
*/
|
|
40
40
|
export function SidebarBlock({
|
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
|
|
5
|
+
import type { IRowProps, ISidebarNavItem, ISidebarNavSubItem } from "@/components/blocks/nav/types"
|
|
6
|
+
import { isActive } from "@/components/blocks/nav/utils"
|
|
5
7
|
import {
|
|
6
8
|
AnimatedSidebarMenuButton,
|
|
7
9
|
AnimatedSidebarMenuItem,
|
|
8
10
|
AnimatedSidebarMenuSub,
|
|
9
11
|
AnimatedSidebarMenuSubButton,
|
|
10
12
|
AnimatedSidebarMenuSubItem,
|
|
11
|
-
} from "@/components/
|
|
12
|
-
|
|
13
|
-
import type { IRowProps, ISidebarNavItem, ISidebarNavSubItem } from "@/components/blocks/nav/types"
|
|
14
|
-
import { isActive } from "@/components/blocks/nav/utils"
|
|
13
|
+
} from "@/components/blocks/shell"
|
|
15
14
|
|
|
16
15
|
export function SidebarNavRow({ item, activeId, onNavigate }: IRowProps) {
|
|
17
16
|
const children = item.items ?? []
|
|
@@ -76,4 +75,4 @@ export function SidebarNavRow({ item, activeId, onNavigate }: IRowProps) {
|
|
|
76
75
|
) : null}
|
|
77
76
|
</AnimatedSidebarMenuItem>
|
|
78
77
|
)
|
|
79
|
-
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test"
|
|
2
|
+
import { render, screen, waitFor } from "@testing-library/react"
|
|
3
|
+
import userEvent from "@testing-library/user-event"
|
|
4
|
+
|
|
5
|
+
import { Scaffold, useScaffold } from "../index"
|
|
6
|
+
import type { TScaffoldPanelChild } from "../type"
|
|
7
|
+
|
|
8
|
+
function Strip() {
|
|
9
|
+
return <span>Strip</span>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function Workspace({
|
|
13
|
+
onClose,
|
|
14
|
+
onSwap,
|
|
15
|
+
onAdd,
|
|
16
|
+
overflowCount,
|
|
17
|
+
SecondaryPanel = <Strip />,
|
|
18
|
+
}: {
|
|
19
|
+
onClose?: () => void
|
|
20
|
+
onSwap?: () => void
|
|
21
|
+
onAdd?: () => void
|
|
22
|
+
overflowCount?: number
|
|
23
|
+
/** Pass null to render the panel without a secondary strip. */
|
|
24
|
+
SecondaryPanel?: TScaffoldPanelChild | null
|
|
25
|
+
}) {
|
|
26
|
+
const scaffold = useScaffold()
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Scaffold.Root {...scaffold.providerProps}>
|
|
30
|
+
<Scaffold.Sidebar>
|
|
31
|
+
<button onClick={scaffold.toggleInspector} type="button">
|
|
32
|
+
Toggle inspector
|
|
33
|
+
</button>
|
|
34
|
+
</Scaffold.Sidebar>
|
|
35
|
+
<Scaffold.Main>
|
|
36
|
+
<Scaffold.Actions onAdd={onAdd} overflowCount={overflowCount} />
|
|
37
|
+
<Scaffold.Canvas>
|
|
38
|
+
<Scaffold.Panel
|
|
39
|
+
key="alpha"
|
|
40
|
+
name="Alpha"
|
|
41
|
+
onClose={onClose}
|
|
42
|
+
onSwap={onSwap}
|
|
43
|
+
SecondaryPanel={SecondaryPanel ?? undefined}
|
|
44
|
+
>
|
|
45
|
+
<span>Primary body</span>
|
|
46
|
+
</Scaffold.Panel>
|
|
47
|
+
</Scaffold.Canvas>
|
|
48
|
+
<Scaffold.Inspector>
|
|
49
|
+
<span>Inspector body</span>
|
|
50
|
+
</Scaffold.Inspector>
|
|
51
|
+
</Scaffold.Main>
|
|
52
|
+
</Scaffold.Root>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The seam menu's compact toggle (icon-only, named by `swapLabel`). */
|
|
57
|
+
const menuToggle = () =>
|
|
58
|
+
screen.queryByRole("button", { name: "Swap panel content" })
|
|
59
|
+
|
|
60
|
+
describe("Scaffold", () => {
|
|
61
|
+
test("renders rail, panel surfaces and secondary strip", () => {
|
|
62
|
+
render(<Workspace />)
|
|
63
|
+
|
|
64
|
+
expect(screen.getByRole("navigation", { name: "Primary" })).toBeDefined()
|
|
65
|
+
const panel = screen.getByRole("region", { name: "Alpha" })
|
|
66
|
+
expect(panel.textContent).toContain("Primary body")
|
|
67
|
+
expect(panel.textContent).toContain("Strip")
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test("close and menu buttons render only with their callbacks", async () => {
|
|
71
|
+
const user = userEvent.setup()
|
|
72
|
+
const onClose = mock(() => {})
|
|
73
|
+
|
|
74
|
+
const { rerender } = render(<Workspace />)
|
|
75
|
+
expect(screen.queryByRole("button", { name: "Close panel" })).toBeNull()
|
|
76
|
+
expect(menuToggle()).toBeNull()
|
|
77
|
+
|
|
78
|
+
rerender(<Workspace onClose={onClose} onSwap={() => {}} />)
|
|
79
|
+
await user.click(screen.getByRole("button", { name: "Close panel" }))
|
|
80
|
+
expect(onClose).toHaveBeenCalledTimes(1)
|
|
81
|
+
expect(menuToggle()).toBeDefined()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test("seam menu opens; Swap fires onSwap, flips the panel and collapses the menu", async () => {
|
|
85
|
+
const user = userEvent.setup()
|
|
86
|
+
const onSwap = mock(() => {})
|
|
87
|
+
render(<Workspace onSwap={onSwap} />)
|
|
88
|
+
|
|
89
|
+
const panel = screen.getByRole("region", { name: "Alpha" })
|
|
90
|
+
expect(panel.getAttribute("data-swapped")).toBeNull()
|
|
91
|
+
|
|
92
|
+
// The compact toggle trades places with the Expand | Swap actions.
|
|
93
|
+
await user.click(menuToggle() as HTMLElement)
|
|
94
|
+
await user.click(await screen.findByRole("button", { name: "Swap" }))
|
|
95
|
+
|
|
96
|
+
expect(onSwap).toHaveBeenCalledTimes(1)
|
|
97
|
+
expect(panel.getAttribute("data-swapped")).toBe("")
|
|
98
|
+
|
|
99
|
+
// Acting collapses the menu back to the compact toggle; the actions
|
|
100
|
+
// leave with their exit animation.
|
|
101
|
+
expect(
|
|
102
|
+
await screen.findByRole("button", { name: "Swap panel content" })
|
|
103
|
+
).toBeDefined()
|
|
104
|
+
await waitFor(() =>
|
|
105
|
+
expect(screen.queryByRole("button", { name: "Swap" })).toBeNull()
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test("expand trades the flexible slot and flips the chevron", async () => {
|
|
110
|
+
const user = userEvent.setup()
|
|
111
|
+
render(<Workspace onSwap={() => {}} />)
|
|
112
|
+
|
|
113
|
+
const panel = screen.getByRole("region", { name: "Alpha" })
|
|
114
|
+
const [top, bottom] = Array.from(
|
|
115
|
+
panel.querySelectorAll('[data-slot^="scaffold-sub-panel"]')
|
|
116
|
+
)
|
|
117
|
+
expect(top.getAttribute("data-expanded")).toBe("")
|
|
118
|
+
expect(bottom.getAttribute("data-expanded")).toBeNull()
|
|
119
|
+
|
|
120
|
+
await user.click(menuToggle() as HTMLElement)
|
|
121
|
+
await user.click(await screen.findByRole("button", { name: "Expand" }))
|
|
122
|
+
|
|
123
|
+
expect(top.getAttribute("data-expanded")).toBeNull()
|
|
124
|
+
expect(bottom.getAttribute("data-expanded")).toBe("")
|
|
125
|
+
|
|
126
|
+
// Reopen: the chevron reflects the flipped state.
|
|
127
|
+
await user.click(
|
|
128
|
+
await screen.findByRole("button", { name: "Swap panel content" })
|
|
129
|
+
)
|
|
130
|
+
const expandButton = await screen.findByRole("button", { name: "Expand" })
|
|
131
|
+
expect(
|
|
132
|
+
expandButton
|
|
133
|
+
.querySelector("svg.lucide-chevron-down")
|
|
134
|
+
?.classList.contains("rotate-180")
|
|
135
|
+
).toBe(true)
|
|
136
|
+
|
|
137
|
+
// Expanding again restores the primary slot.
|
|
138
|
+
await user.click(expandButton)
|
|
139
|
+
expect(top.getAttribute("data-expanded")).toBe("")
|
|
140
|
+
expect(bottom.getAttribute("data-expanded")).toBeNull()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test("seam menu needs a secondary strip", () => {
|
|
144
|
+
render(<Workspace onSwap={() => {}} SecondaryPanel={null} />)
|
|
145
|
+
|
|
146
|
+
expect(menuToggle()).toBeNull()
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test("actions cluster: Add fires, overflow segment follows the count", async () => {
|
|
150
|
+
const user = userEvent.setup()
|
|
151
|
+
const onAdd = mock(() => {})
|
|
152
|
+
|
|
153
|
+
const { rerender } = render(<Workspace onAdd={onAdd} />)
|
|
154
|
+
expect(screen.queryByRole("button", { name: "Browse panels" })).toBeNull()
|
|
155
|
+
|
|
156
|
+
await user.click(screen.getByRole("button", { name: "Panel" }))
|
|
157
|
+
expect(onAdd).toHaveBeenCalledTimes(1)
|
|
158
|
+
|
|
159
|
+
// Zero overflowed panels: the segment shows without a badge.
|
|
160
|
+
rerender(<Workspace overflowCount={0} onAdd={onAdd} />)
|
|
161
|
+
expect(
|
|
162
|
+
screen.getByRole("button", { name: "Browse panels" }).textContent
|
|
163
|
+
).toBe("")
|
|
164
|
+
|
|
165
|
+
rerender(<Workspace overflowCount={2} onAdd={onAdd} />)
|
|
166
|
+
const browse = screen.getByRole("button", { name: "Browse panels" })
|
|
167
|
+
expect(browse.textContent).toContain("2")
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test("inspector opens from outside state and hides again", async () => {
|
|
171
|
+
const user = userEvent.setup()
|
|
172
|
+
render(<Workspace />)
|
|
173
|
+
|
|
174
|
+
const inspector = () =>
|
|
175
|
+
screen.getByText("Inspector body").closest("aside") as HTMLElement
|
|
176
|
+
expect(inspector().getAttribute("aria-hidden")).toBe("true")
|
|
177
|
+
|
|
178
|
+
await user.click(screen.getByRole("button", { name: "Toggle inspector" }))
|
|
179
|
+
expect(inspector().getAttribute("aria-hidden")).toBeNull()
|
|
180
|
+
expect(
|
|
181
|
+
screen.getByRole("complementary", { name: "Inspector" })
|
|
182
|
+
).toBeDefined()
|
|
183
|
+
|
|
184
|
+
await user.click(screen.getByRole("button", { name: "Toggle inspector" }))
|
|
185
|
+
expect(inspector().getAttribute("aria-hidden")).toBe("true")
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test("root manages inspector state itself when uncontrolled", () => {
|
|
189
|
+
render(
|
|
190
|
+
<Scaffold.Root defaultInspectorOpen>
|
|
191
|
+
<Scaffold.Main>
|
|
192
|
+
<Scaffold.Inspector>
|
|
193
|
+
<span>Drawer</span>
|
|
194
|
+
</Scaffold.Inspector>
|
|
195
|
+
</Scaffold.Main>
|
|
196
|
+
</Scaffold.Root>
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
expect(
|
|
200
|
+
screen.getByRole("complementary", { name: "Inspector" })
|
|
201
|
+
).toBeDefined()
|
|
202
|
+
})
|
|
203
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Icon-rail width in px (the rail sits directly on the desktop backdrop). */
|
|
2
|
+
export const SCAFFOLD_SIDEBAR_WIDTH = 64
|
|
3
|
+
|
|
4
|
+
/** Inspector drawer width in px. */
|
|
5
|
+
export const SCAFFOLD_INSPECTOR_WIDTH = 272
|
|
6
|
+
|
|
7
|
+
/** Gap in px between the drawer/actions and the viewport edges. */
|
|
8
|
+
export const SCAFFOLD_EDGE_GUTTER = 10
|
|
9
|
+
|
|
10
|
+
/** Vertical room in px reserved above the canvas for the actions cluster. */
|
|
11
|
+
export const SCAFFOLD_HEADER_HEIGHT = 52
|
|
12
|
+
|
|
13
|
+
/** Height in px of a panel's secondary strip. */
|
|
14
|
+
export const SCAFFOLD_SECONDARY_HEIGHT = 52
|
|
15
|
+
|
|
16
|
+
/** Gap in px between a panel's primary surface and its secondary strip. */
|
|
17
|
+
export const SCAFFOLD_PANEL_GAP = 10
|
|
18
|
+
|
|
19
|
+
/** How long the seam menu lingers expanded after the pointer leaves it (ms)
|
|
20
|
+
* before it collapses back to the compact toggle. The timer keeps counting
|
|
21
|
+
* even when the pointer leaves the window entirely. */
|
|
22
|
+
export const SCAFFOLD_MENU_COLLAPSE_DELAY = 4000
|
|
23
|
+
|
|
24
|
+
/** Morph duration in seconds for drawer slides and panel layout shifts. */
|
|
25
|
+
export const SCAFFOLD_MORPH_DURATION = 0.3
|
|
26
|
+
|
|
27
|
+
/** `--ease-smooth-out` as a motion/react easing tuple. */
|
|
28
|
+
export const SCAFFOLD_EASE = [0.22, 1, 0.36, 1] as const
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PanelCloseButton } from "./panel-close-button"
|
|
2
|
+
import { PanelMenuButton } from "./panel-menu-button.tsx"
|
|
3
|
+
import { ScaffoldActions } from "./scaffold-actions"
|
|
4
|
+
import { ScaffoldCanvas } from "./scaffold-canvas"
|
|
5
|
+
import { ScaffoldInspector } from "./scaffold-inspector"
|
|
6
|
+
import { ScaffoldMain } from "./scaffold-main"
|
|
7
|
+
import { ScaffoldPanel } from "./scaffold-panel"
|
|
8
|
+
import { ScaffoldRoot } from "./scaffold-root"
|
|
9
|
+
import { ScaffoldSidebar } from "./scaffold-sidebar"
|
|
10
|
+
import { ScaffoldSubPanel } from "@/components/blocks/scaffold/scaffold-sub-panel.tsx"
|
|
11
|
+
|
|
12
|
+
export { useScaffoldContext } from "./scaffold-context"
|
|
13
|
+
export { useScaffold } from "./use-scaffold"
|
|
14
|
+
export type * from "./type"
|
|
15
|
+
export * from "./constants"
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
PanelCloseButton,
|
|
19
|
+
PanelMenuButton,
|
|
20
|
+
ScaffoldActions,
|
|
21
|
+
ScaffoldCanvas,
|
|
22
|
+
ScaffoldInspector,
|
|
23
|
+
ScaffoldMain,
|
|
24
|
+
ScaffoldPanel,
|
|
25
|
+
ScaffoldRoot,
|
|
26
|
+
ScaffoldSidebar,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Scaffold = {
|
|
30
|
+
Root: ScaffoldRoot,
|
|
31
|
+
Sidebar: ScaffoldSidebar,
|
|
32
|
+
Main: ScaffoldMain,
|
|
33
|
+
Actions: ScaffoldActions,
|
|
34
|
+
Canvas: ScaffoldCanvas,
|
|
35
|
+
Panel: ScaffoldPanel,
|
|
36
|
+
Inspector: ScaffoldInspector,
|
|
37
|
+
SubPanel: ScaffoldSubPanel
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { RiCloseLine } from "@remixicon/react"
|
|
4
|
+
import * as React from "react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
import type { PanelFloatingButtonProps } from "./type"
|
|
8
|
+
import { floatingButtonClass, revealOnPanelHoverClass } from "./utils"
|
|
9
|
+
|
|
10
|
+
/** Floating close affordance in a panel's top-right corner. */
|
|
11
|
+
export function PanelCloseButton({
|
|
12
|
+
onClick,
|
|
13
|
+
label,
|
|
14
|
+
sound = true,
|
|
15
|
+
className,
|
|
16
|
+
}: PanelFloatingButtonProps): React.ReactElement {
|
|
17
|
+
return (
|
|
18
|
+
<button
|
|
19
|
+
id="scaffold-panel-close-button"
|
|
20
|
+
aria-label={label}
|
|
21
|
+
className={cn(
|
|
22
|
+
floatingButtonClass,
|
|
23
|
+
revealOnPanelHoverClass,
|
|
24
|
+
"absolute top-4 right-3.5 z-10",
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
data-cuelume-press={sound ? "" : undefined}
|
|
28
|
+
data-cuelume-release={sound ? "" : undefined}
|
|
29
|
+
data-slot="scaffold-panel-close"
|
|
30
|
+
onClick={onClick}
|
|
31
|
+
type="button"
|
|
32
|
+
>
|
|
33
|
+
<RiCloseLine aria-hidden className="size-4" />
|
|
34
|
+
</button>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AnimatePresence,
|
|
7
|
+
motion,
|
|
8
|
+
useReducedMotion,
|
|
9
|
+
type Variants,
|
|
10
|
+
} from "motion/react"
|
|
11
|
+
import { More } from "iconsax-reactjs"
|
|
12
|
+
import { LucideArrowUpDown, LucideChevronDown } from "lucide-react"
|
|
13
|
+
|
|
14
|
+
import { cn } from "@/lib/utils"
|
|
15
|
+
import type { PanelMenuButtonProps } from "./type"
|
|
16
|
+
import { floatingButtonClass, revealOnPanelHoverClass } from "./utils"
|
|
17
|
+
import { Button } from "@/components/ui/button";
|
|
18
|
+
import { GlassButtonGroup } from "@/components/ui/glasscn/glass-button-group.tsx"
|
|
19
|
+
import { EASE_OUT, SPRING_LAYOUT } from "@/lib/ease.ts"
|
|
20
|
+
import { useHoverCapable } from "@/lib/hooks/use-hover-capable"
|
|
21
|
+
import { SCAFFOLD_MENU_COLLAPSE_DELAY } from "./constants"
|
|
22
|
+
|
|
23
|
+
/** Menu segments blur/fade in place while the track morphs around them. The
|
|
24
|
+
* exit is a fast tween, not the layout spring — the track stays
|
|
25
|
+
* overflow-visible, so the popped-out buttons must be gone before the
|
|
26
|
+
* collapsing pill leaves them behind as a ghost. */
|
|
27
|
+
const MENU_SEGMENT_VARIANTS: Variants = {
|
|
28
|
+
hidden: { opacity: 0, filter: "blur(4px)" },
|
|
29
|
+
visible: { opacity: 1, filter: "blur(0px)" },
|
|
30
|
+
exit: {
|
|
31
|
+
opacity: 0,
|
|
32
|
+
filter: "blur(4px)",
|
|
33
|
+
transition: { duration: 0.18, ease: EASE_OUT },
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Floating swap affordance centered on the seam between a panel's primary
|
|
39
|
+
* surface and its secondary strip.
|
|
40
|
+
*/
|
|
41
|
+
export function PanelMenuButton({
|
|
42
|
+
onClick,
|
|
43
|
+
onExpand,
|
|
44
|
+
secondaryExpanded = false,
|
|
45
|
+
label,
|
|
46
|
+
sound = true,
|
|
47
|
+
className,
|
|
48
|
+
}: PanelMenuButtonProps): React.ReactElement {
|
|
49
|
+
|
|
50
|
+
const reduce = useReducedMotion()
|
|
51
|
+
const canHover = useHoverCapable()
|
|
52
|
+
const actionsId = React.useId()
|
|
53
|
+
const groupRef = React.useRef<HTMLDivElement>(null)
|
|
54
|
+
const actionsRef = React.useRef<HTMLDivElement>(null)
|
|
55
|
+
const actionsLeftRef = React.useRef(0)
|
|
56
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
57
|
+
|
|
58
|
+
const transition = reduce ? { duration: 0 } : SPRING_LAYOUT
|
|
59
|
+
|
|
60
|
+
const collapseTimerRef = React.useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
61
|
+
const suppressHoverOpenUntilRef = React.useRef(0)
|
|
62
|
+
const focusActionsOnOpenRef = React.useRef(false)
|
|
63
|
+
|
|
64
|
+
React.useEffect(() => () => clearTimeout(collapseTimerRef.current), [])
|
|
65
|
+
|
|
66
|
+
const cancelCollapse = React.useCallback(() => {
|
|
67
|
+
clearTimeout(collapseTimerRef.current)
|
|
68
|
+
}, [])
|
|
69
|
+
|
|
70
|
+
// Arms when the pointer stops hovering the group: the menu lingers for the
|
|
71
|
+
// grace period, then collapses — unless the pointer (or focus) came back.
|
|
72
|
+
const armCollapse = React.useCallback(() => {
|
|
73
|
+
if (!canHover) return
|
|
74
|
+
clearTimeout(collapseTimerRef.current)
|
|
75
|
+
collapseTimerRef.current = setTimeout(() => {
|
|
76
|
+
// Focus keeps the menu open — don't collapse under the keyboard.
|
|
77
|
+
if (groupRef.current?.contains(document.activeElement)) return
|
|
78
|
+
setExpanded(false)
|
|
79
|
+
}, SCAFFOLD_MENU_COLLAPSE_DELAY)
|
|
80
|
+
}, [canHover])
|
|
81
|
+
|
|
82
|
+
// The grace period must keep counting when the pointer leaves the whole
|
|
83
|
+
// app — leaving the window can skip the group's own pointerleave, so arm
|
|
84
|
+
// on viewport exit and window blur as well.
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (!expanded || !canHover) return
|
|
87
|
+
const root = document.documentElement
|
|
88
|
+
root.addEventListener("pointerleave", armCollapse)
|
|
89
|
+
window.addEventListener("blur", armCollapse)
|
|
90
|
+
return () => {
|
|
91
|
+
root.removeEventListener("pointerleave", armCollapse)
|
|
92
|
+
window.removeEventListener("blur", armCollapse)
|
|
93
|
+
}
|
|
94
|
+
}, [expanded, canHover, armCollapse])
|
|
95
|
+
|
|
96
|
+
// Click-opens replace the toggle with the actions — hand focus over so
|
|
97
|
+
// keyboard users aren't dropped onto <body>.
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
if (!expanded || !focusActionsOnOpenRef.current) return
|
|
100
|
+
focusActionsOnOpenRef.current = false
|
|
101
|
+
actionsRef.current?.querySelector<HTMLButtonElement>("button")?.focus()
|
|
102
|
+
}, [expanded])
|
|
103
|
+
|
|
104
|
+
const collapse = () => {
|
|
105
|
+
// The shrinking toggle can glide under a resting cursor and hover-reopen
|
|
106
|
+
// the menu it just closed — ignore hover-opens until it has settled.
|
|
107
|
+
suppressHoverOpenUntilRef.current = Date.now() + 600
|
|
108
|
+
setExpanded(false)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Acting collapses the menu — the pill returns to the compact toggle.
|
|
112
|
+
const handleAction = (action?: () => void) => {
|
|
113
|
+
action?.()
|
|
114
|
+
collapse()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Click open — the touch and keyboard path.
|
|
118
|
+
const handleOnExpand = () => {
|
|
119
|
+
if (groupRef.current?.contains(document.activeElement)) {
|
|
120
|
+
focusActionsOnOpenRef.current = true
|
|
121
|
+
}
|
|
122
|
+
setExpanded(true)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Hover on the toggle opens the menu (hover-capable devices only — touch
|
|
126
|
+
// and keyboard go through the click toggle).
|
|
127
|
+
const handleToggleHover = () => {
|
|
128
|
+
if (!canHover || Date.now() < suppressHoverOpenUntilRef.current) return
|
|
129
|
+
cancelCollapse()
|
|
130
|
+
setExpanded(true)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// popLayout pops the exiting actions group out of the flow — pin it back to
|
|
134
|
+
// where it sat so it stays visually attached to the toggle while leaving.
|
|
135
|
+
React.useLayoutEffect(() => {
|
|
136
|
+
const actionsNode = actionsRef.current
|
|
137
|
+
if (!actionsNode) return
|
|
138
|
+
|
|
139
|
+
if (!expanded) {
|
|
140
|
+
actionsNode.style.left = `${
|
|
141
|
+
actionsLeftRef.current - actionsNode.getBoundingClientRect().left
|
|
142
|
+
}px`
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
actionsNode.style.left = ""
|
|
147
|
+
actionsLeftRef.current = actionsNode.getBoundingClientRect().left
|
|
148
|
+
}, [expanded])
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<GlassButtonGroup
|
|
152
|
+
ref={groupRef}
|
|
153
|
+
layout
|
|
154
|
+
transition={transition}
|
|
155
|
+
onPointerEnter={cancelCollapse}
|
|
156
|
+
onPointerLeave={armCollapse}
|
|
157
|
+
glassVariant="subtle"
|
|
158
|
+
className={cn(
|
|
159
|
+
floatingButtonClass,
|
|
160
|
+
revealOnPanelHoverClass,
|
|
161
|
+
// Centered on the seam: secondary height (52px) + half the 10px gap.
|
|
162
|
+
"absolute top-1/2 z-10 -translate-y-1/2 overflow-visible!",
|
|
163
|
+
className
|
|
164
|
+
)}
|
|
165
|
+
>
|
|
166
|
+
<AnimatePresence mode="popLayout" initial={false}>
|
|
167
|
+
{expanded ? (
|
|
168
|
+
<motion.div
|
|
169
|
+
key="menu-actions"
|
|
170
|
+
ref={actionsRef}
|
|
171
|
+
id={actionsId}
|
|
172
|
+
layout
|
|
173
|
+
variants={MENU_SEGMENT_VARIANTS}
|
|
174
|
+
initial={reduce ? { opacity: 0 } : "hidden"}
|
|
175
|
+
animate={reduce ? { opacity: 1 } : "visible"}
|
|
176
|
+
exit={reduce ? { opacity: 0 } : "exit"}
|
|
177
|
+
transition={transition}
|
|
178
|
+
className="relative flex w-max items-stretch"
|
|
179
|
+
>
|
|
180
|
+
<Button
|
|
181
|
+
id="scaffold-panel-menu-expand"
|
|
182
|
+
size="sm"
|
|
183
|
+
variant="ghost"
|
|
184
|
+
sound={sound}
|
|
185
|
+
data-slot="scaffold-panel-menu-swap"
|
|
186
|
+
// The motion wrapper hides these from the group's corner
|
|
187
|
+
// selectors — restore what ButtonGroup would have applied.
|
|
188
|
+
className="rounded-r-none"
|
|
189
|
+
onClick={() => handleAction(onExpand)}
|
|
190
|
+
>
|
|
191
|
+
{/* Button's [&_svg]:transition-transform eases the flip. */}
|
|
192
|
+
<LucideChevronDown
|
|
193
|
+
size={16}
|
|
194
|
+
className={cn(secondaryExpanded && "rotate-180")}
|
|
195
|
+
/>
|
|
196
|
+
Expand
|
|
197
|
+
</Button>
|
|
198
|
+
<Button
|
|
199
|
+
id="scaffold-panel-menu-swap"
|
|
200
|
+
size="sm"
|
|
201
|
+
variant="ghost"
|
|
202
|
+
sound={sound}
|
|
203
|
+
data-slot="scaffold-panel-menu-swap"
|
|
204
|
+
className="rounded-l-none border-l-0"
|
|
205
|
+
onClick={() => handleAction(onClick)}
|
|
206
|
+
>
|
|
207
|
+
<LucideArrowUpDown size={16} />
|
|
208
|
+
Swap
|
|
209
|
+
</Button>
|
|
210
|
+
</motion.div>
|
|
211
|
+
) : (
|
|
212
|
+
<motion.div
|
|
213
|
+
key="menu-toggle"
|
|
214
|
+
layout
|
|
215
|
+
variants={MENU_SEGMENT_VARIANTS}
|
|
216
|
+
initial={reduce ? { opacity: 0 } : "hidden"}
|
|
217
|
+
animate={reduce ? { opacity: 1 } : "visible"}
|
|
218
|
+
exit={reduce ? { opacity: 0 } : "exit"}
|
|
219
|
+
transition={transition}
|
|
220
|
+
className="flex shrink-0"
|
|
221
|
+
>
|
|
222
|
+
<Button
|
|
223
|
+
id="scaffold-panel-menu-toggle-button"
|
|
224
|
+
aria-label={label}
|
|
225
|
+
aria-expanded={expanded}
|
|
226
|
+
size="icon-sm"
|
|
227
|
+
variant="ghost"
|
|
228
|
+
sound={sound}
|
|
229
|
+
data-slot="scaffold-panel-menu-toggle"
|
|
230
|
+
onClick={handleOnExpand}
|
|
231
|
+
onPointerEnter={handleToggleHover}
|
|
232
|
+
>
|
|
233
|
+
<More size={16} />
|
|
234
|
+
</Button>
|
|
235
|
+
</motion.div>
|
|
236
|
+
)}
|
|
237
|
+
</AnimatePresence>
|
|
238
|
+
</GlassButtonGroup>
|
|
239
|
+
)
|
|
240
|
+
}
|