@estiva-app/ui 0.89.0 → 0.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AppShell.d.ts +9 -1
- package/dist/AppShell.d.ts.map +1 -1
- package/dist/index.js +224 -207
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +13 -1
- package/src/AppShell.mdx +6 -0
- package/src/AppShell.stories.tsx +25 -0
- package/src/AppShell.test.tsx +47 -0
- package/src/AppShell.tsx +32 -3
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"kind": "package",
|
|
5
5
|
"repo": "estiva-ui",
|
|
6
6
|
"package": "@estiva-app/ui",
|
|
7
|
-
"packageVersion": "0.
|
|
7
|
+
"packageVersion": "0.90.1",
|
|
8
8
|
"exports": 210,
|
|
9
9
|
"typeExports": 211,
|
|
10
10
|
"files": null
|
|
@@ -251,6 +251,18 @@
|
|
|
251
251
|
"required": true,
|
|
252
252
|
"note": "The navigation: a `Sidebar` in the solid manner, a `Rail` in the floating one."
|
|
253
253
|
},
|
|
254
|
+
{
|
|
255
|
+
"name": "navOpen",
|
|
256
|
+
"takes": "true/false",
|
|
257
|
+
"required": false,
|
|
258
|
+
"note": "Whether the navigation is shown, in the solid and inset manners."
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"name": "onNavOpenChange",
|
|
262
|
+
"takes": "a handler",
|
|
263
|
+
"required": false,
|
|
264
|
+
"note": null
|
|
265
|
+
},
|
|
254
266
|
{
|
|
255
267
|
"name": "children",
|
|
256
268
|
"takes": "anything",
|
package/src/AppShell.mdx
CHANGED
|
@@ -85,6 +85,12 @@ import { AppShell, Banner, IdentityMenu, Rail, RailItem } from '@estiva-app/ui'
|
|
|
85
85
|
Ctrl+K.
|
|
86
86
|
- In the floating manner the card owns `overflow-hidden` — your content
|
|
87
87
|
manages its own scrolling inside it.
|
|
88
|
+
- **Folding the navigation**, in the solid and inset manners: pass `navOpen`
|
|
89
|
+
and `onNavOpenChange`, and the frame draws the fold as the top bar's menu
|
|
90
|
+
button ("Hide the sidebar" / "Show the sidebar") and, folded, keeps only
|
|
91
|
+
the content's own margin. Where the state is kept (remembered, started
|
|
92
|
+
folded in a narrow window) is yours. A `menu` you pass replaces the fold
|
|
93
|
+
button.
|
|
88
94
|
- Desktop only for now — no narrow-screen behaviour is provided.
|
|
89
95
|
- In the Signal theme the floating frame draws the control-room dot grid on
|
|
90
96
|
its ground, behind the card. Nothing to add: the preset makes it.
|
package/src/AppShell.stories.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { useState } from 'react'
|
|
2
3
|
import { IconMenu2, IconSquareRounded } from '@tabler/icons-react'
|
|
4
|
+
import { expect, userEvent, within } from 'storybook/test'
|
|
3
5
|
import { AppShell } from './AppShell'
|
|
4
6
|
import { Banner } from './Banner'
|
|
5
7
|
import { EmptyState } from './EmptyState'
|
|
@@ -105,6 +107,29 @@ export const Inset: Story = {
|
|
|
105
107
|
),
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
/** The navigation folds away from the top bar's menu button, and comes back from the same place. */
|
|
111
|
+
export const InsetFolds: Story = {
|
|
112
|
+
args: { variant: 'inset' },
|
|
113
|
+
render: function Render(args) {
|
|
114
|
+
const [open, setOpen] = useState(true)
|
|
115
|
+
return (
|
|
116
|
+
<AppShell {...args} logo="Estiva" identity={identity} nav={sidebar} navOpen={open} onNavOpenChange={setOpen}>
|
|
117
|
+
<EmptyState message="Nothing here yet." />
|
|
118
|
+
</AppShell>
|
|
119
|
+
)
|
|
120
|
+
},
|
|
121
|
+
// Measured as drawn: in a Tailwind 3 app the `hidden` attribute alone loses to a display class (LED-3, 0.90.0).
|
|
122
|
+
play: async ({ canvasElement }) => {
|
|
123
|
+
const canvas = within(canvasElement)
|
|
124
|
+
const drawn = () => canvasElement.querySelector('nav')?.getBoundingClientRect().width ?? 0
|
|
125
|
+
await expect(drawn()).toBeGreaterThan(0)
|
|
126
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Hide the sidebar' }))
|
|
127
|
+
await expect(drawn()).toBe(0)
|
|
128
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Show the sidebar' }))
|
|
129
|
+
await expect(drawn()).toBeGreaterThan(0)
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
|
|
108
133
|
export const InsetWithBanner: Story = {
|
|
109
134
|
args: { variant: 'inset' },
|
|
110
135
|
render: (args) => (
|
package/src/AppShell.test.tsx
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* Chrome on Ship's four pages.
|
|
8
8
|
*/
|
|
9
9
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
10
|
+
import { useState } from 'react'
|
|
10
11
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
12
|
+
import userEvent from '@testing-library/user-event'
|
|
11
13
|
import { AppShell } from './AppShell'
|
|
12
14
|
import { Sidebar } from './Sidebar'
|
|
13
15
|
|
|
@@ -46,6 +48,51 @@ describe('AppShell', () => {
|
|
|
46
48
|
expect(panel?.className).toContain('mr-4')
|
|
47
49
|
})
|
|
48
50
|
|
|
51
|
+
it('folds the navigation from the top bar’s menu button and brings it back', async () => {
|
|
52
|
+
function Folding() {
|
|
53
|
+
const [open, setOpen] = useState(true)
|
|
54
|
+
return (
|
|
55
|
+
<AppShell variant="inset" nav={<Sidebar>Rows</Sidebar>} navOpen={open} onNavOpenChange={setOpen}>
|
|
56
|
+
<p>Page</p>
|
|
57
|
+
</AppShell>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
const user = userEvent.setup()
|
|
61
|
+
render(<Folding />)
|
|
62
|
+
await user.click(screen.getByRole('button', { name: 'Hide the sidebar' }))
|
|
63
|
+
expect(screen.queryByRole('navigation')).toBeNull()
|
|
64
|
+
expect(screen.getByText('Page')).toBeTruthy()
|
|
65
|
+
await user.click(screen.getByRole('button', { name: 'Show the sidebar' }))
|
|
66
|
+
expect(screen.getByRole('navigation').textContent).toBe('Rows')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('keeps a menu the caller passes in place of the fold, and draws no fold on the floating rail', () => {
|
|
70
|
+
const { unmount } = render(
|
|
71
|
+
<AppShell variant="inset" menu={<button>Own menu</button>} nav={<Sidebar>Rows</Sidebar>} navOpen onNavOpenChange={() => {}}>
|
|
72
|
+
<p>Page</p>
|
|
73
|
+
</AppShell>,
|
|
74
|
+
)
|
|
75
|
+
expect(screen.getByRole('button', { name: 'Own menu' })).toBeTruthy()
|
|
76
|
+
expect(screen.queryByRole('button', { name: /sidebar/ })).toBeNull()
|
|
77
|
+
unmount()
|
|
78
|
+
render(
|
|
79
|
+
<AppShell variant="floating" nav={<nav>Rail</nav>} navOpen onNavOpenChange={() => {}}>
|
|
80
|
+
<p>Page</p>
|
|
81
|
+
</AppShell>,
|
|
82
|
+
)
|
|
83
|
+
expect(screen.queryByRole('button', { name: /sidebar/ })).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('draws no fold when the caller does not keep one', () => {
|
|
87
|
+
render(
|
|
88
|
+
<AppShell variant="inset" nav={<Sidebar>Rows</Sidebar>}>
|
|
89
|
+
<p>Page</p>
|
|
90
|
+
</AppShell>,
|
|
91
|
+
)
|
|
92
|
+
expect(screen.queryByRole('button', { name: /sidebar/ })).toBeNull()
|
|
93
|
+
expect(screen.getByRole('navigation')).toBeTruthy()
|
|
94
|
+
})
|
|
95
|
+
|
|
49
96
|
it('leaves the floating manner’s card as it was', () => {
|
|
50
97
|
render(
|
|
51
98
|
<AppShell variant="floating" nav={<nav>Nav</nav>}>
|
package/src/AppShell.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
|
+
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from '@tabler/icons-react'
|
|
2
3
|
import { cn } from './cn'
|
|
3
4
|
import { Card } from './Card'
|
|
5
|
+
import { IconButton } from './IconButton'
|
|
4
6
|
import { ScrollArea } from './ScrollArea'
|
|
5
7
|
import { SidebarOnGround } from './Sidebar'
|
|
6
8
|
import { TopBar } from './TopBar'
|
|
@@ -46,11 +48,31 @@ export interface AppShellProps {
|
|
|
46
48
|
banner?: ReactNode
|
|
47
49
|
/** The navigation: a `Sidebar` in the solid manner, a `Rail` in the floating one. */
|
|
48
50
|
nav: ReactNode
|
|
51
|
+
/**
|
|
52
|
+
* Whether the navigation is shown, in the solid and inset manners. With `onNavOpenChange`, the frame draws the
|
|
53
|
+
* fold as the top bar's menu button (unless `menu` is given) and, folded, leaves only the content's own margin
|
|
54
|
+
* (LED-3, Katerina, 28 October: the sidebar fold top left, on the top bar's menu button). Where it is kept is
|
|
55
|
+
* the caller's.
|
|
56
|
+
*/
|
|
57
|
+
navOpen?: boolean
|
|
58
|
+
onNavOpenChange?: (open: boolean) => void
|
|
49
59
|
children: ReactNode
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
export function AppShell({ variant = 'solid', menu, logo, search, onSearch, searchPlaceholder, identity, banner, nav, children }: AppShellProps) {
|
|
53
|
-
|
|
62
|
+
export function AppShell({ variant = 'solid', menu, logo, search, onSearch, searchPlaceholder, identity, banner, nav, navOpen = true, onNavOpenChange, children }: AppShellProps) {
|
|
63
|
+
// The floating manner's rail does not fold here: its collapse stays the app's.
|
|
64
|
+
const fold = onNavOpenChange && variant !== 'floating' && (
|
|
65
|
+
<IconButton
|
|
66
|
+
tooltip={navOpen ? 'Hide the sidebar' : 'Show the sidebar'}
|
|
67
|
+
tooltipPlacement="bottom"
|
|
68
|
+
aria-label={navOpen ? 'Hide the sidebar' : 'Show the sidebar'}
|
|
69
|
+
aria-expanded={navOpen}
|
|
70
|
+
onClick={() => onNavOpenChange(!navOpen)}
|
|
71
|
+
>
|
|
72
|
+
{navOpen ? <IconLayoutSidebarLeftCollapse size={16} stroke={1.5} /> : <IconLayoutSidebarLeftExpand size={16} stroke={1.5} />}
|
|
73
|
+
</IconButton>
|
|
74
|
+
)
|
|
75
|
+
const bar = <TopBar variant={variant} menu={menu ?? fold} logo={logo} search={search} onSearch={onSearch} searchPlaceholder={searchPlaceholder} right={identity} />
|
|
54
76
|
const inset = variant === 'inset'
|
|
55
77
|
|
|
56
78
|
if (variant === 'floating') {
|
|
@@ -113,7 +135,14 @@ export function AppShell({ variant = 'solid', menu, logo, search, onSearch, sear
|
|
|
113
135
|
<div className="relative flex h-full min-h-0 flex-col overflow-hidden bg-bg-base text-text-primary">
|
|
114
136
|
{bar}
|
|
115
137
|
<div className="flex min-h-0 flex-1">
|
|
116
|
-
|
|
138
|
+
{/* Folded, the navigation stays mounted and hidden, so it comes back as it was left (its scroll, its open
|
|
139
|
+
rows); open, `contents` keeps it a direct flex child of the row. Hidden by the class as well as the
|
|
140
|
+
attribute: in a Tailwind 3 app `[hidden]` loses to `.contents`, and the sidebar stayed drawn (0.90.0). */}
|
|
141
|
+
<div className={navOpen ? 'contents' : 'hidden'} hidden={!navOpen}>
|
|
142
|
+
<SidebarOnGround.Provider value={inset}>{nav}</SidebarOnGround.Provider>
|
|
143
|
+
</div>
|
|
144
|
+
{/* Folded: the inset card keeps a left margin as wide as its right one. */}
|
|
145
|
+
{!navOpen && inset && <div className="w-4 flex-none" />}
|
|
117
146
|
{/* `inset`: the content is a card on the ground, the Card's own surface look,
|
|
118
147
|
16px from the right and bottom as the floating card is, 8px corners (Katerina,
|
|
119
148
|
28 September). */}
|