@estiva-app/ui 0.75.0 → 0.77.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/Button.d.ts +5 -0
- package/dist/Button.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +119 -0
- package/dist/CommentBox.d.ts.map +1 -0
- package/dist/ComposeBox.d.ts +2 -0
- package/dist/ComposeBox.d.ts.map +1 -1
- package/dist/EmptyState.d.ts +2 -4
- package/dist/EmptyState.d.ts.map +1 -1
- package/dist/EntryShell.d.ts +50 -0
- package/dist/EntryShell.d.ts.map +1 -0
- package/dist/ReactionRow.d.ts +44 -0
- package/dist/ReactionRow.d.ts.map +1 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +2340 -2043
- package/dist/editor.js.map +4 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +402 -324
- package/dist/index.js.map +4 -4
- package/package.json +6 -2
- package/registry.json +375 -4
- package/src/Button.tsx +6 -0
- package/src/CommentBox.mdx +83 -0
- package/src/CommentBox.stories.tsx +218 -0
- package/src/CommentBox.test.tsx +265 -0
- package/src/CommentBox.tsx +472 -0
- package/src/ComposeBox.tsx +5 -4
- package/src/EmptyState.tsx +2 -2
- package/src/EntryShell.mdx +69 -0
- package/src/EntryShell.stories.tsx +48 -0
- package/src/EntryShell.test.tsx +69 -0
- package/src/EntryShell.tsx +76 -0
- package/src/ReactionRow.mdx +50 -0
- package/src/ReactionRow.stories.tsx +91 -0
- package/src/ReactionRow.test.tsx +68 -0
- package/src/ReactionRow.tsx +118 -0
- package/src/editor.ts +11 -0
- package/src/index.ts +3 -1
- package/src/registry/registry.test.ts +5 -5
- package/stories/Choosing.mdx +4 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* What the page claims: busy draws the logo alone and says so to assistive
|
|
4
|
+
* technology; a stopped entry draws the line (announced politely, never empty)
|
|
5
|
+
* and, only when given one, the button that runs the caller's action from the
|
|
6
|
+
* tap, and holds it while disabled.
|
|
7
|
+
*/
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
9
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
10
|
+
import userEvent from '@testing-library/user-event'
|
|
11
|
+
import { EntryShell } from './EntryShell'
|
|
12
|
+
|
|
13
|
+
afterEach(cleanup)
|
|
14
|
+
|
|
15
|
+
const logo = <span>Logo</span>
|
|
16
|
+
|
|
17
|
+
describe('EntryShell', () => {
|
|
18
|
+
it('shows only the logo while entry is busy, even when given a line and an action', () => {
|
|
19
|
+
render(<EntryShell logo={logo} busy message="Why." action={{ label: 'Continue', onClick: () => {} }} />)
|
|
20
|
+
expect(screen.getByText('Logo')).not.toBeNull()
|
|
21
|
+
expect(screen.queryByText('Why.')).toBeNull()
|
|
22
|
+
expect(screen.queryByRole('button')).toBeNull()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('announces a busy screen as a busy status with its label', () => {
|
|
26
|
+
render(<EntryShell logo={logo} busy busyLabel="Opening" />)
|
|
27
|
+
const status = screen.queryByRole('status', { name: 'Opening' })
|
|
28
|
+
expect(status).not.toBeNull()
|
|
29
|
+
expect(status?.getAttribute('aria-busy')).toBe('true')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('names a busy screen "Loading" when no label is given', () => {
|
|
33
|
+
render(<EntryShell logo={logo} busy />)
|
|
34
|
+
expect(screen.queryByRole('status', { name: 'Loading' })).not.toBeNull()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('shows the line as a polite status and one button that runs the action when pressed', async () => {
|
|
38
|
+
const user = userEvent.setup()
|
|
39
|
+
const onClick = vi.fn()
|
|
40
|
+
render(<EntryShell logo={logo} message="Why." action={{ label: 'Continue', onClick }} />)
|
|
41
|
+
expect(screen.queryByRole('status')?.textContent).toBe('Why.')
|
|
42
|
+
const buttons = screen.getAllByRole('button')
|
|
43
|
+
expect(buttons).toHaveLength(1)
|
|
44
|
+
expect(buttons[0].textContent).toBe('Continue')
|
|
45
|
+
await user.click(buttons[0])
|
|
46
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('does not run a disabled action when its button is pressed', async () => {
|
|
50
|
+
const user = userEvent.setup()
|
|
51
|
+
const onClick = vi.fn()
|
|
52
|
+
render(<EntryShell logo={logo} message="Why." action={{ label: 'Continue', onClick, disabled: true }} />)
|
|
53
|
+
await user.click(screen.getByRole('button', { name: 'Continue' }))
|
|
54
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('shows the line and no button when there is nothing the person can do', () => {
|
|
58
|
+
render(<EntryShell logo={logo} message="Only an administrator can clear this." />)
|
|
59
|
+
expect(screen.getByText('Logo')).not.toBeNull()
|
|
60
|
+
expect(screen.getByText('Only an administrator can clear this.')).not.toBeNull()
|
|
61
|
+
expect(screen.queryByRole('button')).toBeNull()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('draws no line for an empty message, and the button alone', () => {
|
|
65
|
+
const { container } = render(<EntryShell logo={logo} message="" action={{ label: 'Try again', onClick: () => {} }} />)
|
|
66
|
+
expect(container.querySelector('p')).toBeNull()
|
|
67
|
+
expect(screen.getByRole('button', { name: 'Try again' })).not.toBeNull()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { cloneElement, type ReactElement, type ReactNode } from 'react'
|
|
2
|
+
import { Button, type ButtonAction } from './Button'
|
|
3
|
+
import { cn } from './cn'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What an app shows while nobody is signed in to it: its logo, one line saying
|
|
7
|
+
* why, and at most one button. Peek's AuthShell (PEEK-116), moved here so every
|
|
8
|
+
* app draws the same screen (AUT-3, 2026-10-17).
|
|
9
|
+
*
|
|
10
|
+
* The words are the caller's: a shared part has none of its own for why entry
|
|
11
|
+
* stopped.
|
|
12
|
+
*/
|
|
13
|
+
export interface EntryShellProps {
|
|
14
|
+
/**
|
|
15
|
+
* The app's own mark, drawn at the top in every state, as given: the app
|
|
16
|
+
* sizes it. An element that takes a `className`, because while `busy` the
|
|
17
|
+
* pulse goes on the mark itself.
|
|
18
|
+
*/
|
|
19
|
+
logo: ReactElement<{ className?: string }>
|
|
20
|
+
/**
|
|
21
|
+
* Entry is still being decided: the logo alone, faded in after 150ms (as a
|
|
22
|
+
* Skeleton is), so an entry that resolves at once flashes nothing. The
|
|
23
|
+
* message and the action are not drawn. Assistive technology hears a busy
|
|
24
|
+
* status named `busyLabel`. The logo carries the pulse class too, as Peek's
|
|
25
|
+
* did; the reveal overrides it here, and an app that themes the pulse (Peek's
|
|
26
|
+
* Signal shimmer) draws its own instead.
|
|
27
|
+
*/
|
|
28
|
+
busy?: boolean
|
|
29
|
+
/** What a screen reader hears while `busy`; nothing is drawn for it. */
|
|
30
|
+
busyLabel?: string
|
|
31
|
+
/**
|
|
32
|
+
* The one line saying why nobody is signed in, announced politely when it
|
|
33
|
+
* appears. Nothing is drawn for an empty one.
|
|
34
|
+
*/
|
|
35
|
+
message?: ReactNode
|
|
36
|
+
/**
|
|
37
|
+
* The one thing to do about it, drawn under the line (or alone, with no
|
|
38
|
+
* `message`) as the package's primary Button. Leave it out when nothing the
|
|
39
|
+
* person can do would help: a button that cannot work is worse than none.
|
|
40
|
+
* `onClick` runs from the tap itself, so a prompt that needs the person's
|
|
41
|
+
* gesture may start in it; `disabled` holds the button while that runs, so a
|
|
42
|
+
* second tap starts nothing.
|
|
43
|
+
*/
|
|
44
|
+
action?: ButtonAction & { disabled?: boolean }
|
|
45
|
+
className?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isEmpty = (node: ReactNode) => node == null || node === false || (typeof node === 'string' && node.trim() === '')
|
|
49
|
+
|
|
50
|
+
export function EntryShell({ logo, busy = false, busyLabel = 'Loading', message, action, className }: EntryShellProps) {
|
|
51
|
+
return (
|
|
52
|
+
<div className={cn('min-h-screen bg-bg-base flex items-center justify-center p-6', className)}>
|
|
53
|
+
{busy ? (
|
|
54
|
+
<div role="status" aria-busy="true" aria-label={busyLabel} className="flex flex-col items-center gap-4">
|
|
55
|
+
{/* On the mark itself, not on a box around it: a box would pulse its own square corners
|
|
56
|
+
and, where an app themes the pulse (Peek's Signal shimmer), sweep outside the mark. */}
|
|
57
|
+
{cloneElement(logo, { className: cn(logo.props.className, 'animate-skeleton-in animate-pulse') })}
|
|
58
|
+
</div>
|
|
59
|
+
) : (
|
|
60
|
+
<div className="flex flex-col items-center gap-4">
|
|
61
|
+
{logo}
|
|
62
|
+
{!isEmpty(message) && (
|
|
63
|
+
<p role="status" className="text-body-2 text-text-secondary max-w-sm text-center">
|
|
64
|
+
{message}
|
|
65
|
+
</p>
|
|
66
|
+
)}
|
|
67
|
+
{action && (
|
|
68
|
+
<Button variant="primary" type="button" onClick={action.onClick} disabled={action.disabled}>
|
|
69
|
+
{action.label}
|
|
70
|
+
</Button>
|
|
71
|
+
)}
|
|
72
|
+
</div>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as ReactionRowStories from './ReactionRow.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={ReactionRowStories} />
|
|
5
|
+
|
|
6
|
+
# ReactionRow
|
|
7
|
+
|
|
8
|
+
The one row of reactions under a comment or a line, in every app: **Reaction** pills in the order first chosen, yours lit, who reacted on hover, and the add button with **ReactionPicker**.
|
|
9
|
+
|
|
10
|
+
<Canvas of={ReactionRowStories.Default} />
|
|
11
|
+
|
|
12
|
+
## When
|
|
13
|
+
|
|
14
|
+
- **Under anything people react to**, in every app.
|
|
15
|
+
- `onToggle` absent where nobody can react (read-only, signed out): the pills show, disabled, and there is no add button.
|
|
16
|
+
- **AddReactionButton** alone where nobody has reacted yet: the row draws nothing, and the button sits with the other actions.
|
|
17
|
+
|
|
18
|
+
<Canvas of={ReactionRowStories.ManyPeople} />
|
|
19
|
+
|
|
20
|
+
## When not
|
|
21
|
+
|
|
22
|
+
- Choosing an emoji anywhere else → **ReactionPicker**, the row of choices on its own.
|
|
23
|
+
- One count on its own → **Reaction**.
|
|
24
|
+
|
|
25
|
+
## How
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { ReactionRow, AddReactionButton } from '@estiva-app/ui'
|
|
29
|
+
|
|
30
|
+
// groupReactions and REACTION_EMOJI: @estiva-app/conversation, which this package does not depend on.
|
|
31
|
+
const options = REACTION_EMOJI.map(({ emoji, name }) => ({ emoji, label: name }))
|
|
32
|
+
const reactions = groupReactions(decorations.byId[id].reactions, me)[id] ?? []
|
|
33
|
+
|
|
34
|
+
<ReactionRow reactions={reactions} options={options} nameOf={nameOf} viewer={me} onToggle={(emoji) => toggle(id, emoji)} />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **The counts are the app's to read**, by SPEC §6.6, through `@estiva-app/conversation`: `decorationsOf` and `groupReactions`. The row draws what it is given.
|
|
38
|
+
- **`onToggle` is yours on or off**: the app writes the reaction, or its retraction.
|
|
39
|
+
- `nameOf` names each reactor for "who reacted"; past eight names the rest are counted.
|
|
40
|
+
|
|
41
|
+
## What it owns
|
|
42
|
+
|
|
43
|
+
| It does | So you never write |
|
|
44
|
+
|---|---|
|
|
45
|
+
| No row when nobody reacted | an empty check |
|
|
46
|
+
| "Person one, Person two and you reacted with Makes sense" on hover | the sentence |
|
|
47
|
+
| The picker over the add button, closing on a pick | a popover |
|
|
48
|
+
| Disabled pills and no add button without `onToggle` | a read-only branch |
|
|
49
|
+
|
|
50
|
+
<Controls />
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { AddReactionButton, ReactionRow, type ReactionCount } from './ReactionRow'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The one reaction row under a comment or a line. Live: press a pill to take
|
|
7
|
+
* yours back or add it, and the add button for another. Hover a pill for who
|
|
8
|
+
* reacted.
|
|
9
|
+
*/
|
|
10
|
+
const meta = {
|
|
11
|
+
title: 'Primitives/ReactionRow',
|
|
12
|
+
component: ReactionRow,
|
|
13
|
+
parameters: { layout: 'padded' },
|
|
14
|
+
} satisfies Meta<typeof ReactionRow>
|
|
15
|
+
|
|
16
|
+
export default meta
|
|
17
|
+
type Story = StoryObj
|
|
18
|
+
|
|
19
|
+
const OPTIONS = [
|
|
20
|
+
{ emoji: '👍', label: 'Makes sense' },
|
|
21
|
+
{ emoji: '💯', label: 'Agree' },
|
|
22
|
+
{ emoji: '🙏', label: 'Thank you' },
|
|
23
|
+
{ emoji: '🎉', label: 'Celebrate' },
|
|
24
|
+
{ emoji: '👀', label: 'Looking' },
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
const ME = 'me'
|
|
28
|
+
const NAMES: Record<string, string> = { me: 'Me', a: 'Person one', b: 'Person two', c: 'Person three', d: 'Person four', e: 'Person five' }
|
|
29
|
+
const nameOf = (id: string) => NAMES[id] ?? 'Someone'
|
|
30
|
+
|
|
31
|
+
/** Yours on or off, as the relay would count it. */
|
|
32
|
+
const toggled = (reactions: ReactionCount[], emoji: string): ReactionCount[] => {
|
|
33
|
+
const found = reactions.find((r) => r.emoji === emoji)
|
|
34
|
+
if (!found) return [...reactions, { emoji, by: [ME] }]
|
|
35
|
+
return reactions
|
|
36
|
+
.map((r) => (r.emoji !== emoji ? r : { ...r, by: r.by.includes(ME) ? r.by.filter((id) => id !== ME) : [...r.by, ME] }))
|
|
37
|
+
.filter((r) => r.by.length > 0)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Live({ start, readOnly }: { start: ReactionCount[]; readOnly?: boolean }) {
|
|
41
|
+
const [reactions, setReactions] = useState(start)
|
|
42
|
+
return (
|
|
43
|
+
<ReactionRow
|
|
44
|
+
reactions={reactions}
|
|
45
|
+
options={OPTIONS}
|
|
46
|
+
nameOf={nameOf}
|
|
47
|
+
viewer={ME}
|
|
48
|
+
onToggle={readOnly ? undefined : (emoji) => setReactions((all) => toggled(all, emoji))}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A few reactions, yours lit. */
|
|
54
|
+
export const Default: Story = {
|
|
55
|
+
render: () => (
|
|
56
|
+
<Live
|
|
57
|
+
start={[
|
|
58
|
+
{ emoji: '👍', by: ['a', ME] },
|
|
59
|
+
{ emoji: '🙏', by: ['b'] },
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Many people on one emoji: the count, and who on hover. */
|
|
66
|
+
export const ManyPeople: Story = {
|
|
67
|
+
render: () => (
|
|
68
|
+
<Live
|
|
69
|
+
start={[
|
|
70
|
+
{ emoji: '👍', by: ['a', 'b', 'c', 'd', 'e', ME] },
|
|
71
|
+
{ emoji: '🎉', by: ['c', 'd'] },
|
|
72
|
+
{ emoji: '👀', by: ['e'] },
|
|
73
|
+
]}
|
|
74
|
+
/>
|
|
75
|
+
),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Read-only: the pills show, and nothing can be added or taken back. */
|
|
79
|
+
export const ReadOnly: Story = { render: () => <Live readOnly start={[{ emoji: '👍', by: ['a', 'b'] }]} /> }
|
|
80
|
+
|
|
81
|
+
/** Nobody reacted: no row; the add button sits with the other actions. */
|
|
82
|
+
export const NoReactions: Story = {
|
|
83
|
+
render: function NoReactions() {
|
|
84
|
+
const [reactions, setReactions] = useState<ReactionCount[]>([])
|
|
85
|
+
return reactions.length > 0 ? (
|
|
86
|
+
<ReactionRow reactions={reactions} options={OPTIONS} nameOf={nameOf} viewer={ME} onToggle={(emoji) => setReactions((all) => toggled(all, emoji))} />
|
|
87
|
+
) : (
|
|
88
|
+
<AddReactionButton options={OPTIONS} onPick={(emoji) => setReactions((all) => toggled(all, emoji))} />
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* The shared reaction row (COMM-2): the pills in the order first chosen, the
|
|
4
|
+
* viewer's lit, who reacted, toggling, and no row when nobody reacted.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
8
|
+
import { ReactionRow, whoReacted } from './ReactionRow'
|
|
9
|
+
|
|
10
|
+
const OPTIONS = [
|
|
11
|
+
{ emoji: '👍', label: 'Makes sense' },
|
|
12
|
+
{ emoji: '🙏', label: 'Thank you' },
|
|
13
|
+
]
|
|
14
|
+
const NAMES: Record<string, string> = { a: 'Person one', b: 'Person two', me: 'Me' }
|
|
15
|
+
const nameOf = (id: string) => NAMES[id] ?? 'Someone'
|
|
16
|
+
|
|
17
|
+
afterEach(() => cleanup())
|
|
18
|
+
|
|
19
|
+
describe('the pills', () => {
|
|
20
|
+
it('draws each emoji with its count in the order first chosen, the viewer’s pressed', () => {
|
|
21
|
+
render(
|
|
22
|
+
<ReactionRow
|
|
23
|
+
reactions={[
|
|
24
|
+
{ emoji: '🙏', by: ['a'] },
|
|
25
|
+
{ emoji: '👍', by: ['a', 'me'] },
|
|
26
|
+
]}
|
|
27
|
+
options={OPTIONS}
|
|
28
|
+
nameOf={nameOf}
|
|
29
|
+
viewer="me"
|
|
30
|
+
onToggle={() => {}}
|
|
31
|
+
/>,
|
|
32
|
+
)
|
|
33
|
+
const pills = screen.getAllByRole('button').filter((b) => b.getAttribute('aria-label') !== 'Add a reaction')
|
|
34
|
+
expect(pills.map((p) => p.getAttribute('aria-label'))).toEqual(['Thank you, 1', 'Makes sense, 2'])
|
|
35
|
+
expect(pills.map((p) => p.getAttribute('aria-pressed'))).toEqual(['false', 'true'])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('a click toggles your reaction; read-only, the pills are disabled and nothing adds one', () => {
|
|
39
|
+
const onToggle = vi.fn()
|
|
40
|
+
const { rerender } = render(<ReactionRow reactions={[{ emoji: '👍', by: ['a'] }]} options={OPTIONS} nameOf={nameOf} viewer="me" onToggle={onToggle} />)
|
|
41
|
+
fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 1' }))
|
|
42
|
+
expect(onToggle).toHaveBeenCalledWith('👍')
|
|
43
|
+
rerender(<ReactionRow reactions={[{ emoji: '👍', by: ['a'] }]} options={OPTIONS} nameOf={nameOf} viewer="me" />)
|
|
44
|
+
expect((screen.getByRole('button', { name: 'Makes sense, 1' }) as HTMLButtonElement).disabled).toBe(true)
|
|
45
|
+
expect(screen.queryByRole('button', { name: 'Add a reaction' })).toBeNull()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('nobody reacted: no row at all', () => {
|
|
49
|
+
const { container } = render(<ReactionRow reactions={[{ emoji: '👍', by: [] }]} options={OPTIONS} nameOf={nameOf} onToggle={() => {}} />)
|
|
50
|
+
expect(container.innerHTML).toBe('')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('who reacted', () => {
|
|
55
|
+
it('names the others, then you, with what the emoji means', () => {
|
|
56
|
+
expect(whoReacted({ emoji: '👍', by: ['a', 'me', 'b'] }, nameOf, OPTIONS, 'me')).toBe('Person one, Person two and you reacted with Makes sense')
|
|
57
|
+
expect(whoReacted({ emoji: '🦆', by: ['me'] }, nameOf, OPTIONS, 'me')).toBe('You reacted with 🦆')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('says nothing when nobody holds the emoji', () => {
|
|
61
|
+
expect(whoReacted({ emoji: '👍', by: [] }, nameOf, OPTIONS, 'me')).toBe('')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('counts the names past eight', () => {
|
|
65
|
+
const many = Array.from({ length: 11 }, (_, i) => `p${i}`)
|
|
66
|
+
expect(whoReacted({ emoji: '👍', by: many }, () => 'P', OPTIONS)).toBe('P, P, P, P, P, P, P, P and 3 more reacted with Makes sense')
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { IconMoodPlus } from '@tabler/icons-react'
|
|
3
|
+
import { cn } from './cn'
|
|
4
|
+
import { IconButton } from './IconButton'
|
|
5
|
+
import { Popover } from './Popover'
|
|
6
|
+
import { Reaction } from './Reaction'
|
|
7
|
+
import { ReactionPicker, type ReactionOption } from './ReactionPicker'
|
|
8
|
+
import { WithTooltip } from './Tooltip'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The one reaction row every app draws under a comment or a chat line, from
|
|
12
|
+
* the approved prototype (`concept/comments-everywhere`, Miky 17 October):
|
|
13
|
+
* `Reaction` pills in the order they were first chosen, each saying who
|
|
14
|
+
* reacted on hover, then the add button with `ReactionPicker`. Nobody reacted:
|
|
15
|
+
* no row; the add button sits with the other actions (`AddReactionButton`).
|
|
16
|
+
*
|
|
17
|
+
* What a reaction writes and how reactions are counted stay in
|
|
18
|
+
* `@estiva-app/conversation` (SPEC §6.6): its `groupReactions` answers the
|
|
19
|
+
* `reactions` this takes, and its `REACTION_EMOJI` the five `options`.
|
|
20
|
+
*
|
|
21
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/every-app-writes-and-reacts-with-one-shared-box.md
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** One emoji on one target, and who put it there, in the order they reacted. */
|
|
25
|
+
export interface ReactionCount {
|
|
26
|
+
emoji: string
|
|
27
|
+
by: readonly string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Names past this many are counted, not listed. */
|
|
31
|
+
const NAMED = 8
|
|
32
|
+
|
|
33
|
+
const meaningOf = (options: readonly ReactionOption[], emoji: string) => options.find((o) => o.emoji === emoji)?.label ?? emoji
|
|
34
|
+
|
|
35
|
+
/** "Person one, Person two and you reacted with Makes sense". */
|
|
36
|
+
export function whoReacted(reaction: ReactionCount, nameOf: (id: string) => string, options: readonly ReactionOption[], viewer?: string): string {
|
|
37
|
+
if (reaction.by.length === 0) return ''
|
|
38
|
+
const others = reaction.by.filter((id) => id !== viewer).map(nameOf)
|
|
39
|
+
const you = viewer !== undefined && reaction.by.includes(viewer)
|
|
40
|
+
const named = others.slice(0, you ? NAMED - 1 : NAMED)
|
|
41
|
+
const rest = others.length - named.length
|
|
42
|
+
const names = [...named, ...(rest > 0 ? [`${rest} more`] : []), ...(you ? ['you'] : [])]
|
|
43
|
+
const list = names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : (names[0] ?? '')
|
|
44
|
+
return `${list.charAt(0).toUpperCase()}${list.slice(1)} reacted with ${meaningOf(options, reaction.emoji)}`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AddReactionButtonProps {
|
|
48
|
+
/** The emoji offered, each named. */
|
|
49
|
+
options: readonly ReactionOption[]
|
|
50
|
+
onPick: (emoji: string) => void
|
|
51
|
+
className?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The add button: `ReactionPicker` opens over it. */
|
|
55
|
+
export function AddReactionButton({ options, onPick, className }: AddReactionButtonProps) {
|
|
56
|
+
const [picking, setPicking] = useState(false)
|
|
57
|
+
return (
|
|
58
|
+
<Popover
|
|
59
|
+
open={picking}
|
|
60
|
+
onOpenChange={setPicking}
|
|
61
|
+
side="top"
|
|
62
|
+
align="left"
|
|
63
|
+
ariaLabel="Add a reaction"
|
|
64
|
+
contentClassName="p-1"
|
|
65
|
+
className={className}
|
|
66
|
+
trigger={
|
|
67
|
+
<IconButton variant="muted" tooltip="Add a reaction" aria-label="Add a reaction">
|
|
68
|
+
<IconMoodPlus size={16} stroke={1.5} />
|
|
69
|
+
</IconButton>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<ReactionPicker
|
|
73
|
+
options={[...options]}
|
|
74
|
+
surface={false}
|
|
75
|
+
onSelect={(emoji) => {
|
|
76
|
+
setPicking(false)
|
|
77
|
+
onPick(emoji)
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
</Popover>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ReactionRowProps {
|
|
85
|
+
/** Each emoji and who chose it, in the order first chosen. An emoji nobody holds is not drawn. */
|
|
86
|
+
reactions: readonly ReactionCount[]
|
|
87
|
+
/** The emoji offered, each named; also what a pill's name is read from. */
|
|
88
|
+
options: readonly ReactionOption[]
|
|
89
|
+
/** A reactor's name, as "who reacted" says it. */
|
|
90
|
+
nameOf: (id: string) => string
|
|
91
|
+
/** Who is looking: their pills are lit, and "who reacted" says "you". */
|
|
92
|
+
viewer?: string
|
|
93
|
+
/** Your reaction on or off. Absent, the row only shows (read-only, signed out). */
|
|
94
|
+
onToggle?: (emoji: string) => void
|
|
95
|
+
className?: string
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function ReactionRow({ reactions, options, nameOf, viewer, onToggle, className }: ReactionRowProps) {
|
|
99
|
+
const shown = reactions.filter((r) => r.by.length > 0)
|
|
100
|
+
if (shown.length === 0) return null
|
|
101
|
+
return (
|
|
102
|
+
<div data-reaction-row className={cn('flex flex-wrap items-center gap-1', className)}>
|
|
103
|
+
{shown.map((r) => (
|
|
104
|
+
<WithTooltip key={r.emoji} label={whoReacted(r, nameOf, options, viewer)}>
|
|
105
|
+
<Reaction
|
|
106
|
+
emoji={r.emoji}
|
|
107
|
+
count={r.by.length}
|
|
108
|
+
pressed={viewer !== undefined && r.by.includes(viewer)}
|
|
109
|
+
disabled={!onToggle}
|
|
110
|
+
aria-label={`${meaningOf(options, r.emoji)}, ${r.by.length}`}
|
|
111
|
+
onClick={() => onToggle?.(r.emoji)}
|
|
112
|
+
/>
|
|
113
|
+
</WithTooltip>
|
|
114
|
+
))}
|
|
115
|
+
{onToggle && <AddReactionButton options={options} onPick={onToggle} />}
|
|
116
|
+
</div>
|
|
117
|
+
)
|
|
118
|
+
}
|
package/src/editor.ts
CHANGED
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { KeptSelection, SelectionToolbar, keepSelection, releaseSelection, normalizeHref, type MarkId, type SelectionAction, type SelectionToolbarProps } from './SelectionToolbar'
|
|
11
11
|
export { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, type ComposeBoxProps } from './ComposeBox'
|
|
12
|
+
export {
|
|
13
|
+
CommentBox,
|
|
14
|
+
commentBoxRows,
|
|
15
|
+
type CommentBoxProps,
|
|
16
|
+
type CommentBoxDraft,
|
|
17
|
+
type CommentBoxEdit,
|
|
18
|
+
type BoxFile,
|
|
19
|
+
type BoxFileState,
|
|
20
|
+
type SendAnswer,
|
|
21
|
+
type UploadAnswer,
|
|
22
|
+
} from './CommentBox'
|
|
12
23
|
export { InlineText, type InlineTextProps, type InlineTextHandle } from './InlineText'
|
|
13
24
|
export {
|
|
14
25
|
CommentHighlights,
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { MembersPill, type MembersPillProps } from './MembersPill'
|
|
|
18
18
|
export { MembersDialog, type MembersDialogCandidate, type MembersDialogMember, type MembersDialogProps, type MembersDialogSelfAction } from './MembersDialog'
|
|
19
19
|
export { Banner, type BannerProps, type BannerTone } from './Banner'
|
|
20
20
|
export { BlockHandle, blockAtY, type BlockHandleProps, type BlockHandleEditing, type HandleBlock } from './BlockHandle'
|
|
21
|
-
export { Button, type ButtonProps, type ButtonSize, type ButtonVariant } from './Button'
|
|
21
|
+
export { Button, type ButtonAction, type ButtonProps, type ButtonSize, type ButtonVariant } from './Button'
|
|
22
22
|
export { Card, type CardAttention, type CardFill, type CardHover, type CardProps } from './Card'
|
|
23
23
|
export { Checkbox, type CheckboxProps } from './Checkbox'
|
|
24
24
|
export { Chip, type ChipProps, type ChipType } from './Chip'
|
|
@@ -69,6 +69,7 @@ export { DialogShell, type DialogShellProps } from './DialogShell'
|
|
|
69
69
|
export { Divider, type DividerProps } from './Divider'
|
|
70
70
|
export { EditableText, type EditableTextProps } from './EditableText'
|
|
71
71
|
export { EmptyState, type EmptyStateProps } from './EmptyState'
|
|
72
|
+
export { EntryShell, type EntryShellProps } from './EntryShell'
|
|
72
73
|
export { ErrorBoundary, type ErrorBoundaryProps } from './ErrorBoundary'
|
|
73
74
|
export { ProgressBar, type ProgressBarProps, type ProgressBarVariant } from './ProgressBar'
|
|
74
75
|
export { SkeletonBar, SkeletonList, SkeletonRow } from './Skeleton'
|
|
@@ -117,6 +118,7 @@ export { TopBar, type TopBarProps } from './TopBar'
|
|
|
117
118
|
export { PersonTrigger, type PersonTriggerProps } from './PersonTrigger'
|
|
118
119
|
export { Property, type PropertyProps } from './Property'
|
|
119
120
|
export { Reaction, type ReactionProps } from './Reaction'
|
|
121
|
+
export { ReactionRow, AddReactionButton, whoReacted, type ReactionRowProps, type AddReactionButtonProps, type ReactionCount } from './ReactionRow'
|
|
120
122
|
export { SearchInput, type SearchInputProps } from './SearchInput'
|
|
121
123
|
export { SectionHeader, type SectionAction, type SectionHeaderProps } from './SectionHeader'
|
|
122
124
|
export { ContainerHeader, type ContainerHeaderProps } from './ContainerHeader'
|
|
@@ -48,20 +48,20 @@ describe('the registry builds', () => {
|
|
|
48
48
|
expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
it('counts
|
|
51
|
+
it('counts 203 names over 95 files: 138 components, 62 helpers and 3 hooks (EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
|
|
52
52
|
// The reconciliation GATES.md §24 explains. If this changes, that changes.
|
|
53
53
|
// The `EDITOR_EXTENSIONS` count as components by their names; they are
|
|
54
54
|
// editor extensions, documented on SelectionToolbar's, BlockNodes' and
|
|
55
55
|
// ComposerTriggers' pages.
|
|
56
56
|
const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
|
|
57
|
-
expect(kinds).toEqual({ component:
|
|
58
|
-
expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(
|
|
57
|
+
expect(kinds).toEqual({ component: 138, helper: 62, hook: 3 })
|
|
58
|
+
expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(95)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
it('gives every entry a purpose, from its own page or from the comment above it', () => {
|
|
62
62
|
expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
|
|
63
|
-
expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(
|
|
64
|
-
expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(
|
|
63
|
+
expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(89)
|
|
64
|
+
expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(114)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
it('takes a name with a page of its own from the page, and a name without one from the code', () => {
|
package/stories/Choosing.mdx
CHANGED
|
@@ -67,13 +67,15 @@ fork freely, owe nothing back, mention it on the package's ticket.
|
|
|
67
67
|
| A hint on hover or on keyboard focus | **Tooltip** / **WithTooltip** — one `TooltipProvider` at the app root shares the delay |
|
|
68
68
|
| A strip of controls that act on one thing | **Toolbar** — one Tab stop for the row, arrow keys along it |
|
|
69
69
|
| Reactions to choose from | **ReactionPicker** — the row; **Reaction** is the pill it produces |
|
|
70
|
+
| The reactions under something people react to, and adding one | **ReactionRow** — the pills, who reacted, and the picker; **AddReactionButton** alone while nobody has reacted |
|
|
70
71
|
| One window to find something and act on it, opened by a shortcut | **CommandPalette** — rows, forms and written answers, one level at a time |
|
|
71
72
|
| A list that opens as you type in an editor — `/` for commands, `@` for people | **SuggestionMenu** — the editor keeps the caret and hands it the arrow keys; `suggestionPopup` from `@estiva-app/ui/editor` wires it to a Tiptap plugin |
|
|
72
73
|
| Bold, italic and the like over selected text in an editor | **SelectionToolbar**, from `@estiva-app/ui/editor` — it follows the selection by itself |
|
|
73
74
|
| A composer's `@`, `!@`, `[` and `/` — mention a person, reference something, format or insert | **ComposerTriggers** — `PersonMention`, `UrgentPersonMention`, `CaptionedReference`, `ReferenceTrigger` and `SlashCommands` from `@estiva-app/ui/editor`; the app passes its people, its items and its own `/` rows |
|
|
74
75
|
| An editor that saves a block document and must keep its block ids | **BlockNodes** — `BlockId`, `UnknownBlock`, `ReferenceNode` and `AttachmentNode` from `@estiva-app/ui/editor`, beside StarterKit and TableKit |
|
|
75
76
|
| A page's title or the line under it, edited where it stands, as in a document | **InlineText**, from `@estiva-app/ui/editor` — no box; Enter saves and moves on |
|
|
76
|
-
|
|
|
77
|
+
| A comment, a reply or a line written and sent, in any app | **CommentBox**, from `@estiva-app/ui/editor` — triggers, keys, drafts, files, editing and a refused send; the app supplies its people, its `[` sections, its `/` rows and a send |
|
|
78
|
+
| The box alone, around an editor the app makes itself | **ComposeBox**, from `@estiva-app/ui/editor` — the app brings its editor and adds `ComposeKeys` |
|
|
77
79
|
| Comments on words, a passage or whole blocks of a document, drawn where they are | **CommentHighlights**, from `@estiva-app/ui/editor` — a run of blocks and the words quoted; says which was clicked and which moved or are gone |
|
|
78
80
|
| Move, turn, duplicate or delete one block of a document being edited | **EditorBlockHandle**, from `@estiva-app/ui/editor`, with your rows after its own |
|
|
79
81
|
| Add or delete a table's rows and columns in a document being edited | **EditorTableControls**, from `@estiva-app/ui/editor`, inside the EditorBlockHandle |
|
|
@@ -146,6 +148,7 @@ the **floating** TopBar goes with the **Rail** and the content card.
|
|
|
146
148
|
| A 64px icon strip | **Rail**, filled with **RailItem** tiles |
|
|
147
149
|
| The menu button and the logo | the TopBar's `menu` and `logo` slots — collapsing stays yours |
|
|
148
150
|
| Where pictures come from, and how to change page without a reload, said once | **AppProvider**, around the whole app |
|
|
151
|
+
| What shows while nobody is signed in: the logo, one line, at most one button | **EntryShell** — in place of the whole app; `busy` while entry is decided |
|
|
149
152
|
| The list beside the thing that is open | **ListColumn** — 290px, its name in a **ContainerHeader**, the list under it scrolling |
|
|
150
153
|
| A panel of a page that is not a list — details, a thread, what is open — with a body that must never be cut off | **Panel** — a header, a body that scrolls whenever it is taller, and a `footer` that stays put |
|
|
151
154
|
|