@estiva-app/ui 0.117.0 → 0.119.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/ConversationLayout.d.ts.map +1 -1
- package/dist/DialogShell.d.ts +11 -3
- package/dist/DialogShell.d.ts.map +1 -1
- package/dist/ListColumn.d.ts +6 -1
- package/dist/ListColumn.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.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/conversationScroll.d.ts +6 -0
- package/dist/conversationScroll.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +586 -433
- package/dist/index.js.map +4 -4
- package/dist/revealCurrentRow.d.ts +28 -0
- package/dist/revealCurrentRow.d.ts.map +1 -0
- package/dist/showInConversation.d.ts +5 -0
- package/dist/showInConversation.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +253 -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/ConversationLayout.mdx +5 -2
- package/src/ConversationLayout.scroll.test.tsx +62 -1
- package/src/ConversationLayout.stories.tsx +44 -0
- package/src/ConversationLayout.tsx +33 -2
- package/src/DialogShell.mdx +8 -2
- package/src/DialogShell.stories.tsx +20 -7
- package/src/DialogShell.tsx +10 -4
- package/src/ListColumn.mdx +1 -0
- package/src/ListColumn.stories.tsx +53 -1
- package/src/ListColumn.tsx +10 -2
- 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 +2 -10
- package/src/NavTree.mdx +7 -1
- package/src/NavTree.stories.tsx +75 -1
- package/src/NavTree.test.tsx +18 -0
- package/src/NavTree.tsx +23 -34
- 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/conversationScroll.ts +11 -0
- package/src/index.ts +2 -0
- package/src/registry/registry.test.ts +5 -5
- package/src/revealCurrentRow.test.tsx +168 -0
- package/src/revealCurrentRow.ts +68 -0
- package/src/showInConversation.ts +9 -1
- package/stories/Choosing.mdx +2 -0
|
@@ -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
|
+
})
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState, type MouseEvent, type ReactNode } from 'react'
|
|
2
|
+
import { cn } from './cn'
|
|
3
|
+
import { Link } from './Link'
|
|
4
|
+
|
|
5
|
+
/** How wide a column is: `small` 80px (a number, a few faces), `medium` 96px (a date), `large` 112px (a name). */
|
|
6
|
+
export type ListTableColumnWidth = 'small' | 'medium' | 'large'
|
|
7
|
+
|
|
8
|
+
/** Which columns give way first when the list runs short of room: `low` ones, then `high` ones. */
|
|
9
|
+
export type ListTableColumnKeep = 'high' | 'low'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* One column after the name: its heading, how wide it is, and how long it stays when room runs short. A column's
|
|
13
|
+
* fields are not the list's props, so their words are named types, not read by the registry as props' values.
|
|
14
|
+
*/
|
|
15
|
+
export interface ListTableColumn {
|
|
16
|
+
/** Its heading: "Team", "Members", "Active". */
|
|
17
|
+
label: string
|
|
18
|
+
/** `small` 80px (a number, a few faces), `medium` 96px (a date), `large` 112px (a name). Default `medium`. */
|
|
19
|
+
width?: ListTableColumnWidth
|
|
20
|
+
/**
|
|
21
|
+
* When the list runs short of room, which columns give way: `low` ones first, then `high` ones; the name and the
|
|
22
|
+
* end never do. Default `high`.
|
|
23
|
+
*/
|
|
24
|
+
keep?: ListTableColumnKeep
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ListTableProps {
|
|
28
|
+
/** What the list is, to assistive technology: "Initiatives". */
|
|
29
|
+
'aria-label': string
|
|
30
|
+
/** The first column's heading. Default "Name". */
|
|
31
|
+
nameLabel?: string
|
|
32
|
+
/** The columns after the name, in their order. None: no headings, only the rows — a list with no facts to show. */
|
|
33
|
+
columns: ListTableColumn[]
|
|
34
|
+
/** The rows hold something at their end — a small `Button`, a dot and a ⋮ — and the list keeps 64px for it. */
|
|
35
|
+
end?: boolean
|
|
36
|
+
/**
|
|
37
|
+
* The column headings on screen. Default true. `false` where the heading over the part already names the list and
|
|
38
|
+
* its facts read without a label — a team's page, under "Topics": faces and a number, "Yesterday" (Katerina,
|
|
39
|
+
* 16 November). Assistive technology still reads them, so each cell keeps its heading.
|
|
40
|
+
*/
|
|
41
|
+
headings?: boolean
|
|
42
|
+
/** The rows: `ListTableRow`s. */
|
|
43
|
+
children: ReactNode
|
|
44
|
+
/** Placement only. */
|
|
45
|
+
className?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ListTableRowProps {
|
|
49
|
+
/** Where the row leads. The whole row is the link. */
|
|
50
|
+
href: string
|
|
51
|
+
/** Its name, one line, cut short with an ellipsis. */
|
|
52
|
+
label: string
|
|
53
|
+
/** Under the name, one line, cut short: what it is about. */
|
|
54
|
+
description?: string
|
|
55
|
+
/** 16px, before the name: its kind. */
|
|
56
|
+
icon?: ReactNode
|
|
57
|
+
/** One per column, in the columns' order: words, or a part (`AvatarGroup`, `MetaText`). Absent, a dash: not read yet. */
|
|
58
|
+
cells: ReactNode[]
|
|
59
|
+
/** At the row's end, its own control: a small `Button` (Join), or the row's dot and ⋮. Never covered by the row's link. */
|
|
60
|
+
end?: ReactNode
|
|
61
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void
|
|
62
|
+
/** Marks for the app's own tests and photo runs. */
|
|
63
|
+
[data: `data-${string}`]: string | boolean | undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const WIDTH_PX = { small: 80, medium: 96, large: 112 } as const
|
|
67
|
+
const WIDTH_CLASSES = { small: 'w-20', medium: 'w-24', large: 'w-28' } as const
|
|
68
|
+
/** The least room the name keeps before a column gives way. */
|
|
69
|
+
const NAME_LEAST_PX = 200
|
|
70
|
+
const DEFAULT_WIDTH = 'medium'
|
|
71
|
+
const sizeOf = (column: ListTableColumn) => column.width ?? DEFAULT_WIDTH
|
|
72
|
+
/** The row's 12px either side, the icon and its 12px gap. */
|
|
73
|
+
const ROW_FRAME_PX = 24 + 16 + 12
|
|
74
|
+
/** Each column's 12px gap before it. */
|
|
75
|
+
const GAP_PX = 12
|
|
76
|
+
const END_PX = 64
|
|
77
|
+
|
|
78
|
+
type Shown = 'all' | 'high' | 'none'
|
|
79
|
+
const ListTableContext = createContext<{ columns: ListTableColumn[]; shown: Shown; end: boolean } | null>(null)
|
|
80
|
+
|
|
81
|
+
const showsColumn = (column: ListTableColumn, shown: Shown) => shown === 'all' || (shown === 'high' && (column.keep ?? 'high') === 'high')
|
|
82
|
+
|
|
83
|
+
const widthOf = (columns: ListTableColumn[], end: boolean) =>
|
|
84
|
+
ROW_FRAME_PX + NAME_LEAST_PX + columns.reduce((sum, column) => sum + GAP_PX + WIDTH_PX[sizeOf(column)], 0) + (end ? GAP_PX + END_PX : 0)
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A list of things on a page, under column headings: each row leads to its thing, with its name and what it is about,
|
|
88
|
+
* then a few short facts in columns, then an action at its end. The columns give way to the name by the list's own
|
|
89
|
+
* width, not the window's — `low` ones first, then `high` ones — so a list beside a sidebar keeps its names. The name
|
|
90
|
+
* is at most 384px and the facts sit beside it; the room left goes before the end, which keeps the list's right edge.
|
|
91
|
+
* The list takes the whole width it is given, as every page's body does (Katerina, 16 November).
|
|
92
|
+
*
|
|
93
|
+
* Peek's Explore topics, Ship's Topics and Leaf's Explore topics each drew this by hand, class for class, and their
|
|
94
|
+
* columns hid only at the phone's width: in a narrow window the names were cut to two letters (Katerina, 16 November).
|
|
95
|
+
*/
|
|
96
|
+
export function ListTable({ 'aria-label': label, nameLabel = 'Name', columns, end = false, headings = true, children, className }: ListTableProps) {
|
|
97
|
+
const box = useRef<HTMLDivElement>(null)
|
|
98
|
+
const [shown, setShown] = useState<Shown>('all')
|
|
99
|
+
const measure = useCallback(() => {
|
|
100
|
+
const width = box.current?.getBoundingClientRect().width ?? 0
|
|
101
|
+
// jsdom has no layout: a list it draws shows every column.
|
|
102
|
+
if (width === 0) return
|
|
103
|
+
const high = columns.filter((column) => (column.keep ?? 'high') === 'high')
|
|
104
|
+
setShown(width >= widthOf(columns, end) ? 'all' : width >= widthOf(high, end) ? 'high' : 'none')
|
|
105
|
+
}, [columns, end])
|
|
106
|
+
useLayoutEffect(() => {
|
|
107
|
+
measure()
|
|
108
|
+
const list = box.current
|
|
109
|
+
if (!list || typeof ResizeObserver === 'undefined') return
|
|
110
|
+
const observer = new ResizeObserver(measure)
|
|
111
|
+
observer.observe(list)
|
|
112
|
+
return () => observer.disconnect()
|
|
113
|
+
}, [measure])
|
|
114
|
+
return (
|
|
115
|
+
<ListTableContext.Provider value={{ columns, shown, end }}>
|
|
116
|
+
<div ref={box} role="table" aria-label={label} className={cn('flex w-full flex-col gap-2', className)}>
|
|
117
|
+
{/* With no columns there is nothing to head: the part's own heading names the list, and a lone "Name" said nothing (Katerina, 16 November). */}
|
|
118
|
+
{columns.length > 0 && (
|
|
119
|
+
// Hidden, it is out of the flow too: the rows start where the list does, with no gap for it.
|
|
120
|
+
<div role="row" className={cn('flex items-center gap-3 px-3 text-caption text-text-muted', !headings && 'sr-only')}>
|
|
121
|
+
{/* Over the name, past the icon; as wide as the names' cells. */}
|
|
122
|
+
<span role="columnheader" className="min-w-0 max-w-sm flex-1 pl-7">
|
|
123
|
+
{nameLabel}
|
|
124
|
+
</span>
|
|
125
|
+
{columns.map((column) =>
|
|
126
|
+
showsColumn(column, shown) ? (
|
|
127
|
+
<span key={column.label} role="columnheader" className={cn('shrink-0 truncate', WIDTH_CLASSES[sizeOf(column)])}>
|
|
128
|
+
{column.label}
|
|
129
|
+
</span>
|
|
130
|
+
) : null,
|
|
131
|
+
)}
|
|
132
|
+
{end && <span role="columnheader" aria-label="Actions" className="ml-auto w-16 shrink-0" />}
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
{/* 2px between rows, as a list column's and a menu's. */}
|
|
136
|
+
<div role="rowgroup" className="flex flex-col gap-0.5">
|
|
137
|
+
{children}
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</ListTableContext.Provider>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** One row of a `ListTable`: the whole row leads to its thing; its end stays its own control. */
|
|
145
|
+
export function ListTableRow({ href, label, description, icon, cells, end, onClick, ...rest }: ListTableRowProps) {
|
|
146
|
+
const table = useContext(ListTableContext)
|
|
147
|
+
if (!table) throw new Error('ListTableRow is a row of a ListTable: put it inside one.')
|
|
148
|
+
return (
|
|
149
|
+
// A row's look in every list: 8px corners, the fill under the pointer and no edge.
|
|
150
|
+
<div role="row" className="relative flex min-w-0 items-center gap-3 rounded-lg px-3 py-2 hover:bg-bg-hover" {...rest}>
|
|
151
|
+
{/* At most 384px: a short name keeps its facts beside it, not across the page (Katerina, 16 November). */}
|
|
152
|
+
<span role="cell" className="flex min-w-0 max-w-sm flex-1 items-center gap-3">
|
|
153
|
+
{icon != null && <span className="flex shrink-0 items-center text-text-secondary">{icon}</span>}
|
|
154
|
+
{/* 2px between the name and its line, as every two-line row in the kit (LinkCard, LinkRow, PartCard, a tall MenuItem); they touched (Katerina, 16 November). */}
|
|
155
|
+
<Link href={href} variant="plain" cover className="flex min-w-0 flex-1 flex-col gap-0.5" {...(onClick ? { onClick } : {})}>
|
|
156
|
+
<span className="truncate text-body-2 font-medium text-text-primary">{label}</span>
|
|
157
|
+
{description && <span className="truncate text-caption text-text-secondary">{description}</span>}
|
|
158
|
+
</Link>
|
|
159
|
+
</span>
|
|
160
|
+
{table.columns.map((column, i) =>
|
|
161
|
+
showsColumn(column, table.shown) ? (
|
|
162
|
+
// A cell's parts sit 6px apart: faces and their number.
|
|
163
|
+
<span key={column.label} role="cell" className={cn('flex shrink-0 items-center gap-1.5 truncate text-caption text-text-secondary', WIDTH_CLASSES[sizeOf(column)])}>
|
|
164
|
+
{cells[i] ?? '–'}
|
|
165
|
+
</span>
|
|
166
|
+
) : null,
|
|
167
|
+
)}
|
|
168
|
+
{table.end && (
|
|
169
|
+
// After the covering link and `relative`, so what is here stays its own control.
|
|
170
|
+
// The room the name leaves goes before it: the end keeps the list's right edge. A button's height (24px) in every
|
|
171
|
+
// row, so a row with nothing at its end is as tall as one with its ⋮ (40px; it was 36, Katerina, 16 November).
|
|
172
|
+
<span role="cell" className="relative ml-auto flex h-6 w-16 shrink-0 items-center justify-end gap-1">
|
|
173
|
+
{end}
|
|
174
|
+
</span>
|
|
175
|
+
)}
|
|
176
|
+
</div>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
@@ -22,6 +22,14 @@ describe('MembersDialog', () => {
|
|
|
22
22
|
expect(dialog.textContent).toContain('2')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
it('draws Add members’ way back whole: the bar’s own arrow, not a button pulled out of the title’s clipping box', async () => {
|
|
26
|
+
render(<MembersDialog members={members} candidates={[{ id: 'ravi', label: 'Ravi Mehta' }]} onAdd={() => {}} initialView="add" onClose={() => {}} />)
|
|
27
|
+
const back = await screen.findByRole('button', { name: 'Back to members' })
|
|
28
|
+
// Its fill and ring were cut off: it sat inside the title's box, which clips, pulled 8px out by -ml-2 (Katerina, 16 November).
|
|
29
|
+
expect(back.closest('.overflow-hidden')?.className).toContain('h-12')
|
|
30
|
+
expect(back.className).not.toMatch(/-m[lx]-/)
|
|
31
|
+
})
|
|
32
|
+
|
|
25
33
|
it('offers no Join, Leave or Add when none is given', async () => {
|
|
26
34
|
render(<MembersDialog members={members} onClose={() => {}} />)
|
|
27
35
|
await screen.findByRole('dialog')
|
package/src/MembersDialog.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useId, useState, type ReactNode } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { IconUserMinus, IconUserPlus } from '@tabler/icons-react'
|
|
3
3
|
import { Avatar } from './Avatar'
|
|
4
4
|
import { Button } from './Button'
|
|
5
5
|
import { Chip } from './Chip'
|
|
@@ -7,7 +7,6 @@ import { ChipInput, type ChipInputOption } from './ChipInput'
|
|
|
7
7
|
import { DialogShell } from './DialogShell'
|
|
8
8
|
import { Field } from './Field'
|
|
9
9
|
import { Form } from './Form'
|
|
10
|
-
import { IconButton } from './IconButton'
|
|
11
10
|
import { MenuItem } from './Menu'
|
|
12
11
|
|
|
13
12
|
/** One row of the roster: a face, a name, and an optional second line. */
|
|
@@ -129,14 +128,7 @@ export function AddPeopleLayer({
|
|
|
129
128
|
<DialogShell
|
|
130
129
|
title={title}
|
|
131
130
|
onClose={onClose}
|
|
132
|
-
|
|
133
|
-
<div className="flex min-w-0 items-center gap-2">
|
|
134
|
-
<IconButton tooltip={backLabel} aria-label={backLabel} className="-ml-2" onClick={onBack}>
|
|
135
|
-
<IconArrowLeft size={16} stroke={1.5} />
|
|
136
|
-
</IconButton>
|
|
137
|
-
<span className="truncate text-h4 text-text-primary">{title}</span>
|
|
138
|
-
</div>
|
|
139
|
-
}
|
|
131
|
+
back={{ label: backLabel, onClick: onBack }}
|
|
140
132
|
bodyClassName="flex flex-col gap-6"
|
|
141
133
|
footer={
|
|
142
134
|
<>
|
package/src/NavTree.mdx
CHANGED
|
@@ -66,6 +66,12 @@ rows to any depth.
|
|
|
66
66
|
|
|
67
67
|
<Canvas of={NavTreeStories.WithActionsAndUnread} />
|
|
68
68
|
|
|
69
|
+
- A group's `count` is how many rows it holds, 8px after its title, shown
|
|
70
|
+
open or shut — never written into the title ("Group · 2"), where it takes
|
|
71
|
+
the heading's type.
|
|
72
|
+
|
|
73
|
+
<Canvas of={NavTreeStories.GroupCount} />
|
|
74
|
+
|
|
69
75
|
- A group's `menu` is its "More options" ⋮, after its actions and its
|
|
70
76
|
`trailing`: what acts on the whole group — a folder's Rename, Archive. A
|
|
71
77
|
row's `menu` acts on that row.
|
|
@@ -158,7 +164,7 @@ It does these by itself. Write none of them around it.
|
|
|
158
164
|
| It does | So you never write | Refused when written by hand |
|
|
159
165
|
|---|---|---|
|
|
160
166
|
| Draws every level from one list, rows under rows | a recursive render of **NavItem**s and **CollapsibleSection**s | |
|
|
161
|
-
| Opens the group and the rows above the current row, once per row, and scrolls to it | a search through the list for the current row, an effect that opens it, a scroll into view | |
|
|
167
|
+
| Opens the group and the rows above the current row, once per row, and scrolls to it, however late it is drawn — by a fold that reads its rows once it opens, too | a search through the list for the current row, an effect that opens it, a scroll into view | |
|
|
162
168
|
| Opens the group a link led to, once per arrival, and scrolls to it | an effect that opens it, a `querySelector` and a scroll into view | |
|
|
163
169
|
| Says it is loading, or empty, in the rows' place | a skeleton or an **EmptyState** placed by hand | |
|
|
164
170
|
| Says when the pointer rests on a group, 150ms, and not while it sweeps past | a timer on pointer enter and leave | |
|
package/src/NavTree.stories.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { IconSquareRounded } from '@tabler/icons-react'
|
|
3
|
-
import { useState, type ReactNode } from 'react'
|
|
3
|
+
import { useEffect, useState, type ReactNode } from 'react'
|
|
4
4
|
import { IconArrowUpRight, IconFolder, IconPlus } from '@tabler/icons-react'
|
|
5
5
|
import { Button } from './Button'
|
|
6
6
|
import { Chip } from './Chip'
|
|
@@ -149,6 +149,20 @@ export const GroupIcons: Story = {
|
|
|
149
149
|
},
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/** A group that says how many rows it holds, 8px after its title, open or shut. */
|
|
153
|
+
export const GroupCount: Story = {
|
|
154
|
+
args: {
|
|
155
|
+
groups: [
|
|
156
|
+
{ id: 'n1', title: 'Group one', count: 2, defaultOpen: true, nodes: [
|
|
157
|
+
{ id: 'n1a', label: 'Item one', href: '#', icon: placeholder },
|
|
158
|
+
{ id: 'n1b', label: 'Item two', href: '#', icon: placeholder },
|
|
159
|
+
] },
|
|
160
|
+
{ id: 'n2', title: 'Group two', count: 1, defaultOpen: false, nodes: [{ id: 'n2a', label: 'Item three', href: '#', icon: placeholder }] },
|
|
161
|
+
],
|
|
162
|
+
selected: undefined,
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
|
|
152
166
|
/** Read as it opens: a group still being read, a group with nothing in it, a row whose rows are read when it opens, and one that could not be read. */
|
|
153
167
|
export const ReadAsItOpens: Story = {
|
|
154
168
|
args: {
|
|
@@ -272,6 +286,66 @@ export const OpensOntoTheCurrentRow: Story = {
|
|
|
272
286
|
},
|
|
273
287
|
}
|
|
274
288
|
|
|
289
|
+
/** A fold that reads its own rows once it opens, a moment later (a team's Files in Peek): its rows are drawn by it, not by the tree. */
|
|
290
|
+
function FilesFold({ selected, onOpen }: { selected?: string; onOpen: (id: string) => void }) {
|
|
291
|
+
const [open, setOpen] = useState(false)
|
|
292
|
+
const [rows, setRows] = useState<string[] | null>(null)
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (!open || rows) return
|
|
295
|
+
const timer = setTimeout(() => setRows(Array.from({ length: 12 }, (_, i) => `f${i + 1}`)), 1000)
|
|
296
|
+
return () => clearTimeout(timer)
|
|
297
|
+
}, [open, rows])
|
|
298
|
+
const holds = selected?.startsWith('f') === true
|
|
299
|
+
return (
|
|
300
|
+
<NavTreeSection title="Files" icon={folder} open={open} onOpenChange={setOpen} loading={open && !rows} {...(holds && selected ? { openFor: selected } : {})}>
|
|
301
|
+
{rows?.map((id) => (
|
|
302
|
+
<NavItem
|
|
303
|
+
key={id}
|
|
304
|
+
href="#"
|
|
305
|
+
label={`Project ${id.slice(1)}`}
|
|
306
|
+
icon={placeholder}
|
|
307
|
+
active={id === selected}
|
|
308
|
+
onClick={(event) => {
|
|
309
|
+
event.preventDefault()
|
|
310
|
+
onOpen(id)
|
|
311
|
+
}}
|
|
312
|
+
/>
|
|
313
|
+
))}
|
|
314
|
+
</NavTreeSection>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The current row is in a fold at the bottom that reads its rows only once it opens. Open Project 9 from the page: the
|
|
320
|
+
* fold opens, reads for a second, and the column scrolls to the row once the fold has drawn it (Katerina, 17 November:
|
|
321
|
+
* it stayed below the fold). Scroll away: it stays where you put it.
|
|
322
|
+
*/
|
|
323
|
+
export const CurrentRowDrawnLateByAFold: Story = {
|
|
324
|
+
render: function Render(args) {
|
|
325
|
+
const [selected, setSelected] = useState<string | undefined>(undefined)
|
|
326
|
+
return (
|
|
327
|
+
<div className="flex h-screen bg-bg-base">
|
|
328
|
+
<Sidebar>
|
|
329
|
+
<NavTree title={args.title} selected={selected}>
|
|
330
|
+
{Array.from({ length: 6 }, (_, g) => (
|
|
331
|
+
<NavTreeSection key={g} title={`Group ${g + 1}`} icon={folder} defaultOpen>
|
|
332
|
+
{Array.from({ length: 5 }, (_, i) => (
|
|
333
|
+
<NavItem key={i} href="#" label={`Item ${g * 5 + i + 1}`} icon={placeholder} />
|
|
334
|
+
))}
|
|
335
|
+
</NavTreeSection>
|
|
336
|
+
))}
|
|
337
|
+
<FilesFold selected={selected} onOpen={setSelected} />
|
|
338
|
+
</NavTree>
|
|
339
|
+
</Sidebar>
|
|
340
|
+
<Page>
|
|
341
|
+
<Button variant="outlined" size="small" onClick={() => setSelected('f9')}>Open Project 9, in Files</Button>
|
|
342
|
+
<Button variant="outlined" size="small" onClick={() => setSelected(undefined)}>Close it</Button>
|
|
343
|
+
</Page>
|
|
344
|
+
</div>
|
|
345
|
+
)
|
|
346
|
+
},
|
|
347
|
+
}
|
|
348
|
+
|
|
275
349
|
/** A link to a group — a folder's own: it opens, closed by hand too, and the column scrolls to it at once. Close it: it stays closed until a link leads to it again. Nothing is marked. */
|
|
276
350
|
export const OpensOntoAGroup: Story = {
|
|
277
351
|
args: { groups: SHUT_GROUPS, selected: undefined },
|