Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

[Component Audit] Code: restore complete API discovery (#6914)

Cindy Zhangd2daa25689f6
diff --git a/.changeset/code-api-discovery.md b/.changeset/code-api-discovery.md
new file mode 100644
index 0000000000..0c15f254c7
--- /dev/null
+++ b/.changeset/code-api-discovery.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Make Code's complete public API and theme target discoverable in component documentation.
+
+@cixzhang
diff --git a/.github/scripts/story-play-guard.js b/.github/scripts/story-play-guard.js
index 3b18a5e5c5..4900a5e4da 100644
--- a/.github/scripts/story-play-guard.js
+++ b/.github/scripts/story-play-guard.js
@@ -48,6 +48,24 @@ const TARGETS = [
story: 'core-multiselector--sizes',
guards: 'compact trigger variants match their size tokens',
},
+ {
+ component: 'Code',
+ story: 'core-code--colors',
+ guards:
+ 'primary, secondary, and inherited text colors remain distinct and inheritance follows the surrounding text',
+ },
+ {
+ component: 'Code',
+ story: 'core-code--long-inline-content',
+ guards:
+ 'an unbroken inline identifier wraps without overflowing its constrained prose container',
+ },
+ {
+ component: 'Code',
+ story: 'core-code--text-sizes',
+ guards:
+ 'size="inherit" matches each surrounding font size and line height across distinct text roles',
+ },
{
component: 'ChartTooltip',
story: 'charts-chrome-tooltip--modal-layering',
diff --git a/apps/storybook/stories/Code.stories.tsx b/apps/storybook/stories/Code.stories.tsx
index f419b7bf62..00e456ce0f 100644
--- a/apps/storybook/stories/Code.stories.tsx
+++ b/apps/storybook/stories/Code.stories.tsx
@@ -1,6 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import type {Meta, StoryObj} from '@storybook/react';
+import {expect} from 'storybook/test';
import {Code} from '@astryxdesign/core/Code';
import {Text} from '@astryxdesign/core/Text';
import {Stack} from '@astryxdesign/core/Stack';
@@ -28,6 +29,57 @@ export const Default: Story = {
},
};
+export const Colors: Story = {
+ render: () => (
+ <Stack gap={2}>
+ <Text type="body">
+ Primary:{' '}
+ <Code color="primary" data-testid="code-primary">
+ const primary = true
+ </Code>
+ </Text>
+ <Text type="body">
+ Secondary:{' '}
+ <Code color="secondary" data-testid="code-secondary">
+ const secondary = true
+ </Code>
+ </Text>
+ <Text type="body" color="accent" data-testid="inherited-color-parent">
+ Inherited:{' '}
+ <Code color="inherit" data-testid="code-inherit">
+ const inherited = true
+ </Code>
+ </Text>
+ </Stack>
+ ),
+ play: async ({canvasElement}) => {
+ await document.fonts.ready;
+ const primary = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="code-primary"]',
+ );
+ const secondary = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="code-secondary"]',
+ );
+ const inherited = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="code-inherit"]',
+ );
+ const inheritedParent = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="inherited-color-parent"]',
+ );
+ if (!primary || !secondary || !inherited || !inheritedParent) {
+ throw new Error('Code color fixture did not render every state');
+ }
+
+ const primaryColor = getComputedStyle(primary).color;
+ const secondaryColor = getComputedStyle(secondary).color;
+ const inheritedColor = getComputedStyle(inherited).color;
+ expect(secondaryColor).not.toBe(primaryColor);
+ expect(inheritedColor).toBe(getComputedStyle(inheritedParent).color);
+ expect(inheritedColor).not.toBe(primaryColor);
+ expect(inheritedColor).not.toBe(secondaryColor);
+ },
+};
+
export const InParagraph: Story = {
name: 'Inline in paragraph',
render: () => (
@@ -93,22 +145,88 @@ export const VariousContent: Story = {
),
};
+export const LongInlineContent: Story = {
+ render: () => (
+ <div data-testid="long-inline-container" style={{maxWidth: 240}}>
+ <Text type="body">
+ Long token:{' '}
+ <Code data-testid="long-inline-code">
+ aVeryLongUnbrokenIdentifierThatMustWrapInsideItsProseContainer
+ </Code>
+ </Text>
+ </div>
+ ),
+ play: async ({canvasElement}) => {
+ await document.fonts.ready;
+ await new Promise<void>(resolve =>
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
+ );
+ const container = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="long-inline-container"]',
+ );
+ const code = canvasElement.querySelector<HTMLElement>(
+ '[data-testid="long-inline-code"]',
+ );
+ if (!container || !code) {
+ throw new Error('Code wrapping fixture did not render');
+ }
+
+ expect(code.getClientRects().length).toBeGreaterThan(1);
+ expect(container.scrollWidth).toBeLessThanOrEqual(container.clientWidth);
+ },
+};
+
export const TextSizes: Story = {
name: 'Across text sizes',
render: () => (
<Stack gap={2}>
- <Text type="large">
- Heading with <Code>inline code</Code>
+ <Text type="large" data-testid="text-large">
+ Heading with{' '}
+ <Code size="inherit" data-testid="code-large">
+ inline code
+ </Code>
</Text>
- <Text type="body">
- Body text with <Code>inline code</Code>
+ <Text type="body" data-testid="text-body">
+ Body text with{' '}
+ <Code size="inherit" data-testid="code-body">
+ inline code
+ </Code>
</Text>
- <Text type="supporting">
- Detail text with <Code>inline code</Code>
+ <Text type="supporting" data-testid="text-supporting">
+ Detail text with{' '}
+ <Code size="inherit" data-testid="code-supporting">
+ inline code
+ </Code>
</Text>
- <Text type="label">
- Label text with <Code>inline code</Code>
+ <Text type="label" data-testid="text-label">
+ Label text with{' '}
+ <Code size="inherit" data-testid="code-label">
+ inline code
+ </Code>
</Text>
</Stack>
),
+ play: async ({canvasElement}) => {
+ await document.fonts.ready;
+ const sizes = ['large', 'body', 'supporting', 'label'];
+ const fontSizes: string[] = [];
+ for (const size of sizes) {
+ const parent = canvasElement.querySelector<HTMLElement>(
+ `[data-testid="text-${size}"]`,
+ );
+ const code = canvasElement.querySelector<HTMLElement>(
+ `[data-testid="code-${size}"]`,
+ );
+ if (!parent || !code) {
+ throw new Error(`Code inherited-size fixture did not render ${size}`);
+ }
+
+ const parentStyle = getComputedStyle(parent);
+ const codeStyle = getComputedStyle(code);
+ expect(codeStyle.fontSize).toBe(parentStyle.fontSize);
+ expect(codeStyle.lineHeight).toBe(parentStyle.lineHeight);
+ fontSizes.push(codeStyle.fontSize);
+ }
+ expect(new Set(fontSizes).size).toBeGreaterThan(1);
+ },
};
diff --git a/packages/cli/foundation/doc-compiler/inputs.test.mjs b/packages/cli/foundation/doc-compiler/inputs.test.mjs
index 4621086276..8a8ee97e23 100644
--- a/packages/cli/foundation/doc-compiler/inputs.test.mjs
+++ b/packages/cli/foundation/doc-compiler/inputs.test.mjs
@@ -90,7 +90,6 @@ describe('collectDocInputs over what this repo ships', () => {
).toEqual([
'Chat',
'ChatComposerTokenElement',
- 'Code',
'ContextMenuItem',
'Heading',
'Indicator',
diff --git a/packages/core/src/Code/Code.doc.mjs b/packages/core/src/Code/Code.doc.mjs
new file mode 100644
index 0000000000..1a4c17d934
--- /dev/null
+++ b/packages/core/src/Code/Code.doc.mjs
@@ -0,0 +1,145 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
+export const docs = {
+ name: 'Code',
+ displayName: 'Code',
+ group: 'Code',
+ category: 'Content',
+ description:
+ 'Inline code element with a monospace font and muted background. Use it for short code references within prose.',
+ usage: {
+ description:
+ 'Code marks short inline references such as function names, variables, file paths, and command-line flags. Use CodeBlock for standalone or multi-line snippets.',
+ bestPractices: [
+ {
+ guidance: true,
+ description:
+ 'Use Code for short technical terms inside prose, such as a function name, prop, file path, or command-line flag.',
+ },
+ {
+ guidance: true,
+ description:
+ "Set size to 'inherit' when inline code should match the surrounding text size and line height.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Use Code for multi-line or standalone snippets. Use CodeBlock instead so readers get appropriate block formatting and syntax support.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Use Code as an interactive copy or navigation control. Pair it with the appropriate Button or Link when an action is required.',
+ },
+ ],
+ anatomy: [
+ {
+ name: 'Container',
+ required: true,
+ description:
+ 'The semantic code element that contains the inline code content and paints the background, typography, padding, and radius.',
+ },
+ ],
+ },
+ playground: {
+ defaults: {
+ children: 'const count = 0',
+ },
+ },
+ props: [
+ {
+ name: 'children',
+ type: 'ReactNode',
+ description: 'The inline code content.',
+ required: true,
+ },
+ {
+ name: 'color',
+ type: "'primary' | 'secondary' | 'inherit'",
+ description:
+ "Text color. Use 'inherit' to take the surrounding text color.",
+ default: "'primary'",
+ },
+ {
+ name: 'size',
+ type: "'inherit'",
+ description:
+ "Set to 'inherit' to take the surrounding font size and line height. Omit it to use the code type-scale size.",
+ },
+ {
+ name: 'ref',
+ type: 'React.Ref<HTMLElement>',
+ description: 'Ref forwarded to the semantic code element.',
+ },
+ {
+ name: 'xstyle',
+ type: 'StyleXStyles',
+ description:
+ 'StyleX styles for layout customization. Must be a stylex.create() value, not an inline style object like style={{}}.',
+ },
+ {
+ name: 'className',
+ type: 'string',
+ description:
+ 'CSS class name for the root element. Prefer xstyle for styling.',
+ },
+ {
+ name: 'style',
+ type: 'CSSProperties',
+ description:
+ 'Inline styles for the root element. Prefer xstyle for StyleX-optimized styling.',
+ },
+ {
+ name: 'data-testid',
+ type: 'string',
+ description: 'Test selector for automated testing frameworks.',
+ },
+ ],
+ theming: {
+ targets: [{className: 'astryx-code', visualProps: ['color']}],
+ },
+};
+
+/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
+export const docsDense = {
+ description:
+ 'inline semantic code for short technical references in prose; CodeBlock handles standalone or multi-line snippets',
+ usage: {
+ description:
+ 'Use for short function names, variables, paths, and CLI flags inside prose. Use CodeBlock for standalone or multi-line snippets.',
+ bestPractices: [
+ {
+ guidance: true,
+ description: 'Use for short technical references inside prose.',
+ },
+ {
+ guidance: true,
+ description:
+ "Set size='inherit' to match surrounding text size and line height.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Use for multi-line or standalone snippets; use CodeBlock instead.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Use as an interactive control; pair with Button or Link for actions.',
+ },
+ ],
+ },
+ propDescriptions: {
+ children: 'inline code content.',
+ color:
+ 'text color: primary, secondary, or inherited from surrounding text.',
+ size: "set to 'inherit' to take the surrounding font size and line height.",
+ ref: 'ref forwarded to the semantic code element.',
+ xstyle:
+ 'StyleX layout styles; must be a stylex.create() value, not an inline style object.',
+ className: 'CSS class for the root; prefer xstyle.',
+ style: 'inline styles for the root; prefer xstyle.',
+ 'data-testid': 'test selector for automated testing frameworks.',
+ },
+};
diff --git a/packages/core/src/Code/Code.spec.md b/packages/core/src/Code/Code.spec.md
new file mode 100644
index 0000000000..8686a02220
--- /dev/null
+++ b/packages/core/src/Code/Code.spec.md
@@ -0,0 +1,172 @@
+---
+schema_version: 3
+template_version: 6
+kind: component
+id: component:Code
+authority: draft
+archive_reason: null
+superseded_by: null
+approved_by: null
+approved_at: null
+owners: [cixzhang]
+review_triggers: [public-api, behavior, theming, accessibility, visual]
+verified_by:
+ [
+ packages/core/src/Code/Code.test.tsx,
+ packages/core/src/theme/themingTargets.test.ts,
+ packages/core/src/docPropLiterals.test.ts,
+ packages/core/src/docPropReferences.test.ts,
+ packages/cli/foundation/doc-compiler/inputs.test.mjs,
+ .github/scripts/story-play-guard.js,
+ apps/storybook/stories/Code.stories.tsx,
+ apps/storybook/rtl-audit/verified-not-applicable.json,
+ ]
+modules: []
+families: []
+design_specs: []
+architecture:
+ [
+ architecture:public-component-api,
+ architecture:component-theming-surface,
+ architecture:component-test-sufficiency,
+ ]
+contributing: []
+system_specs: []
+---
+
+# Code component contract
+
+## Contract at a glance
+
+| Area | Contract |
+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Public contract | `Code` is exported from `@astryxdesign/core/Code`; it requires `children`, defaults `color` to `primary`, optionally accepts `secondary` or `inherit`, and accepts `size="inherit"`. |
+| Behavior | Code renders one semantic `<code>` element, uses the code type scale by default, and may inherit surrounding color or typography through explicit props. |
+| End-user impact | Readers receive recognizable inline code that wraps instead of forcing its prose container wider. |
+| Builder impact | Builders can discover the complete released API, use Code for short inline references, and use CodeBlock for standalone or multi-line snippets. |
+| Compatibility/readiness | This audit restores missing consumer metadata and expands browser evidence. Runtime types, defaults, layout, and production component output are unchanged. |
+| Review checks | Reject a non-`code` root, dropped content or root props, a ref that misses the root, a visual prop not reflected on the `code` target, undocumented released props/defaults, or a change that turns the inline component into a block-code replacement. |
+| Governing rules | `architecture:public-component-api/INV1,INV5,INV6,INV8–INV9`; `architecture:component-theming-surface/INV3–INV7`; `architecture:component-test-sufficiency/INV1–INV7,INV10–INV11`. |
+
+This table is a review projection; the body below is authoritative only after owner approval.
+
+## Intent
+
+Present short technical references inside prose with native code semantics and a compact, themeable inline treatment.
+
+## Compatibility and migration
+
+- Released default preserved: yes
+- Compatibility class: documentation and ownership restoration only; no runtime, type, default, style, target, or export change
+- Controlled/uncontrolled behavior: not applicable; Code owns no state
+- Migration decision: none
+
+Consumer migration instructions belong in consumer docs and release notes.
+
+## Ownership boundary
+
+**Owns**
+
+- The semantic inline-code root, code typography and wrapping, primary/secondary/inherited text color, optional inherited size, supported root props and ref, and the `code` theme target.
+
+**Does not own / non-goals**
+
+- Syntax highlighting, line numbers, copy behavior, titles, fenced or multi-line presentation — owned by `component:CodeBlock`.
+- The meaning, localization, or bidirectional ordering of caller-supplied code content — owned by the product callsite and platform text engine.
+- An interactive action or navigation contract — builders compose the appropriate Button or Link outside Code.
+
+## Public concepts
+
+| Concept | Closed values or states | Meaning | Availability | Default | Owner | Stability | Invalid-value behavior |
+| ------------ | --------------------------------- | ------------------------------------------------------------------------------- | ------------ | ---------- | ---------------- | --------- | --------------------------- |
+| color | `primary`, `secondary`, `inherit` | Selects the inline code text color source. | Every render | `primary` | `component:Code` | stable | rejected by the public type |
+| size | code scale, inherited | Uses the code type scale when omitted or surrounding typography when inherited. | Every render | code scale | `component:Code` | stable | rejected by the public type |
+| code content | caller-supplied React content | Supplies the content inside the semantic code element. | Every render | required | product callsite | stable | ordinary React rendering |
+
+## Behavioral and layout contract
+
+| ID | Candidate invariant | Basis | Draft review state |
+| --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------ |
+| FR1 | Code MUST render one semantic `<code>` root containing the caller content. | shipped source, tests, docs, and HTML semantics | verify |
+| FR2 | Omitting `size` MUST use the code type-scale size; `size="inherit"` MUST inherit the surrounding font size and line height. `color` MUST select primary, secondary, or inherited text color. | shipped public types, source, tests, and stories | verify |
+| FR3 | Long inline content MUST remain wrap-capable, and Code MUST add only logical inline/block padding rather than physical-direction geometry. | shipped source and representative prose stories | verify |
+| FR4 | Supported DOM props, `className`, `style`, and `xstyle` MUST compose on the root, and the public ref MUST reach that root. | `architecture:public-component-api/INV5,INV6,INV8`; shipped source and tests | verify |
+| FR5 | The painted root MUST retain the public `code` target and reflect the `color` visual axis. No internal target or separate state target is part of the shipped surface. | `architecture:component-theming-surface/INV3–INV7`; source and theming-target inventory | verify |
+
+### Allowed variation
+
+- **AV1 — Theme paint.** The `code` target may vary supported typography, color, background, padding, radius, and other accepted paint without changing semantic content or inline ownership.
+- **AV2 — Caller content.** Code content may contain any React content accepted by the released `children` type; its meaning remains caller-owned.
+- **AV3 — Surrounding typography.** Builders may explicitly inherit surrounding color or size; omission preserves the component defaults.
+
+### Representative states
+
+| State | Required invariant | Allowed variation |
+| ------------------- | ------------------------------------------------------------------ | ------------------------------------------ |
+| default | Semantic code root, primary color, code type-scale size. | Caller content and theme paint. |
+| secondary color | Same root and layout with the secondary text-color source. | Caller content and theme paint. |
+| inherited color | Same root and layout with surrounding text color. | Surrounding color and caller content. |
+| inherited size | Same root and paint with surrounding font size and line height. | Surrounding typography and caller content. |
+| long inline content | Content wraps without component-owned physical-direction geometry. | Break opportunities in caller content. |
+
+### Transformation and precedence order
+
+- **ORD1 — Root props.** Supported caller DOM props → component target and visual-axis reflection → base/color/size/xstyle classes → consumer class and inline style composition.
+- **ORD2 — Typography.** Omitted size → code type-scale size; explicit `inherit` → surrounding font size and line height.
+
+### Performance and resources
+
+- **PR1 — Pure render.** Code owns no state, Effect, listener, observer, timer, external resource, or asynchronous work.
+
+## Accessibility contract
+
+- **AR1 — Native semantics.** The root remains a semantic `<code>` element and adds no interactive role, focus target, or component-authored accessible name.
+- **AR2 — Caller content.** The caller-supplied content remains the accessible content; Code does not translate, hide, or duplicate it.
+
+## Design relationships
+
+| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
+| ---------------- | -------------------------------------------------------------------------------------------- | ------------------------------- | ------------------------ | ------------------ |
+| Container | Distinguishes short technical text through code typography and compact background treatment. | observed shipped representation | inline technical content | FR1–FR5, AR1–AR2 |
+
+No current design record prescribes exact Code pixels. This observational draft records the shipped representation without promoting draft typography guidance.
+
+### Theming anatomy
+
+<!-- anatomy-theming:v1 -->
+
+```json
+{
+ "Container": {"target": "code"}
+}
+```
+
+## Family and system relationships
+
+- `architecture:public-component-api` owns export reachability, accepted root props, styling composition, ref reachability, released defaults, and consumer documentation.
+- `architecture:component-theming-surface` owns target qualification, target placement, visual-axis reflection, and metadata ownership.
+- `architecture:component-test-sufficiency` owns the rational evidence set and rejects component functional tests for documentation-only corrections when shared schema and projection checks are the capable layer.
+
+## Verification map
+
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| ----------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
+| FR1, AR1–AR2 | `Code.test.tsx`; semantic review of the Storybook fixtures | default and prose composition | The root stops being a code element, content disappears, or the component invents interaction or accessible naming. | `audit:Code/a11y` |
+| FR2 | `Code.test.tsx`; `Colors` and `TextSizes` play assertions in the required Chromium story-play guard | primary, secondary, inherited color, inherited size | A color choice stops reaching the target or inherited typography becomes visually indistinguishable from the fixed default. | `audit:Code/behavior` |
+| FR3 | `LongInlineContent` play assertion in the required Chromium story-play guard | constrained prose with an unbroken identifier | Inline code forces physical-direction geometry or no longer wraps in constrained prose. | `audit:Code/responsive` |
+| FR4 | `Code.test.tsx`; strict type/lint validation | ref plus supported styling and DOM passthrough | The ref misses the root or supported consumer inputs stop composing on it. | `audit:Code/api` |
+| FR5 | `themingTargets.test.ts`; Code consumer docs; source review | every color value | The target disappears or moves off the painter, color is no longer reflected, or metadata assigns the target to another owner. | `audit:Code/theming` |
+| RTL N/A | `verified-not-applicable.json` | every current story | Directional glyph, physical inline placement, ordering, scrolling, overlay, or horizontal keyboard behavior appears unmeasured. | `audit:Code/rtl` |
+| Consumer metadata | CLI `component Code --json`; docs typecheck; `docPropLiterals.test.ts`; `docPropReferences.test.ts` | required content, color values/default, inherited size | A released prop/default/target disappears from consumer discovery or docs name a value the source does not accept. | `audit:Code/docs` |
+
+## Decision log
+
+None. This audit restores missing consumer metadata and records shipped behavior; it makes no new product decision.
+
+## Open questions
+
+None. This observational draft does not decide exact visual tuning or broaden Code into a block-code component.
+
+## Content boundary
+
+This file does not duplicate consumer examples, current audit scores, implementation steps, CodeBlock behavior, or draft typography policy. It links to their owners.
diff --git a/packages/core/src/Code/Code.test.tsx b/packages/core/src/Code/Code.test.tsx
index b0d714d9e7..462ca443cb 100644
--- a/packages/core/src/Code/Code.test.tsx
+++ b/packages/core/src/Code/Code.test.tsx
@@ -11,8 +11,15 @@
import {describe, it, expect, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
+import * as stylex from '@stylexjs/stylex';
import {Code} from './Code';
+const testStyles = stylex.create({
+ root: {
+ marginTop: 1,
+ },
+});
+
describe('Code', () => {
it('renders children inside a <code> element', () => {
render(<Code>const x = 1</Code>);
@@ -44,14 +51,25 @@ describe('Code', () => {
expect(screen.getByText('code')).toHaveAttribute('data-color', 'inherit');
});
- it('adds a size class when size="inherit" (font-size + line-height inherit)', () => {
- const {rerender} = render(<Code>code</Code>);
- const defaultClass = screen.getByText('code').getAttribute('class');
+ it('forwards supported root props and composes styling inputs', () => {
+ render(
+ <Code
+ aria-label="Code sample"
+ className="consumer-class"
+ data-testid="code"
+ style={{opacity: 0.5}}
+ xstyle={testStyles.root}>
+ code
+ </Code>,
+ );
- rerender(<Code size="inherit">code</Code>);
- const inheritClass = screen.getByText('code').getAttribute('class');
+ const element = screen.getByTestId('code');
+ const xstyleClassName = stylex.props(testStyles.root).className;
- // size="inherit" adds an extra StyleX class beyond the default rendering.
- expect(inheritClass).not.toEqual(defaultClass);
+ expect(element).toHaveAttribute('aria-label', 'Code sample');
+ expect(element).toHaveClass('consumer-class');
+ expect(xstyleClassName).toBeTypeOf('string');
+ expect(element).toHaveClass(xstyleClassName as string);
+ expect(element).toHaveStyle({opacity: '0.5'});
});
});
diff --git a/packages/core/src/Code/Code.tsx b/packages/core/src/Code/Code.tsx
index 68cb64795b..1898ef6551 100644
--- a/packages/core/src/Code/Code.tsx
+++ b/packages/core/src/Code/Code.tsx
@@ -7,7 +7,9 @@
* @position Core implementation; lives in own Code/ dir, re-exported by CodeBlock/
*
* SYNC: When modified, update:
- * - /packages/core/src/CodeBlock/index.ts (exports if types change)
+ * - /packages/core/src/Code/Code.doc.mjs (consumer API and theming metadata)
+ * - /packages/core/src/Code/Code.spec.md (behavior and verification map)
+ * - /packages/core/src/CodeBlock/index.ts (compatibility re-exports if types change)
* - /packages/cli/assets/templates/blocks/components/Code/ (showcase blocks)
* - /packages/cli/assets/templates/blocks/components/CodeBlock/ (showcase blocks)
*/
diff --git a/packages/core/src/CodeBlock/Code.doc.mjs b/packages/core/src/CodeBlock/Code.doc.mjs
deleted file mode 100644
index 4445cf31d0..0000000000
--- a/packages/core/src/CodeBlock/Code.doc.mjs
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
-
-export const docs = {
- name: 'Code',
- subComponentOf: 'CodeBlock',
- displayName: 'Code',
- description: 'Inline code element. Renders a styled <code> with monospace font and muted background. For fenced blocks, use CodeBlock.',
- props: [
- {
- name: 'children',
- type: 'ReactNode',
- description: 'Code content.',
- required: true,
- },
- {
- name: 'xstyle',
- type: 'StyleXStyles',
- description: 'StyleX styles for layout customization. Must be a stylex.create() value.',
- },
- {
- name: 'className',
- type: 'string',
- description: 'CSS class name for the root element. Prefer xstyle for styling.',
- },
- {
- name: 'style',
- type: 'CSSProperties',
- description: 'Inline styles. Prefer xstyle for StyleX-optimized styling.',
- },
- {
- name: 'data-testid',
- type: 'string',
- description: 'Test selector for automated testing frameworks.',
- },
- ],
-};
-
-export const docsZh = {
- name: 'Code',
- displayName: 'Code',
- description: '内联代码元素。渲染带等宽字体和低调背景的 <code>。如需围栏代码块,请使用 CodeBlock。',
- propDescriptions: {
- children: '代码内容。',
- xstyle: 'StyleX 布局自定义样式。必须是 stylex.create() 的值。',
- className: '根元素的 CSS 类名。优先使用 xstyle。',
- style: '内联样式。优先使用 xstyle。',
- "data-testid": '自动化测试框架的测试选择器。',
- },
-};
-
-export const docsDense = {
- name: 'Code',
- displayName: 'Code',
- description: 'inline code element; styled <code> w/ monospace+muted bg; for prose',
- propDescriptions: {
- children: 'code content',
- xstyle: 'StyleX layout styles; must be stylex.create() value',
- className: 'CSS class for root; prefer xstyle',
- style: 'inline styles; prefer xstyle',
- "data-testid": 'test selector',
- },
-};
diff --git a/packages/core/src/CodeBlock/CodeBlock.doc.mjs b/packages/core/src/CodeBlock/CodeBlock.doc.mjs
index cafa98f011..5ff045c15d 100644
--- a/packages/core/src/CodeBlock/CodeBlock.doc.mjs
+++ b/packages/core/src/CodeBlock/CodeBlock.doc.mjs
@@ -146,7 +146,6 @@ export const docs = {
},
theming: {
targets: [
- {className: 'astryx-code', visualProps: ['color']},
{className: 'astryx-code-block', visualProps: ['size', 'language', 'container']},
{className: 'astryx-code-block-header', visualProps: ['size', 'language', 'container']},
{className: 'astryx-code-block-title', visualProps: ['size', 'language']},