Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions apps/storybook/stories/CommentPin.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ const PEOPLE = {
ada: {
id: 'ada',
name: 'Ada Lovelace',
avatarSrc: 'https://i.pravatar.cc/80?img=47',
src: 'https://i.pravatar.cc/80?img=47',
},
lin: {
id: 'lin',
name: 'Lin Chen',
avatarSrc: 'https://i.pravatar.cc/80?img=32',
src: 'https://i.pravatar.cc/80?img=32',
},
mira: {
id: 'mira',
name: 'Mira Patel',
avatarSrc: 'https://i.pravatar.cc/80?img=5',
src: 'https://i.pravatar.cc/80?img=5',
},
noah: {
id: 'noah',
name: 'Noah Williams',
avatarSrc: 'https://i.pravatar.cc/80?img=12',
src: 'https://i.pravatar.cc/80?img=12',
},
sam: {
id: 'sam',
name: 'Sam Rivera',
avatarSrc: 'https://i.pravatar.cc/80?img=15',
src: 'https://i.pravatar.cc/80?img=15',
},
};

Expand Down Expand Up @@ -250,16 +250,6 @@ export const StateMatrix: Story = {
</Text>
<FocusedSelectedPin />
</HStack>
<HStack gap={4} xstyle={styles.row}>
<Text type="supporting" xstyle={styles.stateLabel}>
Other pin dimmed
</Text>
<CommentPin
label="Open another annotation from Mira"
participants={[PEOPLE.mira]}
isDimmed
/>
</HStack>
<HStack gap={4} xstyle={styles.row}>
<Text type="supporting" xstyle={styles.stateLabel}>
Grouped
Expand Down Expand Up @@ -324,18 +314,6 @@ export const StateMatrix: Story = {
unreadCount={3}
/>
</HStack>
<HStack gap={4} xstyle={styles.row}>
<Text type="supporting" xstyle={styles.stateLabel}>
Resolved, selected
</Text>
{/* An unselected resolved pin renders nothing. */}
<CommentPin
label="Current resolved annotation from Mira"
participants={[PEOPLE.mira]}
isResolved
isSelected
/>
</HStack>
<HStack gap={4} xstyle={styles.row}>
<Text type="supporting" xstyle={styles.stateLabel}>
Disabled / pending
Expand All @@ -356,9 +334,8 @@ export const OverContentAndInMargin: Story = {
const [selected, setSelected] = useState<'content' | 'margin' | null>(
'content',
);
// aria-pressed toggle semantics: activating the selected pin clears it.
const toggle = (id: 'content' | 'margin') =>
setSelected(current => (current === id ? null : id));
const select = (id: 'content' | 'margin') => (isSelected: boolean) =>
setSelected(isSelected ? id : null);
return (
<div {...stylex.props(styles.canvas)}>
<img
Expand All @@ -371,17 +348,15 @@ export const OverContentAndInMargin: Story = {
participants={[PEOPLE.ada, PEOPLE.lin]}
threadCount={4}
isSelected={selected === 'content'}
isDimmed={selected != null && selected !== 'content'}
onClick={() => toggle('content')}
onSelectedChange={select('content')}
xstyle={styles.overMarker}
/>
<div {...stylex.props(styles.margin)}>
<CommentPin
label="Open margin annotation from Mira"
participants={[PEOPLE.mira]}
isSelected={selected === 'margin'}
isDimmed={selected != null && selected !== 'margin'}
onClick={() => toggle('margin')}
onSelectedChange={select('margin')}
xstyle={styles.marginMarker}
/>
</div>
Expand Down
167 changes: 87 additions & 80 deletions docs/specs/components/CommentPin/CommentPin.spec.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lab/blocks/CommentPinInMargin.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: 'Host-owned placement',
displayName: 'Comment pin in a document margin',
description:
'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.',
'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.',
exampleFor: 'CommentPin',
isReady: true,
aspectRatio: 16 / 9,
Expand Down
9 changes: 2 additions & 7 deletions packages/lab/blocks/CommentPinInMargin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
'use client';

/**
* @input A host-positioned CommentPin, its lead commenter, and local
* selected state
* @input A host-positioned CommentPin and its lead commenter
* @output A document passage with one comment pin in its margin; activating
* the pin toggles its selection and aria-pressed state
* the pin toggles its own selection and aria-pressed state
* @position Copyable Lab CommentPin placement example
*/

import {useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {Card} from '@astryxdesign/core/Card';
import {Text} from '@astryxdesign/core/Text';
Expand Down Expand Up @@ -45,7 +43,6 @@ const styles = stylex.create({
});

export default function CommentPinInMargin() {
const [isSelected, setIsSelected] = useState(false);
return (
<Card padding={0} width={520}>
<div {...stylex.props(styles.document)}>
Expand All @@ -66,8 +63,6 @@ export default function CommentPinInMargin() {
<CommentPin
label="Open comment from Maya"
participants={[{id: 'maya', name: 'Maya Chen'}]}
isSelected={isSelected}
onClick={() => setIsSelected(current => !current)}
xstyle={styles.pin}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/lab/blocks/CommentPinShowcase.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
name: 'Avatar-first annotations',
displayName: 'Avatar-first annotations',
description:
'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.',
'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.',
exampleFor: 'CommentPin',
isReady: true,
isShowcase: true,
Expand Down
41 changes: 18 additions & 23 deletions packages/lab/blocks/CommentPinShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

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

Expand All @@ -29,27 +28,27 @@ const PEOPLE = {
ada: {
id: 'ada',
name: 'Ada Lovelace',
avatarSrc: 'https://i.pravatar.cc/80?img=47',
src: 'https://i.pravatar.cc/80?img=47',
},
lin: {
id: 'lin',
name: 'Lin Chen',
avatarSrc: 'https://i.pravatar.cc/80?img=32',
src: 'https://i.pravatar.cc/80?img=32',
},
mira: {
id: 'mira',
name: 'Mira Patel',
avatarSrc: 'https://i.pravatar.cc/80?img=5',
src: 'https://i.pravatar.cc/80?img=5',
},
noah: {
id: 'noah',
name: 'Noah Williams',
avatarSrc: 'https://i.pravatar.cc/80?img=12',
src: 'https://i.pravatar.cc/80?img=12',
},
sam: {
id: 'sam',
name: 'Sam Rivera',
avatarSrc: 'https://i.pravatar.cc/80?img=15',
src: 'https://i.pravatar.cc/80?img=15',
},
};

Expand Down Expand Up @@ -87,7 +86,7 @@ const styles = stylex.create({
insetBlockStart: '30%',
transform: 'translateY(-100%)',
},
resolvedMarker: {
singleMarker: {
position: 'absolute',
insetInlineStart: '66%',
insetBlockStart: '69%',
Expand Down Expand Up @@ -116,13 +115,12 @@ const styles = stylex.create({
},
});

type PinId = 'grouped' | 'margin' | 'resolved';
type PinId = 'grouped' | 'margin' | 'single';

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

return (
<VStack gap={4} xstyle={styles.root}>
Expand Down Expand Up @@ -155,17 +153,15 @@ export default function CommentPinShowcase() {
threadCount={6}
unreadCount={2}
isSelected={selected === 'grouped'}
isDimmed={selected != null && selected !== 'grouped'}
onClick={() => toggle('grouped')}
onSelectedChange={select('grouped')}
xstyle={styles.groupedMarker}
/>
<CommentPin
label="Open annotation from Mira"
participants={[PEOPLE.mira]}
isSelected={selected === 'resolved'}
isDimmed={selected != null && selected !== 'resolved'}
onClick={() => toggle('resolved')}
xstyle={styles.resolvedMarker}
isSelected={selected === 'single'}
onSelectedChange={select('single')}
xstyle={styles.singleMarker}
/>
</div>

Expand All @@ -176,8 +172,7 @@ export default function CommentPinShowcase() {
participants={[PEOPLE.mira]}
unreadCount={1}
isSelected={selected === 'margin'}
isDimmed={selected != null && selected !== 'margin'}
onClick={() => toggle('margin')}
onSelectedChange={select('margin')}
xstyle={styles.marginMarker}
/>
</div>
Expand Down
Loading
Loading