@estiva-app/ui 0.98.0 → 0.99.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.
Files changed (193) hide show
  1. package/README.md +1 -1
  2. package/dist/AppProvider.d.ts +6 -3
  3. package/dist/AppProvider.d.ts.map +1 -1
  4. package/dist/ArchiveDialog.d.ts +35 -0
  5. package/dist/ArchiveDialog.d.ts.map +1 -0
  6. package/dist/AttachedCard.d.ts +13 -2
  7. package/dist/AttachedCard.d.ts.map +1 -1
  8. package/dist/Card.d.ts +6 -1
  9. package/dist/Card.d.ts.map +1 -1
  10. package/dist/ChipInput.d.ts +3 -1
  11. package/dist/ChipInput.d.ts.map +1 -1
  12. package/dist/CollapsibleSection.d.ts +27 -2
  13. package/dist/CollapsibleSection.d.ts.map +1 -1
  14. package/dist/CommentBox.d.ts +2 -2
  15. package/dist/CommentBox.d.ts.map +1 -1
  16. package/dist/ConfirmDialog.d.ts +15 -2
  17. package/dist/ConfirmDialog.d.ts.map +1 -1
  18. package/dist/ConversationCard.d.ts +6 -1
  19. package/dist/ConversationCard.d.ts.map +1 -1
  20. package/dist/ConversationLayout.d.ts +19 -4
  21. package/dist/ConversationLayout.d.ts.map +1 -1
  22. package/dist/ConversationPlace.d.ts +17 -0
  23. package/dist/ConversationPlace.d.ts.map +1 -0
  24. package/dist/DocumentEditor.d.ts +38 -0
  25. package/dist/DocumentEditor.d.ts.map +1 -1
  26. package/dist/DocumentField.d.ts +50 -0
  27. package/dist/DocumentField.d.ts.map +1 -0
  28. package/dist/EditableText.d.ts +38 -4
  29. package/dist/EditableText.d.ts.map +1 -1
  30. package/dist/EmptyState.d.ts +10 -5
  31. package/dist/EmptyState.d.ts.map +1 -1
  32. package/dist/FormDialog.d.ts +38 -0
  33. package/dist/FormDialog.d.ts.map +1 -0
  34. package/dist/InlineText.d.ts.map +1 -1
  35. package/dist/MoveDialog.d.ts +61 -0
  36. package/dist/MoveDialog.d.ts.map +1 -0
  37. package/dist/NavItem.d.ts +9 -2
  38. package/dist/NavItem.d.ts.map +1 -1
  39. package/dist/NavTree.d.ts +16 -3
  40. package/dist/NavTree.d.ts.map +1 -1
  41. package/dist/PinnedComment.d.ts +3 -1
  42. package/dist/PinnedComment.d.ts.map +1 -1
  43. package/dist/ReactionHorizon.d.ts +5 -1
  44. package/dist/ReactionHorizon.d.ts.map +1 -1
  45. package/dist/ResolveDialog.d.ts +3 -1
  46. package/dist/ResolveDialog.d.ts.map +1 -1
  47. package/dist/SelectionToolbar.d.ts +2 -2
  48. package/dist/Thread.d.ts +6 -3
  49. package/dist/Thread.d.ts.map +1 -1
  50. package/dist/commentBoxFrame.d.ts.map +1 -1
  51. package/dist/conversation.examples.d.ts +4 -1
  52. package/dist/conversation.examples.d.ts.map +1 -1
  53. package/dist/conversationScroll.d.ts +80 -0
  54. package/dist/conversationScroll.d.ts.map +1 -0
  55. package/dist/editor.d.ts +1 -0
  56. package/dist/editor.d.ts.map +1 -1
  57. package/dist/editor.js +228 -69
  58. package/dist/editor.js.map +4 -4
  59. package/dist/eslint/index.js +2 -2
  60. package/dist/eslint/index.js.map +2 -2
  61. package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
  62. package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
  63. package/dist/eslint/no-native-title.d.ts +1 -1
  64. package/dist/eslint/no-native-title.d.ts.map +1 -1
  65. package/dist/formBusy.d.ts +5 -2
  66. package/dist/formBusy.d.ts.map +1 -1
  67. package/dist/index.d.ts +14 -6
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +2210 -1458
  70. package/dist/index.js.map +4 -4
  71. package/dist/looks.d.ts +8 -0
  72. package/dist/looks.d.ts.map +1 -1
  73. package/dist/seenOnScreen.d.ts +27 -0
  74. package/dist/seenOnScreen.d.ts.map +1 -0
  75. package/dist/showInConversation.d.ts +31 -0
  76. package/dist/showInConversation.d.ts.map +1 -0
  77. package/dist/threadCard.d.ts +13 -0
  78. package/dist/threadCard.d.ts.map +1 -1
  79. package/package.json +1 -1
  80. package/registry.json +904 -139
  81. package/src/AppProvider.mdx +4 -0
  82. package/src/AppProvider.test.tsx +34 -2
  83. package/src/AppProvider.tsx +17 -6
  84. package/src/ArchiveDialog.mdx +70 -0
  85. package/src/ArchiveDialog.stories.tsx +64 -0
  86. package/src/ArchiveDialog.test.tsx +90 -0
  87. package/src/ArchiveDialog.tsx +70 -0
  88. package/src/AttachedCard.mdx +6 -0
  89. package/src/AttachedCard.stories.tsx +9 -1
  90. package/src/AttachedCard.test.tsx +111 -2
  91. package/src/AttachedCard.tsx +77 -7
  92. package/src/Card.mdx +20 -1
  93. package/src/Card.stories.tsx +20 -0
  94. package/src/Card.test.tsx +87 -1
  95. package/src/Card.tsx +51 -3
  96. package/src/ChipInput.mdx +7 -1
  97. package/src/ChipInput.stories.tsx +9 -0
  98. package/src/ChipInput.test.tsx +42 -0
  99. package/src/ChipInput.tsx +7 -3
  100. package/src/CollapsibleSection.mdx +20 -1
  101. package/src/CollapsibleSection.stories.tsx +19 -1
  102. package/src/CollapsibleSection.test.tsx +85 -2
  103. package/src/CollapsibleSection.tsx +54 -15
  104. package/src/CommentBox.mdx +2 -1
  105. package/src/CommentBox.test.tsx +81 -1
  106. package/src/CommentBox.tsx +32 -11
  107. package/src/ConfirmDialog.mdx +25 -3
  108. package/src/ConfirmDialog.stories.tsx +27 -0
  109. package/src/ConfirmDialog.test.tsx +87 -1
  110. package/src/ConfirmDialog.tsx +39 -8
  111. package/src/ConversationCard.mdx +4 -0
  112. package/src/ConversationCard.stories.tsx +11 -1
  113. package/src/ConversationCard.test.tsx +116 -0
  114. package/src/ConversationCard.tsx +53 -36
  115. package/src/ConversationLayout.mdx +30 -4
  116. package/src/ConversationLayout.scroll.test.tsx +411 -0
  117. package/src/ConversationLayout.stories.tsx +79 -1
  118. package/src/ConversationLayout.test.tsx +79 -0
  119. package/src/ConversationLayout.tsx +136 -15
  120. package/src/ConversationPlace.mdx +53 -0
  121. package/src/ConversationPlace.stories.tsx +48 -0
  122. package/src/ConversationPlace.test.tsx +51 -0
  123. package/src/ConversationPlace.tsx +30 -0
  124. package/src/DocumentEditor.mdx +2 -1
  125. package/src/DocumentEditor.tsx +118 -64
  126. package/src/DocumentField.mdx +83 -0
  127. package/src/DocumentField.stories.tsx +110 -0
  128. package/src/DocumentField.test.tsx +281 -0
  129. package/src/DocumentField.tsx +199 -0
  130. package/src/EditableText.buttons.test.tsx +318 -0
  131. package/src/EditableText.mdx +50 -2
  132. package/src/EditableText.stories.tsx +96 -2
  133. package/src/EditableText.tsx +189 -5
  134. package/src/EmptyState.mdx +33 -8
  135. package/src/EmptyState.stories.tsx +26 -1
  136. package/src/EmptyState.test.tsx +63 -2
  137. package/src/EmptyState.tsx +28 -6
  138. package/src/Form.mdx +3 -1
  139. package/src/FormDialog.mdx +78 -0
  140. package/src/FormDialog.stories.tsx +90 -0
  141. package/src/FormDialog.test.tsx +183 -0
  142. package/src/FormDialog.tsx +93 -0
  143. package/src/InlineText.mdx +1 -0
  144. package/src/InlineText.tsx +2 -1
  145. package/src/MoveDialog.mdx +74 -0
  146. package/src/MoveDialog.stories.tsx +121 -0
  147. package/src/MoveDialog.test.tsx +203 -0
  148. package/src/MoveDialog.tsx +183 -0
  149. package/src/NavItem.mdx +15 -0
  150. package/src/NavItem.stories.tsx +15 -0
  151. package/src/NavItem.test.tsx +64 -1
  152. package/src/NavItem.tsx +10 -2
  153. package/src/NavTree.mdx +26 -4
  154. package/src/NavTree.stories.tsx +59 -0
  155. package/src/NavTree.test.tsx +232 -2
  156. package/src/NavTree.tsx +93 -43
  157. package/src/PinnedComment.mdx +6 -1
  158. package/src/PinnedComment.stories.tsx +11 -1
  159. package/src/PinnedComment.tsx +15 -2
  160. package/src/ReactionHorizon.mdx +3 -0
  161. package/src/ReactionHorizon.stories.tsx +3 -0
  162. package/src/ReactionHorizon.test.tsx +55 -0
  163. package/src/ReactionHorizon.tsx +30 -11
  164. package/src/ReplyCard.mdx +3 -0
  165. package/src/ReplyCard.stories.tsx +19 -1
  166. package/src/ResolveDialog.mdx +2 -0
  167. package/src/ResolveDialog.test.tsx +21 -0
  168. package/src/ResolveDialog.tsx +11 -39
  169. package/src/SelectionToolbar.tsx +2 -2
  170. package/src/Textarea.mdx +1 -0
  171. package/src/Thread.mdx +18 -1
  172. package/src/Thread.stories.tsx +55 -3
  173. package/src/Thread.test.tsx +11 -0
  174. package/src/Thread.tsx +53 -11
  175. package/src/commentBoxFrame.tsx +2 -2
  176. package/src/conversation.examples.tsx +10 -2
  177. package/src/conversationScroll.ts +155 -0
  178. package/src/editor.ts +1 -0
  179. package/src/editorSelection.test.tsx +53 -0
  180. package/src/eslint/no-field-outside-a-form.test.ts +4 -0
  181. package/src/eslint/no-field-outside-a-form.ts +2 -2
  182. package/src/eslint/no-native-title.ts +1 -1
  183. package/src/formBusy.ts +5 -2
  184. package/src/index.ts +16 -6
  185. package/src/looks.ts +10 -0
  186. package/src/registry/registry.test.ts +12 -6
  187. package/src/seenOnScreen.test.tsx +182 -0
  188. package/src/seenOnScreen.ts +146 -0
  189. package/src/showInConversation.test.tsx +168 -0
  190. package/src/showInConversation.ts +93 -0
  191. package/src/threadCard.ts +16 -0
  192. package/stories/Choosing.mdx +7 -2
  193. package/tailwind-preset.js +7 -0
@@ -12,32 +12,102 @@
12
12
  * it, and an app that draws its sent card as an `AttachedCard` hands it that,
13
13
  * so the box's ✕ is the one (Katerina, 30 Oct: no card in a card).
14
14
  */
15
- import { createContext, useContext, type ReactNode } from 'react'
15
+ import { createContext, useContext, useEffect, useRef, type ReactNode, type RefObject } from 'react'
16
16
  import { RemoveBadge } from './AttachmentCard'
17
17
  import { LinkCard } from './LinkCard'
18
- import type { LinkState } from './linked'
18
+ import { loadingShapeOf, type CardShapeMemory, type LinkState, type LoadingShape } from './linked'
19
19
 
20
20
  interface AttachedCardBase {
21
21
  /** Draws the ✕. Without it the card shows with none, as it does to anyone but the author. */
22
22
  onRemove?: () => void
23
23
  }
24
24
 
25
+ /** Where a card's shape is kept between loads: the app's `cardShapeMemory`, and the card's id in it (its address). */
26
+ export interface AttachedCardMemory {
27
+ memory: CardShapeMemory
28
+ id: string
29
+ }
30
+
25
31
  /**
26
32
  * The card is a `LinkCard` of `link`, or the app's own card as `children`: an
27
33
  * app that draws a sent card itself draws the one in its box the same way.
28
34
  */
29
- export type AttachedCardProps = AttachedCardBase & ({ link: LinkState; children?: never } | { link?: never; children: ReactNode })
35
+ export type AttachedCardProps = AttachedCardBase &
36
+ (
37
+ | {
38
+ link: LinkState
39
+ /**
40
+ * Keeps its height while it loads: the card it draws is measured and noted in `memory` under `id`, and the
41
+ * next time it loads it holds that height and that shape, so nothing around it moves.
42
+ */
43
+ remember?: AttachedCardMemory
44
+ children?: never
45
+ }
46
+ | { link?: never; remember?: never; children: ReactNode }
47
+ )
30
48
 
31
49
  /** Inside an `AttachedCard`: one inside it draws only its card. */
32
50
  const Attached = createContext(false)
33
51
 
34
- export function AttachedCard({ link, children, onRemove }: AttachedCardProps) {
35
- const card = link ? <LinkCard link={link} /> : children
52
+ /**
53
+ * A card that keeps its height while it loads (Peek's peek#533 and #534, then Ship's copy, moved here so no app
54
+ * measures its own): drawn, its shape and height are noted, and noted again once a resize settles; loading, it holds
55
+ * the height and the shape it last drew at on this device. Returns the shape to load with and the height to hold.
56
+ */
57
+ function useRememberedHeight(link: LinkState | undefined, remember: AttachedCardMemory | undefined, box: RefObject<HTMLDivElement | null>) {
58
+ const memory = remember?.memory
59
+ const id = remember?.id
60
+ const kept = memory && id && link?.state === 'loading' ? memory.of(id, link.kind) : undefined
61
+ // The drawn card's shape, kept for its placeholder next time; the height holds what the shape cannot say: a summary
62
+ // the kit wraps to two lines.
63
+ const shapeKey = memory && id && link?.state === 'ready' ? JSON.stringify(loadingShapeOf(link.linked)) : undefined
64
+ const kind = link?.state === 'ready' ? link.linked.kind : link?.kind
65
+ useEffect(() => {
66
+ const card = box.current
67
+ if (!memory || !id || !kind || !shapeKey || !card) return
68
+ const drawn = JSON.parse(shapeKey) as LoadingShape
69
+ // A card not on screen (a closed panel) measures 0: it keeps the height it last drew at.
70
+ const note = () => {
71
+ const height = Math.round(card.getBoundingClientRect().height)
72
+ memory.note(id, height > 0 ? { ...drawn, height } : { ...drawn, height: memory.of(id, kind)?.height })
73
+ }
74
+ note()
75
+ if (typeof ResizeObserver === 'undefined') return
76
+ // A window being resized changes every card's height each frame: note it once it settles.
77
+ let settle: ReturnType<typeof setTimeout> | undefined
78
+ const observer = new ResizeObserver(() => {
79
+ clearTimeout(settle)
80
+ settle = setTimeout(note, 500)
81
+ })
82
+ observer.observe(card)
83
+ return () => {
84
+ observer.disconnect()
85
+ clearTimeout(settle)
86
+ }
87
+ }, [box, memory, id, kind, shapeKey])
88
+ return { kept, held: kept?.height ? { minHeight: kept.height } : undefined }
89
+ }
90
+
91
+ export function AttachedCard({ link, children, onRemove, remember }: AttachedCardProps) {
92
+ const box = useRef<HTMLDivElement>(null)
93
+ const { kept, held } = useRememberedHeight(link, remember, box)
94
+ // Loading with no shape of the app's own: the one it last drew at here.
95
+ const shown = link?.state === 'loading' && !link.shape && kept ? { ...link, shape: kept } : link
96
+ const card = shown ? <LinkCard link={shown} /> : children
36
97
  const inside = useContext(Attached)
37
- if (inside) return <>{card}</>
98
+ if (inside) {
99
+ // Only its card, as one inside another draws; remembered, in a plain box of its own that measures and holds it.
100
+ return remember ? (
101
+ <div ref={box} style={held}>
102
+ {card}
103
+ </div>
104
+ ) : (
105
+ <>{card}</>
106
+ )
107
+ }
38
108
  return (
39
109
  // At most 480px, so it never runs a column's or a wide box's whole width (Katerina, 29 and 30 Oct).
40
- <div className="group/card relative max-w-[480px]">
110
+ <div ref={box} className="group/card relative max-w-[480px]" style={held}>
41
111
  <Attached.Provider value>{card}</Attached.Provider>
42
112
  {onRemove && (
43
113
  <RemoveBadge
package/src/Card.mdx CHANGED
@@ -27,6 +27,8 @@ move it.
27
27
  hover.
28
28
  - `hover="fill"` — a card in a feed: it lights up when pointed at, so the light
29
29
  says which one you are on. `quietUntilHover` hides its hairline until then.
30
+ - `onPress` — the card opens what it stands for: a press anywhere on it but on
31
+ a button, a link or a field inside it, and Enter or Space once Tab reaches it.
30
32
  - `hovered` — hold that look while the pointer is elsewhere: a card whose own
31
33
  menu or picker is open stays lit, because the menu opens outside the card.
32
34
  - `selected` — the one you are on. `active` — the one being changed in place.
@@ -38,6 +40,8 @@ move it.
38
40
 
39
41
  <Canvas of={CardStories.InAFeed} />
40
42
 
43
+ <Canvas of={CardStories.OpensOnAPress} />
44
+
41
45
  ## When not
42
46
 
43
47
  - You type in it → **TextInput**, **Textarea**, or your editor's box — a field,
@@ -63,6 +67,11 @@ import { Card } from '@estiva-app/ui'
63
67
  the content pad itself.
64
68
  - With `href` it renders `Link`'s anchor, with every anchor prop passed through,
65
69
  so it changes page as **Link** does and the address stays real.
70
+ - A card that opens on a press takes `onPress`, not `onClick`: it works out for you
71
+ whether a press was on the card or on a control inside it, a menu it opened
72
+ (outside it in the page), a double click or words being picked, and it is
73
+ a Tab stop that Enter and Space open. `onClick` stays for a card that only
74
+ needs the click.
66
75
  - Without `href`, a card that responds to a click gets `cursor-pointer` from its
67
76
  `hover` and your `onClick` — the selected one too, since it can open again;
68
77
  the one being changed does not. Controls inside it should stop their own
@@ -87,7 +96,17 @@ It does these by itself. Write none of them around it.
87
96
  | It does | So you never write | Refused when written by hand |
88
97
  |---|---|---|
89
98
  | With `href`, becomes a link: Link's anchor, with a real address | an anchor around the card | |
90
- | Without `href`, shows it can be clicked when you pass `onClick` | `cursor-pointer` | |
99
+ | Without `href`, shows it can be clicked when you pass `onClick` or `onPress` | `cursor-pointer` | |
100
+ | With `onPress`: a press on the card, never on a button, link, field or menu inside it, nor a double click or picked words; a Tab stop, opened by Enter and Space | a click guard (`closest('button')`), a key handler, a `tabIndex` | |
101
+
102
+ ## Keys
103
+
104
+ With `onPress`:
105
+
106
+ | Input | What happens |
107
+ |---|---|
108
+ | Tab | stops on the card |
109
+ | Enter / Space | on the card: opens it; on a button, a link or a field inside it: that control's own |
91
110
 
92
111
  ## Props
93
112
 
@@ -1,4 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { fn } from 'storybook/test'
3
+ import { Button } from './Button'
2
4
  import { Card } from './Card'
3
5
 
4
6
  const Body = ({ title = 'Item one', line = 'A line about the item.' }: { title?: string; line?: string }) => (
@@ -75,6 +77,24 @@ export const InAFeed: Story = {
75
77
  ),
76
78
  }
77
79
 
80
+ /** It opens on a press: anywhere on it but on its own button, and by Enter or Space once Tab reaches it. */
81
+ export const OpensOnAPress: Story = {
82
+ args: {
83
+ hover: 'fill',
84
+ quietUntilHover: true,
85
+ onPress: fn(),
86
+ className: 'flex w-[280px] flex-col items-start gap-3 p-3',
87
+ children: (
88
+ <>
89
+ <Body />
90
+ <Button variant="outlined" size="small">
91
+ Action
92
+ </Button>
93
+ </>
94
+ ),
95
+ },
96
+ }
97
+
78
98
  /** Its menu is open: the pointer is on the menu, outside the card, and the card stays lit under it. */
79
99
  export const HeldWhileItsMenuIsOpen: Story = { args: { hover: 'fill', quietUntilHover: true, hovered: true, onClick: () => {}, className: 'p-3' } }
80
100
 
package/src/Card.test.tsx CHANGED
@@ -8,7 +8,8 @@
8
8
  * dashed; and the caller's className — placement, padding, layout — lands last.
9
9
  */
10
10
  import { afterEach, describe, expect, it, vi } from 'vitest'
11
- import { cleanup, render, screen } from '@testing-library/react'
11
+ import { createPortal } from 'react-dom'
12
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react'
12
13
  import userEvent from '@testing-library/user-event'
13
14
  import { Card } from './Card'
14
15
 
@@ -145,3 +146,88 @@ describe('Card', () => {
145
146
  expect(classes).toContain('p-3')
146
147
  })
147
148
  })
149
+
150
+ /*
151
+ A card that opens what it stands for on a press (`onPress`): ConversationCard's press, which every card now has. A
152
+ press on what acts by itself inside it is that control's; so is a press in a menu the card opened, which lands
153
+ outside it in the page but reaches it through React's tree (Peek's Screener row, which worked this out by hand).
154
+ */
155
+ describe('Card, pressed', () => {
156
+ it('opens on a press anywhere on it', () => {
157
+ const onPress = vi.fn()
158
+ render(<Card hover="fill" onPress={onPress}><p>Item one</p></Card>)
159
+ fireEvent.click(screen.getByText('Item one'))
160
+ expect(onPress).toHaveBeenCalledTimes(1)
161
+ })
162
+
163
+ it('a press on a button, a link or a field inside it is theirs, not the card’s', () => {
164
+ const onPress = vi.fn()
165
+ const onAct = vi.fn()
166
+ render(
167
+ <Card hover="fill" onPress={onPress}>
168
+ <p>Item one</p>
169
+ <button type="button" onClick={onAct}>Act</button>
170
+ <a href="#somewhere">Go</a>
171
+ <input aria-label="Field" />
172
+ <span role="button" tabIndex={0}>Also acts</span>
173
+ <span data-interactive="">Its own</span>
174
+ </Card>,
175
+ )
176
+ fireEvent.click(screen.getByRole('button', { name: 'Act' }))
177
+ fireEvent.click(screen.getByRole('link', { name: 'Go' }))
178
+ fireEvent.click(screen.getByRole('textbox', { name: 'Field' }))
179
+ fireEvent.click(screen.getByRole('button', { name: 'Also acts' }))
180
+ fireEvent.click(screen.getByText('Its own'))
181
+ expect(onAct).toHaveBeenCalledTimes(1)
182
+ expect(onPress).not.toHaveBeenCalled()
183
+ })
184
+
185
+ it('a press in a menu it opened, outside it in the page, is not a press on it', () => {
186
+ const onPress = vi.fn()
187
+ render(
188
+ <Card hover="fill" onPress={onPress}>
189
+ <p>Item one</p>
190
+ {createPortal(<div role="menu"><span>Later today</span></div>, document.body)}
191
+ </Card>,
192
+ )
193
+ fireEvent.click(screen.getByText('Later today'))
194
+ expect(onPress).not.toHaveBeenCalled()
195
+ })
196
+
197
+ it('a double click, or words picked on it, is not a press', () => {
198
+ const onPress = vi.fn()
199
+ render(<Card hover="fill" onPress={onPress}><p>Item one</p></Card>)
200
+ fireEvent.click(screen.getByText('Item one'), { detail: 2 })
201
+ const words = document.createRange()
202
+ words.selectNodeContents(screen.getByText('Item one'))
203
+ window.getSelection()?.removeAllRanges()
204
+ window.getSelection()?.addRange(words)
205
+ fireEvent.click(screen.getByText('Item one'), { detail: 1 })
206
+ window.getSelection()?.removeAllRanges()
207
+ expect(onPress).not.toHaveBeenCalled()
208
+ })
209
+
210
+ it('Tab stops on it, and Enter or Space opens it; a key on a control inside it is the control’s', async () => {
211
+ const onPress = vi.fn()
212
+ render(
213
+ <Card hover="fill" onPress={onPress}>
214
+ <p>Item one</p>
215
+ <button type="button">Act</button>
216
+ </Card>,
217
+ )
218
+ await userEvent.tab()
219
+ const pressable = screen.getByText('Item one').closest('div')!
220
+ expect(document.activeElement).toBe(pressable)
221
+ fireEvent.keyDown(pressable, { key: 'Enter' })
222
+ fireEvent.keyDown(pressable, { key: ' ' })
223
+ expect(onPress).toHaveBeenCalledTimes(2)
224
+ fireEvent.keyDown(screen.getByRole('button', { name: 'Act' }), { key: 'Enter' })
225
+ expect(onPress).toHaveBeenCalledTimes(2)
226
+ })
227
+
228
+ it('shows it can be pressed, and a card with nothing to press is no Tab stop', () => {
229
+ expect(classesOf(card(<Card hover="fill" onPress={() => {}}>Item one</Card>))).toContain('cursor-pointer')
230
+ cleanup()
231
+ expect(card(<Card hover="fill">Item one</Card>).getAttribute('tabindex')).toBeNull()
232
+ })
233
+ })
package/src/Card.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import type { ComponentPropsWithRef, ReactNode } from 'react'
1
+ import type { ComponentPropsWithRef, KeyboardEvent, MouseEvent, ReactNode } from 'react'
2
2
  import { cn } from './cn'
3
3
  import { Link } from './Link'
4
4
 
@@ -92,9 +92,32 @@ export interface CardProps extends ComponentPropsWithRef<'div'> {
92
92
  * runs edge to edge (UIG-9, 17 September; the apps passed `overflow-hidden`).
93
93
  */
94
94
  clip?: boolean
95
+ /**
96
+ * Pressing the card opens what it stands for: a click anywhere on it but on what acts by itself inside it, and Enter
97
+ * or Space on the card itself, which is a Tab stop. Without `href`.
98
+ */
99
+ onPress?: () => void
95
100
  children: ReactNode
96
101
  }
97
102
 
103
+ /** What acts by itself inside a card: a press on it is its own, never the card's. */
104
+ const ACTS_BY_ITSELF = 'button, a, input, textarea, [contenteditable="true"], [role="button"], [role="toolbar"], [data-interactive]'
105
+
106
+ /**
107
+ * Whether a click is a press on the card: anywhere on it, but for what acts by itself (a button, a link, a field, a
108
+ * toolbar). A click in a picker or a menu the card opened lands here too, through React's tree, from outside the card:
109
+ * that is not a press on it. A double click picks a word and a drag picks words: neither is a press, or what the card
110
+ * opens would open and close under the reader. ConversationCard's press (Katerina, 31 October), for every card.
111
+ */
112
+ function isPress(event: MouseEvent<HTMLElement>): boolean {
113
+ const target = event.target as HTMLElement
114
+ if (!event.currentTarget.contains(target)) return false
115
+ if (event.detail > 1) return false
116
+ const picked = typeof window === 'undefined' ? null : window.getSelection()
117
+ if (picked && !picked.isCollapsed && picked.anchorNode && event.currentTarget.contains(picked.anchorNode)) return false
118
+ return !target.closest(ACTS_BY_ITSELF)
119
+ }
120
+
98
121
  export function Card({
99
122
  fill = 'surface',
100
123
  href,
@@ -106,6 +129,7 @@ export function Card({
106
129
  attention,
107
130
  unreadable = false,
108
131
  clip = false,
132
+ onPress,
109
133
  className,
110
134
  children,
111
135
  ...props
@@ -122,7 +146,7 @@ export function Card({
122
146
  !still && hovered && hover === 'hairline' && HAIRLINE_HELD_CLASSES[fill],
123
147
  !still && hovered && hover === 'fill' && 'bg-bg-hover border-border-default',
124
148
  // The one you are on can still be clicked (it opens again); the one being changed cannot.
125
- !active && hover !== 'none' && !href && props.onClick && 'cursor-pointer',
149
+ !active && hover !== 'none' && !href && (props.onClick || onPress) && 'cursor-pointer',
126
150
  selected && 'bg-bg-selected border-border-subtle',
127
151
  active && 'bg-bg-selected border-accent-primary',
128
152
  !active && attention && ATTENTION_CLASSES[attention],
@@ -142,7 +166,31 @@ export function Card({
142
166
  }
143
167
  return (
144
168
  // @estiva-escape(no-copied-look): N6 (Katerina, 24 September: leave alone): a card that cuts its content to its corners shares four words with the palette's window by coincidence
145
- <div className={classes} {...props}>
169
+ <div
170
+ className={classes}
171
+ // A card that opens on a press is reached by the keyboard too: Tab stops on it, and Enter or Space opens it. Only
172
+ // the card's own focus: a key in a link, a button or a field inside it is theirs.
173
+ {...props}
174
+ tabIndex={props.tabIndex ?? (onPress ? 0 : undefined)}
175
+ onClick={
176
+ onPress
177
+ ? (event: MouseEvent<HTMLDivElement>) => {
178
+ props.onClick?.(event)
179
+ if (isPress(event)) onPress()
180
+ }
181
+ : props.onClick
182
+ }
183
+ onKeyDown={
184
+ onPress
185
+ ? (event: KeyboardEvent<HTMLDivElement>) => {
186
+ props.onKeyDown?.(event)
187
+ if (event.target !== event.currentTarget || (event.key !== 'Enter' && event.key !== ' ')) return
188
+ event.preventDefault()
189
+ onPress()
190
+ }
191
+ : props.onKeyDown
192
+ }
193
+ >
146
194
  {children}
147
195
  </div>
148
196
  )
package/src/ChipInput.mdx CHANGED
@@ -16,6 +16,10 @@ leading slots.
16
16
 
17
17
  - Choosing several entries from a directory: members for a group,
18
18
  recipients, tags.
19
+ - **One** entry from a directory too large to list, found by typing — an
20
+ owner, an assignee: `single`. A later pick replaces the chosen one.
21
+
22
+ <Canvas of={ChipInputStories.OnePerson} />
19
23
  - **InputChip** is exported on its own for the display-only case — chosen
20
24
  things shown somewhere no editing happens.
21
25
 
@@ -23,7 +27,7 @@ leading slots.
23
27
 
24
28
  ## When not
25
29
 
26
- - One value → **Select**.
30
+ - One value from a list short enough to read through → **Select**.
27
31
  - Free text that becomes an entry — it only picks from `options`; if
28
32
  typing must create things, that is your surface's logic around it.
29
33
 
@@ -51,6 +55,8 @@ const directory: { id: string; label: string; picture?: string }[] = people
51
55
  - `chipLeading` is 16px in a chip; `rowLeading` is 32px in a suggestion
52
56
  row. The chip's padding follows its contents — a face sits 2px from the
53
57
  edge, a bare label gets 8px.
58
+ - `single` holds one: a pick replaces the chip already there, and `onChange`
59
+ hands back a list of one (or none, after Backspace or the ✕).
54
60
  - Suggestions appear **only once the user types** — focusing must not drop
55
61
  the whole directory over the surface below.
56
62
  - It is a **combobox over a listbox**: focus stays in the text while the
@@ -66,6 +66,15 @@ export const WithChips: Story = {
66
66
  },
67
67
  }
68
68
 
69
+ /** `single`: one person — an owner. Type another name and pick it: it replaces the chip rather than joining it. */
70
+ export const OnePerson: Story = {
71
+ parameters: { controls: { disable: true } },
72
+ render: (args) => {
73
+ const [value, setValue] = useState<ChipInputOption[]>([PEOPLE[0]])
74
+ return <ChipInput {...args} {...personLeading} single value={value} onChange={setValue} placeholder="Search people…" />
75
+ },
76
+ }
77
+
69
78
  /** `excludeIds` keeps someone out of the suggestions — the current user, say. */
70
79
  export const ExcludingSomeone: Story = {
71
80
  parameters: { controls: { disable: true } },
@@ -132,6 +132,48 @@ describe('ChipInput', () => {
132
132
  expect(onChange).toHaveBeenLastCalledWith([PEOPLE[0]])
133
133
  })
134
134
 
135
+ describe('single: a field that holds one', () => {
136
+ function Single({ initial = [], onChange }: { initial?: ChipInputOption[]; onChange?: (v: ChipInputOption[]) => void }) {
137
+ const [value, setValue] = useState(initial)
138
+ return (
139
+ <ChipInput
140
+ single
141
+ value={value}
142
+ onChange={(next) => {
143
+ setValue(next)
144
+ onChange?.(next)
145
+ }}
146
+ options={PEOPLE}
147
+ placeholder="Search people"
148
+ />
149
+ )
150
+ }
151
+
152
+ it('a later pick replaces the one chosen, rather than adding a second', async () => {
153
+ const user = userEvent.setup()
154
+ const onChange = vi.fn()
155
+ render(<Single initial={[PEOPLE[0]]} onChange={onChange} />)
156
+ await user.type(screen.getByRole('combobox'), 'grace')
157
+ await screen.findByRole('listbox')
158
+ await user.keyboard('{ArrowDown}{Enter}')
159
+ expect(onChange).toHaveBeenLastCalledWith([PEOPLE[1]])
160
+ expect(screen.queryByRole('button', { name: 'Remove Ada Lovelace' })).toBeNull()
161
+ expect(screen.getByRole('button', { name: 'Remove Grace Hopper' })).toBeTruthy()
162
+ })
163
+
164
+ it('the first pick is the one, and Backspace still takes it', async () => {
165
+ const user = userEvent.setup()
166
+ const onChange = vi.fn()
167
+ render(<Single onChange={onChange} />)
168
+ await user.type(screen.getByRole('combobox'), 'ada')
169
+ await screen.findByRole('listbox')
170
+ await user.keyboard('{ArrowDown}{Enter}')
171
+ expect(onChange).toHaveBeenLastCalledWith([PEOPLE[0]])
172
+ await user.keyboard('{Backspace}')
173
+ expect(onChange).toHaveBeenLastCalledWith([])
174
+ })
175
+ })
176
+
135
177
  it('a chip’s ✕ removes that chip', async () => {
136
178
  const user = userEvent.setup()
137
179
  const onChange = vi.fn()
package/src/ChipInput.tsx CHANGED
@@ -5,7 +5,7 @@ import { IconX } from '@tabler/icons-react'
5
5
  import { cn } from './cn'
6
6
  import { MenuItem, MenuPanel } from './Menu'
7
7
  import { ScrollArea } from './ScrollArea'
8
- import { BARE_INPUT_CLASSES, FIELD_SHELL_CLASSES } from './looks'
8
+ import { BARE_INPUT_CLASSES, FIELD_SHELL_CLASSES, FIELD_SHELL_FOCUS_CLASSES } from './looks'
9
9
 
10
10
  /* The chip's own look, written once: `InputChip` draws it for a caller who
11
11
  wants a chip on its own, and `ChipInput` gives the same classes to Base UI's
@@ -144,6 +144,8 @@ export interface ChipInputProps<T extends ChipInputOption = ChipInputOption> {
144
144
  'aria-label'?: string
145
145
  /** The id of what names the field on the page — a visible "To:", say. */
146
146
  'aria-labelledby'?: string
147
+ /** It holds one — an owner, an assignee: a later pick replaces the chosen one rather than adding a second. */
148
+ single?: boolean
147
149
  }
148
150
 
149
151
  export function ChipInput<T extends ChipInputOption = ChipInputOption>({
@@ -155,6 +157,7 @@ export function ChipInput<T extends ChipInputOption = ChipInputOption>({
155
157
  excludeIds = [],
156
158
  chipLeading,
157
159
  rowLeading,
160
+ single = false,
158
161
  ...aria
159
162
  }: ChipInputProps<T>) {
160
163
  const [query, setQuery] = useState('')
@@ -233,7 +236,8 @@ export function ChipInput<T extends ChipInputOption = ChipInputOption>({
233
236
  items={available}
234
237
  value={value}
235
238
  onValueChange={(next) => {
236
- onChange(next as T[])
239
+ // One held: the pick just made is the last, and it replaces the one before.
240
+ onChange(single ? (next as T[]).slice(-1) : (next as T[]))
237
241
  setQuery('')
238
242
  }}
239
243
  inputValue={query}
@@ -246,7 +250,7 @@ export function ChipInput<T extends ChipInputOption = ChipInputOption>({
246
250
  >
247
251
  {/* The box the chips and the input share. `Combobox.Chips` is what makes
248
252
  the two one control for the keyboard; the look is what it always was. */}
249
- <Combobox.Chips ref={setBox} className={cn(FIELD_SHELL_CLASSES, 'focus-within:border-border-focus focus-within:hover:border-border-focus group-hover/field:focus-within:border-border-focus px-3 py-1.5 flex flex-wrap items-center gap-1.5 min-h-[38px] cursor-text signal:transition-shadow signal:focus-within:shadow-focus-ring')}>
253
+ <Combobox.Chips ref={setBox} className={cn(FIELD_SHELL_CLASSES, FIELD_SHELL_FOCUS_CLASSES, 'px-3 py-1.5 flex flex-wrap items-center gap-1.5 min-h-[38px] cursor-text')}>
250
254
  {value.map((option) => (
251
255
  <Combobox.Chip key={option.id} className={cn(CHIP_BOX, chipPadding(!!chipLeading, true))}>
252
256
  {chipLeading && <span className="flex shrink-0 items-center">{chipLeading(option)}</span>}
@@ -20,6 +20,15 @@ toggle, and the rows under it, sliding shut and open.
20
20
  reloads: this browser remembers, under that key. The app prefixes the
21
21
  key (`app.sidebar.starred`).
22
22
  - `open` + `onOpenChange` when the app owns the state.
23
+ - `useRememberedOpen(storageKey, fallback)` when the app must know whether
24
+ it is open before it draws the rows — rows read only once it opens: it
25
+ gives `open` and `onOpenChange` the memory `storageKey` keeps, in the same
26
+ words, known on the first draw. `fallback` decides until the reader does,
27
+ and stays live (open while it holds the current item); only the reader's
28
+ choice is remembered.
29
+
30
+ <Canvas of={CollapsibleSectionStories.RememberedByTheApp} />
31
+
23
32
  - `pending` when the rows are read as it opens and usually arrive quickly:
24
33
  the title turns open at once (and says `aria-busy`), the panel stays shut
25
34
  until `pending` is false, then opens once with every row. A skeleton that
@@ -53,6 +62,9 @@ composition lives:
53
62
  - Several panels where opening one closes the others → not here; that is
54
63
  an accordion, and no app has asked for one.
55
64
  - Content that appears on demand from a control elsewhere → **Popover**.
65
+ - A memory of the app's own beside `open` (`localStorage` read and written by
66
+ hand) → `useRememberedOpen`; or just `storageKey`, when nothing has to know
67
+ before the reader opens it.
56
68
 
57
69
  ## How
58
70
 
@@ -75,7 +87,14 @@ import { CollapsibleSection, NavItem } from '@estiva-app/ui'
75
87
  is the box the rows sit in: the gap between them.
76
88
  - A closed section stays closed whatever is selected inside it — the
77
89
  reader closed it. An app that wants it to spring open owns the state
78
- with `open`.
90
+ with `open`; `useRememberedOpen` keeps that state remembered.
91
+
92
+ ```tsx
93
+ const [open, setOpen] = useRememberedOpen(`app.sidebar.folder.${id}`, holdsCurrent)
94
+ <CollapsibleSection title={name} open={open} onOpenChange={setOpen}>
95
+ {open && <NavItem href={`/folder/${id}`} label="Read only once open" />}
96
+ </CollapsibleSection>
97
+ ```
79
98
  - A browser that blocks storage still gets a working section; it forgets.
80
99
 
81
100
  ## What it owns
@@ -1,7 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { IconPlus } from '@tabler/icons-react'
3
3
  import { Chip } from './Chip'
4
- import { CollapsibleSection } from './CollapsibleSection'
4
+ import { CollapsibleSection, useRememberedOpen } from './CollapsibleSection'
5
5
  import { MenuItem } from './Menu'
6
6
  import { NavItem } from './NavItem'
7
7
 
@@ -43,6 +43,24 @@ export const WithTrailing: Story = {
43
43
  /** Close it and reload the page: still closed. This browser remembers, under the key. */
44
44
  export const Remembered: Story = { args: { storageKey: 'estiva-ui.stories.collapsible-section' } }
45
45
 
46
+ /** `useRememberedOpen`: the app knows whether the section is open before it draws the rows, which it draws only while open, and this browser remembers it as `storageKey` does. Close it and reload: still closed, no rows drawn. */
47
+ export const RememberedByTheApp: Story = {
48
+ render: function Render(args) {
49
+ const [open, setOpen] = useRememberedOpen('estiva-ui.stories.collapsible-section.app', true)
50
+ return (
51
+ <CollapsibleSection {...args} open={open} onOpenChange={setOpen}>
52
+ {open && (
53
+ <>
54
+ <NavItem href="#" label="Item one" count={7} countLabel="7 open" />
55
+ <NavItem href="#" label="Item two" count={2} countLabel="2 open" />
56
+ <NavItem href="#" label="Item three" />
57
+ </>
58
+ )}
59
+ </CollapsibleSection>
60
+ )
61
+ },
62
+ }
63
+
46
64
 
47
65
  /** `look="row"`: a fold that is a row among rows — a folder in a sidebar. The title at a row's weight, the rows indented under it, past the chevron. */
48
66
  export const AsARow: Story = {