Installation
Set up a Next.js or Vite project, then add components with the shadcn CLI.
Requirements
- React 19
- Tailwind CSS v4
- An
@/import alias pointing at your source folder - TypeScript 5 or later, if you use TypeScript. Every file passes strict mode.
synccn installs through the shadcn CLI. If your project already uses shadcn/ui, skip to Connect synccn.
Project setup
Create the app
$ pnpm create next-app my-app --yesThe defaults include TypeScript, Tailwind CSS v4, the App Router and the
@/*alias. Add--jsfor a JavaScript project.Set up the shadcn CLI
$ pnpm dlx shadcn@latest initThis creates
components.json, adds theme variables toapp/globals.cssand writes thecn()helper. Any base colour works: you can swap it for one from the Themes page later. For dark mode and the toaster, see Next.js.
Connect synccn
Run this once per project. It tells the CLI where synccn's components live.
$ pnpm dlx shadcn@latest registry add @synccn=https://synccn.com/r/{name}.jsonIt adds this to your components.json, which you can also do by hand:
{ "registries": { "@synccn": "https://synccn.com/r/{name}.json" }}Add components
$ pnpm dlx shadcn@latest add @synccn/button @synccn/dialogThe CLI copies each component into components/ui, installs its npm packages and adds any other components it builds on. The first one also adds synccn's styles to your CSS file: three colour tokens, the animations and a few utility classes. In a JavaScript project you get .jsx files.
Add -demo to a name for the example shown on its page, like @synccn/date-picker-demo. Blocks install the same way: @synccn/dashboard.
import { Button } from "@/components/ui/button";export default function App() { return <Button>Hello</Button>;}Manual installation
If you'd rather not use the CLI, set things up once, then copy components from their pages.
Install the helpers' dependencies
$ pnpm add clsx tailwind-merge lucide-reactAdd your theme
Paste the variables from the Themes page into your CSS file, below
@import "tailwindcss";.globals.css@import "tailwindcss";@custom-variant dark (&:where(.dark, .dark *));/* Paste the variables from the Themes page here */:root { --radius: 0.625rem; --background: oklch(1 0 0); --foreground: oklch(0.145 0 0); /* … */}Add the synccn styles
Colour tokens, animations and utility classes the components use. Paste them below your theme.
globals.css/* synccn styles: add below your theme variables */:root { --success: oklch(0.62 0.15 155); --warning: oklch(0.76 0.16 75); --brand-soft: oklch(0.205 0 0 / 0.06);}.dark { --success: oklch(0.72 0.16 155); --warning: oklch(0.8 0.15 80); --brand-soft: oklch(1 0 0 / 0.08);}@theme inline { --color-success: var(--success); --color-warning: var(--warning); --color-brand-soft: var(--brand-soft); --animate-marquee: marquee var(--duration, 30s) linear infinite; --animate-marquee-y: marquee-y var(--duration, 30s) linear infinite; --animate-shimmer: shimmer 2.4s linear infinite; --animate-beam: beam calc(var(--beam-duration, 6) * 1s) linear infinite; --animate-orbit: orbit calc(var(--orbit-duration, 20) * 1s) linear infinite; --animate-meteor: meteor 5s linear infinite; --animate-in: enter 0.18s ease-out; --animate-out: exit 0.15s ease-in forwards; --animate-sheet-right: sheet-right 0.28s cubic-bezier(0.32, 0.72, 0, 1); --animate-sheet-left: sheet-left 0.28s cubic-bezier(0.32, 0.72, 0, 1); --animate-sheet-bottom: sheet-bottom 0.3s cubic-bezier(0.32, 0.72, 0, 1); --animate-fade: fade 0.2s ease-out; --animate-blink: blink 1s step-end infinite; --animate-ripple: ripple 0.6s ease-out forwards; --animate-pulse-ring: pulse-ring 2s ease-out infinite;}@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(calc(-100% - var(--gap))); }}@keyframes marquee-y { from { transform: translateY(0); } to { transform: translateY(calc(-100% - var(--gap))); }}@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; }}@keyframes beam { to { offset-distance: 100%; }}@keyframes orbit { from { transform: rotate(0deg) translateY(calc(var(--orbit-radius) * 1px)) rotate(0deg); } to { transform: rotate(360deg) translateY(calc(var(--orbit-radius) * 1px)) rotate(-360deg); }}@keyframes meteor { 0% { transform: rotate(215deg) translateX(0); opacity: 1; } 70% { opacity: 1; } 100% { transform: rotate(215deg) translateX(-600px); opacity: 0; }}@keyframes enter { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; }}@keyframes exit { to { opacity: 0; transform: translateY(4px) scale(0.98); }}@keyframes sheet-right { from { transform: translateX(100%); }}@keyframes sheet-left { from { transform: translateX(-100%); }}@keyframes sheet-bottom { from { transform: translateY(100%); }}@keyframes indeterminate { from { left: -35%; } to { left: 100%; }}@keyframes fade { from { opacity: 0; }}@keyframes blink { 50% { opacity: 0; }}@keyframes ripple { from { transform: scale(0); opacity: 0.35; } to { transform: scale(4); opacity: 0; }}@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 var(--brand-soft); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; }}@utility surface { background: var(--card); &:where(.dark, .dark *) { box-shadow: inset 0 1px 0 0 oklch(1 0 0 / 0.05); }}@utility scrollbar-none { scrollbar-width: none; &::-webkit-scrollbar { display: none; }}@utility scrollbar-thin { scrollbar-width: thin; scrollbar-color: var(--border) transparent;}@utility bg-grid { background-image: linear-gradient(to right, var(--border) 1px, transparent 1px), linear-gradient(to bottom, var(--border) 1px, transparent 1px); background-size: 32px 32px;}@utility bg-dots { background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 18px 18px;}@utility text-fade { background-image: linear-gradient(to bottom, var(--foreground) 30%, color-mix(in srgb, var(--foreground) 58%, transparent)); -webkit-background-clip: text; background-clip: text; color: transparent;}Copy the helpers
Every component imports
cn()fromlib/utils. Interactive ones also use small hooks fromlib/hooks, and Copy Button and Code Block uselib/clipboard.Languagelib/utils.tsimport { clsx, type ClassValue } from "clsx";import { twMerge } from "tailwind-merge";/** Merges class names and resolves conflicting Tailwind utilities (last one wins). */export function cn(...inputs: ClassValue[]): string { return twMerge(clsx(inputs));}lib/hooks.ts"use client";import { useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, type RefObject } from "react";type SetValue<T> = (next: T | ((prev: T) => T)) => void;/** * Lets a component be controlled (value + onChange) or uncontrolled (defaultValue). * Returns the current value and a setter that works in both modes. */export function useControllable<T>({ value, defaultValue, onChange,}: { value?: T; defaultValue: T; onChange?: (value: T) => void;}): [T, SetValue<T>] { const [inner, setInner] = useState<T>(defaultValue); const isControlled = value !== undefined; const current = (isControlled ? value : inner) as T; const setValue = useCallback<SetValue<T>>( (next) => { const v = typeof next === "function" ? (next as (prev: T) => T)(current) : next; if (!isControlled) setInner(v); onChange?.(v); }, [current, isControlled, onChange] ); return [current, setValue];}type ElementRef = RefObject<HTMLElement | null>;/** Calls `handler` when a pointer goes down outside every element in `refs`. */export function useClickOutside(refs: ElementRef | ElementRef[], handler: (e: PointerEvent) => void, enabled = true): void { useEffect(() => { if (!enabled) return; const list = Array.isArray(refs) ? refs : [refs]; const onDown = (e: PointerEvent) => { if (list.some((r) => r.current && r.current.contains(e.target as Node))) return; handler(e); }; document.addEventListener("pointerdown", onDown); return () => document.removeEventListener("pointerdown", onDown); }, [refs, handler, enabled]);}/** Calls `handler` when Escape is pressed. */export function useEscape(handler: (e: KeyboardEvent) => void, enabled = true): void { useEffect(() => { if (!enabled) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") handler(e); }; document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [handler, enabled]);}/** Stops the page from scrolling while `enabled` is true. */export function useLockScroll(enabled: boolean): void { useEffect(() => { if (!enabled) return; const prev = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.body.style.overflow = prev; }; }, [enabled]);}/** Keeps an element mounted while its exit animation plays. */export function usePresence(open: boolean, duration = 160): { mounted: boolean; closing: boolean } { const [mounted, setMounted] = useState(open); const [closing, setClosing] = useState(false); useEffect(() => { if (open) { setMounted(true); setClosing(false); } else if (mounted) { setClosing(true); const t = setTimeout(() => { setMounted(false); setClosing(false); }, duration); return () => clearTimeout(t); } }, [open]); // eslint-disable-line react-hooks/exhaustive-deps return { mounted, closing };}/** True once the element has scrolled into view (fires once). */export function useInView<T extends HTMLElement = HTMLDivElement>( options: IntersectionObserverInit = { threshold: 0.2 }): [RefObject<T | null>, boolean] { const ref = useRef<T>(null); const [inView, setInView] = useState(false); useEffect(() => { const el = ref.current; if (!el) return; const io = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) { setInView(true); io.disconnect(); } }, options); io.observe(el); return () => io.disconnect(); }, []); // eslint-disable-line react-hooks/exhaustive-deps return [ref, inView];}/** Subscribes to a CSS media query. Returns false during server rendering. */export function useMediaQuery(query: string): boolean { const subscribe = useCallback( (onChange: () => void) => { const mq = window.matchMedia(query); mq.addEventListener("change", onChange); return () => mq.removeEventListener("change", onChange); }, [query] ); // Server and first client render agree on false, so hydration never mismatches. return useSyncExternalStore( subscribe, () => window.matchMedia(query).matches, () => false );}/** Keeps Tab focus inside a container while active, and restores focus afterwards. */export function useFocusTrap(ref: RefObject<HTMLElement | null>, active: boolean): void { useEffect(() => { if (!active || !ref.current) return; const el = ref.current; const prev = document.activeElement as HTMLElement | null; const sel = 'a[href],button:not([disabled]),input:not([disabled]),select,textarea,[tabindex]:not([tabindex="-1"])'; const first = el.querySelector<HTMLElement>("[data-autofocus]") || el.querySelector<HTMLElement>(sel); (first || el).focus({ preventScroll: true }); const onKey = (e: KeyboardEvent) => { if (e.key !== "Tab") return; const items = [...el.querySelectorAll<HTMLElement>(sel)].filter((n) => n.offsetParent !== null); if (!items.length) return; const a = items[0]; const b = items[items.length - 1]; if (e.shiftKey && document.activeElement === a) { e.preventDefault(); b.focus(); } else if (!e.shiftKey && document.activeElement === b) { e.preventDefault(); a.focus(); } }; el.addEventListener("keydown", onKey); return () => { el.removeEventListener("keydown", onKey); prev?.focus?.({ preventScroll: true }); }; }, [ref, active]);}/** * Picks "top" or "bottom" for a floating layer so it isn't cut off by the * viewport or by any vertically clipping ancestor of the anchor. */export function useAutoSide( anchorRef: RefObject<HTMLElement | null>, floatingRef: RefObject<HTMLElement | null>, mounted: boolean, preferred: "top" | "bottom" = "bottom"): "top" | "bottom" { const [side, setSide] = useState(preferred); useLayoutEffect(() => { if (!mounted) return setSide(preferred); const a = anchorRef.current; const f = floatingRef.current; if (!a || !f) return; const ar = a.getBoundingClientRect(); const need = f.offsetHeight + 10; let top = 0; let bottom = window.innerHeight; for (let el = a.parentElement; el && el !== document.body; el = el.parentElement) { const st = getComputedStyle(el); if (/(hidden|auto|scroll|clip)/.test(st.overflowY)) { const r = el.getBoundingClientRect(); top = Math.max(top, r.top); bottom = Math.min(bottom, r.bottom); } } const below = bottom - ar.bottom; const above = ar.top - top; setSide(below < need && above > below ? "top" : "bottom"); }, [mounted]); // eslint-disable-line react-hooks/exhaustive-deps return side;}const noop = () => () => {};/** False during server rendering and hydration, true afterwards. Use it to guard portals. */export function useIsClient(): boolean { return useSyncExternalStore( noop, () => true, () => false );}/** * The current time, read in the browser only: null while server rendering and * during hydration, then the real time. With `interval` (ms) it keeps updating. * Reading the clock during render breaks prerendering in Next.js (Cache * Components) and causes hydration mismatches, so time-based components use this. */export function useNow(interval?: number): Date | null { const [now, setNow] = useState<Date | null>(null); useEffect(() => { setNow(new Date()); if (!interval) return; const t = setInterval(() => setNow(new Date()), interval); return () => clearInterval(t); }, [interval]); return now;}lib/clipboard.ts/** Copies text to the clipboard, falling back to execCommand where the Clipboard API is blocked. */export async function copyText(text: string): Promise<boolean> { try { await navigator.clipboard.writeText(text); return true; } catch { try { const ta = document.createElement("textarea"); ta.value = text; ta.style.position = "fixed"; ta.style.opacity = "0"; document.body.appendChild(ta); ta.select(); const ok = document.execCommand("copy"); ta.remove(); return ok; } catch { return false; } }}Copy components
Open any component, choose the Manual tab and copy its source into
components/ui. Components that build on others link to them.