Skip to content

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

TypeScript

fix(sandbox): the motion lab fits a phone screen (#8617)

Cindy Zhang26c7664bdeee
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionControlRail.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionControlRail.tsx
index c633dcfb0b..b2d0a46bbc 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionControlRail.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionControlRail.tsx
@@ -74,7 +74,7 @@ export function MotionControlRail() {
return (
<HStack gap={3} vAlign="center" wrap="wrap" {...stylex.props(sx.rail)}>
- <HStack gap={1.5} vAlign="center">
+ <HStack gap={1.5} vAlign="center" wrap="wrap">
<Text type="supporting" color="secondary">
Speed
</Text>
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLabShell.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLabShell.tsx
index cfd224f9df..c9e2a88627 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLabShell.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLabShell.tsx
@@ -30,6 +30,8 @@ import {
LayoutPanel,
VStack,
} from '@astryxdesign/core/Layout';
+import {Collapsible} from '@astryxdesign/core/Collapsible';
+import {useMediaQuery} from '@astryxdesign/core/hooks';
import {List, ListItem} from '@astryxdesign/core/List';
import {Text} from '@astryxdesign/core/Text';
import {useMotionLab} from './MotionLabStore';
@@ -53,8 +55,21 @@ const sx = stylex.create({
firstGroupLabel: {
paddingBlockStart: '2px',
},
+ narrowNav: {
+ paddingInline: '12px',
+ borderBlockEndWidth: '1px',
+ borderBlockEndStyle: 'solid',
+ borderBlockEndColor: 'var(--color-border)',
+ },
});
+/**
+ * Below this width the 228px page panel would leave the lab's cards a
+ * column too narrow to read, so the pages fold into a collapsible list above
+ * the content instead.
+ */
+const NARROW_QUERY = '(max-width: 719px)';
+
/**
* Hrefs stay unprefixed: SandboxLink applies the Vite base path once in the
* LinkProvider, and usePathname() returns the path within that base path.
@@ -102,6 +117,10 @@ function LabNav() {
export function MotionLabShell({children}: {children: ReactNode}) {
const {registerScope, reducedMotion} = useMotionLab();
const ref = useRef<HTMLDivElement | null>(null);
+ const isNarrow = useMediaQuery(NARROW_QUERY);
+ // The shell outlives a page change; keying the folded list by page closes
+ // it after a pick, so the chosen page starts on screen.
+ const pathname = usePathname();
useEffect(() => {
registerScope(ref.current);
@@ -117,13 +136,25 @@ export function MotionLabShell({children}: {children: ReactNode}) {
<Layout
height="fill"
start={
- <LayoutPanel hasDivider width={228} padding={0} role="navigation">
- <LabNav />
- </LayoutPanel>
+ isNarrow ? undefined : (
+ <LayoutPanel hasDivider width={228} padding={0} role="navigation">
+ <LabNav />
+ </LayoutPanel>
+ )
}
content={
<LayoutContent padding={0}>
<VStack gap={0}>
+ {isNarrow && (
+ <div {...stylex.props(sx.narrowNav)}>
+ <Collapsible
+ key={pathname}
+ trigger="Motion Lab pages"
+ defaultIsOpen={false}>
+ <LabNav />
+ </Collapsible>
+ </div>
+ )}
<MotionControlRail />
{children}
</VStack>
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/js-mirror/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/js-mirror/page.tsx
index 3013a4749f..05c3ddfe04 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/js-mirror/page.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/js-mirror/page.tsx
@@ -430,7 +430,7 @@ export default function MotionJsMirrorPage() {
<ChartPane mode="after" />
<Text type="supporting" color="secondary">
<code>scaledMs(&apos;--duration-reveal&apos;)</code> and{' '}
- <code>
+ <code style={{overflowWrap: 'anywhere'}}>
bezierAt(parseBezier(rawToken(&apos;--ease-move&apos;)),
k)
</code>{' '}
@@ -468,7 +468,7 @@ export default function MotionJsMirrorPage() {
/>
</VStack>
- <Grid columns={{minWidth: 460}} gap={4}>
+ <Grid columns={{minWidth: 460, max: 2}} gap={4}>
<DemoCard
title="Why the defaults are not hardcoded in JS"
question="Because a theme retunes the whole scale, and a constants file would quietly stop agreeing with the stylesheet.">
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/preview-plan/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/preview-plan/page.tsx
index dc68dcc28d..7de4b81821 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/preview-plan/page.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/preview-plan/page.tsx
@@ -307,7 +307,7 @@ export default function PreviewPlanPage() {
<Heading level={2}>{group}</Heading>
<Badge label={`${rows.length}`} />
</HStack>
- <Grid columns={{minWidth: 420}} gap={3}>
+ <Grid columns={{minWidth: 420, max: 2}} gap={3}>
{rows.map(row => (
<RowCard key={row.id} row={row} />
))}
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previews/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previews/page.tsx
index 655f5650ef..f1de537c67 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previews/page.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previews/page.tsx
@@ -247,7 +247,7 @@ export default function PreviewsPage() {
</DemoBody>
</DemoCard>
- <Grid columns={{minWidth: 420}} gap={4}>
+ <Grid columns={{minWidth: 420, max: 2}} gap={4}>
<DemoCard
title="Checkbox tick"
question="A high-frequency surface, so criterion 2 applies: the answer may be that it should be almost nothing."
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/springs/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/springs/page.tsx
index 798215d0db..c0c5abf2cb 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/springs/page.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/springs/page.tsx
@@ -82,6 +82,9 @@ function SpringPlot({duration, bounce}: {duration: number; bounce: number}) {
className={styles.curveCanvas}
width={PLOT_WIDTH}
height={PLOT_HEIGHT}
+ // Shrinks with a card narrower than the plot (a phone); its own size
+ // otherwise.
+ style={{maxWidth: '100%', height: 'auto'}}
viewBox={`0 0 ${PLOT_WIDTH} ${PLOT_HEIGHT}`}
role="img"
aria-label={`Spring position over time, duration ${duration} seconds, bounce ${bounce}`}>
@@ -353,7 +356,7 @@ export default function MotionSpringsPage() {
}
/>
- <Grid columns={{minWidth: 420}} gap={4}>
+ <Grid columns={{minWidth: 420, max: 2}} gap={4}>
{SPRINGS.map(spec => (
<SpringCard
key={spec.name}
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/tokens/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/tokens/page.tsx
index 7f57842dfb..e571559bae 100644
--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/tokens/page.tsx
+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/tokens/page.tsx
@@ -206,7 +206,7 @@ export default function MotionTokensPage() {
Drag a control point and every demo in the lab moves with it. Arrow
keys nudge; hold shift for a bigger step.
</Text>
- <Grid columns={{minWidth: 420}} gap={4}>
+ <Grid columns={{minWidth: 420, max: 2}} gap={4}>
{SEMANTIC_EASES.map(ease => {
const duration = previewDuration(ease.name);
const value = rawToken(ease.name);
@@ -249,7 +249,10 @@ export default function MotionTokensPage() {
</Text>
{ease.evidence != null && (
<Text type="supporting" color="secondary">
- Already in the code: <code>{ease.evidence}</code>
+ Already in the code:{' '}
+ <code style={{overflowWrap: 'anywhere'}}>
+ {ease.evidence}
+ </code>
</Text>
)}
</DemoBody>
@@ -265,7 +268,7 @@ export default function MotionTokensPage() {
Aliases onto the existing primitives, so a theme retunes them for free
through the motion scale it already has.
</Text>
- <Grid columns={{minWidth: 380}} gap={4}>
+ <Grid columns={{minWidth: 380, max: 2}} gap={4}>
{SEMANTIC_DURATIONS.map(duration => (
<DemoCard
key={duration.name}