Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 7 additions & 0 deletions .changeset/commentpin-core-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/cli': patch
---

[docs] `astryx template` lists CommentPin's blocks among Core's component blocks: the "Avatar-first annotations" showcase and the "Comment pin in a document margin" example.

@ernestt
7 changes: 7 additions & 0 deletions .changeset/promote-commentpin-to-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[component] Promote `CommentPin` to Core, imported from `@astryxdesign/core/CommentPin` or the package root together with `CommentUser`, the person record its participants take. CommentPin is the avatar-first button that anchors a comment thread, or a group of threads, over content or in a content margin. A single pin shows its lead participant; a group shows up to three participant circles and the thread total. An accent dot marks unread threads. Three sizes follow the element-size scale. Activation flips the selection, which the pin keeps, or the host controls through `isSelected` and `onSelectedChange`. The host owns anchors, grouping, and which pins render.

@ernestt
2 changes: 2 additions & 0 deletions apps/sandbox/scripts/next-export-routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@
"/templates/CommandPalettePickerMode/",
"/templates/CommandPaletteRichItems/",
"/templates/CommandPaletteShowcase/",
"/templates/CommentPinInMargin/",
"/templates/CommentPinShowcase/",
"/templates/ComplexSelectorDeadlinePicker/",
"/templates/ComplexSelectorShowcase/",
"/templates/ComplexSelectorTreeSearch/",
Expand Down
4 changes: 2 additions & 2 deletions apps/storybook/rtl-audit/verified-not-applicable.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@
"reason": "EmojiPicker is a search field above CSS grids of emoji whose columns follow CSS direction, with sticky group headings and a footer preview in logical-property flex rows; its search glyph is radially symmetric. Its one direction-sensitive behavior, horizontal arrow keys, comes from core useGridFocus, which resolves direction per keydown with isRtlElement; that hook's RTL tests and EmojiPicker's own right-to-left keyboard test cover it, and no audit dimension measures keyboard direction."
},
{
"component": "lab/CommentPin",
"reason": "CommentPin sets its fixed 4px speech-bubble corner with the logical border-end-start-radius longhand (the other corners use logical longhands too), so it mirrors under RTL by construction, and switches transform origin from left-bottom to right-bottom. Absolute examples place the inline-start edge at the anchor and translate only on the block axis, so bottom-start placement mirrors without a physical inline offset. Its flex row, avatar overlap, and padding use logical properties; avatars and the numeric count have no directional glyph or keyboard semantics to reverse."
"component": "core/CommentPin",
"reason": "CommentPin sets its fixed 2px speech-bubble corner with the logical border-end-start-radius longhand (the other corners use logical longhands too), so it mirrors under RTL by construction, and switches transform origin from left-bottom to right-bottom. Absolute examples place the inline-start edge at the anchor and translate only on the block axis, so bottom-start placement mirrors without a physical inline offset. Its flex row, avatar overlap, and padding use logical properties; avatars and the numeric count have no directional glyph or keyboard semantics to reverse."
},
{
"component": "lab/CommentComposer",
Expand Down
4 changes: 2 additions & 2 deletions apps/storybook/stories/CommentPin.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type {Meta, StoryObj} from '@storybook/react';
import {useEffect, useRef, useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {CommentPin} from '@astryxdesign/lab';
import {CommentPin} from '@astryxdesign/core/CommentPin';
import {Text} from '@astryxdesign/core/Text';
import {HStack, VStack} from '@astryxdesign/core/Stack';
import {
Expand Down Expand Up @@ -169,7 +169,7 @@ function FocusedSelectedPin() {
}

const meta: Meta<typeof CommentPin> = {
title: 'Lab/CommentPin',
title: 'Core/CommentPin',
component: CommentPin,
tags: ['autodocs'],
parameters: {layout: 'centered'},
Expand Down
64 changes: 39 additions & 25 deletions docs/specs/components/CommentPin/CommentPin.spec.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2268,16 +2268,6 @@
"DR2",
"design:bidirectionality"
],
"packages/lab/src/CommentPin/CommentPin.tsx": [
"FR1",
"FR2",
"FR2",
"FR2",
"FR4",
"FR6",
"ORD4",
"spec:AST-085"
],
"packages/lab/src/Comments/CommentActions.tsx": [
"architecture:react-component-runtime/INV2"
],
Expand Down
12 changes: 7 additions & 5 deletions internal/shadcn-registry/routes.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@
"path": "components/command-palette-list",
"aliases": []
},
{
"name": "component-comment-pin",
"path": "components/comment-pin",
"aliases": [
"components/lab/comment-pin"
]
},
{
"name": "component-complex-selector",
"path": "components/complex-selector",
Expand Down Expand Up @@ -597,11 +604,6 @@
"path": "components/lab/comment-composer",
"aliases": []
},
{
"name": "component-lab-comment-pin",
"path": "components/lab/comment-pin",
"aliases": []
},
{
"name": "component-lab-comment-thread",
"path": "components/lab/comment-thread",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
export default {
export const doc = {
type: 'block',
name: 'Host-owned placement',
displayName: 'Comment pin in a document margin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* @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 own selection and aria-pressed state
* @position Copyable Lab CommentPin placement example
* @position Copyable CommentPin placement example
*/

import * as stylex from '@stylexjs/stylex';
import {Card} from '@astryxdesign/core/Card';
import {Text} from '@astryxdesign/core/Text';
import {VStack} from '@astryxdesign/core/Stack';
import {colorVars, spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
import {CommentPin} from '@astryxdesign/lab';
import {CommentPin} from '@astryxdesign/core/CommentPin';
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

const styles = stylex.create({
document: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
export default {
export const doc = {
type: 'block',
name: 'Avatar-first annotations',
displayName: 'Avatar-first annotations',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* @output A grouped pin with a three-circle participant cap and an unread
* 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
* @position CommentPin docsite showcase and copyable CLI block
*/

import {useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {CommentPin} from '@astryxdesign/lab';
import {CommentPin} from '@astryxdesign/core/CommentPin';
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
import {Text} from '@astryxdesign/core/Text';
import {VStack} from '@astryxdesign/core/Stack';
import {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/test/swizzle-proof/samples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ export const samples = {
},
});
},
core__CommentPin: ({C, React}) =>
React.createElement(C, {
label: 'Open annotation from Ada',
participants: [{id: 'ada', name: 'Ada Lovelace'}],
onClick: noop,
}),
core__Heading: ({C, React}) =>
React.createElement(C, {level: 2}, 'Section title'),
core__Kbd: ({C, React}) => React.createElement(C, {keys: 'mod+k'}),
Expand Down Expand Up @@ -360,12 +366,6 @@ export const samples = {
}),
lab__CommentComposer: ({C, React}) =>
React.createElement(C, {value: '', onChange: noop, onSubmit: noop}),
lab__CommentPin: ({C, React}) =>
React.createElement(C, {
label: 'Open annotation from Ada',
participants: [{id: 'ada', name: 'Ada Lovelace'}],
onClick: noop,
}),
lab__CommentThread: ({C, React}) =>
React.createElement(
'div',
Expand Down
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@
"types": "./dist/CommandPalette/index.d.ts",
"default": "./dist/CommandPalette/index.js"
},
"./CommentPin": {
"source": "./src/CommentPin/index.ts",
"types": "./dist/CommentPin/index.d.ts",
"default": "./dist/CommentPin/index.js"
},
"./ComplexSelector": {
"source": "./src/ComplexSelector/index.ts",
"types": "./dist/ComplexSelector/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/**
* @file CommentPin.doc.mjs
* @input CommentPin API, anatomy, ownership boundaries, and examples
* @output Consumer documentation for the Lab comment pin
* @position CLI and docsite metadata; the runnable showcase lives in packages/lab/blocks
* @output Consumer documentation for the comment pin
* @position CLI and docsite metadata; the runnable showcase lives in
* packages/cli/assets/templates/blocks/components/CommentPin
*/

/** @type {import('@astryxdesign/cli/authoring').ComponentAnatomyElement[]} */
Expand Down Expand Up @@ -45,6 +46,8 @@ const anatomy = [
export const docs = {
name: 'CommentPin',
displayName: 'Comment Pin',
// Keeps the registry route CommentPin had as a Lab component.
registry: {aliases: ['lab/comment-pin']},
group: 'Comments',
category: 'Chat',
keywords: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {describe, expect, it, vi} from 'vitest';
import {fireEvent, render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as stylex from '@stylexjs/stylex';
import {colorVars} from '@astryxdesign/core/theme/tokens.stylex';
import {colorVars} from '../theme/tokens.stylex';
import {CommentPin} from './CommentPin';

const ADA = {id: 'ada', name: 'Ada Lovelace'};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,34 @@
* total and unread represented thread counts (unread shows as a dot), a
* size on the element-size scale, controlled or uncontrolled selection,
* disabled state, and button DOM props
* @output Exports the avatar-first CommentPin button and its props type
* @position Lab collaboration primitive for annotation anchors over content or
* in content margins; callers own grouping, coordinates, and opened content
* @output Exports the avatar-first CommentPin button, its props type, and
* the CommentUser person record its participants share with Comments
* @position Core collaboration primitive for annotation anchors over content
* or in content margins; callers own grouping, coordinates, and opened
* content
*
* SYNC: When modified, update these files to stay in sync:
* - /packages/lab/src/CommentPin/CommentPin.doc.mjs
* - /packages/core/src/CommentPin/CommentPin.doc.mjs
* - /docs/specs/components/CommentPin/CommentPin.spec.md
* - /packages/lab/src/CommentPin/CommentPin.test.tsx
* - /packages/core/src/CommentPin/CommentPin.test.tsx
* - /packages/core/src/CommentPin/index.ts
* - /packages/lab/src/CommentPin/index.ts
* - /apps/storybook/stories/CommentPin.stories.tsx
* - /packages/lab/blocks/CommentPinShowcase.tsx
* - /packages/cli/assets/templates/blocks/components/CommentPin/CommentPinShowcase.tsx
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
*/

import {useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {BaseProps} from '@astryxdesign/core';
import {Avatar, type AvatarSize} from '@astryxdesign/core/Avatar';
import {AvatarGroup, AvatarGroupOverflow} from '@astryxdesign/core/AvatarGroup';
import {
useDevWarning,
useMergedRefs,
usePressFeedback,
} from '@astryxdesign/core/hooks';
import {Icon, type IconSize} from '@astryxdesign/core/Icon';
import type {ElementSize} from '@astryxdesign/core/SizeContext';
import {StatusDot} from '@astryxdesign/core/StatusDot';
import {Avatar, type AvatarSize} from '../Avatar/Avatar';
import {AvatarGroup} from '../AvatarGroup/AvatarGroup';
import {AvatarGroupOverflow} from '../AvatarGroup/AvatarGroupOverflow';
import type {BaseProps} from '../BaseProps';
import {useDevWarning} from '../hooks/useDevWarning';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {usePressFeedback} from '../hooks/usePressFeedback';
import {Icon, type IconSize} from '../Icon/Icon';
import type {ElementSize} from '../SizeContext/SizeContext';
import {StatusDot} from '../StatusDot/StatusDot';
import {
borderVars,
colorVars,
Expand All @@ -43,15 +45,37 @@ import {
spacingVars,
typeScaleVars,
typographyVars,
} from '@astryxdesign/core/theme/tokens.stylex';
import {useTooltip} from '@astryxdesign/core/Tooltip';
import {
focusOutlineProps,
interactionOverlayStyles,
mergeProps,
themeProps,
} from '@astryxdesign/core/utils';
import type {CommentUser} from '../Comments/types';
} from '../theme/tokens.stylex';
import {useTooltip} from '../Tooltip/useTooltip';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {mergeProps} from '../utils/mergeProps';
import {themeProps} from '../utils/themeProps';

/**
* A person or agent who writes comments, reacts, or acts on the item. A
* CommentPin's participants and the Comments family take the same records.
*/
export interface CommentUser {
/** Stable host-owned id, used for equality ("is this my comment?"). */
id: string;
/** Full display name. Never a viewer-relative label such as "You". */
name: string;
/**
* An agent shows its logo (`src`), or square-cornered initials without
* one, and an Agent badge beside its name in a comment. A CommentPin draws
* every participant the same way.
* @default 'person'
*/
kind?: 'person' | 'agent';
/** Where the author's name links in a comment, such as their profile. */
href?: string;
/**
* Profile picture, or an agent's square logo, as Avatar's `src`. Initials
* without one.
*/
src?: string;
}

export interface CommentPinProps extends Omit<
BaseProps<HTMLButtonElement>,
Expand Down Expand Up @@ -194,7 +218,7 @@ const styles = stylex.create({
// GrayText is the platform's disabled affordance there. Defaults repeat the
// base values, since StyleX merges per property. Only unselected pins take
// it — the selected treatment keeps its forced-colors Highlight, so a
// selected disabled pin stays prominent (ORD4).
// selected disabled pin stays prominent.
disabledUnselected: {
borderColor: {
default: 'transparent',
Expand Down Expand Up @@ -302,7 +326,7 @@ const OVERFLOW_ICON_SIZE: Record<ElementSize, IconSize> = {
};

function takeDistinctParticipants(
participants: readonly CommentUser[],
participants: ReadonlyArray<CommentUser>,
limit: number,
): CommentUser[] {
const result: CommentUser[] = [];
Expand Down Expand Up @@ -448,7 +472,7 @@ export function CommentPin({
});
const mergedRef = useMergedRefs(ref, hasTooltip ? tooltip.ref : undefined);

const avatarParticipants: readonly CommentUser[] =
const avatarParticipants: ReadonlyArray<CommentUser> =
visibleParticipants.length > 0
? visibleParticipants
: [{id: '__anonymous__', name: ''}];
Expand All @@ -462,17 +486,17 @@ export function CommentPin({
aria-label={label}
aria-pressed={isSelected}
// A disabled pin keeps its tab stop and is announced as disabled through
// aria-disabled instead of the native attribute (spec:AST-085 FR1). The
// activation guards below keep it inert (FR2); focus is kept when the
// pin becomes disabled while focused (FR4), and the shared focus outline
// still paints, dimmed with the rest of the pin (FR6).
// aria-disabled instead of the native attribute. The activation guards
// below keep it inert. Focus stays when the pin becomes disabled while
// focused, and the shared focus outline still paints, dimmed with the
// rest of the pin.
aria-disabled={isDisabled ? 'true' : undefined}
onClick={e => {
if (isDisabled) {
// A natively disabled element dispatched no click at all, so an
// aria-disabled pin must not reach the caller's handler, and the
// click must not leak to a clickable ancestor (annotation surface)
// the native attribute never let it reach either (FR2).
// the native attribute never let it reach either.
e.preventDefault();
e.stopPropagation();
return;
Expand All @@ -485,7 +509,7 @@ export function CommentPin({
onSelectedChange?.(nextIsSelected);
}}
// The keyboard paths to activation are Enter and Space; other keys still
// reach caller handlers, as on an enabled pin (FR2).
// reach caller handlers, as on an enabled pin.
onKeyDown={e => {
if (isDisabled && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/CommentPin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
* @file index.ts
* @input CommentPin implementation and public types
* @output Exports CommentPin, CommentPinProps, and CommentUser
* @position Entry point for @astryxdesign/core/CommentPin; re-exported by
* /packages/core/src/index.ts and /packages/lab/src/CommentPin/index.ts
*
* SYNC: When modified, update /packages/core/src/CommentPin/CommentPin.doc.mjs
* and /packages/lab/src/CommentPin/index.ts
*/

export {CommentPin} from './CommentPin';
export type {CommentPinProps, CommentUser} from './CommentPin';
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
Loading