Polish
The bar every dxbh-ui item meets before it ships. It distills Emil Kowalski's design-engineering practice and Apple's Designing Fluid Interfaces. pnpm registry:check enforces the mechanical rules (marked checked). Reviewers enforce the rest.
Live docs: ui.dxbh.dev/docs/polish. Install any item with npx shadcn@latest add @dxbh-ui/<name>.
Read this before you build or review an item.
1. Decide whether it should move at all
| How often people see it | Decision |
|---|---|
| 100+ times a day (keyboard shortcuts, palette toggle) | No animation |
| Tens of times a day (hover, list navigation) | Remove it or make it very small |
| Occasionally (modals, drawers, toasts) | Standard motion |
| Rarely (onboarding, celebrations) | Room for delight |
- Never animate keyboard-initiated actions. Keyboard actions repeat, and motion makes them feel slow.
- Every animation needs a purpose: spatial consistency, state change, feedback, or avoiding a jarring jump. "It looks nice" doesn't count for anything people see often.
- Data people read, such as sparklines and tables, does not animate on first paint.
2. Tokens
The @dxbh-ui/style item ships these. Components use them through Tailwind (ease-out, duration-(--duration-press)).
--ease-out: cubic-bezier(0.23, 1, 0.32, 1); /* enter and exit */
--ease-in-out: cubic-bezier(0.77, 0, 0.175, 1); /* on-screen movement */
--ease-drawer: cubic-bezier(0.32, 0.72, 0, 1); /* sheets and drawers */
--duration-press: 120ms; /* press feedback */
--duration-popover: 180ms; /* popovers, tooltips, icon swaps (150–200ms) */
--duration-modal: 240ms; /* modals, drawers (200–300ms) */
- Exits run about 20% faster than enters.
- UI motion stays under 300ms.
- Never use
ease-inon UI. It starts slowly, at the moment the user is watching. Checked. - Colours:
--positiveand--negativefor deltas and status. Pair colour with a glyph or text so meaning never depends on colour alone. - Everything else comes from the consumer's shadcn palette. dxbh-ui ships no brand colours.
3. Press and hover
className="transition-transform duration-(--duration-press) ease-out active:scale-[0.97]"
- Every pressable element gets
active:scale-[0.97](0.95–0.98). Feedback lands on pointer-down, not on release. - Tailwind v4's
hover:variant already applies only where hover exists. Raw CSS needs@media (hover: hover) and (pointer: fine)itself. - Hover colour changes can be instant. If you transition them, name the property.
4. Enter and exit
/* Good */
.enter { opacity: 0; transform: scale(0.95); }
/* Never */
.enter { transform: scale(0); }
- Never start from
scale(0). Start at 0.95 or higher, with opacity. Checked (scale(0)andscale-0). - Popovers scale from their trigger: set
transform-originto the trigger side. Modals stay centred. - Enter and exit along the same path. Something that slides in from the right leaves to the right.
- A cross-fade between two states gets about 2px of
filter: blur()so it reads as one thing morphing. Keep blur under 20px. - Prefer
@starting-styleor CSS transitions over keyframes for anything that can be triggered again mid-flight. Transitions retarget; keyframes restart from zero.
5. Only cheap properties
- Animate only
transform,opacity,clip-pathandfilter. - Never
transition-all. Checked. - Height animates only in Disclosure, which uses the opacity-plus-height pairing Sonner uses.
- Write per-frame values straight to
element.style.transform. Don't route them through an inherited CSS variable on a parent, which recalculates styles for every child. - Stagger lists by 30–80ms per item (
--i). Never block input while a stagger plays.
6. Gesture UI
Use @dxbh-ui/spring and @dxbh-ui/use-snap-track. Don't write a new physics loop.
| Interaction | Damping | Response |
|---|---|---|
| Default, settle, reposition | 1.0 (critically damped) | 0.3–0.4s |
| After a flick (release speed > ~400px/s) | 0.8 | 0.3–0.4s |
1:1 tracking. Content stays under the finger and keeps the grab offset.
Interruptible. Grabbing a moving element stops it where it is on screen, not at its target.
spring.set(spring.value).Velocity handoff. Pass the release velocity to the spring:
spring.to(target, { velocity }).Projection. Choose the snap point from where the flick is going, not from where the finger lifted:
const resting = current + project(velocity); // 0.998 deceleration const target = nearestSnap(resting);Rubber-band past the edges with
rubberband(overshoot, size)(c = 0.55). Never stop hard.Pointer capture after a 10px hysteresis. Cancel the gesture if the first movement is mostly vertical.
Multi-touch protection. Ignore a second pointer while one is dragging.
A drag must not also fire a click on the element under the finger.
Decide commit or cancel from the velocity's sign, not from the position alone.
7. Materials
<div className="material-regular" /> // or material-thin
- Translucent surfaces (
material-thin,material-regular) blur and saturate what's behind them and carry a bright top edge. - Never stack translucent surfaces.
- Modal tasks pair the surface with a dimming scrim. Non-blocking panels don't.
- Use a scroll-edge mask instead of a hard divider where content meets floating chrome.
prefers-reduced-transparency: reduceturns materials solid. The style item handles this.
8. Reduced motion
Reduced motion means gentler motion, not none.
- Replace slides, springs and parallax with an opacity cross-fade or an instant change. Keep opacity changes that help people follow what happened.
- In JS, use
useReducedMotion(). It also honoursdata-reduce-motionon<html>.createSpringjumps straight to the target when you passreducedMotion: prefersReducedMotion. - In CSS, use Tailwind's
motion-reduce:variant, for examplemotion-reduce:scale-100 motion-reduce:blur-none. - Travel distances can be multiplied by
--motion-distance, which is 0 under reduced motion. - Shimmer and loops stop under reduced motion.
9. Accessibility and feedback
- Announce results in an
aria-live="polite"status region. Keep an element's accessible name stable while its visuals change. - Numbers that change use
tabular-numsso they don't jitter. - Every interactive element is reachable and operable from the keyboard, with a visible
focus-visiblering. - Time and other client-only values render a stable server fallback (
<time dateTime>) and swap in after hydration (useClientValue,useNow).
10. Portability
These rules are checked:
- No
next/*imports in registry code. Links and images come throughasChild, a render prop, or a plain<a>/<img>. lucide-reactfor icons. Noreact-icons.- No Radix or Base UI unless it is unavoidable.
- Import other dxbh-ui items through
@/registry/dxbh-ui/..., which shadcn rewrites on install. Relative imports may only point inside the same item. Every import must be a declareddependencyorregistryDependency.
Review routine
- Play the demo in Slow-mo (the preview toolbar runs CSS animations at 0.1×). Look for two states overlapping, a wrong origin, or properties falling out of sync.
- Turn on Reduce motion and interact again. You should see only opacity, or nothing.
- Check it at 390px wide. Nothing scrolls horizontally.
- Test touch interactions on a real device.
- Look at it again the next day.