Skip to content

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

TypeScript

fix(docs): show default icons in icon table (#3162)

David Petersen9856b27468f5
diff --git a/apps/docsite/src/components/docs/TableBlock.tsx b/apps/docsite/src/components/docs/TableBlock.tsx
index 8d3971161b..821c32eafe 100644
--- a/apps/docsite/src/components/docs/TableBlock.tsx
+++ b/apps/docsite/src/components/docs/TableBlock.tsx
@@ -2,11 +2,44 @@
'use client';
+import * as stylex from '@stylexjs/stylex';
import {Text} from '@astryxdesign/core/Text';
-import {Table} from '@astryxdesign/core/Table';
+import {Table, pixel, type TableColumn} from '@astryxdesign/core/Table';
import {Card} from '@astryxdesign/core/Card';
+import {HStack} from '@astryxdesign/core/Layout';
+import {Icon, getIconRegistry} from '@astryxdesign/core/Icon';
+import type {IconName} from '@astryxdesign/core/Icon';
import {renderInlineMarkdown} from './inlineMarkdown';
+const styles = stylex.create({
+ tableCard: {maxWidth: 'var(--docs-table-max-width)'},
+ iconNameCell: {minWidth: 0},
+ iconNameText: {minWidth: 0},
+});
+
+const semanticIconNames = new Set<IconName>(
+ Object.keys(getIconRegistry()) as IconName[],
+);
+
+function isIconName(value: string): value is IconName {
+ return semanticIconNames.has(value as IconName);
+}
+
+function renderCellContent(value: string, header: string) {
+ if (header === 'Name' && isIconName(value)) {
+ return (
+ <HStack gap={2} align="center" xstyle={styles.iconNameCell}>
+ <Icon icon={value} size="sm" color="secondary" />
+ <Text type="code" maxLines={1} xstyle={styles.iconNameText}>
+ {value}
+ </Text>
+ </HStack>
+ );
+ }
+
+ return <Text>{renderInlineMarkdown(value)}</Text>;
+}
+
export function TableBlock({
headers,
rows,
@@ -22,16 +55,16 @@ export function TableBlock({
return obj;
});
- const columns = headers.map(h => ({
+ const columns: TableColumn<Record<string, unknown>>[] = headers.map(h => ({
key: h,
header: h,
- renderCell: (item: Record<string, unknown>) => (
- <Text>{renderInlineMarkdown(item[h] as string)}</Text>
- ),
+ width: h === 'Name' ? pixel(220) : undefined,
+ renderCell: (item: Record<string, unknown>) =>
+ renderCellContent((item[h] as string) ?? '', h),
}));
return (
- <Card>
+ <Card xstyle={styles.tableCard}>
<Table
data={data}
columns={columns}