An open source design system that's fully customizable and agent ready
TypeScript
sandbox(motion-lab): NavItem's hover tint on the state token, gated to fine pointers (#8609)
Cindy Zhang2c7ef0e223ff
diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsxindex b5e980e4d8..9f1d45dc2d 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/LabDemos.tsx@@ -982,6 +982,73 @@ export function TintRig({mode}: {mode: Mode}) {);}+// --- nav item hover tint ----------------------------------------------------++const NAV_ITEMS = ['Overview', 'Projects', 'Settings'];+const FINE_HOVER = '(hover: hover) and (pointer: fine)';++/** Whether this device hovers with a fine pointer, as the gate reads it. */+function useFineHover(): boolean | null {+ const [matches, setMatches] = useState<boolean | null>(null);+ useEffect(() => {+ const query = window.matchMedia(FINE_HOVER);+ setMatches(query.matches);+ const update = () => setMatches(query.matches);+ query.addEventListener('change', update);+ return () => query.removeEventListener('change', update);+ }, []);+ return matches;+}++/**+ * NavItem's hover tint. Before: today's item, which tints at once wherever+ * the device hovers, as shipped nav items paint it. After: the tint+ * fades on Astryx's state token (`--duration-fast`, whatever the theme sets,+ * on the shipped `--ease-standard` curve), and only where the device hovers+ * with a fine pointer, so a tap leaves no tint behind.+ */+export function NavTintRig({mode}: {mode: Mode}) {+ const {speed, reducedMotion} = useMotionLab();+ const isFineHover = useFineHover();+ const after =+ mode === 'after'+ ? {+ // The system token, stretched by the rail's slow motion; the+ // Delete policy removes the fade, Degrade keeps it (colour is not+ // movement).+ ['--tint-duration' as string]:+ reducedMotion === 'delete'+ ? '0ms'+ : `calc(var(--duration-fast) * ${speed})`,+ ['--tint-ease' as string]: 'var(--ease-standard-today)',+ }+ : {['--tint-duration' as string]: '0ms'};+ return (+ <VStack gap={1} {...stylex.props(sx.full)}>+ {NAV_ITEMS.map(item => (+ <div+ key={item}+ className={mode === 'after' ? styles.navTintFine : styles.navTint}+ style={after}>+ <Text type="supporting">{item}</Text>+ </div>+ ))}+ <Hint>+ {mode === 'before'+ ? 'Today: the tint snaps on at once wherever the device hovers.'+ : "The theme's state token (--duration-fast on --ease-standard), only on a fine pointer that hovers."}+ </Hint>+ {mode === 'after' && isFineHover != null && (+ <Hint>+ {isFineHover+ ? 'This device hovers with a fine pointer: the tint is on.'+ : 'This device has no fine hover: a tap leaves no tint.'}+ </Hint>+ )}+ </VStack>+ );+}+// --- press / library compatibility -------------------------------------------export function PressRig({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 382edee8ac..8f3ebd4c5e 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@@ -234,7 +234,9 @@.scrimAfter[data-open='true'] {opacity: 1;visibility: visible;- transition: opacity var(--lab-duration-overlay) linear, visibility 0s;+ transition:+ opacity var(--lab-duration-overlay) linear,+ visibility 0s;}.scrimBefore[data-open='true'] {@@ -321,7 +323,9 @@.drawer[data-open='true'] {transform: translateX(0);visibility: visible;- transition: transform var(--drawer-slide, 410ms) var(--ease-drawer), visibility 0s;+ transition:+ transform var(--drawer-slide, 410ms) var(--ease-drawer),+ visibility 0s;}/* The unmount timer firing while the slide is still running. */@@ -351,7 +355,11 @@}.trackTimer {- background: color-mix(in srgb, var(--color-text-error, #d3543f) 45%, transparent);+ background: color-mix(+ in srgb,+ var(--color-text-error, #d3543f) 45%,+ transparent+ );}/* --------------------------------------------------- sliding indicator --- */@@ -669,7 +677,8 @@height: 11px;border-radius: 50%;background: var(--color-background-success, #3f9a6b);- animation: pulseRing var(--loop-duration, 2s) var(--loop-ease, ease-in-out) infinite;+ animation: pulseRing var(--loop-duration, 2s) var(--loop-ease, ease-in-out)+ infinite;}@keyframes pulseRing {@@ -693,7 +702,8 @@var(--color-background-base) 80%);background-size: 220% 100%;- animation: shimmer var(--loop-duration, 1.5s) var(--loop-ease, ease-in-out) infinite;+ animation: shimmer var(--loop-duration, 1.5s) var(--loop-ease, ease-in-out)+ infinite;}@keyframes shimmer {@@ -761,13 +771,37 @@.tintRow {padding: var(--space-2, 6px) var(--space-3, 10px);border-radius: var(--radius-sm, 6px);- transition: background-color var(--tint-duration, 150ms) var(--tint-ease, ease);+ transition: background-color var(--tint-duration, 150ms)+ var(--tint-ease, ease);}.tintRow:hover {background: var(--color-background-hover, var(--color-background-elevated));}+/* NavItem's hover tint (NavTintRig). Before: as shipped, it snaps on where+ the device hovers. After: it fades on the duration and curve the rig passes+ in, and only where the device hovers with a fine pointer. */+.navTint,+.navTintFine {+ padding: var(--space-2, 6px) var(--space-3, 10px);+ border-radius: var(--radius-sm, 6px);+ transition: background-color var(--tint-duration, 0ms) var(--tint-ease, ease);+}++/* Today, as shipped nav items paint it: on any device that hovers. */+@media (hover: hover) {+ .navTint:hover {+ background: var(--color-overlay-hover, var(--color-background-elevated));+ }+}++@media (hover: hover) and (pointer: fine) {+ .navTintFine:hover {+ background: var(--color-overlay-hover, var(--color-background-elevated));+ }+}+/* A `transitionProperty` with no duration: the rule reads like motion inreview and does nothing at all. */.noopRow {@@ -865,7 +899,9 @@}.lightboxFade[data-open='true'] {- transition: opacity var(--lab-duration-enter) var(--ease-entry), visibility 0s;+ transition:+ opacity var(--lab-duration-enter) var(--ease-entry),+ visibility 0s;}.lightboxNone {diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.tsindex a46433a4a1..040d264849 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-lab/previewPlan.ts@@ -597,12 +597,12 @@ export const PREVIEW_PLAN: ReadonlyArray<PreviewRow> = [today: 'Nothing.',gap: 'No hover or active transition, unlike every sibling nav item.',shows:- 'A tint transition at the state token, beside the untransitioned original.',+ 'A tint transition at the state token (--duration-fast on --ease-standard), gated to fine pointers that hover, beside the untransitioned original.',hardCase:'Hover on a touch device, where a tap fires a false hover. The rubric requires this to be gated to fine pointers, and this is the cheapest place to prove the gate works.',controls: ['duration', 'pointer type', 'reduced motion'],status: 'built',- rig: 'TintRig',+ rig: 'NavTintRig',priority: 3,measurementNote: null,},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 593cf55a52..3c8bbd7d6e 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@@ -26,6 +26,7 @@ import {ChipRig,DisclosureRig,ListReorderRig,+ NavTintRig,RailRig,SkeletonSwapRig,StatCountRig,@@ -294,6 +295,26 @@ export default function PreviewsPage() {]}/></DemoCard>++ <DemoCard+ title="NavItem hover tint"+ question="Hover a row in each pane. Today the tint snaps on; the proposal fades it on the state token, and narrows the hover gate to a fine pointer that hovers."+ badges={<Badge variant="error" label="ADD" />}>+ <ComparePanes+ panes={[+ {+ tone: 'before',+ label: 'Today — snaps on hover',+ content: <NavTintRig mode="before" />,+ },+ {+ tone: 'after',+ label: 'State token, fine pointers only',+ content: <NavTintRig mode="after" />,+ },+ ]}+ />+ </DemoCard></Grid><VStack gap={2}>