An open source design system that's fully customizable and agent ready
TypeScript
sandbox(motion-lab): Outline's marker on transform, at reading pace and at a scroll rate (#8610)
Cindy Zhang09640085060b
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsxindex c0ab61df43..b700455935 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx@@ -90,6 +90,10 @@ const sx = stylex.create({width: '100%',},outlineItem: {+ // One item per row, so the marker moves on every step.+ display: 'block',+ width: '100%',+ textAlign: 'start',padding: '5px 0 5px 14px',cursor: 'pointer',color: 'var(--color-text-secondary)',@@ -779,7 +783,14 @@ const OUTLINE_ITEMS = ['Risks',];-export function OutlineMarkerRig({mode}: {mode: Mode}) {+export function OutlineMarkerRig({+ mode,+ intervalMs = 1700,+}: {+ mode: Mode;+ /** How often the marker moves on: 1700 is reading pace, 250 a fast scroll. */+ intervalMs?: number;+}) {const [index, setIndex] = useState(0);const listRef = useRef<HTMLDivElement | null>(null);const markerRef = useRef<HTMLSpanElement | null>(null);@@ -802,7 +813,12 @@ export function OutlineMarkerRig({mode}: {mode: Mode}) {}}, [index, mode]);- useLoop(() => setIndex(i => (i + 1) % OUTLINE_ITEMS.length), 1700);+ // The scroll rate runs faster than the lab's usual 700 ms floor.+ useLoop(+ () => setIndex(i => (i + 1) % OUTLINE_ITEMS.length),+ intervalMs,+ Math.min(700, intervalMs),+ );return (<VStack gap={2} {...stylex.props(sx.full)}>diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabPrimitives.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabPrimitives.tsxindex 343c558967..8c144217ef 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabPrimitives.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabPrimitives.tsx@@ -592,7 +592,12 @@ export function useReplay(run: () => void) {}/** Drives a demo on a loop while the rail's loop switch is on. */-export function useLoop(run: () => void, periodMs: number) {+export function useLoop(+ run: () => void,+ periodMs: number,+ /** The shortest period the loop runs at; a card showing a fast rate lowers it. */+ minPeriodMs = 700,+) {const {isLooping, replayNonce} = useMotionLab();const ref = useRef(run);useLayoutEffect(() => {@@ -603,7 +608,10 @@ export function useLoop(run: () => void, periodMs: number) {if (!isLooping) {return;}- const id = window.setInterval(() => ref.current(), Math.max(700, periodMs));+ const id = window.setInterval(+ () => ref.current(),+ Math.max(minPeriodMs, periodMs),+ );return () => window.clearInterval(id);- }, [isLooping, periodMs, replayNonce]);+ }, [isLooping, minPeriodMs, periodMs, replayNonce]);}diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLab.module.css b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLab.module.cssindex 81a71ae575..f76f79ea2c 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLab.module.css+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/MotionLab.module.css@@ -545,7 +545,9 @@inset-inline-start: 0;width: 3px;border-radius: 2px;- background: var(--color-brand);+ /* Astryx's accent: the sandbox defines no --color-brand, which left the+ marker transparent. */+ background: var(--color-accent);}.markerLayout {diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.tsindex 040d264849..692bdc1da0 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts@@ -616,7 +616,7 @@ export const PREVIEW_PLAN: ReadonlyArray<PreviewRow> = [today: 'Marker slide plus item tint.',gap: 'Animates top and height, which thrashes layout.',shows:- 'The same marker on transform and on top/height, with a paint-cost readout.',+ "The same marker on transform and on top/height, at reading pace and at a fast scroll rate. useAnimator keeps velocity through an interrupted move, but it has one scale, not scaleY, so it cannot stretch the marker to an item's height.",hardCase:'Scroll-linked movement. The marker moves on every scroll frame, so a layout-triggering property here costs more than anywhere else in the audit.',controls: ['duration', 'technique', 'scroll rate'],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.tsxindex 9bdc26a405..15b836e9fe 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@@ -13,11 +13,16 @@* order the brief argues for and the order these should be picked up in.*/+import {useState} from 'react';import {Badge} from '@astryxdesign/core/Badge';import {Banner} from '@astryxdesign/core/Banner';import {Grid} from '@astryxdesign/core/Grid';import {Link} from '@astryxdesign/core/Link';import {VStack} from '@astryxdesign/core/Layout';+import {+ SegmentedControl,+ SegmentedControlItem,+} from '@astryxdesign/core/SegmentedControl';import {Heading, Text} from '@astryxdesign/core/Text';import {LabPage} from '../PageFrame';import {ComparePanes, DemoBody, DemoCard, TokenSlider} from '../LabPrimitives';@@ -27,6 +32,7 @@ import {DisclosureRig,ListReorderRig,NavTintRig,+ OutlineMarkerRig,ProgressFillRig,RailRig,SkeletonSwapRig,@@ -313,6 +319,8 @@ export default function PreviewsPage() {]}/></DemoCard>++ <OutlinePreview /></Grid><DemoCard@@ -351,3 +359,50 @@ export default function PreviewsPage() {</LabPage>);}++/**+ * Outline's marker, on top/height (today) and on transform (proposed), at+ * reading pace or at the rate a fast scroll moves it.+ */+function OutlinePreview() {+ const [pace, setPace] = useState<'reading' | 'scroll'>('reading');+ const intervalMs = pace === 'reading' ? 1700 : 250;+ return (+ <DemoCard+ title="Outline marker"+ question="The marker follows the reading position, so on a scroll-linked page it moves on every scroll frame. Switch to the scroll rate: top and height re-lay-out the list each frame; transform never does."+ badges={<Badge variant="warning" label="PARTIAL" />}>+ <SegmentedControl+ label="How fast the marker moves on"+ size="sm"+ value={pace}+ onChange={value => setPace(value as 'reading' | 'scroll')}>+ <SegmentedControlItem value="reading" label="Reading pace" />+ <SegmentedControlItem value="scroll" label="Scroll rate" />+ </SegmentedControl>+ <ComparePanes+ panes={[+ {+ tone: 'before',+ label: 'Today — top and height',+ content: <OutlineMarkerRig mode="before" intervalMs={intervalMs} />,+ },+ {+ tone: 'after',+ label: 'Proposed — transform only',+ content: <OutlineMarkerRig mode="after" intervalMs={intervalMs} />,+ },+ ]}+ />+ <DemoBody>+ <Text type="supporting" color="secondary">+ The proposed marker uses a CSS transition on transform, so a move that+ starts mid-slide begins from where the marker is. The public+ useAnimator keeps each channel's velocity through an interrupted move,+ but it drives one scale, not scaleY, so it can move this 1px marker+ but not stretch it to the item's height.+ </Text>+ </DemoBody>+ </DemoCard>+ );+}