@estiva-app/ui 0.115.1 → 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 +12 -2
- package/dist/NavItem.d.ts.map +1 -1
- package/dist/PreviewCard.d.ts +9 -1
- package/dist/PreviewCard.d.ts.map +1 -1
- package/dist/SectionHeader.d.ts.map +1 -1
- package/dist/UnreadDot.d.ts +12 -1
- package/dist/UnreadDot.d.ts.map +1 -1
- package/dist/WhoFollowsDialog.d.ts +12 -2
- package/dist/WhoFollowsDialog.d.ts.map +1 -1
- package/dist/eslint/index.js +3 -2
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-restyled-part.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +434 -378
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +54 -3
- 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 +16 -2
- package/src/NavItem.stories.tsx +23 -0
- package/src/NavItem.test.tsx +46 -1
- package/src/NavItem.tsx +20 -5
- package/src/PreviewCard.mdx +7 -3
- package/src/PreviewCard.test.tsx +107 -0
- package/src/PreviewCard.tsx +22 -2
- package/src/SectionHeader.mdx +2 -0
- package/src/SectionHeader.test.tsx +16 -0
- package/src/SectionHeader.tsx +4 -2
- package/src/UnreadDot.mdx +7 -1
- package/src/UnreadDot.stories.tsx +3 -0
- package/src/UnreadDot.test.tsx +16 -9
- package/src/UnreadDot.tsx +23 -3
- 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/eslint/no-restyled-part.ts +2 -1
- package/src/index.ts +1 -1
- package/stories/Choosing.mdx +2 -2
package/src/PreviewCard.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useState, type PointerEvent, type ReactNode } from 'react'
|
|
1
|
+
import { useEffect, useRef, useState, type PointerEvent, type ReactNode } from 'react'
|
|
2
2
|
import { PreviewCard as BasePreviewCard } from '@base-ui/react/preview-card'
|
|
3
3
|
import { cn } from './cn'
|
|
4
4
|
import { ScrollArea } from './ScrollArea'
|
|
@@ -53,6 +53,14 @@ export interface PreviewCardProps {
|
|
|
53
53
|
* hover-only, because a tap on a row opens the row.
|
|
54
54
|
*/
|
|
55
55
|
openOnTap?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* Called once each time the card opens (`true`) and once each time it closes (`false`), however it got there: a
|
|
58
|
+
* pointer resting, keyboard focus, a tap with `openOnTap`, Escape, a press outside, or the card unmounted while
|
|
59
|
+
* open. Never twice in a row with the same value, and never on a render. For a caller that counts what the card
|
|
60
|
+
* held as seen, the seen moment is the `false` that follows a `true` — leaving the card after it was open — never
|
|
61
|
+
* the `true`.
|
|
62
|
+
*/
|
|
63
|
+
onOpenChange?: (open: boolean) => void
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
/** The card's own numbers: 12px from the trigger, 8px clear of every screen
|
|
@@ -72,10 +80,22 @@ const OPEN_DELAY = 350
|
|
|
72
80
|
* here the card can be reached, so it can. */
|
|
73
81
|
const CLOSE_DELAY = 200
|
|
74
82
|
|
|
75
|
-
export function PreviewCard({ content, children, side = 'right', delay = OPEN_DELAY, closeDelay = CLOSE_DELAY, className, contentClassName, wrapperClassName, openOnTap = false }: PreviewCardProps) {
|
|
83
|
+
export function PreviewCard({ content, children, side = 'right', delay = OPEN_DELAY, closeDelay = CLOSE_DELAY, className, contentClassName, wrapperClassName, openOnTap = false, onOpenChange: onOpenChangeProp }: PreviewCardProps) {
|
|
76
84
|
// Held here always, so turning `openOnTap` on or off never switches the card between controlled and not; without it
|
|
77
85
|
// every change is Base UI's own (hover, focus, Escape, a press outside), as before.
|
|
78
86
|
const [open, setOpen] = useState(false)
|
|
87
|
+
// The caller hears the open state itself change, never a report of it: Base UI may report open again when focus
|
|
88
|
+
// lands in a card the pointer opened, and a tap may set what is already there, and neither changes `open`. The
|
|
89
|
+
// cleanup is the close, and it runs once whether the card closes or is unmounted while open.
|
|
90
|
+
const tell = useRef(onOpenChangeProp)
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
tell.current = onOpenChangeProp
|
|
93
|
+
})
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!open) return
|
|
96
|
+
tell.current?.(true)
|
|
97
|
+
return () => tell.current?.(false)
|
|
98
|
+
}, [open])
|
|
79
99
|
// The press the next click belongs to: its pointer type, and whether the card was open when it went down. A tap
|
|
80
100
|
// focuses a button inside, and focus may open the card before the click, so the click sets the opposite of what was
|
|
81
101
|
// there before the press, not of what focus just did. The click uses it up.
|
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/UnreadDot.mdx
CHANGED
|
@@ -19,6 +19,11 @@ when one replaces the other.
|
|
|
19
19
|
The 24px slot keeps the two the same size.
|
|
20
20
|
- In a sidebar row, pass **NavItem** `unread` rather than placing it: the row
|
|
21
21
|
draws it, and brightens its words.
|
|
22
|
+
- `tone="reaction"` for a reaction to you. A row with both something new and
|
|
23
|
+
a reaction draws one blue dot, never two: the reaction's dot only when
|
|
24
|
+
nothing blue is there. Choosing the tone is yours.
|
|
25
|
+
|
|
26
|
+
<Canvas of={UnreadDotStories.Reaction} />
|
|
22
27
|
|
|
23
28
|
## When not
|
|
24
29
|
|
|
@@ -52,9 +57,10 @@ It does these by itself. Write none of them around it.
|
|
|
52
57
|
| It does | So you never write | Refused when written by hand |
|
|
53
58
|
|---|---|---|
|
|
54
59
|
| The 6px disc in a 24px slot | a sized box around a round div | |
|
|
55
|
-
| `data-unread`, the attribute tests and photo runs select on | a marker of your own | |
|
|
60
|
+
| `data-unread`, the attribute tests and photo runs select on, and `data-tone` (`blue` or `reaction`) beside it | a marker of your own | |
|
|
56
61
|
| Keeps its size in a tight row | `shrink-0` | |
|
|
57
62
|
| `quiet`: the same 6px as a ring, not marked `data-unread`, for a dot that is always there and has nothing new | a bordered div of your own | |
|
|
63
|
+
| `tone="reaction"`: a reaction to you, in the warning colour | a colour class on the dot | |
|
|
58
64
|
|
|
59
65
|
## Props
|
|
60
66
|
|
|
@@ -11,6 +11,9 @@ type Story = StoryObj<typeof meta>
|
|
|
11
11
|
|
|
12
12
|
export const Default: Story = {}
|
|
13
13
|
|
|
14
|
+
/** `tone="reaction"`: a reaction to you, drawn in the warning colour. */
|
|
15
|
+
export const Reaction: Story = { args: { tone: 'reaction' } }
|
|
16
|
+
|
|
14
17
|
/** Nothing new: the ring a dot that is always there draws, so the slot does not empty. */
|
|
15
18
|
export const Quiet: Story = { args: { quiet: true } }
|
|
16
19
|
|
package/src/UnreadDot.test.tsx
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
/** What the page claims: the
|
|
2
|
+
/** What the page claims: the dot is marked for tests and photo runs, `data-unread` and its `data-tone`. */
|
|
3
3
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
4
4
|
import { cleanup, render } from '@testing-library/react'
|
|
5
5
|
import { UnreadDot } from './UnreadDot'
|
|
6
6
|
|
|
7
7
|
afterEach(cleanup)
|
|
8
8
|
|
|
9
|
+
const slotOf = (container: HTMLElement) => container.firstElementChild as HTMLElement
|
|
10
|
+
|
|
9
11
|
describe('UnreadDot', () => {
|
|
10
|
-
it('is
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
it('is marked data-unread, and blue by default: data-tone="blue"', () => {
|
|
13
|
+
const slot = slotOf(render(<UnreadDot />).container)
|
|
14
|
+
expect(slot.hasAttribute('data-unread')).toBe(true)
|
|
15
|
+
expect(slot.getAttribute('data-tone')).toBe('blue')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('a reaction is still unread, and says so in data-tone="reaction"', () => {
|
|
19
|
+
const slot = slotOf(render(<UnreadDot tone="reaction" />).container)
|
|
13
20
|
expect(slot.hasAttribute('data-unread')).toBe(true)
|
|
14
|
-
expect(slot.
|
|
15
|
-
expect((slot.firstElementChild as HTMLElement).className).toContain('w-1.5')
|
|
21
|
+
expect(slot.getAttribute('data-tone')).toBe('reaction')
|
|
16
22
|
})
|
|
17
23
|
|
|
18
|
-
it('a quiet dot, with nothing new, is not marked data-unread, so nothing reads it as unread', () => {
|
|
19
|
-
const
|
|
20
|
-
expect(
|
|
24
|
+
it('a quiet dot, with nothing new, is not marked data-unread nor given a tone, so nothing reads it as unread', () => {
|
|
25
|
+
const slot = slotOf(render(<UnreadDot quiet tone="reaction" />).container)
|
|
26
|
+
expect(slot.hasAttribute('data-unread')).toBe(false)
|
|
27
|
+
expect(slot.hasAttribute('data-tone')).toBe(false)
|
|
21
28
|
})
|
|
22
29
|
})
|
package/src/UnreadDot.tsx
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { cn } from './cn'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* What kind of new a dot says, named for what it is, not its colour: `blue`, the accent, for something new;
|
|
5
|
+
* `reaction` for a reaction to you.
|
|
6
|
+
*/
|
|
7
|
+
export type UnreadDotTone = 'blue' | 'reaction'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The disc's fill per tone, in one place. A reaction is drawn in the warning family, the urgent mark's colour (ACT-7);
|
|
11
|
+
* if Katerina gives it a colour or a token of its own, only this line changes.
|
|
12
|
+
*/
|
|
13
|
+
const TONE_FILL: Record<UnreadDotTone, string> = {
|
|
14
|
+
blue: 'bg-accent-primary',
|
|
15
|
+
reaction: 'bg-warning-default',
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* The accent dot that says "something new here": a 6px disc centred in a
|
|
5
20
|
* 24px slot, so it sits where a control would and the row does not shift when
|
|
@@ -12,11 +27,16 @@ import { cn } from './cn'
|
|
|
12
27
|
* page's title, which is always there because it opens the page's list
|
|
13
28
|
* (ACT-4; the activity indicator prototype Miky approved, 10 November). A
|
|
14
29
|
* quiet dot is not marked `data-unread`.
|
|
30
|
+
*
|
|
31
|
+
* `tone="reaction"` draws a reaction to you, in the warning colour (ACT-7; the
|
|
32
|
+
* same prototype). A dot that is not quiet says its tone in `data-tone`,
|
|
33
|
+
* `blue` or `reaction`, beside `data-unread`. Which tone a row shows is the
|
|
34
|
+
* caller's: a row with both kinds of new draws one blue dot.
|
|
15
35
|
*/
|
|
16
|
-
export function UnreadDot({ className, quiet = false }: { className?: string; quiet?: boolean }) {
|
|
36
|
+
export function UnreadDot({ className, quiet = false, tone = 'blue' }: { className?: string; quiet?: boolean; tone?: UnreadDotTone }) {
|
|
17
37
|
return (
|
|
18
|
-
<div className={cn('flex h-6 w-6 shrink-0 items-center justify-center', className)} {...(quiet ? {} : { 'data-unread': '' })}>
|
|
19
|
-
<div className={cn('h-1.5 w-1.5 rounded-full', quiet ? 'border border-border-strong' :
|
|
38
|
+
<div className={cn('flex h-6 w-6 shrink-0 items-center justify-center', className)} {...(quiet ? {} : { 'data-unread': '', 'data-tone': tone })}>
|
|
39
|
+
<div className={cn('h-1.5 w-1.5 rounded-full', quiet ? 'border border-border-strong' : TONE_FILL[tone])} />
|
|
20
40
|
</div>
|
|
21
41
|
)
|
|
22
42
|
}
|
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)}
|
|
@@ -149,7 +149,7 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
|
|
|
149
149
|
MenuItem: ['size', 'selected', 'destructive'],
|
|
150
150
|
MenuSub: ['selected'],
|
|
151
151
|
MetaText: ['size'],
|
|
152
|
-
NavItem: ['active'],
|
|
152
|
+
NavItem: ['active', 'unreadTone'],
|
|
153
153
|
Person: ['size'],
|
|
154
154
|
ProgressBar: ['variant'],
|
|
155
155
|
Property: ['layout'],
|
|
@@ -167,6 +167,7 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
|
|
|
167
167
|
Toolbar: ['surface'],
|
|
168
168
|
ToolbarButton: ['variant', 'pressed', 'glow'],
|
|
169
169
|
TopBar: ['variant'],
|
|
170
|
+
UnreadDot: ['tone'],
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
/** The class props of a part: `className`, and the ones for an inner box. */
|
package/src/index.ts
CHANGED
|
@@ -82,7 +82,7 @@ export { SkeletonBar, SkeletonConversation, SkeletonList, SkeletonRow } from './
|
|
|
82
82
|
export { Breadcrumb, type BreadcrumbProps, type Crumb } from './Breadcrumb'
|
|
83
83
|
export { EnterHint, Menu, MenuItem, MenuPanel, MenuRow, MenuSection, MenuSeparator, MenuSub, type MenuItemProps, type MenuPanelProps, type MenuProps, type MenuSubProps } from './Menu'
|
|
84
84
|
export { NavItem, type NavItemProps } from './NavItem'
|
|
85
|
-
export { UnreadDot } from './UnreadDot'
|
|
85
|
+
export { UnreadDot, type UnreadDotTone } from './UnreadDot'
|
|
86
86
|
export { NAV_TREE_PENDING_MS, NavTree, NavTreeSection, type NavTreeGroup, type NavTreeNode, type NavTreeProps, type NavTreeSectionProps } from './NavTree'
|
|
87
87
|
export { Popover, type PopoverProps } from './Popover'
|
|
88
88
|
export { SuggestionMenu, type SuggestionMenuHandle, type SuggestionMenuProps, type SuggestionMenuRow, type SuggestionMenuSection } from './SuggestionMenu'
|
package/stories/Choosing.mdx
CHANGED
|
@@ -66,7 +66,7 @@ fork freely, owe nothing back, mention it on the package's ticket.
|
|
|
66
66
|
|---|---|
|
|
67
67
|
| A list of verbs from a trigger | **Menu** — Escape, outside-click and the arrow keys come with it |
|
|
68
68
|
| A panel of *content* from a trigger — a field, a toolbar, a small form | **Popover** — the menu's surface without a menu's keyboard |
|
|
69
|
-
| More of a thing on hover | **PreviewCard** — unlike a tooltip, you can point at it; on a sidebar row, **NavItem** `preview` opens it; `openOnTap` when nothing else on the trigger answers a tap |
|
|
69
|
+
| More of a thing on hover | **PreviewCard** — unlike a tooltip, you can point at it; on a sidebar row, **NavItem** `preview` opens it; `openOnTap` when nothing else on the trigger answers a tap; `onOpenChange` to hear it open and close |
|
|
70
70
|
| A hint on hover or on keyboard focus | **Tooltip** / **WithTooltip** — one `TooltipProvider` at the app root shares the delay |
|
|
71
71
|
| A strip of controls that act on one thing | **Toolbar** — one Tab stop for the row, arrow keys along it |
|
|
72
72
|
| Reactions to choose from | **ReactionPicker** — the row; **Reaction** is the pill it produces |
|
|
@@ -120,7 +120,7 @@ The same conversation in every app; only its colours are each app's.
|
|
|
120
120
|
| A box that can hold more than fits — a list that grows with its data counts, even when today's data fits | **ScrollArea** — its bar is drawn over the content and takes no width |
|
|
121
121
|
| Text that can run long above things the reader needs, cut behind a fade | **ShowMore** — measures; what fits has no button |
|
|
122
122
|
| A status, a count or a category, in a small pill | **Chip** — six colour types; the colour is the message, the label makes it legible |
|
|
123
|
-
| Something new on a row or a card, no count | **UnreadDot** — the 6px dot in a 24px slot; in a sidebar row, **NavItem** `unread` draws it; `quiet` for a dot that is always there with nothing new |
|
|
123
|
+
| Something new on a row or a card, no count | **UnreadDot** — the 6px dot in a 24px slot; in a sidebar row, **NavItem** `unread` draws it; `quiet` for a dot that is always there with nothing new; `tone="reaction"` for a reaction to you (NavItem `unreadTone`) |
|
|
124
124
|
| One thing — a conversation, a project, an object — as a box you can pick | **Card** — the fill by what it sits on; `href` for a link, `hover="fill"` in a feed, `onPress` when a press opens it |
|
|
125
125
|
| A section heading, chevron, hover actions, a count beside the title | **SectionHeader** |
|
|
126
126
|
| A group of rows that opens and closes, and stays how you left it | **CollapsibleSection** — `storageKey` remembers |
|