@estiva-app/ui 0.89.0 → 0.90.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.89.0",
3
+ "version": "0.90.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
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.89.0",
7
+ "packageVersion": "0.90.0",
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.
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
2
3
  import { IconMenu2, IconSquareRounded } from '@tabler/icons-react'
3
4
  import { AppShell } from './AppShell'
4
5
  import { Banner } from './Banner'
@@ -105,6 +106,19 @@ export const Inset: Story = {
105
106
  ),
106
107
  }
107
108
 
109
+ /** The navigation folds away from the top bar's menu button, and comes back from the same place. */
110
+ export const InsetFolds: Story = {
111
+ args: { variant: 'inset' },
112
+ render: function Render(args) {
113
+ const [open, setOpen] = useState(true)
114
+ return (
115
+ <AppShell {...args} logo="Estiva" identity={identity} nav={sidebar} navOpen={open} onNavOpenChange={setOpen}>
116
+ <EmptyState message="Nothing here yet." />
117
+ </AppShell>
118
+ )
119
+ },
120
+ }
121
+
108
122
  export const InsetWithBanner: Story = {
109
123
  args: { variant: 'inset' },
110
124
  render: (args) => (
@@ -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
- const bar = <TopBar variant={variant} menu={menu} logo={logo} search={search} onSearch={onSearch} searchPlaceholder={searchPlaceholder} right={identity} />
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,13 @@ 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
- <SidebarOnGround.Provider value={inset}>{nav}</SidebarOnGround.Provider>
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. */}
140
+ <div className="contents" hidden={!navOpen}>
141
+ <SidebarOnGround.Provider value={inset}>{nav}</SidebarOnGround.Provider>
142
+ </div>
143
+ {/* Folded: the inset card keeps a left margin as wide as its right one. */}
144
+ {!navOpen && inset && <div className="w-4 flex-none" />}
117
145
  {/* `inset`: the content is a card on the ground, the Card's own surface look,
118
146
  16px from the right and bottom as the floating card is, 8px corners (Katerina,
119
147
  28 September). */}