@estiva-app/ui 0.116.0 → 0.118.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/ActivityLine.d.ts +37 -0
- package/dist/ActivityLine.d.ts.map +1 -0
- package/dist/CollapsibleSection.d.ts +6 -1
- package/dist/CollapsibleSection.d.ts.map +1 -1
- package/dist/ContainerHeader.d.ts +10 -1
- package/dist/ContainerHeader.d.ts.map +1 -1
- package/dist/DialogShell.d.ts +11 -3
- package/dist/DialogShell.d.ts.map +1 -1
- package/dist/ListTable.d.ts +71 -0
- package/dist/ListTable.d.ts.map +1 -0
- package/dist/MembersDialog.d.ts +1 -0
- package/dist/MembersDialog.d.ts.map +1 -1
- package/dist/Menu.d.ts +9 -2
- package/dist/Menu.d.ts.map +1 -1
- package/dist/NavItem.d.ts.map +1 -1
- package/dist/NavTree.d.ts +12 -1
- package/dist/NavTree.d.ts.map +1 -1
- package/dist/PageHeader.d.ts +11 -2
- package/dist/PageHeader.d.ts.map +1 -1
- package/dist/SectionHeader.d.ts.map +1 -1
- package/dist/WhoFollowsDialog.d.ts +12 -2
- package/dist/WhoFollowsDialog.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +816 -671
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +272 -5
- package/src/ActivityLine.mdx +67 -0
- package/src/ActivityLine.stories.tsx +49 -0
- package/src/ActivityLine.test.tsx +47 -0
- package/src/ActivityLine.tsx +74 -0
- package/src/Button.mdx +5 -0
- package/src/CollapsibleSection.mdx +6 -0
- package/src/CollapsibleSection.stories.tsx +4 -1
- package/src/CollapsibleSection.test.tsx +11 -0
- package/src/CollapsibleSection.tsx +7 -2
- package/src/ContainerHeader.mdx +7 -0
- package/src/ContainerHeader.stories.tsx +3 -0
- package/src/ContainerHeader.test.tsx +12 -1
- package/src/ContainerHeader.tsx +38 -18
- package/src/DialogShell.mdx +8 -2
- package/src/DialogShell.stories.tsx +20 -7
- package/src/DialogShell.tsx +10 -4
- package/src/FollowSwitch.test.tsx +6 -4
- package/src/ListTable.mdx +112 -0
- package/src/ListTable.stories.tsx +133 -0
- package/src/ListTable.test.tsx +81 -0
- package/src/ListTable.tsx +178 -0
- package/src/MembersDialog.test.tsx +8 -0
- package/src/MembersDialog.tsx +3 -11
- package/src/Menu.mdx +3 -0
- package/src/Menu.stories.tsx +23 -0
- package/src/Menu.tsx +13 -3
- package/src/NavItem.mdx +2 -0
- package/src/NavItem.tsx +5 -1
- package/src/NavTree.mdx +6 -0
- package/src/NavTree.stories.tsx +14 -0
- package/src/NavTree.test.tsx +18 -0
- package/src/NavTree.tsx +16 -1
- package/src/PageHeader.mdx +13 -2
- package/src/PageHeader.stories.tsx +35 -1
- package/src/PageHeader.test.tsx +21 -0
- package/src/PageHeader.tsx +17 -5
- package/src/SectionHeader.mdx +2 -0
- package/src/SectionHeader.test.tsx +16 -0
- package/src/SectionHeader.tsx +4 -2
- package/src/WhoFollowsDialog.mdx +2 -0
- package/src/WhoFollowsDialog.stories.tsx +19 -0
- package/src/WhoFollowsDialog.test.tsx +40 -0
- package/src/WhoFollowsDialog.tsx +66 -10
- package/src/index.ts +2 -0
- package/src/registry/registry.test.ts +5 -5
- package/stories/Choosing.mdx +2 -0
|
@@ -56,6 +56,11 @@ export interface CollapsibleSectionProps {
|
|
|
56
56
|
icon?: ReactNode
|
|
57
57
|
/** Beside the title and always visible, before the actions — a count. `SectionHeader`'s. */
|
|
58
58
|
trailing?: ReactNode
|
|
59
|
+
/**
|
|
60
|
+
* How many rows it holds, 8px after the title, shown open or shut — `SectionHeader`'s. Written into the title by
|
|
61
|
+
* hand ("Other teams · 2"), the number took the heading's own type (Katerina, 16 November).
|
|
62
|
+
*/
|
|
63
|
+
count?: number
|
|
59
64
|
/** Beside the title, revealed while the row is hovered or keyboard-focused — `SectionHeader`'s. */
|
|
60
65
|
actions?: SectionAction[]
|
|
61
66
|
/** Beside the actions, revealed with them: the section's "More options" menu, `MenuItem`s — `SectionHeader`'s. */
|
|
@@ -158,7 +163,7 @@ export function useRememberedOpen(storageKey: string | undefined, fallback: bool
|
|
|
158
163
|
return [choice ?? fallback, setOpen]
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
export function CollapsibleSection({ title, defaultOpen = true, open: openProp, onOpenChange, pending = false, storageKey, openFor, icon, trailing, actions, menu, menuLabel, showActions, look = 'heading', indent = false, children, className, contentClassName }: CollapsibleSectionProps) {
|
|
166
|
+
export function CollapsibleSection({ title, defaultOpen = true, open: openProp, onOpenChange, pending = false, storageKey, openFor, icon, trailing, count, actions, menu, menuLabel, showActions, look = 'heading', indent = false, children, className, contentClassName }: CollapsibleSectionProps) {
|
|
162
167
|
// The section's default is the one it was drawn with: a later `defaultOpen` does not move it.
|
|
163
168
|
const [initial] = useState(defaultOpen)
|
|
164
169
|
const [openState, remember] = useRememberedOpen(storageKey, initial)
|
|
@@ -173,7 +178,7 @@ export function CollapsibleSection({ title, defaultOpen = true, open: openProp,
|
|
|
173
178
|
const shown = open && !pending
|
|
174
179
|
return (
|
|
175
180
|
<Collapsible.Root open={shown} onOpenChange={(next, details) => setOpen(pending && details.reason === 'trigger-press' ? !open : next)} className={cn('flex flex-col', className)}>
|
|
176
|
-
<SectionHeader title={title} chevron icon={icon} isExpanded={open} trailing={trailing} actions={actions} menu={menu} menuLabel={menuLabel} showActions={showActions} look={look} className="shrink-0" render={<Collapsible.Trigger aria-expanded={open} aria-busy={pending && open ? true : undefined} />} />
|
|
181
|
+
<SectionHeader title={title} chevron icon={icon} isExpanded={open} trailing={trailing} {...(count != null ? { count } : {})} actions={actions} menu={menu} menuLabel={menuLabel} showActions={showActions} look={look} className="shrink-0" render={<Collapsible.Trigger aria-expanded={open} aria-busy={pending && open ? true : undefined} />} />
|
|
177
182
|
{/* The slide: Base UI measures the panel and writes its height to a
|
|
178
183
|
variable — `auto` again once the slide ends, so rows that arrive
|
|
179
184
|
later are not clipped — and the panel is 0 high on its opening frame
|
package/src/ContainerHeader.mdx
CHANGED
|
@@ -22,6 +22,13 @@ with a hairline under it.
|
|
|
22
22
|
|
|
23
23
|
<Canvas of={ContainerHeaderStories.WithTitleMenu} />
|
|
24
24
|
|
|
25
|
+
- `back`: a way back to the layer before — an arrow before the title, 8px
|
|
26
|
+
from it. The bar gives it its room (12px in), so its fill and its ring
|
|
27
|
+
stay whole: never pull a button of your own out of the bar with a
|
|
28
|
+
negative margin, where the bar cuts it off.
|
|
29
|
+
|
|
30
|
+
<Canvas of={ContainerHeaderStories.WithBack} />
|
|
31
|
+
|
|
25
32
|
## When not
|
|
26
33
|
|
|
27
34
|
- One section inside a column → **SectionHeader**, the 32px row with a
|
|
@@ -35,6 +35,9 @@ export const WithTitleMenu: Story = {
|
|
|
35
35
|
/** A string title, one line, alone. */
|
|
36
36
|
export const Default: Story = {}
|
|
37
37
|
|
|
38
|
+
/** A way back to the layer before: an arrow before the title, 8px from it, the bar giving it its room. */
|
|
39
|
+
export const WithBack: Story = { args: { title: 'Add items', back: { label: 'Back to items', onClick: () => {} } } }
|
|
40
|
+
|
|
38
41
|
/** A chevron after the title, for a title that opens something. */
|
|
39
42
|
export const WithChevron: Story = { args: { title: 'All items', chevron: true } }
|
|
40
43
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* buttons sit at the right edge. The pixels are proved against Peek's own
|
|
6
6
|
* (docs/GATES.md, UIG-13: A).
|
|
7
7
|
*/
|
|
8
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
9
9
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
10
10
|
import userEvent from '@testing-library/user-event'
|
|
11
11
|
import { MenuItem } from './Menu'
|
|
@@ -14,6 +14,17 @@ import { ContainerHeader } from './ContainerHeader'
|
|
|
14
14
|
afterEach(cleanup)
|
|
15
15
|
|
|
16
16
|
describe('ContainerHeader', () => {
|
|
17
|
+
it('draws its way back before the title, outside the title’s clipping box, with no negative margin', async () => {
|
|
18
|
+
const onClick = vi.fn()
|
|
19
|
+
render(<ContainerHeader title="Add items" back={{ label: 'Back to items', onClick }} />)
|
|
20
|
+
const button = screen.getByRole('button', { name: 'Back to items' })
|
|
21
|
+
// Its fill and ring were cut off when it sat inside the box that clips the title, pulled out by -ml-2 (16 November).
|
|
22
|
+
expect(button.closest('.overflow-hidden')?.className).toContain('h-12')
|
|
23
|
+
expect(button.className).not.toMatch(/-m[lx]-/)
|
|
24
|
+
await userEvent.click(button)
|
|
25
|
+
expect(onClick).toHaveBeenCalledOnce()
|
|
26
|
+
})
|
|
27
|
+
|
|
17
28
|
it('is the 48px bar with a hairline under it', () => {
|
|
18
29
|
const { container } = render(<ContainerHeader title="Items" />)
|
|
19
30
|
const bar = container.firstElementChild!.className.split(' ')
|
package/src/ContainerHeader.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
|
-
import { IconChevronDown } from '@tabler/icons-react'
|
|
2
|
+
import { IconArrowLeft, IconChevronDown } from '@tabler/icons-react'
|
|
3
3
|
import { Button as BaseButton } from '@base-ui/react/button'
|
|
4
4
|
import { cn } from './cn'
|
|
5
|
+
import { IconButton } from './IconButton'
|
|
5
6
|
import { MENU_TRIGGER_CLASSES } from './looks'
|
|
6
7
|
import { Menu } from './Menu'
|
|
7
8
|
|
|
@@ -31,10 +32,16 @@ export interface ContainerHeaderProps {
|
|
|
31
32
|
titleMenu?: ReactNode
|
|
32
33
|
/** The column's own buttons, at the right edge: IconButtons with tooltips, 4px apart. */
|
|
33
34
|
actions?: ReactNode
|
|
35
|
+
/**
|
|
36
|
+
* A way back to the layer before, an arrow before the title, 8px from it — a dialog's Add members back to its list.
|
|
37
|
+
* The bar gives the button its room (12px in, so the arrow sits 16px in, where a title would) rather than the button
|
|
38
|
+
* reaching out of it with a negative margin, which cut its fill and its ring off (Katerina, 16 November).
|
|
39
|
+
*/
|
|
40
|
+
back?: { label: string; onClick: () => void }
|
|
34
41
|
className?: string
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export function ContainerHeader({ title, chevron = false, titleMenu, actions, className }: ContainerHeaderProps) {
|
|
44
|
+
export function ContainerHeader({ title, chevron = false, titleMenu, actions, back, className }: ContainerHeaderProps) {
|
|
38
45
|
const text = typeof title === 'string'
|
|
39
46
|
const name = (
|
|
40
47
|
<div className={cn('flex items-center gap-1', text ? 'shrink-0' : 'min-w-0 flex-1')}>
|
|
@@ -42,6 +49,23 @@ export function ContainerHeader({ title, chevron = false, titleMenu, actions, cl
|
|
|
42
49
|
{(chevron || titleMenu != null) && <IconChevronDown size={12} stroke={1.5} className="shrink-0 text-text-secondary" />}
|
|
43
50
|
</div>
|
|
44
51
|
)
|
|
52
|
+
const titleBox = (
|
|
53
|
+
<div className={cn('flex items-center gap-2 overflow-hidden', text && !back ? 'shrink-0' : 'min-w-0 flex-1')}>
|
|
54
|
+
{titleMenu != null ? (
|
|
55
|
+
<Menu
|
|
56
|
+
trigger={
|
|
57
|
+
<BaseButton type="button" className={cn('flex min-w-0 items-center px-1.5 py-1', MENU_TRIGGER_CLASSES)}>
|
|
58
|
+
{name}
|
|
59
|
+
</BaseButton>
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
{titleMenu}
|
|
63
|
+
</Menu>
|
|
64
|
+
) : (
|
|
65
|
+
name
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
45
69
|
return (
|
|
46
70
|
// The title 16px in, where the column's content starts (Katerina, 7 October; it was 20px).
|
|
47
71
|
// With a title menu the bar gives the button 6px of its left padding
|
|
@@ -50,22 +74,18 @@ export function ContainerHeader({ title, chevron = false, titleMenu, actions, cl
|
|
|
50
74
|
// (Katerina, 5 October).
|
|
51
75
|
// 12px between the title and the buttons, as between the right group's own parts: a cut title, and a button
|
|
52
76
|
// after it, ran right up to them (Leaf's adoption review, 4 November). A bar whose title fits does not move.
|
|
53
|
-
<div className={cn('flex h-12 shrink-0 items-center justify-between gap-3 overflow-hidden border-b border-border-subtle py-2 pr-4', titleMenu != null ? 'pl-2.5' : 'pl-4', className)}>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
) : (
|
|
66
|
-
name
|
|
67
|
-
)}
|
|
68
|
-
</div>
|
|
77
|
+
<div className={cn('flex h-12 shrink-0 items-center justify-between gap-3 overflow-hidden border-b border-border-subtle py-2 pr-4', back ? 'pl-3' : titleMenu != null ? 'pl-2.5' : 'pl-4', className)}>
|
|
78
|
+
{back ? (
|
|
79
|
+
// The arrow outside the title's box, which clips: its fill and its ring stay whole; 8px to the title.
|
|
80
|
+
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
81
|
+
<IconButton tooltip={back.label} aria-label={back.label} onClick={back.onClick}>
|
|
82
|
+
<IconArrowLeft size={16} stroke={1.5} />
|
|
83
|
+
</IconButton>
|
|
84
|
+
{titleBox}
|
|
85
|
+
</div>
|
|
86
|
+
) : (
|
|
87
|
+
titleBox
|
|
88
|
+
)}
|
|
69
89
|
{actions && (
|
|
70
90
|
<div className="flex shrink-0 items-center justify-end gap-3">
|
|
71
91
|
<div className="flex shrink-0 items-center gap-1">{actions}</div>
|
package/src/DialogShell.mdx
CHANGED
|
@@ -16,8 +16,14 @@ footer for the buttons. A dialog is just what goes in the three slots.
|
|
|
16
16
|
- Anything with a title, a body, and buttons: a form, a picker, a roster.
|
|
17
17
|
- `footer` absent removes the footer row entirely — a list that simply
|
|
18
18
|
ends keeps the card's own bottom edge.
|
|
19
|
-
- `headerContent` replaces the title text — a
|
|
20
|
-
title
|
|
19
|
+
- `headerContent` replaces the title text — a count chip after the
|
|
20
|
+
title. The close button stays.
|
|
21
|
+
- `back`: a second layer's way back to its first (Add members back to the
|
|
22
|
+
list) — an arrow before the title, the bar's own. Never a button of your
|
|
23
|
+
own in `headerContent`: pulled out of the bar's box, its fill and ring
|
|
24
|
+
were cut off.
|
|
25
|
+
|
|
26
|
+
<Canvas of={DialogShellStories.WithBack} />
|
|
21
27
|
|
|
22
28
|
## When not
|
|
23
29
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState } from 'react'
|
|
3
|
-
import { IconArrowLeft } from '@tabler/icons-react'
|
|
4
3
|
import { Button } from './Button'
|
|
5
4
|
import { Chip } from './Chip'
|
|
6
5
|
import { DialogShell } from './DialogShell'
|
|
7
|
-
import { IconButton } from './IconButton'
|
|
8
6
|
import { Field } from './Field'
|
|
9
7
|
import { Form } from './Form'
|
|
10
8
|
import { TextInput } from './TextInput'
|
|
@@ -72,8 +70,8 @@ export const ALongTitle: Story = {
|
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
|
-
* **`headerContent` replaces the title text** — a
|
|
76
|
-
*
|
|
73
|
+
* **`headerContent` replaces the title text** — a count after it — and the
|
|
74
|
+
* ✕ stays. The dialog is then named by its `title`
|
|
77
75
|
* anyway, since there is no longer a heading to point at.
|
|
78
76
|
*
|
|
79
77
|
* There used to be a `Confirmation` story here. It hand-built what
|
|
@@ -88,9 +86,6 @@ export const WithHeaderContent: Story = {
|
|
|
88
86
|
args: {
|
|
89
87
|
headerContent: (
|
|
90
88
|
<div className="flex items-center gap-2">
|
|
91
|
-
<IconButton aria-label="Back" tooltip="Back">
|
|
92
|
-
<IconArrowLeft size={16} stroke={1.5} />
|
|
93
|
-
</IconButton>
|
|
94
89
|
<span className="text-h4 text-text-primary">Item one</span>
|
|
95
90
|
<Chip label="3" />
|
|
96
91
|
</div>
|
|
@@ -105,6 +100,24 @@ export const WithHeaderContent: Story = {
|
|
|
105
100
|
},
|
|
106
101
|
}
|
|
107
102
|
|
|
103
|
+
/**
|
|
104
|
+
* **A way back**, a second layer to its first: the bar's own arrow before the title, 16px in, its fill and ring whole.
|
|
105
|
+
* Point at it.
|
|
106
|
+
*/
|
|
107
|
+
export const WithBack: Story = {
|
|
108
|
+
args: {
|
|
109
|
+
title: 'Add items',
|
|
110
|
+
back: { label: 'Back to items', onClick: () => {} },
|
|
111
|
+
footer: (
|
|
112
|
+
<>
|
|
113
|
+
<Button variant="muted">Cancel</Button>
|
|
114
|
+
<Button variant="primary">Add</Button>
|
|
115
|
+
</>
|
|
116
|
+
),
|
|
117
|
+
children: <p className="text-body-2 text-text-primary">The layer under the first one.</p>,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
|
|
108
121
|
/**
|
|
109
122
|
* **No footer.** The body keeps the card's own bottom edge — a roster, a list,
|
|
110
123
|
* anything that simply ends rather than asking a question. There is no divider
|
package/src/DialogShell.tsx
CHANGED
|
@@ -36,9 +36,14 @@ export interface DialogShellProps {
|
|
|
36
36
|
* unless `headerContent` replaces it. */
|
|
37
37
|
title: string
|
|
38
38
|
onClose: () => void
|
|
39
|
-
/** Replaces the title text in the header — a
|
|
40
|
-
*
|
|
39
|
+
/** Replaces the title text in the header — a count chip after it. The
|
|
40
|
+
* close button stays. A way back is `back`, never drawn in here. */
|
|
41
41
|
headerContent?: ReactNode
|
|
42
|
+
/**
|
|
43
|
+
* A way back to the layer before — an Add layer back to its list: an arrow before the title, the bar's own, whole
|
|
44
|
+
* (it was the dialog's own button pulled 8px out of the bar's box, its fill and ring cut off; Katerina, 16 November).
|
|
45
|
+
*/
|
|
46
|
+
back?: { label: string; onClick: () => void }
|
|
42
47
|
/** Absent: no footer row, and the body keeps the card's own bottom edge
|
|
43
48
|
* (a roster that simply ends). */
|
|
44
49
|
footer?: ReactNode
|
|
@@ -67,7 +72,7 @@ export interface DialogShellProps {
|
|
|
67
72
|
alert?: boolean
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
export function DialogShell({ title, onClose, headerContent, footer, children, bodyClassName, bodyMaxHeight, width = 502, alert = false }: DialogShellProps) {
|
|
75
|
+
export function DialogShell({ title, onClose, back, headerContent, footer, children, bodyClassName, bodyMaxHeight, width = 502, alert = false }: DialogShellProps) {
|
|
71
76
|
// The two families are the same parts with different dismiss rules, so the
|
|
72
77
|
// chrome below is written once. AlertDialog re-exports Dialog's Backdrop,
|
|
73
78
|
// Popup, Portal and Title types, which is why this substitutes cleanly.
|
|
@@ -119,8 +124,9 @@ export function DialogShell({ title, onClose, headerContent, footer, children, b
|
|
|
119
124
|
The title keeps to its one line and ends in "…": a long name wrapped to
|
|
120
125
|
two lines in the 48px bar and lost its top (Katerina, 1 October). */}
|
|
121
126
|
{/* `pl-5`: a dialog's title stays 20px in, over its body and footer, which are. */}
|
|
127
|
+
{/* With a way back, the bar's own: the arrow 16px in, the title 8px after it (ContainerHeader's `back`). */}
|
|
122
128
|
<ContainerHeader
|
|
123
|
-
className
|
|
129
|
+
{...(back ? { back } : { className: 'pl-5' })}
|
|
124
130
|
title={
|
|
125
131
|
headerContent ?? (
|
|
126
132
|
<Parts.Title className="block truncate text-h4 text-text-primary" render={<span />}>
|
|
@@ -112,13 +112,15 @@ describe('WhoFollowsDialog', () => {
|
|
|
112
112
|
it('lists All then Important with their counts, and Nobody for an empty group', async () => {
|
|
113
113
|
const { rerender } = render(<WhoFollowsDialog title="Item one" all={all} important={important} onClose={() => {}} />)
|
|
114
114
|
const dialog = await screen.findByRole('dialog', { name: 'Who follows Item one' })
|
|
115
|
+
// Each group is a SectionHeader: its title, then its count beside it (no "·" between them in the text).
|
|
115
116
|
const text = dialog.textContent!
|
|
116
|
-
expect(text.indexOf('
|
|
117
|
-
expect(text.indexOf('
|
|
118
|
-
expect(text.indexOf('
|
|
117
|
+
expect(text.indexOf('All1')).toBeGreaterThan(-1)
|
|
118
|
+
expect(text.indexOf('All1')).toBeLessThan(text.indexOf('Ana Duarte'))
|
|
119
|
+
expect(text.indexOf('Ana Duarte')).toBeLessThan(text.indexOf('Important1'))
|
|
120
|
+
expect(text.indexOf('Important1')).toBeLessThan(text.indexOf('Ravi Mehta'))
|
|
119
121
|
expect(text).toContain('Added by Ana Duarte')
|
|
120
122
|
rerender(<WhoFollowsDialog title="Item one" all={[]} important={important} onClose={() => {}} />)
|
|
121
|
-
expect((await screen.findByRole('dialog')).textContent).toContain('
|
|
123
|
+
expect((await screen.findByRole('dialog')).textContent).toContain('All0Nobody')
|
|
122
124
|
})
|
|
123
125
|
|
|
124
126
|
it('offers Add someone only with onAdd, and leaves everyone listed out of the picker', async () => {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as ListTableStories from './ListTable.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={ListTableStories} />
|
|
5
|
+
|
|
6
|
+
# ListTable
|
|
7
|
+
|
|
8
|
+
A list of things on a page, under column headings: each row leads to its thing, a few short facts in columns, and an action at its end.
|
|
9
|
+
|
|
10
|
+
<Canvas of={ListTableStories.Default} />
|
|
11
|
+
|
|
12
|
+
## When
|
|
13
|
+
|
|
14
|
+
- **A page that lists things to find and open**: every topic, every team's
|
|
15
|
+
places, every project — each row its name and what it is about, then its
|
|
16
|
+
facts (its team, who is in it, when it was last active), then what you can
|
|
17
|
+
do from the list (Join).
|
|
18
|
+
- `columns`: the facts after the name, each with its heading and its width —
|
|
19
|
+
`small` 80px (a number, a few faces), `medium` 96px (a date), `large`
|
|
20
|
+
112px (a name).
|
|
21
|
+
- `keep`: which columns give way when the list runs short of room — `low`
|
|
22
|
+
ones first, then `high` ones. The name and the end never do. The list
|
|
23
|
+
measures **its own** width, not the window's: beside a sidebar it gives way
|
|
24
|
+
as it would in a small window.
|
|
25
|
+
|
|
26
|
+
<Canvas of={ListTableStories.Narrow} />
|
|
27
|
+
|
|
28
|
+
<Canvas of={ListTableStories.Narrowest} />
|
|
29
|
+
|
|
30
|
+
- No `columns` (`[]`): a list with no facts to show — the rows alone, with
|
|
31
|
+
no headings; the heading over the part names the list.
|
|
32
|
+
|
|
33
|
+
<Canvas of={ListTableStories.NoColumns} />
|
|
34
|
+
|
|
35
|
+
- `headings={false}`: its facts with no headings on screen, where the
|
|
36
|
+
heading over the part names the list and the facts read without a label
|
|
37
|
+
(faces and a number, "Yesterday"). Screen readers still read each cell's
|
|
38
|
+
heading.
|
|
39
|
+
|
|
40
|
+
<Canvas of={ListTableStories.NoHeadings} />
|
|
41
|
+
|
|
42
|
+
- `end`: the rows hold their own control at the end, and the list keeps 64px
|
|
43
|
+
for it in every row, so the columns stay lined up.
|
|
44
|
+
- A cell is words, or a part: an **AvatarGroup** with its number in
|
|
45
|
+
**MetaText**, 6px apart. A cell not read yet shows a dash.
|
|
46
|
+
|
|
47
|
+
<Canvas of={ListTableStories.NotReadYet} />
|
|
48
|
+
|
|
49
|
+
- It takes the whole width it is given. The name is at most 384px and its
|
|
50
|
+
facts sit beside it; the room left goes before the end, which keeps the
|
|
51
|
+
list's right edge. A name stretched across the page sat far from its
|
|
52
|
+
facts.
|
|
53
|
+
|
|
54
|
+
<Canvas of={ListTableStories.OnAWidePage} />
|
|
55
|
+
|
|
56
|
+
## When not
|
|
57
|
+
|
|
58
|
+
- The rows of a sidebar → **NavItem**, in a **Sidebar** or a **NavTree**.
|
|
59
|
+
- The list beside the thing that is open → **ListColumn**.
|
|
60
|
+
- A link alone on its line, in a file's text → **LinkRow**.
|
|
61
|
+
- A table someone writes, in a document → the editor's table.
|
|
62
|
+
|
|
63
|
+
## How
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { Button, ListTable, ListTableRow } from '@estiva-app/ui'
|
|
67
|
+
|
|
68
|
+
<ListTable
|
|
69
|
+
aria-label="Topics"
|
|
70
|
+
columns={[
|
|
71
|
+
{ label: 'Team', width: 'large' },
|
|
72
|
+
{ label: 'Members', width: 'small', keep: 'low' },
|
|
73
|
+
{ label: 'Active', width: 'medium', keep: 'low' },
|
|
74
|
+
]}
|
|
75
|
+
end
|
|
76
|
+
>
|
|
77
|
+
{topics.map((topic) => (
|
|
78
|
+
<ListTableRow
|
|
79
|
+
key={topic.id}
|
|
80
|
+
href={topic.href}
|
|
81
|
+
label={topic.title}
|
|
82
|
+
description={topic.summary}
|
|
83
|
+
icon={<KindIcon kind="topic" />}
|
|
84
|
+
cells={[topic.team, topic.members, topic.active]}
|
|
85
|
+
end={topic.yours ? undefined : <Button size="small" variant="outlined" onClick={() => join(topic)}>Join</Button>}
|
|
86
|
+
/>
|
|
87
|
+
))}
|
|
88
|
+
</ListTable>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **The row is the link**: a click anywhere on it opens its thing, and the
|
|
92
|
+
keyboard ring goes round the whole row. What is in `end` stays its own
|
|
93
|
+
control, above the link.
|
|
94
|
+
- It draws the headings, the row's look (8px corners, the fill under the
|
|
95
|
+
pointer, no edge), the widths, the dashes and the giving way. Write none of
|
|
96
|
+
them; give it words and parts.
|
|
97
|
+
- Its headings line up with their cells because both come from `columns`:
|
|
98
|
+
never draw a heading row of your own over it.
|
|
99
|
+
|
|
100
|
+
## What it owns
|
|
101
|
+
|
|
102
|
+
| It does | So you never write |
|
|
103
|
+
|---|---|
|
|
104
|
+
| Draws the column headings over the cells | a row of headings by hand |
|
|
105
|
+
| Hides columns by its own width, `low` first | `hidden sm:block` on a column |
|
|
106
|
+
| Draws a row's fill, its 8px corners and no edge | `rounded-md hover:bg-bg-hover` on a row |
|
|
107
|
+
| Makes the whole row the link, its end above it | a covering link and `relative` by hand |
|
|
108
|
+
| Keeps the name at most 384px, the facts beside it, the end at the right | a width of your own on the name |
|
|
109
|
+
|
|
110
|
+
## Props
|
|
111
|
+
|
|
112
|
+
<Controls of={ListTableStories.Default} />
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { IconSquareRounded } from '@tabler/icons-react'
|
|
3
|
+
import { AvatarGroup } from './AvatarGroup'
|
|
4
|
+
import { Button } from './Button'
|
|
5
|
+
import { ListTable, ListTableRow, type ListTableColumn } from './ListTable'
|
|
6
|
+
import { MetaText } from './MetaText'
|
|
7
|
+
|
|
8
|
+
const icon = <IconSquareRounded size={16} stroke={1.5} />
|
|
9
|
+
const columns: ListTableColumn[] = [
|
|
10
|
+
{ label: 'Group', width: 'large' },
|
|
11
|
+
{ label: 'Members', width: 'small', keep: 'low' },
|
|
12
|
+
{ label: 'Active', width: 'medium', keep: 'low' },
|
|
13
|
+
]
|
|
14
|
+
const people = [{ name: 'Ana Duarte' }, { name: 'Ravi Mehta' }, { name: 'Marta Silva' }, { name: 'Jo Kim' }]
|
|
15
|
+
const rows = [
|
|
16
|
+
{ id: '1', title: 'Item one', description: 'What item one is about, in a line that is cut short when there is no more room.', group: 'Group one', members: people, active: '2 hours ago', join: true },
|
|
17
|
+
{ id: '2', title: 'Item two', description: 'What item two is about.', group: 'Group two', members: people.slice(0, 2), active: 'Yesterday', join: false },
|
|
18
|
+
{ id: '3', title: 'Item three with a longer name than the others', group: 'Group one', members: people.slice(0, 1), active: '4 days ago', join: true },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
function Rows() {
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
{rows.map((row) => (
|
|
25
|
+
<ListTableRow
|
|
26
|
+
key={row.id}
|
|
27
|
+
href="#"
|
|
28
|
+
label={row.title}
|
|
29
|
+
{...(row.description ? { description: row.description } : {})}
|
|
30
|
+
icon={icon}
|
|
31
|
+
cells={[
|
|
32
|
+
row.group,
|
|
33
|
+
<>
|
|
34
|
+
<AvatarGroup members={row.members} size={20} />
|
|
35
|
+
<MetaText>{row.members.length}</MetaText>
|
|
36
|
+
</>,
|
|
37
|
+
row.active,
|
|
38
|
+
]}
|
|
39
|
+
end={
|
|
40
|
+
row.join ? (
|
|
41
|
+
<Button size="small" variant="outlined">
|
|
42
|
+
Join
|
|
43
|
+
</Button>
|
|
44
|
+
) : undefined
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const meta = {
|
|
53
|
+
title: 'Page structure/ListTable',
|
|
54
|
+
component: ListTable,
|
|
55
|
+
args: { 'aria-label': 'Items', columns, end: true, children: null },
|
|
56
|
+
argTypes: { columns: { control: false }, children: { control: false } },
|
|
57
|
+
render: (args) => (
|
|
58
|
+
<div className="bg-bg-surface p-6">
|
|
59
|
+
<ListTable {...args}>
|
|
60
|
+
<Rows />
|
|
61
|
+
</ListTable>
|
|
62
|
+
</div>
|
|
63
|
+
),
|
|
64
|
+
} satisfies Meta<typeof ListTable>
|
|
65
|
+
|
|
66
|
+
export default meta
|
|
67
|
+
type Story = StoryObj<typeof meta>
|
|
68
|
+
|
|
69
|
+
/** Rows under column headings: each row leads to its item, its end is its own button. Point at a row: a fill, 8px corners, no edge. */
|
|
70
|
+
export const Default: Story = {}
|
|
71
|
+
|
|
72
|
+
/** On a wide page: the name stops at 384px, its facts beside it, the end at the right edge. */
|
|
73
|
+
export const OnAWidePage: Story = {
|
|
74
|
+
render: (args) => (
|
|
75
|
+
<div className="w-full bg-bg-surface p-6">
|
|
76
|
+
<ListTable {...args}>
|
|
77
|
+
<Rows />
|
|
78
|
+
</ListTable>
|
|
79
|
+
</div>
|
|
80
|
+
),
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** In a narrow box (576px): Members and Active (`keep: 'low'`) give way first, and the names keep their room. */
|
|
84
|
+
export const Narrow: Story = {
|
|
85
|
+
render: (args) => (
|
|
86
|
+
<div className="max-w-xl bg-bg-surface p-6">
|
|
87
|
+
<ListTable {...args}>
|
|
88
|
+
<Rows />
|
|
89
|
+
</ListTable>
|
|
90
|
+
</div>
|
|
91
|
+
),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Narrower still (448px): every column gives way; the name and the end stay. */
|
|
95
|
+
export const Narrowest: Story = {
|
|
96
|
+
render: (args) => (
|
|
97
|
+
<div className="max-w-md bg-bg-surface p-6">
|
|
98
|
+
<ListTable {...args}>
|
|
99
|
+
<Rows />
|
|
100
|
+
</ListTable>
|
|
101
|
+
</div>
|
|
102
|
+
),
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** No facts to show: no headings, only the rows, each its own control at the end. A heading over the part names the list. */
|
|
106
|
+
export const NoColumns: Story = {
|
|
107
|
+
args: { columns: [] },
|
|
108
|
+
render: (args) => (
|
|
109
|
+
<div className="bg-bg-surface p-6">
|
|
110
|
+
<ListTable {...args}>
|
|
111
|
+
{rows.map((row) => (
|
|
112
|
+
<ListTableRow key={row.id} href="#" label={row.title} icon={icon} cells={[]} end={row.join ? <Button size="small" variant="outlined">Join</Button> : undefined} />
|
|
113
|
+
))}
|
|
114
|
+
</ListTable>
|
|
115
|
+
</div>
|
|
116
|
+
),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Its facts with no headings over them, under a heading that names the list: a team's page. Screen readers still read them. */
|
|
120
|
+
export const NoHeadings: Story = {
|
|
121
|
+
args: { headings: false },
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A dash in a cell not read yet. */
|
|
125
|
+
export const NotReadYet: Story = {
|
|
126
|
+
render: (args) => (
|
|
127
|
+
<div className="bg-bg-surface p-6">
|
|
128
|
+
<ListTable {...args}>
|
|
129
|
+
<ListTableRow href="#" label="Item one" icon={icon} cells={[undefined, undefined, undefined]} />
|
|
130
|
+
</ListTable>
|
|
131
|
+
</div>
|
|
132
|
+
),
|
|
133
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* What the page claims: the headings come from `columns` and the cells line up under them; a dash where a cell is not
|
|
4
|
+
* read; the whole row is the link and its end stays its own control; a row's look has no edge.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
import { cleanup, render, screen, within } from '@testing-library/react'
|
|
8
|
+
import userEvent from '@testing-library/user-event'
|
|
9
|
+
import { ListTable, ListTableRow } from './ListTable'
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup)
|
|
12
|
+
|
|
13
|
+
const columns = [{ label: 'Team', width: 'large' as const }, { label: 'Active', keep: 'low' as const }]
|
|
14
|
+
|
|
15
|
+
describe('ListTable', () => {
|
|
16
|
+
it('heads its columns, and each row has one cell per heading, a dash where it is not read', () => {
|
|
17
|
+
render(
|
|
18
|
+
<ListTable aria-label="Items" columns={columns}>
|
|
19
|
+
<ListTableRow href="/one" label="Item one" cells={['Group one', undefined]} />
|
|
20
|
+
</ListTable>,
|
|
21
|
+
)
|
|
22
|
+
const table = screen.getByRole('table', { name: 'Items' })
|
|
23
|
+
expect(within(table).getAllByRole('columnheader').map((cell) => cell.textContent)).toEqual(['Name', 'Team', 'Active'])
|
|
24
|
+
const row = screen.getByText('Item one').closest('[role=row]') as HTMLElement
|
|
25
|
+
expect(within(row).getAllByRole('cell').map((cell) => cell.textContent)).toEqual(['Item one', 'Group one', '–'])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('makes the whole row its link, and its end its own button', async () => {
|
|
29
|
+
const join = vi.fn()
|
|
30
|
+
render(
|
|
31
|
+
<ListTable aria-label="Items" columns={columns} end>
|
|
32
|
+
<ListTableRow href="/one" label="Item one" cells={['Group one', 'Today']} end={<button onClick={join}>Join</button>} data-item="one" />
|
|
33
|
+
</ListTable>,
|
|
34
|
+
)
|
|
35
|
+
const link = screen.getByRole('link', { name: 'Item one' })
|
|
36
|
+
expect(link.getAttribute('href')).toBe('/one')
|
|
37
|
+
await userEvent.click(screen.getByRole('button', { name: 'Join' }))
|
|
38
|
+
expect(join).toHaveBeenCalledOnce()
|
|
39
|
+
const row = link.closest('[role=row]') as HTMLElement
|
|
40
|
+
expect(row.getAttribute('data-item')).toBe('one')
|
|
41
|
+
expect(row.className).toContain('rounded-lg')
|
|
42
|
+
expect(row.className).not.toMatch(/\bborder\b/)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('draws no headings when it has no columns, only the rows', () => {
|
|
46
|
+
render(
|
|
47
|
+
<ListTable aria-label="Items" columns={[]}>
|
|
48
|
+
<ListTableRow href="/one" label="Item one" cells={[]} />
|
|
49
|
+
</ListTable>,
|
|
50
|
+
)
|
|
51
|
+
expect(screen.queryAllByRole('columnheader')).toHaveLength(0)
|
|
52
|
+
expect(screen.getByRole('link', { name: 'Item one' })).toBeTruthy()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('hides its headings on screen with headings={false}, and still names every cell to assistive technology', () => {
|
|
56
|
+
render(
|
|
57
|
+
<ListTable aria-label="Items" columns={columns} headings={false}>
|
|
58
|
+
<ListTableRow href="/one" label="Item one" cells={['Group one', 'Today']} />
|
|
59
|
+
</ListTable>,
|
|
60
|
+
)
|
|
61
|
+
const headers = screen.getAllByRole('columnheader')
|
|
62
|
+
expect(headers.map((cell) => cell.textContent)).toEqual(['Name', 'Team', 'Active'])
|
|
63
|
+
expect(headers[0]!.closest('[role=row]')!.className).toMatch(/\bsr-only\b/)
|
|
64
|
+
const row = screen.getByText('Item one').closest('[role=row]') as HTMLElement
|
|
65
|
+
expect(within(row).getAllByRole('cell').map((cell) => cell.textContent)).toEqual(['Item one', 'Group one', 'Today'])
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('shows its headings by default', () => {
|
|
69
|
+
render(
|
|
70
|
+
<ListTable aria-label="Items" columns={columns}>
|
|
71
|
+
<ListTableRow href="/one" label="Item one" cells={['Group one', 'Today']} />
|
|
72
|
+
</ListTable>,
|
|
73
|
+
)
|
|
74
|
+
expect(screen.getAllByRole('columnheader')[0]!.closest('[role=row]')!.className).not.toMatch(/\bsr-only\b/)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('refuses a row outside a list', () => {
|
|
78
|
+
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
79
|
+
expect(() => render(<ListTableRow href="/one" label="Item one" cells={[]} />)).toThrow(/inside one/)
|
|
80
|
+
})
|
|
81
|
+
})
|