An open source design system that's fully customizable and agent ready
TypeScript
feat(Timestamp): the hover card's copy button resolves its glyph through the timestamp-copy icon slot (#9830)
Xinzi Zhoud7a7dd3bb23a
diff --git a/.changeset/component-icon-slot-timestamp-copy.md b/.changeset/component-icon-slot-timestamp-copy.mdnew file mode 100644index 0000000000..9b07590232--- /dev/null+++ b/.changeset/component-icon-slot-timestamp-copy.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] Timestamp: the hover card's copy button resolves its glyph through the `timestamp-copy` component icon slot with state `{copied}`. With no theme entry it draws `copy`, then `check` while copied, as before. A theme maps it with `defineTheme({componentIcons: {'timestamp-copy': …}})`; `null` hides only the glyph, and the button keeps its name, tooltip, and copy action.++@imdreamrunnerdiff --git a/packages/core/src/Icon/componentIcons.test.tsx b/packages/core/src/Icon/componentIcons.test.tsxindex e3c7031a2c..c4f056bc33 100644--- a/packages/core/src/Icon/componentIcons.test.tsx+++ b/packages/core/src/Icon/componentIcons.test.tsx@@ -347,7 +347,10 @@ describe('ComponentIcon', () => {describe('component icon slot types', () => {it('types slot names, values, and the static view', () => {expectTypeOf<ComponentIconSlotName>().toEqualTypeOf<- 'code-block-copy' | 'example-panel-dismiss' | 'example-nav-item-leading'+ | 'code-block-copy'+ | 'timestamp-copy'+ | 'example-panel-dismiss'+ | 'example-nav-item-leading'>();expectTypeOf<ComponentIconSlotMap[typeof COPY]>().toEqualTypeOf<{readonly copied: boolean;diff --git a/packages/core/src/Icon/index.ts b/packages/core/src/Icon/index.tsindex cd3d4aa6e2..5299091f1d 100644--- a/packages/core/src/Icon/index.ts+++ b/packages/core/src/Icon/index.ts@@ -64,6 +64,8 @@ export type IconVariant = keyof IconVariantMap & string;export interface ComponentIconSlotMap {/** CodeBlock's copy button. `copied` is true while the copied feedback shows. */'code-block-copy': {readonly copied: boolean};+ /** A Timestamp hover card row's copy button. `copied` is true while the copied feedback shows. */+ 'timestamp-copy': {readonly copied: boolean};}/** A slot name from the augmentable {@link ComponentIconSlotMap}. */diff --git a/packages/core/src/Timestamp/Timestamp.doc.mjs b/packages/core/src/Timestamp/Timestamp.doc.mjsindex 5b7da2c98a..c4784925da 100644--- a/packages/core/src/Timestamp/Timestamp.doc.mjs+++ b/packages/core/src/Timestamp/Timestamp.doc.mjs@@ -93,6 +93,23 @@ export const docs = {{className: 'astryx-timestamp', visualProps: ['type', 'color', 'format']},{className: 'astryx-timestamp-copy-button'},],+ componentIcons: [+ {+ slot: 'timestamp-copy',+ description: "The copy button icon on a hover card row.",+ fallback: '`copy`; `check` while copied',+ state: [+ {+ name: 'copied',+ type: 'boolean',+ description:+ 'True while the copied feedback shows after a successful copy.',+ },+ ],+ whenNull:+ 'Hides the glyph. The button keeps its size, name, tooltip, and copy action.',+ },+ ],},usage: {description:diff --git a/packages/core/src/Timestamp/Timestamp.test.tsx b/packages/core/src/Timestamp/Timestamp.test.tsxindex 3eae185125..c5cc9de3db 100644--- a/packages/core/src/Timestamp/Timestamp.test.tsx+++ b/packages/core/src/Timestamp/Timestamp.test.tsx@@ -32,6 +32,11 @@ import {InternationalizationProvider} from '../i18n';import type {CalendarSystem} from '../utils/calendarSystem';import {withChineseTemporalAheadOfIntl} from '../__tests__/temporalAheadOfIntl';import {__resetDevWarnings} from '../utils/devWarning';+import type {ComponentIconMap} from '../Icon/index';+import {defineTheme} from '../theme/defineTheme';+import {Theme} from '../theme/Theme';++let slotThemeCount = 0;async function openTimestampHoverCard(): Promise<HTMLElement> {const timestamp = document.querySelector('time');@@ -1013,6 +1018,80 @@ describe('Timestamp', () => {).toBeInTheDocument(),);});++ describe('copy icon slot', () => {+ // Label each shared icon's artwork, so a test reads which name rendered.+ const icons = {+ copy: <span data-icon="copy" />,+ check: <span data-icon="check" />,+ clock: <span data-icon="clock" />,+ checkDouble: <span data-icon="checkDouble" />,+ };++ async function renderCard(componentIcons?: ComponentIconMap<never>) {+ const theme = defineTheme({+ name: `timestamp-copy-slot-${slotThemeCount++}`,+ icons,+ componentIcons,+ });+ render(+ <Theme theme={theme}>+ <Timestamp value={Date.now() / 1000 - 3600} format="relative" />+ </Theme>,+ );+ const card = await openTimestampHoverCard();+ return card.querySelector('button')!;+ }++ const glyph = (button: HTMLElement) =>+ button.querySelector('[data-icon]')?.getAttribute('data-icon') ?? null;++ async function copy(button: HTMLElement) {+ fireEvent.click(button);+ await waitFor(() => expect(button).toHaveAccessibleName('Copied'));+ }++ it('draws copy, then check while copied, when the theme maps nothing', async () => {+ const button = await renderCard();+ expect(glyph(button)).toBe('copy');+ await copy(button);+ expect(glyph(button)).toBe('check');+ });++ it('passes `copied` to a slot function and draws the name it returns', async () => {+ const slot = vi.fn(({copied}: {copied: boolean}) => ({+ icon: copied ? ('checkDouble' as const) : ('clock' as const),+ }));+ const button = await renderCard({'timestamp-copy': slot});++ expect(glyph(button)).toBe('clock');+ expect(slot).toHaveBeenLastCalledWith({copied: false});+ await copy(button);+ expect(glyph(button)).toBe('checkDouble');+ expect(slot).toHaveBeenLastCalledWith({copied: true});+ });++ it('hides only the glyph for null; the button keeps its name and copy action', async () => {+ const button = await renderCard({'timestamp-copy': null});++ expect(button.querySelector('.astryx-icon')).toBeNull();+ expect(button).toHaveClass('astryx-timestamp-copy-button');+ expect(button.getAttribute('aria-label')).toMatch(/^Copy /);+ await copy(button);+ expect(navigator.clipboard.writeText).toHaveBeenCalled();+ });++ it('changes only the icon size for a size request, not the button', async () => {+ const button = await renderCard({'timestamp-copy': {size: 'lg'}});++ expect(button.querySelector('.astryx-icon')).toHaveAttribute(+ 'data-size',+ 'lg',+ );+ expect(glyph(button)).toBe('copy');+ expect(button).toHaveAttribute('data-size', 'sm');+ });+ });});// --- Multi-zone / multi-format copyable hover card (tooltipEntries) ---diff --git a/packages/core/src/Timestamp/TimestampHoverCard.tsx b/packages/core/src/Timestamp/TimestampHoverCard.tsxindex 32840973ee..6601919b7e 100644--- a/packages/core/src/Timestamp/TimestampHoverCard.tsx+++ b/packages/core/src/Timestamp/TimestampHoverCard.tsx@@ -4,7 +4,8 @@/*** @file TimestampHoverCard.tsx- * @input Uses React, HoverCard, IconButton, Icon, formatted lines+ * @input Uses React, HoverCard, IconButton, the theme's `timestamp-copy` icon+ * slot, formatted lines* @output Default-exports the lazily-loaded copyable hover card for Timestamp* @position Split out of Timestamp so the overlay (HoverCard) and the copy* affordance's Icon/IconButton load only when a card is actually shown — the@@ -28,7 +29,7 @@ import {useCallback} from 'react';import * as stylex from '@stylexjs/stylex';import {HoverCard} from '../HoverCard/HoverCard';import {IconButton} from '../IconButton/IconButton';-import {Icon} from '../Icon/Icon';+import {ComponentIcon} from '../Icon/ComponentIcon';import {useClipboard} from '../hooks/useClipboard';import {themeProps} from '../utils/themeProps';import {@@ -137,7 +138,14 @@ function CopyButton({value}: {value: string}) {<IconButtonvariant="ghost"size="sm"- icon={<Icon icon={copied ? 'check' : 'copy'} size="sm" color="inherit" />}+ icon={+ <ComponentIcon+ slot="timestamp-copy"+ state={{copied}}+ fallback={{icon: copied ? 'check' : 'copy', size: 'sm'}}+ color="inherit"+ />+ }// Visible hover/focus hint via Button's built-in tooltip: 'Copy',// flipping to 'Copied' after a successful copy in step with the icon.// The full 'Copy <value>' string stays the aria-label for assistive tech.