Skip to content

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

TypeScript

feat(core): move CodeBlock collapse chevron to the left with a light reveal (#4515)

Cindy Zhang840e155dbb36
diff --git a/.changeset/codeblock-collapse-chevron-left.md b/.changeset/codeblock-collapse-chevron-left.md
new file mode 100644
index 0000000000..8f521f3bf7
--- /dev/null
+++ b/.changeset/codeblock-collapse-chevron-left.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] CodeBlock: move the collapse chevron to the left of the title/language label, following the leading-disclosure convention (points right `>` when collapsed, down `v` when expanded). It grows into place (width + inline margin) so it slides the title over smoothly instead of popping in and shifting the header. Respects `prefers-reduced-motion` (#4513)
+@cixzhang
diff --git a/apps/storybook/stories/CodeBlock.stories.tsx b/apps/storybook/stories/CodeBlock.stories.tsx
index 9d33ea3595..24a41fbbae 100644
--- a/apps/storybook/stories/CodeBlock.stories.tsx
+++ b/apps/storybook/stories/CodeBlock.stories.tsx
@@ -43,6 +43,8 @@ const meta: Meta<typeof CodeBlock> = {
hasLineNumbers: {control: 'boolean'},
hasCopyButton: {control: 'boolean'},
isWrapped: {control: 'boolean'},
+ isCollapsible: {control: 'boolean'},
+ collapsibleThreshold: {control: 'number'},
},
};
@@ -308,3 +310,13 @@ export const ContainerSection: Story = {
container: 'section',
},
};
+
+export const Collapsible: Story = {
+ args: {
+ code: tsExample,
+ language: 'typescript',
+ title: 'useUser.ts',
+ hasLineNumbers: true,
+ isCollapsible: true,
+ },
+};
diff --git a/packages/core/src/CodeBlock/CodeBlock.tsx b/packages/core/src/CodeBlock/CodeBlock.tsx
index f80d0b59d0..a3f4e96e12 100644
--- a/packages/core/src/CodeBlock/CodeBlock.tsx
+++ b/packages/core/src/CodeBlock/CodeBlock.tsx
@@ -88,6 +88,23 @@ const dynamicStyles = stylex.create({
}),
});
+// Light reveal so the leading chevron eases into view instead of popping in.
+// Growing the chevron's own footprint (width + inline margin) from zero slides
+// the title into place instead of snapping it over, and clipping keeps the
+// glyph from spilling while it's mid-reveal.
+const chevronReveal = stylex.keyframes({
+ from: {
+ width: 0,
+ marginInlineEnd: 0,
+ opacity: 0,
+ },
+ to: {
+ width: '14px',
+ marginInlineEnd: spacingVars['--spacing-1'],
+ opacity: 1,
+ },
+});
+
const styles = stylex.create({
root: {
position: 'relative',
@@ -133,7 +150,6 @@ const styles = stylex.create({
headerTitle: {
display: 'flex',
alignItems: 'center',
- gap: spacingVars['--spacing-1'],
fontSize: typeScaleVars['--text-supporting-size'],
fontFamily: typographyVars['--font-family-code'],
fontWeight: fontWeightVars['--font-weight-medium'],
@@ -173,13 +189,24 @@ const styles = stylex.create({
flexShrink: 0,
width: '14px',
height: '14px',
+ marginInlineEnd: spacingVars['--spacing-1'],
+ overflow: 'hidden',
color: 'var(--color-syntax-comment)',
+ animationName: {
+ default: chevronReveal,
+ '@media (prefers-reduced-motion: reduce)': 'none',
+ },
+ animationDuration: durationVars['--duration-medium'],
+ animationTimingFunction: easeVars['--ease-standard'],
transitionProperty: 'transform',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
},
- collapseChevronCollapsed: {
- transform: 'rotate(180deg)',
+ collapseChevronExpanded: {
+ // Leading disclosure convention (matches TreeList/Table): the resting
+ // chevronRight points right (>) when collapsed; rotate it down (v) when
+ // expanded.
+ transform: 'rotate(90deg)',
},
headerCollapsible: {
cursor: 'pointer',
@@ -845,18 +872,18 @@ export function CodeBlock({
canCollapse && styles.headerCollapsible,
)}>
<span {...stylex.props(styles.headerTitle)}>
- {title}
- {title && languageLabel ? ' — ' : ''}
- {languageLabel}
{canCollapse && (
<span
{...stylex.props(
styles.collapseChevron,
- isCollapsed && styles.collapseChevronCollapsed,
+ !isCollapsed && styles.collapseChevronExpanded,
)}>
- <Icon icon="chevronDown" size="xsm" color="inherit" />
+ <Icon icon="chevronRight" size="xsm" color="inherit" />
</span>
)}
+ {title}
+ {title && languageLabel ? ' — ' : ''}
+ {languageLabel}
</span>
</div>
{copyButtonEl}