@estiva-app/ui 0.106.0 → 0.108.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/ConversationCard.d.ts +5 -0
- package/dist/ConversationCard.d.ts.map +1 -1
- package/dist/FollowSwitch.d.ts +42 -0
- package/dist/FollowSwitch.d.ts.map +1 -0
- package/dist/MembersDialog.d.ts +25 -0
- package/dist/MembersDialog.d.ts.map +1 -1
- package/dist/MembersPill.d.ts +3 -1
- package/dist/MembersPill.d.ts.map +1 -1
- package/dist/PinnedComment.d.ts +7 -1
- package/dist/PinnedComment.d.ts.map +1 -1
- package/dist/WhoFollowsDialog.d.ts +27 -0
- package/dist/WhoFollowsDialog.d.ts.map +1 -0
- package/dist/eslint/index.js +1 -1
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-native-title.d.ts +1 -1
- package/dist/eslint/no-native-title.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1101 -959
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +281 -3
- package/src/ConversationCard.mdx +1 -0
- package/src/ConversationCard.stories.tsx +3 -0
- package/src/ConversationCard.test.tsx +22 -0
- package/src/ConversationCard.tsx +10 -2
- package/src/FollowSwitch.mdx +64 -0
- package/src/FollowSwitch.stories.tsx +54 -0
- package/src/FollowSwitch.test.tsx +139 -0
- package/src/FollowSwitch.tsx +127 -0
- package/src/MembersDialog.tsx +115 -62
- package/src/MembersPill.tsx +4 -2
- package/src/PinnedComment.tsx +11 -3
- package/src/Thread.stories.tsx +14 -1
- package/src/Thread.tsx +1 -1
- package/src/WhoFollowsDialog.mdx +65 -0
- package/src/WhoFollowsDialog.stories.tsx +40 -0
- package/src/WhoFollowsDialog.tsx +74 -0
- package/src/eslint/no-native-title.ts +1 -1
- package/src/index.ts +3 -1
- package/src/registry/registry.test.ts +6 -6
- package/stories/Choosing.mdx +2 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/** What the FollowSwitch and WhoFollowsDialog pages claim, pinned. */
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { act, cleanup, render, screen } from '@testing-library/react'
|
|
5
|
+
import userEvent from '@testing-library/user-event'
|
|
6
|
+
import { FollowSwitch } from './FollowSwitch'
|
|
7
|
+
import { MembersPill } from './MembersPill'
|
|
8
|
+
import { WhoFollowsDialog } from './WhoFollowsDialog'
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup)
|
|
11
|
+
|
|
12
|
+
describe('FollowSwitch', () => {
|
|
13
|
+
it('says the level in its name, and hands back the pick', async () => {
|
|
14
|
+
const user = userEvent.setup()
|
|
15
|
+
const onChoose = vi.fn()
|
|
16
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
17
|
+
await user.click(screen.getByRole('button', { name: 'You follow it at Important: change how you follow Item one' }))
|
|
18
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
19
|
+
expect(onChoose).toHaveBeenCalledWith('all')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('says Not following when there is no level, and hands back off', async () => {
|
|
23
|
+
const user = userEvent.setup()
|
|
24
|
+
const onChoose = vi.fn()
|
|
25
|
+
render(<FollowSwitch level="all" label="Item one" onChoose={onChoose} />)
|
|
26
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
27
|
+
await user.click(await screen.findByRole('menuitem', { name: /^Not following/ }))
|
|
28
|
+
expect(onChoose).toHaveBeenCalledWith('off')
|
|
29
|
+
cleanup()
|
|
30
|
+
render(<FollowSwitch level={undefined} label="Item one" onChoose={onChoose} />)
|
|
31
|
+
expect(screen.getByRole('button', { name: 'Not following: change how you follow Item one' })).toBeTruthy()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('offers Back to the default only with backTo, and hands back default', async () => {
|
|
35
|
+
const user = userEvent.setup()
|
|
36
|
+
const onChoose = vi.fn()
|
|
37
|
+
const { rerender } = render(<FollowSwitch level="all" label="Item one" onChoose={onChoose} />)
|
|
38
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
39
|
+
await screen.findByRole('menuitem', { name: /^All/ })
|
|
40
|
+
expect(screen.queryByRole('menuitem', { name: /Back to/ })).toBeNull()
|
|
41
|
+
await user.keyboard('{Escape}')
|
|
42
|
+
rerender(<FollowSwitch level="all" label="Item one" onChoose={onChoose} backTo="Group one" />)
|
|
43
|
+
await user.click(screen.getByRole('button', { name: /change how you follow/ }))
|
|
44
|
+
const back = await screen.findByRole('menuitem', { name: /Back to Group one’s default/ })
|
|
45
|
+
// A chosen level is public (record a-place-lists-who-chose-a-level-and-its-teams-members): never "only you see".
|
|
46
|
+
expect(back.textContent).not.toContain('only you see')
|
|
47
|
+
await user.click(back)
|
|
48
|
+
expect(onChoose).toHaveBeenCalledWith('default')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('cannot be changed without onChoose', () => {
|
|
52
|
+
render(<FollowSwitch level={undefined} label="Item one" />)
|
|
53
|
+
expect(screen.getByRole('button', { name: /Not following/ }).hasAttribute('disabled')).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('waits while onChoose runs, so one pick is one change', async () => {
|
|
57
|
+
const user = userEvent.setup()
|
|
58
|
+
let done = () => {}
|
|
59
|
+
const onChoose = vi.fn(() => new Promise<void>((resolve) => (done = resolve)))
|
|
60
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
61
|
+
const button = screen.getByRole('button', { name: /change how you follow/ })
|
|
62
|
+
await user.click(button)
|
|
63
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
64
|
+
expect(button.hasAttribute('disabled')).toBe(true)
|
|
65
|
+
await act(async () => done())
|
|
66
|
+
expect(button.hasAttribute('disabled')).toBe(false)
|
|
67
|
+
expect(onChoose).toHaveBeenCalledTimes(1)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('stops waiting when the save fails, without throwing past it', async () => {
|
|
71
|
+
const user = userEvent.setup()
|
|
72
|
+
let fail = (_: Error) => {}
|
|
73
|
+
const onChoose = vi.fn(() => new Promise<void>((_, reject) => (fail = reject)))
|
|
74
|
+
const unhandled = vi.fn()
|
|
75
|
+
process.on('unhandledRejection', unhandled)
|
|
76
|
+
render(<FollowSwitch level="important" label="Item one" onChoose={onChoose} />)
|
|
77
|
+
const button = screen.getByRole('button', { name: /change how you follow/ })
|
|
78
|
+
await user.click(button)
|
|
79
|
+
await user.click(await screen.findByRole('menuitem', { name: /^All/ }))
|
|
80
|
+
await act(async () => fail(new Error('refused')))
|
|
81
|
+
expect(button.hasAttribute('disabled')).toBe(false)
|
|
82
|
+
await act(async () => new Promise((resolve) => setImmediate(resolve)))
|
|
83
|
+
process.off('unhandledRejection', unhandled)
|
|
84
|
+
expect(unhandled).not.toHaveBeenCalled()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('WhoFollowsDialog', () => {
|
|
89
|
+
const all = [{ id: 'ana', name: 'Ana Duarte', caption: 'Chose it' }]
|
|
90
|
+
const important = [{ id: 'ravi', name: 'Ravi Mehta', caption: 'Added by Ana Duarte' }]
|
|
91
|
+
|
|
92
|
+
it('lists All then Important with their counts, and Nobody for an empty group', async () => {
|
|
93
|
+
const { rerender } = render(<WhoFollowsDialog title="Item one" all={all} important={important} onClose={() => {}} />)
|
|
94
|
+
const dialog = await screen.findByRole('dialog', { name: 'Who follows Item one' })
|
|
95
|
+
const text = dialog.textContent!
|
|
96
|
+
expect(text.indexOf('All · 1')).toBeLessThan(text.indexOf('Ana Duarte'))
|
|
97
|
+
expect(text.indexOf('Ana Duarte')).toBeLessThan(text.indexOf('Important · 1'))
|
|
98
|
+
expect(text.indexOf('Important · 1')).toBeLessThan(text.indexOf('Ravi Mehta'))
|
|
99
|
+
expect(text).toContain('Added by Ana Duarte')
|
|
100
|
+
rerender(<WhoFollowsDialog title="Item one" all={[]} important={important} onClose={() => {}} />)
|
|
101
|
+
expect((await screen.findByRole('dialog')).textContent).toContain('All · 0Nobody')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('offers Add someone only with onAdd, and leaves everyone listed out of the picker', async () => {
|
|
105
|
+
const user = userEvent.setup()
|
|
106
|
+
const onAdd = vi.fn()
|
|
107
|
+
const candidates = [
|
|
108
|
+
{ id: 'ana', label: 'Ana Duarte' },
|
|
109
|
+
{ id: 'jonas', label: 'Jonas Weber' },
|
|
110
|
+
]
|
|
111
|
+
const { rerender } = render(<WhoFollowsDialog title="Item one" all={all} important={important} candidates={candidates} onClose={() => {}} />)
|
|
112
|
+
await screen.findByRole('dialog')
|
|
113
|
+
expect(screen.queryByRole('button', { name: 'Add someone' })).toBeNull()
|
|
114
|
+
rerender(<WhoFollowsDialog title="Item one" all={all} important={important} candidates={candidates} onAdd={onAdd} onClose={() => {}} />)
|
|
115
|
+
await user.click(await screen.findByRole('button', { name: 'Add someone' }))
|
|
116
|
+
// Both names hold an "a": only the one not listed is offered.
|
|
117
|
+
await user.type(await screen.findByRole('combobox'), 'a')
|
|
118
|
+
const jonas = await screen.findByRole('option', { name: /Jonas Weber/ })
|
|
119
|
+
expect(screen.queryByRole('option', { name: /Ana Duarte/ })).toBeNull()
|
|
120
|
+
await user.click(jonas)
|
|
121
|
+
await user.click(screen.getByRole('button', { name: 'Invite' }))
|
|
122
|
+
expect(onAdd).toHaveBeenCalledWith([{ id: 'jonas', label: 'Jonas Weber' }])
|
|
123
|
+
expect(await screen.findByRole('dialog', { name: 'Who follows Item one' })).toBeTruthy()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('opens on the add layer from a menu, and its back arrow returns to the list', async () => {
|
|
127
|
+
const user = userEvent.setup()
|
|
128
|
+
render(<WhoFollowsDialog title="Item one" all={all} important={important} onAdd={() => {}} initialView="add" onClose={() => {}} />)
|
|
129
|
+
await user.click(await screen.findByRole('button', { name: 'Back to who follows' }))
|
|
130
|
+
expect(await screen.findByRole('dialog', { name: 'Who follows Item one' })).toBeTruthy()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('MembersPill', () => {
|
|
135
|
+
it('takes its accessible name from label when given', () => {
|
|
136
|
+
render(<MembersPill members={[{ name: 'Ana Duarte' }]} count={2} label="Who follows Item one: 2" onClick={() => {}} />)
|
|
137
|
+
expect(screen.getByRole('button', { name: 'Who follows Item one: 2' })).toBeTruthy()
|
|
138
|
+
})
|
|
139
|
+
})
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { IconCheck, IconCircle, IconCircleDashed, IconCircleDashedPlus, IconUsers, IconUsersPlus } from '@tabler/icons-react'
|
|
3
|
+
import { IconButton } from './IconButton'
|
|
4
|
+
import { Menu, MenuItem, MenuSection } from './Menu'
|
|
5
|
+
|
|
6
|
+
/** A level someone follows a place at. Not following is `undefined`. */
|
|
7
|
+
export type FollowLevel = 'all' | 'important'
|
|
8
|
+
|
|
9
|
+
/** One pick on the switch: a level, Not following, or back to the default a group gives. */
|
|
10
|
+
export type FollowChoice = FollowLevel | 'off' | 'default'
|
|
11
|
+
|
|
12
|
+
const ICON = { size: 16, stroke: 1.5 } as const
|
|
13
|
+
|
|
14
|
+
/** Tabler has no filled people: IconUsers' two people, drawn solid. */
|
|
15
|
+
function IconUsersSolid() {
|
|
16
|
+
return (
|
|
17
|
+
<svg width={16} height={16} viewBox="0 0 24 24" fill="currentColor" aria-hidden>
|
|
18
|
+
<circle cx="9" cy="7" r="4" />
|
|
19
|
+
<path d="M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2z" />
|
|
20
|
+
<circle cx="17.5" cy="7.5" r="3" />
|
|
21
|
+
<path d="M16.6 15h0.9a3.5 3.5 0 0 1 3.5 3.5v2.5h-4.4v-2a5.6 5.6 0 0 0 -1.6 -4z" />
|
|
22
|
+
</svg>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LevelIconProps {
|
|
27
|
+
/** The level it is followed at; `undefined` draws Not following. */
|
|
28
|
+
level: FollowLevel | undefined
|
|
29
|
+
/** People rather than circles: for a place that is a group's own (Miky, 2 Nov). */
|
|
30
|
+
people?: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How a place is followed, as one 16px icon: a dashed circle for Important, a
|
|
35
|
+
* full one for All, a dashed one with a plus, muted, for Not following. With
|
|
36
|
+
* `people`, the same three as people: outline, solid, and a plus.
|
|
37
|
+
*/
|
|
38
|
+
export function LevelIcon({ level, people = false }: LevelIconProps) {
|
|
39
|
+
if (people) {
|
|
40
|
+
if (level === 'all') return <IconUsersSolid />
|
|
41
|
+
if (level === 'important') return <IconUsers {...ICON} aria-hidden />
|
|
42
|
+
return <IconUsersPlus {...ICON} aria-hidden className="text-text-muted" />
|
|
43
|
+
}
|
|
44
|
+
if (level === 'all') return <IconCircle {...ICON} aria-hidden />
|
|
45
|
+
if (level === 'important') return <IconCircleDashed {...ICON} aria-hidden />
|
|
46
|
+
return <IconCircleDashedPlus {...ICON} aria-hidden className="text-text-muted" />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const WORDS: Record<FollowLevel, { label: string; description: string }> = {
|
|
50
|
+
important: { label: 'Important', description: 'New conversations, and replies in the ones you are in' },
|
|
51
|
+
all: { label: 'All', description: 'Every new conversation and every reply' },
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface FollowSwitchProps {
|
|
55
|
+
/** What lights for the viewer now: a level, or `undefined` for Not following. */
|
|
56
|
+
level: FollowLevel | undefined
|
|
57
|
+
/** The place's name, for the button's accessible name. */
|
|
58
|
+
label: string
|
|
59
|
+
/** Changes it. While its promise runs the button waits; a rejection is the caller's to report. Without it the switch shows the level and cannot change it. */
|
|
60
|
+
onChoose?: (choice: FollowChoice) => void | Promise<unknown>
|
|
61
|
+
/** Without `onChoose`: why it cannot be changed, said under the pointer ("This team is archived"). */
|
|
62
|
+
readOnlyReason?: string
|
|
63
|
+
/** People rather than circles, as `LevelIcon`'s `people`. */
|
|
64
|
+
people?: boolean
|
|
65
|
+
/** The line under Not following. */
|
|
66
|
+
offDescription?: string
|
|
67
|
+
/**
|
|
68
|
+
* The name of the group whose default reaches the viewer, when they chose
|
|
69
|
+
* against it: offers "Back to <name>’s default". Leave it out otherwise.
|
|
70
|
+
*/
|
|
71
|
+
backTo?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The one switch on a place: Not following, Important or All, each with what
|
|
76
|
+
* it lights, and "Back to <name>’s default" when the viewer chose against a
|
|
77
|
+
* group's default. It sits before the place's title, drawn as `LevelIcon`.
|
|
78
|
+
*/
|
|
79
|
+
export function FollowSwitch({ level, label, onChoose, readOnlyReason, people = false, offDescription = 'Nothing here lights for you', backTo }: FollowSwitchProps) {
|
|
80
|
+
const [busy, setBusy] = useState(false)
|
|
81
|
+
const now = level ? `You follow it at ${WORDS[level].label}` : 'Not following'
|
|
82
|
+
const button = (
|
|
83
|
+
<IconButton aria-label={`${now}: change how you follow ${label}`} tooltip={now} disabled={!onChoose || busy} disabledReason={onChoose ? undefined : readOnlyReason}>
|
|
84
|
+
<LevelIcon level={level} people={people} />
|
|
85
|
+
</IconButton>
|
|
86
|
+
)
|
|
87
|
+
if (!onChoose) return button
|
|
88
|
+
|
|
89
|
+
const choose = async (choice: FollowChoice) => {
|
|
90
|
+
if (busy) return
|
|
91
|
+
setBusy(true)
|
|
92
|
+
try {
|
|
93
|
+
await onChoose(choice)
|
|
94
|
+
} catch {
|
|
95
|
+
// The caller says it could not save; the switch only stops waiting, and keeps drawing the `level` it is given.
|
|
96
|
+
} finally {
|
|
97
|
+
setBusy(false)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const item = (choice: 'off' | FollowLevel, text: string, description: string, leading: FollowLevel | undefined) => {
|
|
101
|
+
const on = choice === 'off' ? !level : level === choice
|
|
102
|
+
return (
|
|
103
|
+
<MenuItem
|
|
104
|
+
leading={<LevelIcon level={leading} people={people} />}
|
|
105
|
+
label={text}
|
|
106
|
+
description={description}
|
|
107
|
+
selected={on}
|
|
108
|
+
trailing={on ? <IconCheck {...ICON} aria-hidden /> : undefined}
|
|
109
|
+
onClick={() => void choose(choice)}
|
|
110
|
+
/>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
return (
|
|
114
|
+
<Menu trigger={button}>
|
|
115
|
+
<MenuSection label="How you follow it">
|
|
116
|
+
{item('off', 'Not following', offDescription, undefined)}
|
|
117
|
+
{item('important', WORDS.important.label, WORDS.important.description, 'important')}
|
|
118
|
+
{item('all', WORDS.all.label, WORDS.all.description, 'all')}
|
|
119
|
+
</MenuSection>
|
|
120
|
+
{backTo && (
|
|
121
|
+
<MenuSection label={`${backTo} gives you Important`}>
|
|
122
|
+
<MenuItem label={`Back to ${backTo}’s default`} description={level ? 'Your choice no longer applies' : 'Your choice no longer applies; only you see that you changed it'} onClick={() => void choose('default')} />
|
|
123
|
+
</MenuSection>
|
|
124
|
+
)}
|
|
125
|
+
</Menu>
|
|
126
|
+
)
|
|
127
|
+
}
|
package/src/MembersDialog.tsx
CHANGED
|
@@ -67,6 +67,102 @@ export interface MembersDialogProps {
|
|
|
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
68
|
const LEADING_CLASSES = 'size-8 rounded-md bg-accent-muted flex items-center justify-center shrink-0 text-accent-text'
|
|
69
69
|
|
|
70
|
+
/** One person in a roster: a face, a name, a second line, and an optional control at the end. Shared with `WhoFollowsDialog`. */
|
|
71
|
+
export function RosterRow({ member, trailing }: { member: MembersDialogMember; trailing?: ReactNode }) {
|
|
72
|
+
return (
|
|
73
|
+
<div className="flex h-12 items-center gap-3 px-5">
|
|
74
|
+
<Avatar size={32} name={member.name} src={member.picture} bot={member.bot} />
|
|
75
|
+
<div className="flex min-w-0 flex-1 flex-col justify-center gap-[2px]">
|
|
76
|
+
<div className="truncate text-body-2 text-text-primary">{member.name}</div>
|
|
77
|
+
{member.caption && <div className="truncate text-caption text-text-secondary">{member.caption}</div>}
|
|
78
|
+
</div>
|
|
79
|
+
{trailing}
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The row on top that opens the add layer. Shared with `WhoFollowsDialog`. */
|
|
85
|
+
export function AddRow({ label, onClick }: { label: string; onClick: () => void }) {
|
|
86
|
+
return (
|
|
87
|
+
<MenuItem
|
|
88
|
+
size="tall"
|
|
89
|
+
className="py-2"
|
|
90
|
+
onClick={onClick}
|
|
91
|
+
leading={<span className={LEADING_CLASSES}><IconUserPlus size={16} stroke={1.5} /></span>}
|
|
92
|
+
label={label}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The add layer: an "Invite people" picker over `candidates`, with a back
|
|
99
|
+
* arrow. Shared with `WhoFollowsDialog`, so adding somebody looks and works
|
|
100
|
+
* the same wherever it opens (Miky, 6 November: "We have standard that it
|
|
101
|
+
* opens modal and there is add").
|
|
102
|
+
*/
|
|
103
|
+
export function AddPeopleLayer({
|
|
104
|
+
title,
|
|
105
|
+
backLabel,
|
|
106
|
+
candidates,
|
|
107
|
+
excludeIds,
|
|
108
|
+
onAdd,
|
|
109
|
+
onBack,
|
|
110
|
+
onClose,
|
|
111
|
+
}: {
|
|
112
|
+
title: string
|
|
113
|
+
backLabel: string
|
|
114
|
+
candidates: MembersDialogCandidate[]
|
|
115
|
+
excludeIds: string[]
|
|
116
|
+
onAdd: (chosen: MembersDialogCandidate[]) => void | boolean | Promise<void | boolean>
|
|
117
|
+
onBack: () => void
|
|
118
|
+
onClose: () => void
|
|
119
|
+
}) {
|
|
120
|
+
const [chosen, setChosen] = useState<MembersDialogCandidate[]>([])
|
|
121
|
+
const formId = useId()
|
|
122
|
+
const add = async () => {
|
|
123
|
+
if (chosen.length === 0) return
|
|
124
|
+
if ((await onAdd(chosen)) === false) return
|
|
125
|
+
setChosen([])
|
|
126
|
+
onBack()
|
|
127
|
+
}
|
|
128
|
+
return (
|
|
129
|
+
<DialogShell
|
|
130
|
+
title={title}
|
|
131
|
+
onClose={onClose}
|
|
132
|
+
headerContent={
|
|
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
|
+
}
|
|
140
|
+
bodyClassName="flex flex-col gap-6"
|
|
141
|
+
footer={
|
|
142
|
+
<>
|
|
143
|
+
<Button variant="muted" onClick={onClose}>Cancel</Button>
|
|
144
|
+
<Button variant="primary" type="submit" form={formId} disabled={chosen.length === 0}>Invite</Button>
|
|
145
|
+
</>
|
|
146
|
+
}
|
|
147
|
+
>
|
|
148
|
+
<Form id={formId} onSubmit={add}>
|
|
149
|
+
<Field label="Invite people" required>
|
|
150
|
+
<ChipInput
|
|
151
|
+
value={chosen}
|
|
152
|
+
onChange={setChosen}
|
|
153
|
+
options={candidates}
|
|
154
|
+
placeholder="Search people..."
|
|
155
|
+
excludeIds={excludeIds}
|
|
156
|
+
chipLeading={(o) => <Avatar name={o.label} src={o.picture} bot={o.bot} size={16} />}
|
|
157
|
+
rowLeading={(o) => <Avatar name={o.label} src={o.picture} bot={o.bot} size={32} />}
|
|
158
|
+
autoFocus
|
|
159
|
+
/>
|
|
160
|
+
</Field>
|
|
161
|
+
</Form>
|
|
162
|
+
</DialogShell>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
70
166
|
/**
|
|
71
167
|
* Who is in this, with joining, leaving and adding people — the list a
|
|
72
168
|
* `MembersPill` opens.
|
|
@@ -81,9 +177,7 @@ const LEADING_CLASSES = 'size-8 rounded-md bg-accent-muted flex items-center jus
|
|
|
81
177
|
*/
|
|
82
178
|
export function MembersDialog({ members, count, self, candidates = [], onAdd, note, initialView = 'list', onClose }: MembersDialogProps) {
|
|
83
179
|
const [view, setView] = useState<'list' | 'add'>(onAdd ? initialView : 'list')
|
|
84
|
-
const [chosen, setChosen] = useState<MembersDialogCandidate[]>([])
|
|
85
180
|
const [toggling, setToggling] = useState(false)
|
|
86
|
-
const formId = useId()
|
|
87
181
|
|
|
88
182
|
const toggle = async () => {
|
|
89
183
|
if (!self || toggling) return
|
|
@@ -95,13 +189,6 @@ export function MembersDialog({ members, count, self, candidates = [], onAdd, no
|
|
|
95
189
|
}
|
|
96
190
|
}
|
|
97
191
|
|
|
98
|
-
const add = async () => {
|
|
99
|
-
if (!onAdd || chosen.length === 0) return
|
|
100
|
-
if ((await onAdd(chosen)) === false) return
|
|
101
|
-
setChosen([])
|
|
102
|
-
setView('list')
|
|
103
|
-
}
|
|
104
|
-
|
|
105
192
|
// Leave sits on the viewer's own row, drawn first. A viewer with no row of their own gets Leave on top, as Join is.
|
|
106
193
|
const ownRow = self?.action === 'leave' ? members.find((m) => m.id === self.id) : undefined
|
|
107
194
|
const roster = ownRow ? [ownRow, ...members.filter((m) => m !== ownRow)] : members
|
|
@@ -109,40 +196,15 @@ export function MembersDialog({ members, count, self, candidates = [], onAdd, no
|
|
|
109
196
|
|
|
110
197
|
if (view === 'add' && onAdd) {
|
|
111
198
|
return (
|
|
112
|
-
<
|
|
199
|
+
<AddPeopleLayer
|
|
113
200
|
title="Add members"
|
|
201
|
+
backLabel="Back to members"
|
|
202
|
+
candidates={candidates}
|
|
203
|
+
excludeIds={members.map((m) => m.id)}
|
|
204
|
+
onAdd={onAdd}
|
|
205
|
+
onBack={() => setView('list')}
|
|
114
206
|
onClose={onClose}
|
|
115
|
-
|
|
116
|
-
<div className="flex min-w-0 items-center gap-2">
|
|
117
|
-
<IconButton tooltip="Back to members" aria-label="Back to members" className="-ml-2" onClick={() => setView('list')}>
|
|
118
|
-
<IconArrowLeft size={16} stroke={1.5} />
|
|
119
|
-
</IconButton>
|
|
120
|
-
<span className="truncate text-h4 text-text-primary">Add members</span>
|
|
121
|
-
</div>
|
|
122
|
-
}
|
|
123
|
-
bodyClassName="flex flex-col gap-6"
|
|
124
|
-
footer={
|
|
125
|
-
<>
|
|
126
|
-
<Button variant="muted" onClick={onClose}>Cancel</Button>
|
|
127
|
-
<Button variant="primary" type="submit" form={formId} disabled={chosen.length === 0}>Invite</Button>
|
|
128
|
-
</>
|
|
129
|
-
}
|
|
130
|
-
>
|
|
131
|
-
<Form id={formId} onSubmit={add}>
|
|
132
|
-
<Field label="Invite people" required>
|
|
133
|
-
<ChipInput
|
|
134
|
-
value={chosen}
|
|
135
|
-
onChange={setChosen}
|
|
136
|
-
options={candidates}
|
|
137
|
-
placeholder="Search people..."
|
|
138
|
-
excludeIds={members.map((m) => m.id)}
|
|
139
|
-
chipLeading={(o) => <Avatar name={o.label} src={o.picture} bot={o.bot} size={16} />}
|
|
140
|
-
rowLeading={(o) => <Avatar name={o.label} src={o.picture} bot={o.bot} size={32} />}
|
|
141
|
-
autoFocus
|
|
142
|
-
/>
|
|
143
|
-
</Field>
|
|
144
|
-
</Form>
|
|
145
|
-
</DialogShell>
|
|
207
|
+
/>
|
|
146
208
|
)
|
|
147
209
|
}
|
|
148
210
|
|
|
@@ -173,30 +235,21 @@ export function MembersDialog({ members, count, self, candidates = [], onAdd, no
|
|
|
173
235
|
label={self.action === 'join' ? 'Join' : 'Leave'}
|
|
174
236
|
/>
|
|
175
237
|
)}
|
|
176
|
-
{onAdd && (
|
|
177
|
-
<MenuItem
|
|
178
|
-
size="tall"
|
|
179
|
-
className="py-2"
|
|
180
|
-
onClick={() => setView('add')}
|
|
181
|
-
leading={<span className={LEADING_CLASSES}><IconUserPlus size={16} stroke={1.5} /></span>}
|
|
182
|
-
label="Add members"
|
|
183
|
-
/>
|
|
184
|
-
)}
|
|
238
|
+
{onAdd && <AddRow label="Add members" onClick={() => setView('add')} />}
|
|
185
239
|
</div>
|
|
186
240
|
)}
|
|
187
241
|
{roster.map((member) => (
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
</div>
|
|
242
|
+
<RosterRow
|
|
243
|
+
key={member.id}
|
|
244
|
+
member={member}
|
|
245
|
+
trailing={
|
|
246
|
+
member === ownRow && (
|
|
247
|
+
<Button variant="destructive" size="small" disabled={toggling} onClick={() => void toggle()}>
|
|
248
|
+
Leave
|
|
249
|
+
</Button>
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
/>
|
|
200
253
|
))}
|
|
201
254
|
{note && <div className="px-5 pb-2 pt-3 text-caption text-text-secondary">{note}</div>}
|
|
202
255
|
</DialogShell>
|
package/src/MembersPill.tsx
CHANGED
|
@@ -10,6 +10,8 @@ export interface MembersPillProps {
|
|
|
10
10
|
count?: number
|
|
11
11
|
/** Opens the list — usually a `MembersDialog`. Without it the pill is disabled. */
|
|
12
12
|
onClick?: () => void
|
|
13
|
+
/** The button's accessible name, when the list it opens is not "members" — "Who follows <name>: 4". Defaults to "4 members". */
|
|
14
|
+
label?: string
|
|
13
15
|
className?: string
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -23,11 +25,11 @@ export interface MembersPillProps {
|
|
|
23
25
|
* pick of 15 September). `disabled` rather than another element when there is
|
|
24
26
|
* nothing to press, so one element keeps one set of pixels.
|
|
25
27
|
*/
|
|
26
|
-
export function MembersPill({ members, count, onClick, className }: MembersPillProps) {
|
|
28
|
+
export function MembersPill({ members, count, onClick, label, className }: MembersPillProps) {
|
|
27
29
|
const total = count ?? members.length
|
|
28
30
|
if (total === 0) return null
|
|
29
31
|
return (
|
|
30
|
-
<Button variant="outlined" aria-label={`${total} ${total === 1 ? 'member' : 'members'}`} disabled={!onClick} onClick={onClick} className={cn('gap-2 pl-[3px] pr-2', className)}>
|
|
32
|
+
<Button variant="outlined" aria-label={label ?? `${total} ${total === 1 ? 'member' : 'members'}`} disabled={!onClick} onClick={onClick} className={cn('gap-2 pl-[3px] pr-2', className)}>
|
|
31
33
|
<AvatarGroup members={members} />
|
|
32
34
|
<span className={cn(MONO_CAPTION_CLASSES, 'signal:tabular-nums')}>{total}</span>
|
|
33
35
|
</Button>
|
package/src/PinnedComment.tsx
CHANGED
|
@@ -16,18 +16,26 @@ export interface PinnedCommentProps {
|
|
|
16
16
|
words: ReactNode
|
|
17
17
|
/** It was deleted; its replies stay. */
|
|
18
18
|
deleted?: boolean
|
|
19
|
+
/** It wasn't read, and nothing says it was deleted: "This comment can't be shown.", and its replies stay (ONE-9). */
|
|
20
|
+
unseen?: boolean
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
/** What stands in a comment's place when it is gone: deleted, or not shown (SPEC §6.5). */
|
|
24
|
+
export const goneWords = (deleted: boolean) => (deleted ? 'This comment was deleted.' : 'This comment can’t be shown.')
|
|
25
|
+
|
|
26
|
+
/** The box's `closed` under that thread, deleted or not shown, the same in every app: the line above already says why. */
|
|
27
|
+
export const GONE_CLOSED = 'This thread takes no new replies.'
|
|
28
|
+
|
|
21
29
|
/**
|
|
22
30
|
* The comment a thread answers, pinned at the top of the replies column: who, when, and its first line, on a raised
|
|
23
31
|
* card. Peek's pinned message, moved with the conversation.
|
|
24
32
|
*/
|
|
25
|
-
export function PinnedComment({ author, time, at: given, words, deleted = false }: PinnedCommentProps) {
|
|
33
|
+
export function PinnedComment({ author, time, at: given, words, deleted = false, unseen = false }: PinnedCommentProps) {
|
|
26
34
|
const at = momentOf(given)
|
|
27
35
|
return (
|
|
28
36
|
<Card fill="elevated" clip>
|
|
29
|
-
{deleted ? (
|
|
30
|
-
<p className="p-2 text-caption italic text-text-muted">
|
|
37
|
+
{deleted || unseen ? (
|
|
38
|
+
<p className="p-2 text-caption italic text-text-muted">{goneWords(deleted)}</p>
|
|
31
39
|
) : (
|
|
32
40
|
<div className="flex flex-col p-2">
|
|
33
41
|
<div className="flex items-center gap-2">
|
package/src/Thread.stories.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { ConversationCard, ReplyCard } from './ConversationCard'
|
|
|
6
6
|
import { ConversationLayout } from './ConversationLayout'
|
|
7
7
|
import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
|
|
8
8
|
import { MembersPill } from './MembersPill'
|
|
9
|
+
import { GONE_CLOSED } from './PinnedComment'
|
|
9
10
|
import { useSeenOnScreen } from './seenOnScreen'
|
|
10
11
|
import { showInConversation } from './showInConversation'
|
|
11
12
|
import { Thread } from './Thread'
|
|
@@ -154,7 +155,19 @@ export const StartDeleted: Story = {
|
|
|
154
155
|
name: 'Comment deleted',
|
|
155
156
|
render: () => (
|
|
156
157
|
<Side>
|
|
157
|
-
<Thread start={{ ...START, deleted: true }} onClose={() => {}} notice={<WriteBox closed=
|
|
158
|
+
<Thread start={{ ...START, deleted: true }} onClose={() => {}} notice={<WriteBox closed={GONE_CLOSED} />}>
|
|
159
|
+
<Replies />
|
|
160
|
+
</Thread>
|
|
161
|
+
</Side>
|
|
162
|
+
),
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The comment was not read, and nothing says it was deleted: its replies stay, and no new one can be written. */
|
|
166
|
+
export const StartNotShown: Story = {
|
|
167
|
+
name: 'Comment not shown',
|
|
168
|
+
render: () => (
|
|
169
|
+
<Side>
|
|
170
|
+
<Thread start={{ ...START, unseen: true }} onClose={() => {}} notice={<WriteBox closed={GONE_CLOSED} />}>
|
|
158
171
|
<Replies />
|
|
159
172
|
</Thread>
|
|
160
173
|
</Side>
|
package/src/Thread.tsx
CHANGED
|
@@ -163,7 +163,7 @@ export function Thread({
|
|
|
163
163
|
>
|
|
164
164
|
{start && (
|
|
165
165
|
<div className={cn('px-4 pb-2 pt-4', SHOWN_CLASSES)} data-thread-start={start.id}>
|
|
166
|
-
<PinnedComment author={start.author} time={start.time} at={start.at} words={start.words} deleted={start.deleted} />
|
|
166
|
+
<PinnedComment author={start.author} time={start.time} at={start.at} words={start.words} deleted={start.deleted} unseen={start.unseen} />
|
|
167
167
|
</div>
|
|
168
168
|
)}
|
|
169
169
|
<Divider look="section" label="Replies" className="px-4 py-2" />
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as WhoFollowsDialogStories from './WhoFollowsDialog.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={WhoFollowsDialogStories} />
|
|
5
|
+
|
|
6
|
+
# WhoFollowsDialog
|
|
7
|
+
|
|
8
|
+
Who follows a place, at All and at Important, with "Add someone" — the list a
|
|
9
|
+
**MembersPill** opens beside a **FollowSwitch**.
|
|
10
|
+
|
|
11
|
+
<Canvas of={WhoFollowsDialogStories.Default} />
|
|
12
|
+
|
|
13
|
+
## When
|
|
14
|
+
|
|
15
|
+
- Behind the faces beside a place's title: everyone it lists, by level, and
|
|
16
|
+
adding someone.
|
|
17
|
+
- Straight on the add layer (`initialView="add"`), from a menu's "Add someone…".
|
|
18
|
+
|
|
19
|
+
## When not
|
|
20
|
+
|
|
21
|
+
- Being in a thing or not, with no levels → **MembersDialog**.
|
|
22
|
+
- Changing your own level → **FollowSwitch**; nobody's level changes here.
|
|
23
|
+
|
|
24
|
+
## How
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { WhoFollowsDialog } from '@estiva-app/ui'
|
|
28
|
+
|
|
29
|
+
const atAll: { id: string; name: string; picture?: string; caption?: string }[] = []
|
|
30
|
+
const atImportant: { id: string; name: string; picture?: string; caption?: string }[] = []
|
|
31
|
+
const directory: { id: string; label: string; picture?: string }[] = []
|
|
32
|
+
const [open, setOpen] = useState(false)
|
|
33
|
+
|
|
34
|
+
{open && (
|
|
35
|
+
<WhoFollowsDialog
|
|
36
|
+
title="Item one"
|
|
37
|
+
all={atAll}
|
|
38
|
+
important={atImportant}
|
|
39
|
+
candidates={directory}
|
|
40
|
+
onAdd={(chosen) => {}}
|
|
41
|
+
onClose={() => setOpen(false)}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- A row is **MembersDialog**'s: `{ id, name, picture?, bot?, caption? }`. The
|
|
47
|
+
caption says how they are in it ("Chose it", "Added by …").
|
|
48
|
+
- Each group is drawn with its count, and "Nobody" when it is empty.
|
|
49
|
+
- `onAdd` shows **Add someone**, which opens the same add layer as
|
|
50
|
+
**MembersDialog**'s, leaving out everyone listed by id. Return `false` to
|
|
51
|
+
stay on it; otherwise it returns to the list.
|
|
52
|
+
|
|
53
|
+
## What it owns
|
|
54
|
+
|
|
55
|
+
It does these by itself, on top of what **DialogShell** and **ChipInput** own.
|
|
56
|
+
What an add does is yours.
|
|
57
|
+
|
|
58
|
+
| It does | So you never write | Refused when written by hand |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| Goes between the list and the add layer, and back after an add | a view state, or a second dialog | |
|
|
61
|
+
| Leaves everyone listed out of the picker | a filter over your directory | |
|
|
62
|
+
|
|
63
|
+
## Props
|
|
64
|
+
|
|
65
|
+
<Controls of={WhoFollowsDialogStories.Default} />
|