Updated
Sync Button
NewCustomize
Duration1.6s
Success colour
Error colour
Medium
Installation
npx shadcn@latest add https://uibrik.com/r/sync-button.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/sync-button/sync-button.tsx"use client"; import { AnimatePresence, animate, motion, useAnimationControls, useMotionValue, useReducedMotion, type AnimationPlaybackControls } from "motion/react"; import { useEffect, useRef, useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 12, font: 13, icon: 15 }, md: { height: 40, padX: 14, font: 14, icon: 17 }, lg: { height: 48, padX: 17, font: 15, icon: 19 }, } as const; // Degrees per second while spinning; the stop eases out from this speed. const SPEED = 420; type Phase = "idle" | "syncing" | "done" | "error"; export type SyncButtonProps = { /** Runs the sync. Return a promise to spin until it settles; a rejection shows the error state. Without it, a sync of `duration` seconds is simulated. */ onSync?: () => Promise<unknown> | void; /** Seconds a simulated sync takes. */
Adds the files to
components/uibrik/sync-button and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/sync-button.Usage
import { SyncButton } from "@/components/uibrik/sync-button/sync-button";<SyncButton duration={1.6} label="Sync now" syncingLabel="Syncing" syncedLabel="Synced" successColor="#16a34a" errorColor="#dc2626" size="md" errorLabel="Couldn't sync" onSync={() => {}} // defaultLastSynced={…}/>Where to use Sync Button
Integrations and data sources
The time since the last sync stays current, so people know whether the numbers are fresh.
Pairs with MCP Connectors and Integration Box
Dashboards with manual refresh
Arrows that coast to a stop make a fast refresh still feel like it did something.
Pairs with Revenue Dashboard
Offline-first apps
Pass the real sync as a promise; a failure shakes the button and says so in red.
Pairs with Offline Plug
Props
SyncButton- duration
- Type number
- 1.6
- How long a simulated sync takes.
- label
- Type string
- "Sync now"
- Label before the first sync.
- syncingLabel
- Type string
- "Syncing"
- Label while it works.
- syncedLabel
- Type string
- "Synced"
- Prefix for the time since the last sync.
- successColor
- Type string
- "#16a34a"
- Colour of the check.
- errorColor
- Type string
- "#dc2626"
- Colour of the error state.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- onSync
- Type () => Promise<unknown> | void
- –
- Runs the sync. A returned promise keeps it spinning until it settles; a rejection shows the error.
- defaultLastSynced
- Type Date | number
- –
- When the last sync happened, on mount.
- errorLabel
- Type string
- "Couldn't sync"
- Label after a failed sync.
- className
- Type string
- –
- Classes for the wrapper.