An open source design system that's fully customizable and agent ready
TypeScript
feat(sandbox): the motion lab previews ProgressBar's fill as width against scaleX (#8606)
Cindy Zhangeb3d173154a2
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsxindex 97e385caf3..b6a2fdd3af 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx@@ -34,6 +34,7 @@ import {Badge} from '@astryxdesign/core/Badge';import {Button} from '@astryxdesign/core/Button';import {Card} from '@astryxdesign/core/Card';import {CheckboxInput} from '@astryxdesign/core/CheckboxInput';+import {ProgressBar} from '@astryxdesign/core/ProgressBar';import {Tab, TabList} from '@astryxdesign/core/TabList';// A swizzled copy of core's TabList carrying the proposed travelling indicator.import {@@ -43,6 +44,7 @@ import {import {Skeleton} from '@astryxdesign/core/Skeleton';import {SideNav, SideNavItem, SideNavSection} from '@astryxdesign/core/SideNav';import {Token} from '@astryxdesign/core/Token';+import {themeProps} from '@astryxdesign/core/utils';import {HStack, VStack} from '@astryxdesign/core/Layout';import {Text} from '@astryxdesign/core/Text';import {useMotionLab} from './MotionLabStore';@@ -937,6 +939,61 @@ export function OriginRig({kind}: {kind: 'zero' | 'centre' | 'anchored'}) {);}+// --- progress fill -----------------------------------------------------------++/** The values a fast upload might report, one per tick. */+const FILL_STEPS = [12, 58, 34, 86] as const;++/**+ * The determinate fill on a data change. Before is the real ProgressBar,+ * which transitions `width` (a layout property, every frame of every tick).+ * After is a sandbox copy of its track and fill that moves the same fill with+ * `transform: scaleX()` on the same token and curve, so only the technique+ * differs. It carries ProgressBar's theming targets (root, track and fill),+ * so the theme paints it as it paints the real bar.+ */+export function ProgressFillRig({mode}: {mode: Mode}) {+ const [step, setStep] = useState(0);+ useLoop(() => setStep(current => (current + 1) % FILL_STEPS.length), 1600);+ const value = FILL_STEPS[step];++ return (+ <VStack gap={2} {...stylex.props(sx.full)}>+ {mode === 'before' ? (+ <ProgressBar label="Uploading" value={value} hasValueLabel />+ ) : (+ <div {...themeProps('progress-bar', {variant: 'accent'})}>+ <VStack gap={1}>+ <HStack gap={2} hAlign="between">+ <Text>Uploading</Text>+ <Text color="secondary">{value}%</Text>+ </HStack>+ <div+ {...themeProps('progress-bar-track')}+ className={`astryx-progress-bar-track ${styles.fillTrack}`}+ role="progressbar"+ aria-label="Uploading"+ aria-valuemin={0}+ aria-valuemax={100}+ aria-valuenow={value}>+ <div+ {...themeProps('progress-bar-fill', {variant: 'accent'})}+ className={`astryx-progress-bar-fill ${styles.fillScale}`}+ style={{transform: `scaleX(${value / 100})`}}+ />+ </div>+ </VStack>+ </div>+ )}+ <Hint>+ {mode === 'before'+ ? 'Width is a layout property: every frame of every tick re-lays out the bar. A fast upload ticks often enough to behave like a layout loop.'+ : 'The same fill on transform: scaleX, so it runs on the compositor. The cost shows at the ends: the rounded caps squash at small values, which is why this needs an exception or a different structure before it ships.'}+ </Hint>+ </VStack>+ );+}+// --- loops -------------------------------------------------------------------export function LoopRig({policy}: {policy: 'today' | 'delete' | 'degrade'}) {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 9feb2ebabc..3e958a7579 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@@ -736,6 +736,52 @@}}+/* ------------------------------------------------------- progress fill ---- */++/* A copy of ProgressBar's track and fill (8px, muted track, accent fill, full+ radius) whose fill moves with transform instead of width, on the same token+ and curve core uses, so the pair differs only in technique. */+.fillTrack {+ position: relative;+ height: 8px;+ border-radius: var(--radius-full);+ overflow: hidden;+}++.fillScale {+ position: absolute;+ inset: 0;+ border-radius: inherit;+ transform-origin: left center;+ transition: transform var(--duration-medium) var(--ease-standard);+}++/* Core's own paint, in Core's layer, so a theme's rule for the+ ProgressBar targets (the copy carries their classes) wins as it does on+ the real bar. */+@layer astryx-base {+ .fillTrack {+ background: var(--color-background-muted);+ }++ .fillScale {+ background: var(--color-accent);+ }+}++[dir='rtl'] .fillScale {+ transform-origin: right center;+}++/* Forced colours paint the track and fill as Canvas: Core's fill keeps its+ shape with a CanvasText outline, and so does the copy. */+@media (forced-colors: active) {+ .fillScale {+ outline: 1px solid CanvasText;+ outline-offset: -1px;+ }+}+/* ---------------------------------------------------------------- tint ---- *//* The Table hover tint, at whatever duration and curve is being argued over.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 f1de537c67..9bdc26a405 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@@ -27,6 +27,7 @@ import {DisclosureRig,ListReorderRig,NavTintRig,+ ProgressFillRig,RailRig,SkeletonSwapRig,StatCountRig,@@ -314,6 +315,26 @@ export default function PreviewsPage() {</DemoCard></Grid>+ <DemoCard+ title="ProgressBar fill"+ question="Width against transform for the determinate fill. Width re-lays out the bar every frame; scaleX stays on the compositor but squashes the rounded ends."+ badges={<Badge variant="warning" label="PARTIAL" />}>+ <ComparePanes+ panes={[+ {+ tone: 'before',+ label: 'Today — real ProgressBar, width',+ content: <ProgressFillRig mode="before" />,+ },+ {+ tone: 'after',+ label: 'Proposed — transform: scaleX',+ content: <ProgressFillRig mode="after" />,+ },+ ]}+ />+ </DemoCard>+<VStack gap={2}><Heading level={2}>What is not here</Heading><Text color="secondary">