Skip to content

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

TypeScript

docs(Icon): the color doc type lists the palette; native keeps the semantic set (#9821)

Cindy Zhanga7e7d4516e7c
diff --git a/.changeset/icon-color-doc-type.md b/.changeset/icon-color-doc-type.md
new file mode 100644
index 0000000000..4f4864a499
--- /dev/null
+++ b/.changeset/icon-color-doc-type.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[docs] `Icon`'s documented `color` type now lists every value the component takes: the ten semantic colors and the ten palette colors (`blue`, `red`, `green`, `gray`, `cyan`, `teal`, `yellow`, `orange`, `pink`, `purple`). Before, the type listed only the semantic colors, though the description named the palette. Native platforms still draw only the semantic colors.
+
+@cixzhang
diff --git a/packages/cli/test/core-prop-docs.known-drift.json b/packages/cli/test/core-prop-docs.known-drift.json
index ecf5fff2c0..0342573826 100644
--- a/packages/cli/test/core-prop-docs.known-drift.json
+++ b/packages/cli/test/core-prop-docs.known-drift.json
@@ -21,7 +21,6 @@
"src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs DropdownMenuCheckboxItem.value required_mismatch",
"src/FieldStatus/FieldStatus.doc.mjs FieldStatus.variant type_mismatch",
"src/HoverCard/HoverCard.doc.mjs HoverCard.children required_mismatch",
- "src/Icon/Icon.doc.mjs Icon.color type_mismatch",
"src/Layout/Layout.doc.mjs Layout.children not_in_doc",
"src/Layout/LayoutFooter.doc.mjs LayoutFooter.padding not_in_doc",
"src/Layout/LayoutHeader.doc.mjs LayoutHeader.padding not_in_doc",
diff --git a/packages/core/src/Icon/Icon.doc.mjs b/packages/core/src/Icon/Icon.doc.mjs
index 0c25da673a..ffc71884f1 100644
--- a/packages/core/src/Icon/Icon.doc.mjs
+++ b/packages/core/src/Icon/Icon.doc.mjs
@@ -78,7 +78,7 @@ export const docs = {
},
{
name: 'color',
- type: "'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit'",
+ type: "'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit' | 'blue' | 'red' | 'green' | 'gray' | 'cyan' | 'teal' | 'yellow' | 'orange' | 'pink' | 'purple'",
description:
'Color variant mapped to Astryx icon color tokens. Semantic values (primary through warning) follow the role, and inherit uses the surrounding text color. On the web, Icon also accepts the palette values blue, red, green, gray, cyan, teal, yellow, orange, pink, and purple, which pick a non-semantic hue.',
default: "'inherit'",
@@ -233,7 +233,7 @@ export const docsZh = {
},
{
name: 'color',
- type: "'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit'",
+ type: "'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit' | 'blue' | 'red' | 'green' | 'gray' | 'cyan' | 'teal' | 'yellow' | 'orange' | 'pink' | 'purple'",
description:
'映射到 Astryx 图标颜色令牌的颜色变体。语义值(primary 到 warning)跟随角色,inherit 使用周围文字的颜色。在 Web 上,Icon 还接受调色板值 blue、red、green、gray、cyan、teal、yellow、orange、pink 和 purple,它们选择非语义色相。',
default: "'inherit'",
diff --git a/packages/native/src/components/Icon.ts b/packages/native/src/components/Icon.ts
index f39ede65d0..661620496c 100644
--- a/packages/native/src/components/Icon.ts
+++ b/packages/native/src/components/Icon.ts
@@ -15,4 +15,20 @@ export const icon: NativeAdditions = {
baseTarget: 'root',
// A shared icon name (AST-082 FR17); an SVG component stays web-only.
slots: {icon: 'icon'},
+ // The semantic colors every platform draws; the palette colors stay on the
+ // web.
+ projections: {
+ color: {
+ primary: 'primary',
+ secondary: 'secondary',
+ tertiary: 'tertiary',
+ disabled: 'disabled',
+ accent: 'accent',
+ info: 'info',
+ success: 'success',
+ error: 'error',
+ warning: 'warning',
+ inherit: 'inherit',
+ },
+ },
};
diff --git a/packages/native/src/contract/contracts.test.ts b/packages/native/src/contract/contracts.test.ts
index c6cc054ac0..e925110a54 100644
--- a/packages/native/src/contract/contracts.test.ts
+++ b/packages/native/src/contract/contracts.test.ts
@@ -150,6 +150,28 @@ describe('native contracts', () => {
expect(types['core.d.ts']).toContain('icon: IconName;');
});
+ it('gives Icon its semantic colors, and leaves the palette colors on the web', async () => {
+ const {contracts} = await buildContracts(loadCoreDoc);
+ const icon = contracts.find(contract => contract.name === 'Icon');
+ const semantic = [
+ 'primary',
+ 'secondary',
+ 'tertiary',
+ 'disabled',
+ 'accent',
+ 'info',
+ 'success',
+ 'error',
+ 'warning',
+ 'inherit',
+ ];
+ expect(icon!.core.color.type).toEqual({kind: 'enum', values: semantic});
+ expect(Object.entries(icon!.projections?.color ?? {})).toEqual(
+ semantic.map(color => [color, color]),
+ );
+ expect(generateSwift(contracts)['Icon.swift']).not.toContain('case blue');
+ });
+
it('gives Avatar its named sizes, a press, and a link, and leaves pixel sizes on the web', async () => {
const {contracts} = await buildContracts(loadCoreDoc);
const avatar = contracts.find(contract => contract.name === 'Avatar');