Skip to content

Commit c4542db

Browse files
committed
refactor(CommentPin): uncontrolled selection, Comments' person type, and ElementSize; the host hides resolved pins, and nothing dims
CommentPin's API pass before it moves to Core: - Selection takes `isSelected`, `defaultIsSelected`, and `onSelectedChange`. Activation by click, Enter, or Space runs `onClick`, then requests the opposite selection; a pin without `isSelected` also flips itself. A disabled pin does neither. - Participants are the Comments family's `CommentUser` records, read as `{id, name, src}`. `CommentUser.avatarUrl` becomes `src`, Avatar's word, and `CommentPinParticipant` and its `avatarSrc` go away. - `size` takes `ElementSize`; `CommentPinSize` goes away. Values, default, and geometry stay the same. - `isResolved` and its `resolved` theme state go away: a pin never removes itself, and the host stops rendering the pins it hides. The docs say where the host moves focus when it removes a focused pin. - `isDimmed`, its 0.4 opacity, and its `dimmed` theme state go away. The draft component record, docs, stories, and blocks follow.
1 parent d63c249 commit c4542db

14 files changed

Lines changed: 362 additions & 303 deletions

File tree

‎apps/storybook/stories/CommentPin.stories.tsx‎

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ const PEOPLE = {
1717
ada: {
1818
id: 'ada',
1919
name: 'Ada Lovelace',
20-
avatarSrc: 'https://i.pravatar.cc/80?img=47',
20+
src: 'https://i.pravatar.cc/80?img=47',
2121
},
2222
lin: {
2323
id: 'lin',
2424
name: 'Lin Chen',
25-
avatarSrc: 'https://i.pravatar.cc/80?img=32',
25+
src: 'https://i.pravatar.cc/80?img=32',
2626
},
2727
mira: {
2828
id: 'mira',
2929
name: 'Mira Patel',
30-
avatarSrc: 'https://i.pravatar.cc/80?img=5',
30+
src: 'https://i.pravatar.cc/80?img=5',
3131
},
3232
noah: {
3333
id: 'noah',
3434
name: 'Noah Williams',
35-
avatarSrc: 'https://i.pravatar.cc/80?img=12',
35+
src: 'https://i.pravatar.cc/80?img=12',
3636
},
3737
sam: {
3838
id: 'sam',
3939
name: 'Sam Rivera',
40-
avatarSrc: 'https://i.pravatar.cc/80?img=15',
40+
src: 'https://i.pravatar.cc/80?img=15',
4141
},
4242
};
4343

@@ -250,16 +250,6 @@ export const StateMatrix: Story = {
250250
</Text>
251251
<FocusedSelectedPin />
252252
</HStack>
253-
<HStack gap={4} xstyle={styles.row}>
254-
<Text type="supporting" xstyle={styles.stateLabel}>
255-
Other pin dimmed
256-
</Text>
257-
<CommentPin
258-
label="Open another annotation from Mira"
259-
participants={[PEOPLE.mira]}
260-
isDimmed
261-
/>
262-
</HStack>
263253
<HStack gap={4} xstyle={styles.row}>
264254
<Text type="supporting" xstyle={styles.stateLabel}>
265255
Grouped
@@ -324,18 +314,6 @@ export const StateMatrix: Story = {
324314
unreadCount={3}
325315
/>
326316
</HStack>
327-
<HStack gap={4} xstyle={styles.row}>
328-
<Text type="supporting" xstyle={styles.stateLabel}>
329-
Resolved, selected
330-
</Text>
331-
{/* An unselected resolved pin renders nothing. */}
332-
<CommentPin
333-
label="Current resolved annotation from Mira"
334-
participants={[PEOPLE.mira]}
335-
isResolved
336-
isSelected
337-
/>
338-
</HStack>
339317
<HStack gap={4} xstyle={styles.row}>
340318
<Text type="supporting" xstyle={styles.stateLabel}>
341319
Disabled / pending
@@ -356,9 +334,8 @@ export const OverContentAndInMargin: Story = {
356334
const [selected, setSelected] = useState<'content' | 'margin' | null>(
357335
'content',
358336
);
359-
// aria-pressed toggle semantics: activating the selected pin clears it.
360-
const toggle = (id: 'content' | 'margin') =>
361-
setSelected(current => (current === id ? null : id));
337+
const select = (id: 'content' | 'margin') => (isSelected: boolean) =>
338+
setSelected(isSelected ? id : null);
362339
return (
363340
<div {...stylex.props(styles.canvas)}>
364341
<img
@@ -371,17 +348,15 @@ export const OverContentAndInMargin: Story = {
371348
participants={[PEOPLE.ada, PEOPLE.lin]}
372349
threadCount={4}
373350
isSelected={selected === 'content'}
374-
isDimmed={selected != null && selected !== 'content'}
375-
onClick={() => toggle('content')}
351+
onSelectedChange={select('content')}
376352
xstyle={styles.overMarker}
377353
/>
378354
<div {...stylex.props(styles.margin)}>
379355
<CommentPin
380356
label="Open margin annotation from Mira"
381357
participants={[PEOPLE.mira]}
382358
isSelected={selected === 'margin'}
383-
isDimmed={selected != null && selected !== 'margin'}
384-
onClick={() => toggle('margin')}
359+
onSelectedChange={select('margin')}
385360
xstyle={styles.marginMarker}
386361
/>
387362
</div>

‎docs/specs/components/CommentPin/CommentPin.spec.md‎

Lines changed: 87 additions & 80 deletions
Large diffs are not rendered by default.

‎packages/lab/blocks/CommentPinInMargin.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: 'Host-owned placement',
77
displayName: 'Comment pin in a document margin',
88
description:
9-
'A caller-positioned CommentPin in a document margin. The host maps its anchor to the pin’s logical bottom-start corner and owns the surrounding layout; the pin owns its compact interactive surface. Activating the pin toggles its selected state.',
9+
'A caller-positioned CommentPin in a document margin. The host maps its anchor to the pin’s logical bottom-start corner and owns the surrounding layout; the pin owns its compact interactive surface. Activating the pin toggles its own selected state.',
1010
exampleFor: 'CommentPin',
1111
isReady: true,
1212
aspectRatio: 16 / 9,

‎packages/lab/blocks/CommentPinInMargin.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
'use client';
44

55
/**
6-
* @input A host-positioned CommentPin, its lead commenter, and local
7-
* selected state
6+
* @input A host-positioned CommentPin and its lead commenter
87
* @output A document passage with one comment pin in its margin; activating
9-
* the pin toggles its selection and aria-pressed state
8+
* the pin toggles its own selection and aria-pressed state
109
* @position Copyable Lab CommentPin placement example
1110
*/
1211

13-
import {useState} from 'react';
1412
import * as stylex from '@stylexjs/stylex';
1513
import {Card} from '@astryxdesign/core/Card';
1614
import {Text} from '@astryxdesign/core/Text';
@@ -45,7 +43,6 @@ const styles = stylex.create({
4543
});
4644

4745
export default function CommentPinInMargin() {
48-
const [isSelected, setIsSelected] = useState(false);
4946
return (
5047
<Card padding={0} width={520}>
5148
<div {...stylex.props(styles.document)}>
@@ -66,8 +63,6 @@ export default function CommentPinInMargin() {
6663
<CommentPin
6764
label="Open comment from Maya"
6865
participants={[{id: 'maya', name: 'Maya Chen'}]}
69-
isSelected={isSelected}
70-
onClick={() => setIsSelected(current => !current)}
7166
xstyle={styles.pin}
7267
/>
7368
</div>

‎packages/lab/blocks/CommentPinShowcase.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: 'Avatar-first annotations',
77
displayName: 'Avatar-first annotations',
88
description:
9-
'Caller-positioned comment pins over media and in a content margin. Every coordinate maps to the pin’s logical bottom-start corner. The selected group caps its participants at three circles (two Avatars plus an ellipsis) and ends with its total and an accent unread dot; the unread margin pin shows the dot too. Other pins dim without becoming disabled, activating the selected pin again clears the selection, and no pin dims while nothing is selected.',
9+
'Caller-positioned comment pins over media and in a content margin. Every coordinate maps to the pin’s logical bottom-start corner. The selected group caps its participants at three circles (two Avatars plus an ellipsis) and ends with its total and an accent unread dot; the unread margin pin shows the dot too. The host keeps one pin selected through isSelected and onSelectedChange, and activating the selected pin again clears the selection.',
1010
exampleFor: 'CommentPin',
1111
isReady: true,
1212
isShowcase: true,

‎packages/lab/blocks/CommentPinShowcase.tsx‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
/**
66
* @input Three caller-positioned comment pins, logical bottom-start anchors,
7-
* participant/thread/unread counts, and controlled selected/dimmed state
8-
* that may be empty
7+
* participant/thread/unread counts, and one controlled selection that may
8+
* be empty
99
* @output A grouped pin with a three-circle participant cap and an unread
10-
* dot, a single pin, and an unread margin pin; activating the selected
11-
* pin clears the selection, and non-selected pins dim only while another pin
12-
* is selected
10+
* dot, a single pin, and an unread margin pin; selecting a pin clears the
11+
* others, and activating the selected pin clears the selection
1312
* @position CommentPin docsite showcase and copyable Lab block
1413
*/
1514

@@ -29,27 +28,27 @@ const PEOPLE = {
2928
ada: {
3029
id: 'ada',
3130
name: 'Ada Lovelace',
32-
avatarSrc: 'https://i.pravatar.cc/80?img=47',
31+
src: 'https://i.pravatar.cc/80?img=47',
3332
},
3433
lin: {
3534
id: 'lin',
3635
name: 'Lin Chen',
37-
avatarSrc: 'https://i.pravatar.cc/80?img=32',
36+
src: 'https://i.pravatar.cc/80?img=32',
3837
},
3938
mira: {
4039
id: 'mira',
4140
name: 'Mira Patel',
42-
avatarSrc: 'https://i.pravatar.cc/80?img=5',
41+
src: 'https://i.pravatar.cc/80?img=5',
4342
},
4443
noah: {
4544
id: 'noah',
4645
name: 'Noah Williams',
47-
avatarSrc: 'https://i.pravatar.cc/80?img=12',
46+
src: 'https://i.pravatar.cc/80?img=12',
4847
},
4948
sam: {
5049
id: 'sam',
5150
name: 'Sam Rivera',
52-
avatarSrc: 'https://i.pravatar.cc/80?img=15',
51+
src: 'https://i.pravatar.cc/80?img=15',
5352
},
5453
};
5554

@@ -87,7 +86,7 @@ const styles = stylex.create({
8786
insetBlockStart: '30%',
8887
transform: 'translateY(-100%)',
8988
},
90-
resolvedMarker: {
89+
singleMarker: {
9190
position: 'absolute',
9291
insetInlineStart: '66%',
9392
insetBlockStart: '69%',
@@ -116,13 +115,12 @@ const styles = stylex.create({
116115
},
117116
});
118117

119-
type PinId = 'grouped' | 'margin' | 'resolved';
118+
type PinId = 'grouped' | 'margin' | 'single';
120119

121120
export default function CommentPinShowcase() {
122121
const [selected, setSelected] = useState<PinId | null>('grouped');
123-
// aria-pressed toggle semantics: activating the selected pin clears it.
124-
const toggle = (id: PinId) =>
125-
setSelected(current => (current === id ? null : id));
122+
const select = (id: PinId) => (isSelected: boolean) =>
123+
setSelected(isSelected ? id : null);
126124

127125
return (
128126
<VStack gap={4} xstyle={styles.root}>
@@ -155,17 +153,15 @@ export default function CommentPinShowcase() {
155153
threadCount={6}
156154
unreadCount={2}
157155
isSelected={selected === 'grouped'}
158-
isDimmed={selected != null && selected !== 'grouped'}
159-
onClick={() => toggle('grouped')}
156+
onSelectedChange={select('grouped')}
160157
xstyle={styles.groupedMarker}
161158
/>
162159
<CommentPin
163160
label="Open annotation from Mira"
164161
participants={[PEOPLE.mira]}
165-
isSelected={selected === 'resolved'}
166-
isDimmed={selected != null && selected !== 'resolved'}
167-
onClick={() => toggle('resolved')}
168-
xstyle={styles.resolvedMarker}
162+
isSelected={selected === 'single'}
163+
onSelectedChange={select('single')}
164+
xstyle={styles.singleMarker}
169165
/>
170166
</div>
171167

@@ -176,8 +172,7 @@ export default function CommentPinShowcase() {
176172
participants={[PEOPLE.mira]}
177173
unreadCount={1}
178174
isSelected={selected === 'margin'}
179-
isDimmed={selected != null && selected !== 'margin'}
180-
onClick={() => toggle('margin')}
175+
onSelectedChange={select('margin')}
181176
xstyle={styles.marginMarker}
182177
/>
183178
</div>

0 commit comments

Comments
 (0)