@estiva-app/ui 0.116.0 → 0.117.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/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/SectionHeader.d.ts.map +1 -1
- package/dist/WhoFollowsDialog.d.ts +12 -2
- package/dist/WhoFollowsDialog.d.ts.map +1 -1
- package/dist/index.js +392 -351
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +20 -1
- package/src/FollowSwitch.test.tsx +6 -4
- package/src/MembersDialog.tsx +1 -1
- 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/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/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.117.0",
|
|
8
8
|
"exports": 253,
|
|
9
9
|
"typeExports": 264,
|
|
10
10
|
"files": null
|
|
@@ -7079,6 +7079,12 @@
|
|
|
7079
7079
|
"required": false,
|
|
7080
7080
|
"note": "Before the label: a 16px icon (stroke 1.5, secondary), or an Avatar, for rows led by a face."
|
|
7081
7081
|
},
|
|
7082
|
+
{
|
|
7083
|
+
"name": "leadingAt",
|
|
7084
|
+
"takes": "center | top",
|
|
7085
|
+
"required": false,
|
|
7086
|
+
"note": "Where `leading` sits on a row of two lines: beside the first line, or centred on the whole row."
|
|
7087
|
+
},
|
|
7082
7088
|
{
|
|
7083
7089
|
"name": "trailing",
|
|
7084
7090
|
"takes": "anything",
|
|
@@ -7129,6 +7135,13 @@
|
|
|
7129
7135
|
"default",
|
|
7130
7136
|
"tall"
|
|
7131
7137
|
]
|
|
7138
|
+
},
|
|
7139
|
+
{
|
|
7140
|
+
"prop": "leadingAt",
|
|
7141
|
+
"values": [
|
|
7142
|
+
"center",
|
|
7143
|
+
"top"
|
|
7144
|
+
]
|
|
7132
7145
|
}
|
|
7133
7146
|
],
|
|
7134
7147
|
"ownsBehaviours": [
|
|
@@ -12691,6 +12704,12 @@
|
|
|
12691
12704
|
"required": false,
|
|
12692
12705
|
"note": "Adds the people chosen. With it, the \"Add someone\" row shows and opens the same add layer as `MembersDialog`'s."
|
|
12693
12706
|
},
|
|
12707
|
+
{
|
|
12708
|
+
"name": "self",
|
|
12709
|
+
"takes": "a handler",
|
|
12710
|
+
"required": false,
|
|
12711
|
+
"note": "The viewer's own Join or Leave, as `MembersDialog`'s: Leave on their own row, which comes first in its group; with no row of their own (not in it, or in it at no level shown here), Join or Leave on top, beside \"Add someone\"."
|
|
12712
|
+
},
|
|
12694
12713
|
{
|
|
12695
12714
|
"name": "initialView",
|
|
12696
12715
|
"takes": "list | add",
|
|
@@ -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 () => {
|
package/src/MembersDialog.tsx
CHANGED
|
@@ -65,7 +65,7 @@ export interface MembersDialogProps {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// The icon in the accent as text: Ship's button blue read at 2.7:1 on its grey square (Katerina, 8 October).
|
|
68
|
-
const LEADING_CLASSES = 'size-8 rounded-md bg-accent-muted flex items-center justify-center shrink-0 text-accent-text'
|
|
68
|
+
export const LEADING_CLASSES = 'size-8 rounded-md bg-accent-muted flex items-center justify-center shrink-0 text-accent-text'
|
|
69
69
|
|
|
70
70
|
/** One person in a roster: a face, a name, a second line, and an optional control at the end. Shared with `WhoFollowsDialog`. */
|
|
71
71
|
export function RosterRow({ member, trailing }: { member: MembersDialogMember; trailing?: ReactNode }) {
|
package/src/Menu.mdx
CHANGED
|
@@ -28,6 +28,9 @@ definition either way.
|
|
|
28
28
|
- A picker fed by typing: rows are `MenuItem size="tall"` — content height
|
|
29
29
|
with a 40px floor, room for a 32px face via `leading` and a `description`
|
|
30
30
|
line — with an `EnterHint` on the highlighted row.
|
|
31
|
+
- A row of two lines (a `description`) has its icon beside the first line, not centred
|
|
32
|
+
between the two; a tall row's face stays centred (`leadingAt` says either).
|
|
33
|
+
<Canvas of={MenuStories.TwoLines} />
|
|
31
34
|
- Grouped choices where one is current: `MenuSection` over rows, `selected`
|
|
32
35
|
on the chosen one.
|
|
33
36
|
|
package/src/Menu.stories.tsx
CHANGED
|
@@ -46,6 +46,29 @@ export const Items: Story = {
|
|
|
46
46
|
),
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** Rows of two lines: the icon beside the first line, a row with a `description` by default (Katerina, 16 November);
|
|
50
|
+
* `leadingAt="center"` keeps it centred on the whole row, and a row whose `children` run to two lines passes
|
|
51
|
+
* `leadingAt="top"`. */
|
|
52
|
+
export const TwoLines: Story = {
|
|
53
|
+
parameters: { controls: { disable: true } },
|
|
54
|
+
render: () => (
|
|
55
|
+
<MenuPanel className="w-80">
|
|
56
|
+
<MenuSection label="Section">
|
|
57
|
+
<MenuItem label="Item one" description="A second line that says more about it" leading={icon(IconSquareRounded)} onClick={() => {}} />
|
|
58
|
+
<MenuItem label="Item two" description="A second line that says more about it" leading={icon(IconSquareRounded)} selected onClick={() => {}} />
|
|
59
|
+
<MenuItem label="Item three" description="leadingAt center: the icon centred on both lines" leading={icon(IconSquareRounded)} leadingAt="center" onClick={() => {}} />
|
|
60
|
+
</MenuSection>
|
|
61
|
+
<MenuSeparator />
|
|
62
|
+
<MenuItem leading={icon(IconSquareRounded)} leadingAt="top" onClick={() => {}}>
|
|
63
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
64
|
+
<span className="truncate text-body-2 text-text-primary">Item four</span>
|
|
65
|
+
<span className="truncate text-caption text-text-secondary">Its children run to a second line</span>
|
|
66
|
+
</span>
|
|
67
|
+
</MenuItem>
|
|
68
|
+
</MenuPanel>
|
|
69
|
+
),
|
|
70
|
+
}
|
|
71
|
+
|
|
49
72
|
/** Groups under headings, with a divider between them. The divider runs the
|
|
50
73
|
* width of the rows it separates, not the width of the panel's text. */
|
|
51
74
|
export const Sections: Story = {
|
package/src/Menu.tsx
CHANGED
|
@@ -359,6 +359,13 @@ export interface MenuItemProps extends Omit<ComponentPropsWithRef<'button'>, 'ch
|
|
|
359
359
|
aside?: string
|
|
360
360
|
/** Before the label: a 16px icon (stroke 1.5, secondary), or an Avatar, for rows led by a face. */
|
|
361
361
|
leading?: ReactNode
|
|
362
|
+
/**
|
|
363
|
+
* Where `leading` sits on a row of two lines: beside the first line, or centred on the whole row. Default: beside the
|
|
364
|
+
* first line on a default-size row with a `description` (Katerina, 16 November: an icon centred between two lines
|
|
365
|
+
* belongs to neither); centred otherwise, as a tall row's face is. A row whose `children` run to two lines passes
|
|
366
|
+
* `top`.
|
|
367
|
+
*/
|
|
368
|
+
leadingAt?: 'center' | 'top'
|
|
362
369
|
/** At the right edge: a hint, a value — anything. Wins over `shortcut` and `submenu`. */
|
|
363
370
|
trailing?: ReactNode
|
|
364
371
|
/**
|
|
@@ -442,9 +449,10 @@ export function menuItemClassName({ size, selected, shut = false, className }: {
|
|
|
442
449
|
/** Everything inside the row — written once, for the same reason. Shared
|
|
443
450
|
* inside the package like `menuItemClassName`: `CommandPalette` draws it
|
|
444
451
|
* inside Base UI's `Autocomplete.Item`. Not exported from the index. */
|
|
445
|
-
export function MenuItemBody({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected, shut = false }: Pick<MenuItemProps, 'label' | 'children' | 'size' | 'description' | 'aside' | 'leading' | 'trailing' | 'hint' | 'shortcut' | 'submenu' | 'destructive' | 'selected'> & { shut?: boolean }) {
|
|
452
|
+
export function MenuItemBody({ label, children, size = 'default', description, aside, leading, leadingAt, trailing, hint, shortcut, submenu, destructive, selected, shut = false }: Pick<MenuItemProps, 'label' | 'children' | 'size' | 'description' | 'aside' | 'leading' | 'leadingAt' | 'trailing' | 'hint' | 'shortcut' | 'submenu' | 'destructive' | 'selected'> & { shut?: boolean }) {
|
|
446
453
|
// Shut, its words in the disabled colour, a destructive one's too.
|
|
447
454
|
const labelColour = shut ? 'text-text-disabled' : destructive ? 'text-error-default' : 'text-text-primary'
|
|
455
|
+
const firstLine = (leadingAt ?? (size === 'default' && description ? 'top' : 'center')) === 'top'
|
|
448
456
|
const edge =
|
|
449
457
|
trailing ??
|
|
450
458
|
(shortcut ? (
|
|
@@ -454,7 +462,8 @@ export function MenuItemBody({ label, children, size = 'default', description, a
|
|
|
454
462
|
) : null)
|
|
455
463
|
return (
|
|
456
464
|
<>
|
|
457
|
-
{
|
|
465
|
+
{/* Beside the first line: the 20px of a body-2 line, from the row's top, so a 16px icon is centred on that line. */}
|
|
466
|
+
{leading && <span className={cn('flex shrink-0 items-center', firstLine && 'h-5 self-start')}>{leading}</span>}
|
|
458
467
|
{/* Sizes are arbitrary values (the body-2 and caption tokens): these
|
|
459
468
|
lists merge with a colour, and tw-merge drops a token size beside a
|
|
460
469
|
colour. Ship's copy said `text-sm`, which was never the ramp. */}
|
|
@@ -495,7 +504,7 @@ export function MenuItemBody({ label, children, size = 'default', description, a
|
|
|
495
504
|
)
|
|
496
505
|
}
|
|
497
506
|
|
|
498
|
-
export function MenuItem({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected, disabledReason, className, ...props }: MenuItemProps) {
|
|
507
|
+
export function MenuItem({ label, children, size = 'default', description, aside, leading, leadingAt, trailing, hint, shortcut, submenu, destructive, selected, disabledReason, className, ...props }: MenuItemProps) {
|
|
499
508
|
const shut = !!disabledReason
|
|
500
509
|
const body = (
|
|
501
510
|
<MenuItemBody
|
|
@@ -504,6 +513,7 @@ export function MenuItem({ label, children, size = 'default', description, aside
|
|
|
504
513
|
description={description}
|
|
505
514
|
aside={aside}
|
|
506
515
|
leading={leading}
|
|
516
|
+
{...(leadingAt ? { leadingAt } : {})}
|
|
507
517
|
trailing={trailing}
|
|
508
518
|
hint={hint}
|
|
509
519
|
shortcut={shortcut}
|
package/src/NavItem.mdx
CHANGED
|
@@ -27,6 +27,8 @@ count — a muted mono number whose tooltip says what it counts.
|
|
|
27
27
|
is pointed at or keyboard-focused, and moves the count aside for it. On a
|
|
28
28
|
screen with no hover the ⋮ always shows, and the count or dot under it
|
|
29
29
|
stays aside: the row reads as it does under a pointer.
|
|
30
|
+
Its menu opens toward the page: its left edge under the ⋮, spreading
|
|
31
|
+
right over what the column sits beside, not back over the list.
|
|
30
32
|
|
|
31
33
|
<Canvas of={NavItemStories.WithMenu} />
|
|
32
34
|
|
package/src/NavItem.tsx
CHANGED
|
@@ -300,8 +300,12 @@ export function NavItem({
|
|
|
300
300
|
</IconButton>
|
|
301
301
|
)}
|
|
302
302
|
{menu != null && (
|
|
303
|
+
/*
|
|
304
|
+
Toward the page: the menu's left edge under the ⋮, spreading right over what the column sits beside,
|
|
305
|
+
not back over the list and the rail (Katerina, 16 November). At the screen's edge Base UI shifts it in.
|
|
306
|
+
*/
|
|
303
307
|
<Menu
|
|
304
|
-
align="
|
|
308
|
+
align="left"
|
|
305
309
|
trigger={
|
|
306
310
|
<IconButton tooltip="More options" aria-label={name}>
|
|
307
311
|
<IconDotsVertical size={16} stroke={1.5} />
|
package/src/SectionHeader.mdx
CHANGED
|
@@ -30,6 +30,8 @@ title the toggle — that is where a section folds.
|
|
|
30
30
|
- `menu` gives the section a "More options" ⋮ after its actions, with what
|
|
31
31
|
acts on the whole section — a folder's Rename, Archive. It is **NavItem**'s
|
|
32
32
|
⋮, revealed with the actions, and stays while its menu is open.
|
|
33
|
+
Both menus open toward the page, as a row's: their left edge under the
|
|
34
|
+
button, spreading right.
|
|
33
35
|
|
|
34
36
|
<Canvas of={SectionHeaderStories.WithMenu} />
|
|
35
37
|
|
|
@@ -174,3 +174,19 @@ describe('SectionHeader, the trailing slot', () => {
|
|
|
174
174
|
expect(count.previousElementSibling?.textContent).toBe('Section')
|
|
175
175
|
})
|
|
176
176
|
})
|
|
177
|
+
|
|
178
|
+
describe('SectionHeader, the words it shows', () => {
|
|
179
|
+
it('shows only its title and count as words, whatever menus and actions it carries', async () => {
|
|
180
|
+
const { container } = render(
|
|
181
|
+
<SectionHeader
|
|
182
|
+
title="Item"
|
|
183
|
+
count={3}
|
|
184
|
+
actions={[{ icon: <svg aria-hidden />, tooltip: 'Sort', menu: <MenuItem label="Newest first" onClick={() => {}} /> }]}
|
|
185
|
+
menu={<MenuItem label="Rename" onClick={() => {}} />}
|
|
186
|
+
/>,
|
|
187
|
+
)
|
|
188
|
+
await screen.findByRole('button', { name: 'More options for Item' })
|
|
189
|
+
// A stray line of code in the markup draws as text beside the title, and squeezes it (Katerina, 16 November).
|
|
190
|
+
expect(container.textContent).toBe('Item3')
|
|
191
|
+
})
|
|
192
|
+
})
|
package/src/SectionHeader.tsx
CHANGED
|
@@ -238,8 +238,9 @@ export function SectionHeader({ title, chevron = false, icon, isExpanded = true,
|
|
|
238
238
|
action.menu != null ? (
|
|
239
239
|
// `data-section-menu`, as the ⋮ has: the row stays lit while its menu is open.
|
|
240
240
|
<div key={action.tooltip} data-section-menu className="flex items-center">
|
|
241
|
+
{/* Toward the page: its left edge under the button, spreading right (Katerina, 16 November). */}
|
|
241
242
|
<Menu
|
|
242
|
-
align="
|
|
243
|
+
align="left"
|
|
243
244
|
trigger={
|
|
244
245
|
<IconButton tooltip={action.tooltip} aria-label={action.tooltip}>
|
|
245
246
|
{action.icon}
|
|
@@ -257,8 +258,9 @@ export function SectionHeader({ title, chevron = false, icon, isExpanded = true,
|
|
|
257
258
|
)}
|
|
258
259
|
{menu != null && (
|
|
259
260
|
<div data-section-menu className="flex items-center">
|
|
261
|
+
{/* Toward the page, as a row's ⋮ opens (Katerina, 16 November). */}
|
|
260
262
|
<Menu
|
|
261
|
-
align="
|
|
263
|
+
align="left"
|
|
262
264
|
trigger={
|
|
263
265
|
<IconButton tooltip="More options" aria-label={menuLabel ?? `More options for ${title}`}>
|
|
264
266
|
<IconDotsVertical size={16} stroke={1.5} />
|
package/src/WhoFollowsDialog.mdx
CHANGED
|
@@ -46,6 +46,8 @@ const [open, setOpen] = useState(false)
|
|
|
46
46
|
- A row is **MembersDialog**'s: `{ id, name, picture?, bot?, caption? }`. The
|
|
47
47
|
caption says how they are in it ("Chose it", "Added by …").
|
|
48
48
|
- Each group is drawn with its count, and "Nobody" when it is empty.
|
|
49
|
+
- `self` gives the viewer their own Join or Leave, as **MembersDialog**'s: Leave on
|
|
50
|
+
their own row, first in its group; with no row of their own, Join or Leave on top.
|
|
49
51
|
- `onAdd` shows **Add someone**, which opens the same add layer as
|
|
50
52
|
**MembersDialog**'s, leaving out everyone listed by id. Return `false` to
|
|
51
53
|
stay on it; otherwise it returns to the list.
|
|
@@ -38,3 +38,22 @@ export const ListOnly: Story = { args: { onAdd: undefined } }
|
|
|
38
38
|
|
|
39
39
|
/** Opened from a menu's "Add someone…": straight on the add layer, whose back arrow returns to the list. */
|
|
40
40
|
export const Adding: Story = { args: { initialView: 'add' } }
|
|
41
|
+
|
|
42
|
+
/** `self` leave: your own row comes first in its group, with Leave on it. */
|
|
43
|
+
export const WithLeave: Story = { args: { self: { action: 'leave', id: 'me', onToggle: () => {} } } }
|
|
44
|
+
|
|
45
|
+
/** `self` join: not in it, so Join sits on top, above "Add someone". */
|
|
46
|
+
export const NotIn: Story = {
|
|
47
|
+
args: {
|
|
48
|
+
important: [{ id: 'ravi', name: 'Ravi Mehta', caption: 'Added by Ana Duarte' }],
|
|
49
|
+
self: { action: 'join', id: 'me', onToggle: () => {} },
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** `self` leave with no row of your own (in it at a level not listed here): Leave on top, as Join is. */
|
|
54
|
+
export const LeaveOnTop: Story = {
|
|
55
|
+
args: {
|
|
56
|
+
important: [{ id: 'ravi', name: 'Ravi Mehta', caption: 'Added by Ana Duarte' }],
|
|
57
|
+
self: { action: 'leave', id: 'me', onToggle: () => {} },
|
|
58
|
+
},
|
|
59
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/** What the WhoFollowsDialog page claims about your own Join or Leave, pinned. */
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
5
|
+
import userEvent from '@testing-library/user-event'
|
|
6
|
+
import { WhoFollowsDialog } from './WhoFollowsDialog'
|
|
7
|
+
|
|
8
|
+
afterEach(cleanup)
|
|
9
|
+
|
|
10
|
+
const all = [{ id: 'ana', name: 'Ana Duarte' }]
|
|
11
|
+
const important = [
|
|
12
|
+
{ id: 'ravi', name: 'Ravi Mehta' },
|
|
13
|
+
{ id: 'me', name: 'You' },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
describe('WhoFollowsDialog, your own Join or Leave', () => {
|
|
17
|
+
it('offers no Join or Leave when no self is given', async () => {
|
|
18
|
+
render(<WhoFollowsDialog title="Widgets" all={all} important={important} onClose={() => {}} />)
|
|
19
|
+
await screen.findByText('Ana Duarte')
|
|
20
|
+
expect(screen.queryByRole('button', { name: /^(Join|Leave)$/ })).toBeNull()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('puts Leave on your own row, first in its group, and calls onToggle once', async () => {
|
|
24
|
+
const onToggle = vi.fn()
|
|
25
|
+
render(<WhoFollowsDialog title="Widgets" all={all} important={important} self={{ action: 'leave', id: 'me', onToggle }} onClose={() => {}} />)
|
|
26
|
+
const leave = await screen.findByRole('button', { name: 'Leave' })
|
|
27
|
+
const names = screen.getAllByText(/^(Ana Duarte|Ravi Mehta|You)$/).map((el) => el.textContent)
|
|
28
|
+
expect(names).toEqual(['Ana Duarte', 'You', 'Ravi Mehta'])
|
|
29
|
+
expect(leave.parentElement?.textContent).toContain('You')
|
|
30
|
+
await userEvent.setup().click(leave)
|
|
31
|
+
expect(onToggle).toHaveBeenCalledTimes(1)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('puts Join on top when you are not in it', async () => {
|
|
35
|
+
const onToggle = vi.fn()
|
|
36
|
+
render(<WhoFollowsDialog title="Widgets" all={all} important={[important[0]]} self={{ action: 'join', id: 'me', onToggle }} onClose={() => {}} />)
|
|
37
|
+
await userEvent.setup().click(await screen.findByRole('button', { name: 'Join' }))
|
|
38
|
+
expect(onToggle).toHaveBeenCalledTimes(1)
|
|
39
|
+
})
|
|
40
|
+
})
|
package/src/WhoFollowsDialog.tsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
|
+
import { IconUserMinus, IconUserPlus } from '@tabler/icons-react'
|
|
3
|
+
import { Button } from './Button'
|
|
2
4
|
import { DialogShell } from './DialogShell'
|
|
3
5
|
import { EmptyState } from './EmptyState'
|
|
4
|
-
import { AddPeopleLayer, AddRow, RosterRow, type MembersDialogCandidate, type MembersDialogMember } from './MembersDialog'
|
|
5
|
-
import {
|
|
6
|
+
import { AddPeopleLayer, AddRow, LEADING_CLASSES, RosterRow, type MembersDialogCandidate, type MembersDialogMember, type MembersDialogSelfAction } from './MembersDialog'
|
|
7
|
+
import { MenuItem } from './Menu'
|
|
8
|
+
import { SectionHeader } from './SectionHeader'
|
|
6
9
|
|
|
7
10
|
export interface WhoFollowsDialogProps {
|
|
8
11
|
/** The place's name: the title reads "Who follows <title>". */
|
|
@@ -18,6 +21,16 @@ export interface WhoFollowsDialogProps {
|
|
|
18
21
|
* same add layer as `MembersDialog`'s. Return `false` to stay on it.
|
|
19
22
|
*/
|
|
20
23
|
onAdd?: (chosen: MembersDialogCandidate[]) => void | boolean | Promise<void | boolean>
|
|
24
|
+
/**
|
|
25
|
+
* The viewer's own Join or Leave, as `MembersDialog`'s: Leave on their own row, which comes first in its group; with no
|
|
26
|
+
* row of their own (not in it, or in it at no level shown here), Join or Leave on top, beside "Add someone".
|
|
27
|
+
*/
|
|
28
|
+
self?: {
|
|
29
|
+
action: MembersDialogSelfAction
|
|
30
|
+
onToggle: () => void | Promise<unknown>
|
|
31
|
+
/** The viewer's id: the row in `all` or `important` that carries Leave. */
|
|
32
|
+
id: string
|
|
33
|
+
}
|
|
21
34
|
/** `add` opens straight on the add layer, as a menu's "Add someone…" does. */
|
|
22
35
|
initialView?: 'list' | 'add'
|
|
23
36
|
onClose: () => void
|
|
@@ -29,8 +42,25 @@ export interface WhoFollowsDialogProps {
|
|
|
29
42
|
* `MembersDialog` uses. Nobody's level is changed here: each person changes
|
|
30
43
|
* their own on the place's `FollowSwitch`.
|
|
31
44
|
*/
|
|
32
|
-
export function WhoFollowsDialog({ title, all, important, candidates = [], onAdd, initialView = 'list', onClose }: WhoFollowsDialogProps) {
|
|
45
|
+
export function WhoFollowsDialog({ title, all, important, candidates = [], onAdd, self, initialView = 'list', onClose }: WhoFollowsDialogProps) {
|
|
33
46
|
const [view, setView] = useState<'list' | 'add'>(onAdd ? initialView : 'list')
|
|
47
|
+
const [toggling, setToggling] = useState(false)
|
|
48
|
+
const toggle = async () => {
|
|
49
|
+
if (!self) return
|
|
50
|
+
setToggling(true)
|
|
51
|
+
try {
|
|
52
|
+
await self.onToggle()
|
|
53
|
+
} finally {
|
|
54
|
+
setToggling(false)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Leave sits on the viewer's own row, first in its group; with no row of their own, Join or Leave goes on top.
|
|
58
|
+
const ownId = self?.action === 'leave' && [...all, ...important].some((m) => m.id === self.id) ? self.id : undefined
|
|
59
|
+
const ownFirst = (rows: MembersDialogMember[]) => {
|
|
60
|
+
const own = rows.find((m) => m.id === ownId)
|
|
61
|
+
return own ? [own, ...rows.filter((m) => m !== own)] : rows
|
|
62
|
+
}
|
|
63
|
+
const selfOnTop = self && !ownId
|
|
34
64
|
const heading = `Who follows ${title}`
|
|
35
65
|
|
|
36
66
|
if (view === 'add' && onAdd) {
|
|
@@ -47,24 +77,50 @@ export function WhoFollowsDialog({ title, all, important, candidates = [], onAdd
|
|
|
47
77
|
)
|
|
48
78
|
}
|
|
49
79
|
|
|
80
|
+
/*
|
|
81
|
+
A group: the kit's SectionHeader with its count beside the title (Katerina, 7 October: a heading over a list says its
|
|
82
|
+
count as a tab does), and "Nobody" when it is empty. The heading's own 8px and the empty line's own 8px are each
|
|
83
|
+
brought to the rows' 20px with 12px of margin, so title, "Nobody" and the faces start on one line (Katerina,
|
|
84
|
+
15 November: the empty line sat 8px in from the heading, inside a 20px box of its own).
|
|
85
|
+
*/
|
|
50
86
|
const group = (label: string, rows: MembersDialogMember[]) => (
|
|
51
87
|
<div className="flex flex-col pt-2">
|
|
52
|
-
<
|
|
88
|
+
<SectionHeader title={label} count={rows.length} hover="none" className="mx-3" />
|
|
53
89
|
{rows.length === 0 ? (
|
|
54
|
-
<
|
|
55
|
-
<EmptyState scope="rows" message="Nobody" />
|
|
56
|
-
</div>
|
|
90
|
+
<EmptyState scope="rows" message="Nobody" className="mx-3" />
|
|
57
91
|
) : (
|
|
58
|
-
rows.map((m) =>
|
|
92
|
+
ownFirst(rows).map((m) => (
|
|
93
|
+
<RosterRow
|
|
94
|
+
key={m.id}
|
|
95
|
+
member={m}
|
|
96
|
+
trailing={
|
|
97
|
+
m.id === ownId && (
|
|
98
|
+
<Button variant="destructive" size="small" disabled={toggling} onClick={() => void toggle()}>
|
|
99
|
+
Leave
|
|
100
|
+
</Button>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
/>
|
|
104
|
+
))
|
|
59
105
|
)}
|
|
60
106
|
</div>
|
|
61
107
|
)
|
|
62
108
|
|
|
63
109
|
return (
|
|
64
110
|
<DialogShell title={heading} onClose={onClose} bodyMaxHeight="max-h-[400px]" bodyClassName="p-0 py-2">
|
|
65
|
-
{onAdd && (
|
|
111
|
+
{(selfOnTop || onAdd) && (
|
|
66
112
|
<div className="flex flex-col px-2">
|
|
67
|
-
|
|
113
|
+
{selfOnTop && (
|
|
114
|
+
<MenuItem
|
|
115
|
+
size="tall"
|
|
116
|
+
className="py-2"
|
|
117
|
+
disabled={toggling}
|
|
118
|
+
onClick={() => void toggle()}
|
|
119
|
+
leading={<span className={LEADING_CLASSES}>{self.action === 'join' ? <IconUserPlus size={16} stroke={1.5} /> : <IconUserMinus size={16} stroke={1.5} />}</span>}
|
|
120
|
+
label={self.action === 'join' ? 'Join' : 'Leave'}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
{onAdd && <AddRow label="Add someone" onClick={() => setView('add')} />}
|
|
68
124
|
</div>
|
|
69
125
|
)}
|
|
70
126
|
{group('All', all)}
|