Skeleton
NewCustomize
Shimmer2.2s
Reveal0.50s
Radius6px
Installation
npx shadcn@latest add https://uibrik.com/r/skeleton.jsonInstall the packages
npm install motionCopy the source into your project
components/uibrik/skeleton/skeleton.tsx"use client"; import { useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react"; import { motion, useReducedMotion } from "motion/react"; // A skeleton that takes its shape from the real layout instead of a hand-drawn // copy of it. While loading, the content renders invisibly (with placeholder // data if the real data isn't there yet) and every line of text, image, icon // and control in it is measured: text gets one bar per wrapped line, at the // line's real width, and everything else gets its own box with its own corner // radius. One shimmer sweeps across all of them at once, so a long list costs // a single animation. When loading ends, the bars fade away top to bottom // while the content wipes in behind them, rather than everything popping in // at once. // // Shape it by hand where needed: `data-skeleton` turns an element into one // box (an avatar, a chart), `data-skeleton-ignore` leaves it out. export type SkeletonProps = { loading: boolean; children: ReactNode; /** One sweep across the content, in seconds. 0 turns the shimmer off. */ shimmerDuration?: number; /** How long the reveal takes from top to bottom, in seconds. */
Adds the files to
components/uibrik/skeleton and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/skeleton.Usage
import { Skeleton } from "@/components/uibrik/skeleton/skeleton";<Skeleton loading shimmerDuration={2.2} reveal={0.5} radius={6} // data-skeleton={…} // data-skeleton-ignore={…}> <ProfileCard user={user} /></Skeleton>Props
Skeleton- loading
- Type boolean
- true
- Show the skeleton. Turning it off plays the reveal.
- shimmerDuration
- Type number
- 2.2
- One sweep across the content. 0 turns the shimmer off.
- reveal
- Type number
- 0.5
- How long the reveal takes from top to bottom.
- radius
- Type number
- 6
- Corner radius of the text bars. Boxes keep their element's own radius.
- childrenrequired
- Type ReactNode
- –
- The real content, with placeholder data while it loads. Its layout is what gets measured.
- data-skeleton
- Type attribute
- –
- On any element inside: draw it as one box (avatars, charts).
- data-skeleton-ignore
- Type attribute
- –
- On any element inside: leave it out of the skeleton.
- className / style
- Type string / CSSProperties
- –
- For the content box, so layout classes work as if Skeleton weren't there.