@justanarthur/modo-ui 2.6.2 → 2.8.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/blocks/desktop-shell/examples.mdx +40 -0
- package/blocks/desktop-shell/index.tsx +144 -13
- package/components/actions/button-group/examples.mdx +96 -0
- package/components/actions/button-group/index.tsx +161 -0
- package/dist/blocks/desktop-shell/index.d.ts +15 -2
- package/dist/blocks/desktop-shell/index.js +1 -1
- package/dist/components/actions/button-group/index.d.ts +196 -0
- package/dist/components/actions/button-group/index.js +50 -0
- package/dist/index.d.ts +4290 -4220
- package/dist/index.js +9 -1
- package/dist/shared/{components-hhwv5mcm.js → components-dk328yn5.js} +115 -12
- package/dist/shared/components-rr3fa4e5.js +108 -0
- package/dist/styles.css +34 -15
- package/index.ts +1 -0
- package/package.json +1 -1
|
@@ -92,6 +92,46 @@ With `titleBar="card"` nothing runs across the window: the traffic lights and th
|
|
|
92
92
|
</div>
|
|
93
93
|
</div>
|
|
94
94
|
|
|
95
|
+
# Folded sidebar
|
|
96
|
+
|
|
97
|
+
The sidebar starts folded. Hover the window's left edge or the sidebar toggle and it peeks: it slides in over the main card, which doesn't move, and folds back a beat after the pointer leaves; focus inside keeps it open. Click the toggle to pin it. The traffic lights, the toggle and the title share one centre line; `peek={false}` turns the peek off.
|
|
98
|
+
|
|
99
|
+
<div className="w-full overflow-x-auto">
|
|
100
|
+
<div className="h-[560px] w-[960px] overflow-hidden rounded-xl border border-border">
|
|
101
|
+
<DesktopShell
|
|
102
|
+
showControls
|
|
103
|
+
titleBar="card"
|
|
104
|
+
defaultLeftOpen={false}
|
|
105
|
+
title={<span className="truncate text-body weight-medium text-foreground">Businesses</span>}
|
|
106
|
+
trailing={
|
|
107
|
+
<Button variant="ghost" size="icon-compact" aria-label="Search">
|
|
108
|
+
<Search />
|
|
109
|
+
</Button>
|
|
110
|
+
}
|
|
111
|
+
left={
|
|
112
|
+
<Sidebar variant="inset" defaultValue="inbox">
|
|
113
|
+
<Sidebar.Content>
|
|
114
|
+
<Sidebar.Group>
|
|
115
|
+
<Sidebar.GroupLabel>Library</Sidebar.GroupLabel>
|
|
116
|
+
<Sidebar.Menu>
|
|
117
|
+
<Sidebar.MenuItem><Sidebar.MenuButton icon={Inbox} value="inbox">Inbox</Sidebar.MenuButton></Sidebar.MenuItem>
|
|
118
|
+
<Sidebar.MenuItem><Sidebar.MenuButton icon={Star} value="starred">Starred</Sidebar.MenuButton></Sidebar.MenuItem>
|
|
119
|
+
<Sidebar.MenuItem><Sidebar.MenuButton icon={Folder} value="projects">Projects</Sidebar.MenuButton></Sidebar.MenuItem>
|
|
120
|
+
</Sidebar.Menu>
|
|
121
|
+
</Sidebar.Group>
|
|
122
|
+
</Sidebar.Content>
|
|
123
|
+
</Sidebar>
|
|
124
|
+
}
|
|
125
|
+
main={
|
|
126
|
+
<div className="flex flex-1 flex-col gap-2 p-6">
|
|
127
|
+
<span className="text-title text-foreground">Businesses</span>
|
|
128
|
+
<span className="text-body text-muted-foreground">The peek floats over this card instead of pushing it aside.</span>
|
|
129
|
+
</div>
|
|
130
|
+
}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
95
135
|
# Windows and Linux
|
|
96
136
|
|
|
97
137
|
Off macOS the title bar starts at the edge; the stand-in window controls sit at its end. Here the side pane starts folded and there is no left sidebar.
|
|
@@ -6,7 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
'use client'
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
type FocusEvent,
|
|
11
|
+
type PointerEvent,
|
|
12
|
+
type ReactNode,
|
|
13
|
+
useCallback,
|
|
14
|
+
useEffect,
|
|
15
|
+
useLayoutEffect,
|
|
16
|
+
useMemo,
|
|
17
|
+
useRef,
|
|
18
|
+
useState,
|
|
19
|
+
} from 'react'
|
|
10
20
|
import Button from '../../components/actions/button'
|
|
11
21
|
import Sidebar from '../../components/navigation/sidebar'
|
|
12
22
|
import { useSidebarShortcut } from '../../components/navigation/sidebar/sidebar-shortcut'
|
|
@@ -41,6 +51,25 @@ const CORNER_ROOM: Record<DesktopPlatform, string> = {
|
|
|
41
51
|
linux: 'w-6 shrink-0',
|
|
42
52
|
}
|
|
43
53
|
|
|
54
|
+
// While it peeks, the folded sidebar floats over the main card, on the card's own 8px inset, instead of reflowing it.
|
|
55
|
+
// The panel's side padding is that inset; it also leaves the shadow room inside the sidebar's clip.
|
|
56
|
+
const PEEK_OVERLAY =
|
|
57
|
+
'[&>[data-slot=sidebar]]:absolute [&>[data-slot=sidebar]]:inset-y-0 [&>[data-slot=sidebar]]:left-0 [&>[data-slot=sidebar]]:z-10 [&>[data-slot=sidebar]>div]:px-2 [&>[data-slot=sidebar]_[data-sidebar=sidebar]]:shadow-surface-3'
|
|
58
|
+
const PEEK_BG: Record<number, string> = {
|
|
59
|
+
4: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:bg-surface-4',
|
|
60
|
+
5: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:bg-surface-5',
|
|
61
|
+
6: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:bg-surface-6',
|
|
62
|
+
7: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:bg-surface-7',
|
|
63
|
+
8: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:bg-surface-8',
|
|
64
|
+
}
|
|
65
|
+
const PEEK_RADIUS = {
|
|
66
|
+
rounded: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:rounded-xl',
|
|
67
|
+
pill: '[&>[data-slot=sidebar]_[data-sidebar=sidebar]]:rounded-3xl',
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The peek folds back this long after the pointer leaves, like Sidebar's open on hover.
|
|
71
|
+
const PEEK_CLOSE_MS = 300
|
|
72
|
+
|
|
44
73
|
// Below this window width the side pane takes the main card's place.
|
|
45
74
|
const NARROW = 768
|
|
46
75
|
|
|
@@ -71,6 +100,8 @@ interface DesktopShellProps {
|
|
|
71
100
|
defaultLeftOpen?: boolean
|
|
72
101
|
/** Called when the left sidebar opens or folds. */
|
|
73
102
|
onLeftOpenChange?: (open: boolean) => void
|
|
103
|
+
/** While the left sidebar is folded, hovering the window's left edge or the sidebar toggle slides it in over the main card without reflowing it; it folds back a beat after the pointer leaves, and stays while focus is inside it. Defaults to `true`. */
|
|
104
|
+
peek?: boolean
|
|
74
105
|
/** Controlled open state of the side pane. */
|
|
75
106
|
rightOpen?: boolean
|
|
76
107
|
/** The side pane's open state at first. Defaults to `true`. */
|
|
@@ -148,6 +179,64 @@ function WindowControls() {
|
|
|
148
179
|
)
|
|
149
180
|
}
|
|
150
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The folded sidebar's peek. Zones (`data-peek`) are the edge strip, the
|
|
184
|
+
* toggle, the corner and the sidebar: entering an opening one (the strip,
|
|
185
|
+
* the toggle) with a mouse peeks; leaving for anything that isn't a zone
|
|
186
|
+
* folds it back after `PEEK_CLOSE_MS`, unless focus is inside the sidebar.
|
|
187
|
+
*/
|
|
188
|
+
function usePeek(enabled: boolean) {
|
|
189
|
+
const [open, setOpen] = useState(false)
|
|
190
|
+
// The last opening was a peek: the sidebar stays out of flow until it is pinned, so folding back never reflows the card.
|
|
191
|
+
const [overlay, setOverlay] = useState(false)
|
|
192
|
+
const sidebar = useRef<HTMLDivElement | null>(null)
|
|
193
|
+
const over = useRef(false)
|
|
194
|
+
const timer = useRef<ReturnType<typeof setTimeout>>()
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (enabled) return
|
|
198
|
+
clearTimeout(timer.current)
|
|
199
|
+
setOpen(false)
|
|
200
|
+
setOverlay(false)
|
|
201
|
+
}, [enabled])
|
|
202
|
+
useEffect(() => () => clearTimeout(timer.current), [])
|
|
203
|
+
|
|
204
|
+
const close = () => {
|
|
205
|
+
clearTimeout(timer.current)
|
|
206
|
+
timer.current = setTimeout(() => {
|
|
207
|
+
if (!over.current && !sidebar.current?.contains(document.activeElement)) setOpen(false)
|
|
208
|
+
}, PEEK_CLOSE_MS)
|
|
209
|
+
}
|
|
210
|
+
const zone = (opens: boolean) => ({
|
|
211
|
+
'data-peek': '',
|
|
212
|
+
onPointerEnter: (event: PointerEvent) => {
|
|
213
|
+
over.current = true
|
|
214
|
+
clearTimeout(timer.current)
|
|
215
|
+
if (!opens || !enabled || event.pointerType !== 'mouse') return
|
|
216
|
+
setOpen(true)
|
|
217
|
+
setOverlay(true)
|
|
218
|
+
},
|
|
219
|
+
onPointerLeave: (event: PointerEvent) => {
|
|
220
|
+
if (event.relatedTarget instanceof Element && event.relatedTarget.closest('[data-peek]')) return
|
|
221
|
+
over.current = false
|
|
222
|
+
close()
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
const onBlur = (event: FocusEvent) => {
|
|
226
|
+
if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) close()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
enabled,
|
|
231
|
+
open: enabled && open,
|
|
232
|
+
overlay: enabled && overlay,
|
|
233
|
+
dismiss: () => setOpen(false),
|
|
234
|
+
sidebar,
|
|
235
|
+
zone,
|
|
236
|
+
onBlur,
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
151
240
|
/** The main region: an inset card two surface levels up, like Sidebar.Inset. */
|
|
152
241
|
function MainCard({ children }: { children: ReactNode }) {
|
|
153
242
|
const level = useLift(2)
|
|
@@ -183,7 +272,18 @@ function MainCard({ children }: { children: ReactNode }) {
|
|
|
183
272
|
* sidebar's content starts below them), and the title, `trailing` and the
|
|
184
273
|
* side pane toggle head the main card, which drags the window too. With the
|
|
185
274
|
* sidebar folded, the corner controls stay put and the card's header makes
|
|
186
|
-
* room for them.
|
|
275
|
+
* room for them. The corner sits on the card's 8px inset, so the window
|
|
276
|
+
* controls, the toggle and the title share one centre line, 26px from the
|
|
277
|
+
* window's top (22px compact). A native macOS window must put its traffic
|
|
278
|
+
* lights on that line too: with an overlay title bar, set the window's traffic
|
|
279
|
+
* light position (Tauri's `trafficLightPosition`) so they centre there,
|
|
280
|
+
* inside the 72px the corner keeps for them.
|
|
281
|
+
*
|
|
282
|
+
* While the sidebar is folded, hovering the window's left edge or the sidebar
|
|
283
|
+
* toggle peeks it: it slides in over the main card as a card of its own,
|
|
284
|
+
* without reflowing it, stays while the pointer is over it or focus is inside
|
|
285
|
+
* it, and folds back a beat after the pointer leaves. Clicking the toggle
|
|
286
|
+
* pins it open. `peek={false}` turns it off.
|
|
187
287
|
*
|
|
188
288
|
* Under it, the main content is an inset card. The left Sidebar is yours
|
|
189
289
|
* (`left`): it resizes from its rail and folds from its toggle, its rail or
|
|
@@ -211,6 +311,7 @@ export default function DesktopShell({
|
|
|
211
311
|
leftOpen: leftOpenProp,
|
|
212
312
|
defaultLeftOpen = true,
|
|
213
313
|
onLeftOpenChange,
|
|
314
|
+
peek = true,
|
|
214
315
|
rightOpen: rightOpenProp,
|
|
215
316
|
defaultRightOpen = true,
|
|
216
317
|
onRightOpenChange,
|
|
@@ -229,6 +330,10 @@ export default function DesktopShell({
|
|
|
229
330
|
const hasRight = right !== undefined
|
|
230
331
|
const paneOpen = hasRight && rightOpen
|
|
231
332
|
const inCard = titleBar === 'card'
|
|
333
|
+
const shape = useShape()
|
|
334
|
+
const substrate = useLift(0)
|
|
335
|
+
const peekLevel = useLift(3)
|
|
336
|
+
const peeking = usePeek(peek && hasLeft && !leftOpen)
|
|
232
337
|
const paneSizes = useMemo(() => (paneOpen ? [100 - paneSize, paneSize] : [100, 0]), [paneOpen, paneSize])
|
|
233
338
|
|
|
234
339
|
// The window's own width, not the viewport's: a framed or resized window doesn't follow the viewport.
|
|
@@ -259,7 +364,11 @@ export default function DesktopShell({
|
|
|
259
364
|
{showControls && <TrafficLights />}
|
|
260
365
|
</div>
|
|
261
366
|
)}
|
|
262
|
-
{hasLeft &&
|
|
367
|
+
{hasLeft && (
|
|
368
|
+
<span className="contents" {...peeking.zone(true)}>
|
|
369
|
+
<Toggle side="left" label={leftLabel} open={leftOpen} onClick={() => setLeftOpen(!leftOpen)} />
|
|
370
|
+
</span>
|
|
371
|
+
)}
|
|
263
372
|
{leading}
|
|
264
373
|
</>
|
|
265
374
|
)
|
|
@@ -294,7 +403,8 @@ export default function DesktopShell({
|
|
|
294
403
|
<div ref={root} className={cn('relative flex h-full w-full flex-col bg-background', className)}>
|
|
295
404
|
<SizeProvider size={size.variant}>
|
|
296
405
|
{inCard ? (
|
|
297
|
-
|
|
406
|
+
// On the card's 8px inset, so the corner and the card's header share one centre line.
|
|
407
|
+
<div data-tauri-drag-region className={cn(bar, 'absolute top-2 left-0 z-20')} {...peeking.zone(false)}>
|
|
298
408
|
{corner}
|
|
299
409
|
</div>
|
|
300
410
|
) : (
|
|
@@ -306,14 +416,37 @@ export default function DesktopShell({
|
|
|
306
416
|
</SizeProvider>
|
|
307
417
|
{/* Sidebar defaults to the viewport's height; under the title bar it takes the body's. */}
|
|
308
418
|
<Sidebar.Provider
|
|
309
|
-
className=
|
|
419
|
+
className="min-h-0 flex-1"
|
|
310
420
|
persist={false}
|
|
311
421
|
mobileBreakpoint={0}
|
|
312
422
|
shortcut={hasLeft ? undefined : null}
|
|
313
|
-
open={leftOpen}
|
|
314
|
-
onOpenChange={
|
|
423
|
+
open={leftOpen || peeking.open}
|
|
424
|
+
onOpenChange={open => {
|
|
425
|
+
// `[` or the rail folds a peek; only the toggle pins it.
|
|
426
|
+
if (!open) peeking.dismiss()
|
|
427
|
+
setLeftOpen(open)
|
|
428
|
+
}}
|
|
315
429
|
>
|
|
316
|
-
{left}
|
|
430
|
+
{peeking.enabled && <div className="absolute inset-y-0 left-0 z-10 w-2" {...peeking.zone(true)} />}
|
|
431
|
+
<SurfaceProvider value={peeking.overlay ? peekLevel : substrate}>
|
|
432
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: it only watches focus leaving the sidebar; the controls inside are the focusable ones. */}
|
|
433
|
+
<div
|
|
434
|
+
ref={peeking.sidebar}
|
|
435
|
+
className={cn(
|
|
436
|
+
'contents [&>[data-slot=sidebar]]:h-full',
|
|
437
|
+
inCard && CORNER_CLEARANCE[size.variant],
|
|
438
|
+
peeking.overlay && [
|
|
439
|
+
PEEK_OVERLAY,
|
|
440
|
+
PEEK_BG[peekLevel],
|
|
441
|
+
PEEK_RADIUS[shape.bgRadius >= 20 ? 'pill' : 'rounded'],
|
|
442
|
+
],
|
|
443
|
+
)}
|
|
444
|
+
onBlur={peeking.onBlur}
|
|
445
|
+
{...peeking.zone(false)}
|
|
446
|
+
>
|
|
447
|
+
{left}
|
|
448
|
+
</div>
|
|
449
|
+
</SurfaceProvider>
|
|
317
450
|
{/* Flush with an open sidebar (its rows bring their own gutter), 8px from the window edge once it folds. */}
|
|
318
451
|
<div
|
|
319
452
|
className={cn(
|
|
@@ -329,13 +462,11 @@ export default function DesktopShell({
|
|
|
329
462
|
<Resizable.Panel defaultSize={100 - defaultPaneSize} minSize={100 - maxPaneSize}>
|
|
330
463
|
{card(main)}
|
|
331
464
|
</Resizable.Panel>
|
|
332
|
-
{/* The handle is the 8px gutter between the card and the pane, and the card's right edge once it folds.
|
|
465
|
+
{/* The handle is the 8px gutter between the card and the pane, and the card's right edge once it folds.
|
|
466
|
+
Like the sidebar's rail, its hairline shows only while it is hovered, held or focused. */}
|
|
333
467
|
<Resizable.Handle
|
|
334
468
|
label={rightLabel}
|
|
335
|
-
className=
|
|
336
|
-
'w-2 transition-opacity duration-fast',
|
|
337
|
-
!paneOpen && 'opacity-0 hover:opacity-100 focus-visible:opacity-100',
|
|
338
|
-
)}
|
|
469
|
+
className="w-2 opacity-0 transition-opacity duration-fast hover:opacity-100 focus-visible:opacity-100 data-[dragging]:opacity-100"
|
|
339
470
|
/>
|
|
340
471
|
<Resizable.Panel defaultSize={defaultPaneSize} minSize={minPaneSize} maxSize={maxPaneSize} collapsible>
|
|
341
472
|
<div {...inertProps(!paneOpen)} className="flex h-full min-w-0 flex-col">
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ButtonGroup from './index'
|
|
2
|
+
import Dropdown from '../../overlays/dropdown'
|
|
3
|
+
import { AlignCenter, AlignLeft, AlignRight, Archive, Copy, GitMerge, Rocket, Save, Trash2 } from 'lucide-react'
|
|
4
|
+
|
|
5
|
+
# Group
|
|
6
|
+
|
|
7
|
+
Related actions as one control: the outer corners stay round, the inner edges square, and a hairline of the surface parts the segments.
|
|
8
|
+
|
|
9
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
10
|
+
<ButtonGroup variant="secondary" aria-label="Alignment">
|
|
11
|
+
<ButtonGroup.Button size="icon" aria-label="Align left">
|
|
12
|
+
<AlignLeft />
|
|
13
|
+
</ButtonGroup.Button>
|
|
14
|
+
<ButtonGroup.Button size="icon" aria-label="Align center">
|
|
15
|
+
<AlignCenter />
|
|
16
|
+
</ButtonGroup.Button>
|
|
17
|
+
<ButtonGroup.Button size="icon" aria-label="Align right">
|
|
18
|
+
<AlignRight />
|
|
19
|
+
</ButtonGroup.Button>
|
|
20
|
+
</ButtonGroup>
|
|
21
|
+
<ButtonGroup variant="tertiary" aria-label="Message">
|
|
22
|
+
<ButtonGroup.Button leadingIcon={Archive}>Archive</ButtonGroup.Button>
|
|
23
|
+
<ButtonGroup.Button>Snooze</ButtonGroup.Button>
|
|
24
|
+
<ButtonGroup.Button variant="destructive" leadingIcon={Trash2}>Delete</ButtonGroup.Button>
|
|
25
|
+
</ButtonGroup>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
# Split button
|
|
29
|
+
|
|
30
|
+
The main action, and its variants on an attached chevron. The menu grows out of the chevron, lines up with the group's end, and the chevron stays pressed while it shows.
|
|
31
|
+
|
|
32
|
+
<ButtonGroup aria-label="Merge">
|
|
33
|
+
<ButtonGroup.Button leadingIcon={GitMerge}>Merge pull request</ButtonGroup.Button>
|
|
34
|
+
<ButtonGroup.Menu label="Merge options" defaultCheckedIndex={0}>
|
|
35
|
+
<Dropdown.Label>Merge with</Dropdown.Label>
|
|
36
|
+
<Dropdown.Item label="Merge commit" />
|
|
37
|
+
<Dropdown.Item label="Squash and merge" />
|
|
38
|
+
<Dropdown.Item label="Rebase and merge" />
|
|
39
|
+
</ButtonGroup.Menu>
|
|
40
|
+
</ButtonGroup>
|
|
41
|
+
|
|
42
|
+
# Variants
|
|
43
|
+
|
|
44
|
+
Every Button variant joins: filled ones part on a hairline of the surface, framed ones share one frame.
|
|
45
|
+
|
|
46
|
+
<div className="flex flex-col items-start gap-3">
|
|
47
|
+
{['primary', 'secondary', 'tertiary', 'outline', 'ghost', 'destructive', 'success'].map(variant => (
|
|
48
|
+
<ButtonGroup key={variant} variant={variant} aria-label={variant}>
|
|
49
|
+
<ButtonGroup.Button leadingIcon={Save}>Save</ButtonGroup.Button>
|
|
50
|
+
<ButtonGroup.Menu label="Save options">
|
|
51
|
+
<Dropdown.Item icon={Copy} label="Save a copy" />
|
|
52
|
+
<Dropdown.Item icon={Rocket} label="Save and publish" />
|
|
53
|
+
</ButtonGroup.Menu>
|
|
54
|
+
</ButtonGroup>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
# Sizes
|
|
59
|
+
|
|
60
|
+
`size` pins every segment to one step of the ladder, and the menu's rows with them.
|
|
61
|
+
|
|
62
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
63
|
+
<ButtonGroup aria-label="Deploy">
|
|
64
|
+
<ButtonGroup.Button leadingIcon={Rocket}>Deploy</ButtonGroup.Button>
|
|
65
|
+
<ButtonGroup.Menu label="Deploy to">
|
|
66
|
+
<Dropdown.Item label="Production" />
|
|
67
|
+
<Dropdown.Item label="Staging" />
|
|
68
|
+
</ButtonGroup.Menu>
|
|
69
|
+
</ButtonGroup>
|
|
70
|
+
<ButtonGroup size="compact" aria-label="Deploy">
|
|
71
|
+
<ButtonGroup.Button leadingIcon={Rocket}>Deploy</ButtonGroup.Button>
|
|
72
|
+
<ButtonGroup.Menu label="Deploy to">
|
|
73
|
+
<Dropdown.Item label="Production" />
|
|
74
|
+
<Dropdown.Item label="Staging" />
|
|
75
|
+
</ButtonGroup.Menu>
|
|
76
|
+
</ButtonGroup>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
# Disabled
|
|
80
|
+
|
|
81
|
+
`disabled` on the group dims every segment; on one segment, only that one.
|
|
82
|
+
|
|
83
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
84
|
+
<ButtonGroup variant="secondary" disabled aria-label="Deploy">
|
|
85
|
+
<ButtonGroup.Button>Deploy</ButtonGroup.Button>
|
|
86
|
+
<ButtonGroup.Menu label="Deploy to">
|
|
87
|
+
<Dropdown.Item label="Production" />
|
|
88
|
+
</ButtonGroup.Menu>
|
|
89
|
+
</ButtonGroup>
|
|
90
|
+
<ButtonGroup aria-label="Deploy">
|
|
91
|
+
<ButtonGroup.Button disabled>Deploy</ButtonGroup.Button>
|
|
92
|
+
<ButtonGroup.Menu label="Deploy to">
|
|
93
|
+
<Dropdown.Item label="Production" />
|
|
94
|
+
</ButtonGroup.Menu>
|
|
95
|
+
</ButtonGroup>
|
|
96
|
+
</div>
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local addition (not part of Fluid Functionalism): buttons joined into one
|
|
3
|
+
* control, and the split button, an action with a menu of its variants
|
|
4
|
+
* attached on a chevron segment (Dropdown's popup).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import { createContext, forwardRef, type HTMLAttributes, type ReactNode, useContext } from 'react'
|
|
10
|
+
import { type IconComponent, useIcon } from '../../../lib/icon-context'
|
|
11
|
+
import { type SizeVariant, useSizeVariant } from '../../../lib/size-context'
|
|
12
|
+
import { useControllableState } from '../../../lib/use-controllable-state'
|
|
13
|
+
import { cn } from '../../../lib/utils'
|
|
14
|
+
import { SizeScope } from '../../../primitives/systems/sizes'
|
|
15
|
+
import Dropdown, { type DropdownContentProps, type DropdownMenuProps } from '../../overlays/dropdown'
|
|
16
|
+
import Button, { type ButtonProps, type ButtonVariant } from '../button'
|
|
17
|
+
|
|
18
|
+
interface ButtonGroupContextValue {
|
|
19
|
+
variant: ButtonVariant
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ButtonGroupContext = createContext<ButtonGroupContextValue>({ variant: 'primary' })
|
|
24
|
+
|
|
25
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
26
|
+
// Filled segments sit 1px apart, so the surface under them draws the hairline;
|
|
27
|
+
// framed ones overlap by their 1px frame, so the two frames read as one line.
|
|
28
|
+
const JOIN: Record<ButtonVariant, string> = {
|
|
29
|
+
primary: 'gap-px',
|
|
30
|
+
secondary: 'gap-px',
|
|
31
|
+
destructive: 'gap-px',
|
|
32
|
+
success: 'gap-px',
|
|
33
|
+
ghost: 'gap-px',
|
|
34
|
+
link: 'gap-px',
|
|
35
|
+
tertiary: '[&>*+*]:-ml-px',
|
|
36
|
+
outline: '[&>*+*]:-ml-px',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The group keeps the outer corners; a focused segment's ring paints over its neighbours.
|
|
40
|
+
const SEGMENTS = '[&>*:not(:first-child)]:rounded-l-none [&>*:not(:last-child)]:rounded-r-none [&>*:focus-visible]:z-10'
|
|
41
|
+
|
|
42
|
+
interface ButtonGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
43
|
+
/** The look every `ButtonGroup.Button` and `ButtonGroup.Menu` takes, and how the segments join: filled variants show a hairline of the surface between them, framed ones share one frame. Defaults to `"primary"`. */
|
|
44
|
+
variant?: ButtonVariant
|
|
45
|
+
/** Pins every segment, and the rows of a `ButtonGroup.Menu`, to one step of the size ladder (36px default, 28px compact). Defaults to the surrounding SizeProvider. */
|
|
46
|
+
size?: SizeVariant
|
|
47
|
+
/** Disables every segment; a segment's own `disabled` wins. Defaults to `false`. */
|
|
48
|
+
disabled?: boolean
|
|
49
|
+
/** The segments: `ButtonGroup.Button`s and at most one `ButtonGroup.Menu`, last. */
|
|
50
|
+
children: ReactNode
|
|
51
|
+
/** Classes for the group. */
|
|
52
|
+
className?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A segment: a Button in the group's variant, unless it names its own. */
|
|
56
|
+
const ButtonGroupButton = forwardRef<HTMLButtonElement, ButtonProps>(({ variant, disabled, ...props }, ref) => {
|
|
57
|
+
const group = useContext(ButtonGroupContext)
|
|
58
|
+
return <Button ref={ref} variant={variant ?? group.variant} disabled={disabled ?? group.disabled} {...props} />
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
ButtonGroupButton.displayName = 'ButtonGroupButton'
|
|
62
|
+
|
|
63
|
+
interface ButtonGroupMenuProps
|
|
64
|
+
extends DropdownContentProps,
|
|
65
|
+
Pick<DropdownMenuProps, 'open' | 'defaultOpen' | 'onOpenChange' | 'disabled' | 'modal'> {
|
|
66
|
+
/** The chevron segment's accessible name. Defaults to `"More options"`. */
|
|
67
|
+
label?: string
|
|
68
|
+
/** The segment's glyph. Defaults to the icon set's `chevron-down`. */
|
|
69
|
+
icon?: IconComponent
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The split button's menu: a square chevron segment that opens Dropdown's popup, aligned to the group's end. */
|
|
73
|
+
function ButtonGroupMenu({
|
|
74
|
+
label = 'More options',
|
|
75
|
+
icon,
|
|
76
|
+
open: openProp,
|
|
77
|
+
defaultOpen = false,
|
|
78
|
+
onOpenChange,
|
|
79
|
+
disabled,
|
|
80
|
+
modal,
|
|
81
|
+
align = 'end',
|
|
82
|
+
...content
|
|
83
|
+
}: ButtonGroupMenuProps) {
|
|
84
|
+
const group = useContext(ButtonGroupContext)
|
|
85
|
+
const [open, setOpen] = useControllableState(openProp, defaultOpen)
|
|
86
|
+
const compact = useSizeVariant() === 'compact'
|
|
87
|
+
const Chevron = useIcon('chevron-down')
|
|
88
|
+
const Icon = icon ?? Chevron
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Dropdown.Menu
|
|
92
|
+
open={open}
|
|
93
|
+
onOpenChange={(next, details) => {
|
|
94
|
+
onOpenChange?.(next, details)
|
|
95
|
+
if (!details.isCanceled) setOpen(next)
|
|
96
|
+
}}
|
|
97
|
+
disabled={disabled ?? group.disabled}
|
|
98
|
+
modal={modal}
|
|
99
|
+
>
|
|
100
|
+
<Dropdown.Trigger
|
|
101
|
+
render={
|
|
102
|
+
<Button variant={group.variant} size={compact ? 'icon-compact' : 'icon'} aria-label={label} active={open}>
|
|
103
|
+
<Icon />
|
|
104
|
+
</Button>
|
|
105
|
+
}
|
|
106
|
+
/>
|
|
107
|
+
<Dropdown.Content align={align} {...content} />
|
|
108
|
+
</Dropdown.Menu>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Buttons joined into one control: one outer shape, square inner edges and
|
|
114
|
+
* a hairline between the segments.
|
|
115
|
+
*
|
|
116
|
+
* Every segment takes the group's `variant` and `size`, so they share one
|
|
117
|
+
* height and one look. Filled variants (primary, secondary, ghost, the
|
|
118
|
+
* statuses) sit a hairline apart, the surface under them showing through;
|
|
119
|
+
* framed ones (tertiary, outline) overlap so two frames read as one. Each
|
|
120
|
+
* segment keeps the Button's press, hover and focus: a keyboard ring draws
|
|
121
|
+
* over its neighbours, and a disabled segment dims alone.
|
|
122
|
+
*
|
|
123
|
+
* The split button is a `ButtonGroup.Button` for the main action and a
|
|
124
|
+
* `ButtonGroup.Menu` after it: a chevron segment that opens Dropdown's popup
|
|
125
|
+
* (see Dropdown), grown out of the chevron and aligned to the group's end,
|
|
126
|
+
* the segment held pressed while it shows. Its rows follow the group's size.
|
|
127
|
+
*
|
|
128
|
+
* Statics:
|
|
129
|
+
* - `ButtonGroup.Button` — a segment: Button's props; `variant` and
|
|
130
|
+
* `disabled` default to the group's.
|
|
131
|
+
* - `ButtonGroup.Menu` — the split button's chevron and menu: `label`,
|
|
132
|
+
* `icon`, `open`, `defaultOpen`, `onOpenChange`, `disabled`, `modal`, and
|
|
133
|
+
* Dropdown.Content's props (`checkedIndex`, `align` defaulting to `"end"`,
|
|
134
|
+
* the morph options); its children are Dropdown rows.
|
|
135
|
+
*
|
|
136
|
+
* @example {@include ./examples.mdx}
|
|
137
|
+
*/
|
|
138
|
+
const ButtonGroup = Object.assign(
|
|
139
|
+
function ButtonGroup({ variant = 'primary', size, disabled, children, className, ...props }: ButtonGroupProps) {
|
|
140
|
+
return (
|
|
141
|
+
<SizeScope size={size}>
|
|
142
|
+
<ButtonGroupContext.Provider value={{ variant, disabled }}>
|
|
143
|
+
{/* biome-ignore lint/a11y/useSemanticElements: a toolbar-style group of buttons, not a form fieldset */}
|
|
144
|
+
<div
|
|
145
|
+
role="group"
|
|
146
|
+
className={cn('isolate inline-flex items-center', JOIN[variant], SEGMENTS, className)}
|
|
147
|
+
{...props}
|
|
148
|
+
>
|
|
149
|
+
{children}
|
|
150
|
+
</div>
|
|
151
|
+
</ButtonGroupContext.Provider>
|
|
152
|
+
</SizeScope>
|
|
153
|
+
)
|
|
154
|
+
},
|
|
155
|
+
{ Button: ButtonGroupButton, Menu: ButtonGroupMenu },
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
export type { ButtonGroupMenuProps, ButtonGroupProps }
|
|
159
|
+
export { ButtonGroup, ButtonGroupButton, ButtonGroupMenu }
|
|
160
|
+
|
|
161
|
+
export default ButtonGroup
|
|
@@ -31,6 +31,8 @@ interface DesktopShellProps {
|
|
|
31
31
|
defaultLeftOpen?: boolean;
|
|
32
32
|
/** Called when the left sidebar opens or folds. */
|
|
33
33
|
onLeftOpenChange?: (open: boolean) => void;
|
|
34
|
+
/** While the left sidebar is folded, hovering the window's left edge or the sidebar toggle slides it in over the main card without reflowing it; it folds back a beat after the pointer leaves, and stays while focus is inside it. Defaults to `true`. */
|
|
35
|
+
peek?: boolean;
|
|
34
36
|
/** Controlled open state of the side pane. */
|
|
35
37
|
rightOpen?: boolean;
|
|
36
38
|
/** The side pane's open state at first. Defaults to `true`. */
|
|
@@ -66,7 +68,18 @@ type Element_12xgc = JSX_1kxb["Element"];
|
|
|
66
68
|
* sidebar's content starts below them), and the title, `trailing` and the
|
|
67
69
|
* side pane toggle head the main card, which drags the window too. With the
|
|
68
70
|
* sidebar folded, the corner controls stay put and the card's header makes
|
|
69
|
-
* room for them.
|
|
71
|
+
* room for them. The corner sits on the card's 8px inset, so the window
|
|
72
|
+
* controls, the toggle and the title share one centre line, 26px from the
|
|
73
|
+
* window's top (22px compact). A native macOS window must put its traffic
|
|
74
|
+
* lights on that line too: with an overlay title bar, set the window's traffic
|
|
75
|
+
* light position (Tauri's `trafficLightPosition`) so they centre there,
|
|
76
|
+
* inside the 72px the corner keeps for them.
|
|
77
|
+
*
|
|
78
|
+
* While the sidebar is folded, hovering the window's left edge or the sidebar
|
|
79
|
+
* toggle peeks it: it slides in over the main card as a card of its own,
|
|
80
|
+
* without reflowing it, stays while the pointer is over it or focus is inside
|
|
81
|
+
* it, and folds back a beat after the pointer leaves. Clicking the toggle
|
|
82
|
+
* pins it open. `peek={false}` turns it off.
|
|
70
83
|
*
|
|
71
84
|
* Under it, the main content is an inset card. The left Sidebar is yours
|
|
72
85
|
* (`left`): it resizes from its rail and folds from its toggle, its rail or
|
|
@@ -80,5 +93,5 @@ type Element_12xgc = JSX_1kxb["Element"];
|
|
|
80
93
|
*
|
|
81
94
|
* @example {@include ./examples.mdx}
|
|
82
95
|
*/
|
|
83
|
-
declare function DesktopShell({ platform, showControls, titleBar, size: sizeProp, title, leading, trailing, left, right, main, leftOpen: leftOpenProp, defaultLeftOpen, onLeftOpenChange, rightOpen: rightOpenProp, defaultRightOpen, onRightOpenChange, defaultPaneSize, minPaneSize, maxPaneSize, leftLabel, rightLabel, className }: DesktopShellProps): Element_12xgc;
|
|
96
|
+
declare function DesktopShell({ platform, showControls, titleBar, size: sizeProp, title, leading, trailing, left, right, main, leftOpen: leftOpenProp, defaultLeftOpen, onLeftOpenChange, peek, rightOpen: rightOpenProp, defaultRightOpen, onRightOpenChange, defaultPaneSize, minPaneSize, maxPaneSize, leftLabel, rightLabel, className }: DesktopShellProps): Element_12xgc;
|
|
84
97
|
export { DesktopPlatform, DesktopShell, DesktopShellProps, DesktopTitleBar, DesktopShell as default };
|