本文へ移動
日本語

仕組み

Each block is the text colour at 7% opacity (8% in dark), so it reads the same on a card and on a filled panel. The highlight is an ::after band moved with transform rather than background-position, and every block shares one global phase through a negative animation-delay, so blocks mounted at different moments still sweep together. Build the skeleton from the same rows and sizes as the real widget. SkeletonSwap keeps both layers in one grid cell while it cross-fades, so the container never collapses, and unmounts the skeleton after it has faded.

向いている場面

  • First load of content with a predictable structure, such as lists, cards and detail pages, so people see the layout first.
  • Pull to refresh or refetching after a filter change, instead of a full-page spinner.
  • Areas that usually take more than 300ms; faster requests should show the result directly.

向かない場面

  • Feedback for actions such as submit or save: use the loading state inside the button.
  • Content with an unpredictable structure (unknown result counts, rich text): the skeleton would differ a lot, so use a simple spinner.
  • Long tasks with exact progress, such as uploads and exports: use a progress bar or ring.

使い方

import { Skeleton, SkeletonSwap } from './Skeleton.jsx'

export function OrderCard({ order }) {
  return (
    <SkeletonSwap
      loading={!order}
      label="Loading order"
      skeleton={
        <div style={{ display: 'flex', gap: 12 }}>
          <Skeleton variant="circle" height={40} />
          <Skeleton lines={2} />
        </div>
      }
    >
      {order && <OrderDetail order={order} />}
    </SkeletonSwap>
  )
}

プロパティ

プロパティ型既定値説明
Skeleton.variant'line' | 'circle' | 'rect''line'Shape: text line, round avatar, or rectangle for an image or button.
Skeleton.widthnumber | string—Width; numbers are px. line and rect default to 100%, circle to its height.
Skeleton.heightnumber | string—Height; numbers are px. line defaults to 0.75em (follows font size), circle and rect to 40px.
Skeleton.linesnumber1Number of lines (line only). With more than one, the last line shortens to 60%.
Skeleton.radiusnumber | string—Corner radius; defaults to a full pill for line, 10px for rect and a full circle for circle.
Skeleton.durationnumber1600Sweep period in ms. When omitted, follows the surrounding SkeletonSwap's shimmerDuration.
Skeleton.animatebooleantrueSweeps the highlight. When false, only the static base colour stays.
SkeletonSwap.loadingboolean—Whether it is loading. When it turns false, the skeleton fades out and the content fades in while rising.
SkeletonSwap.skeletonReactNode—The skeleton shown while loading; match the real content's size as closely as you can.
SkeletonSwap.childrenReactNode—The real content; not rendered while loading.
SkeletonSwap.shimmerDurationnumber1600Sweep period in ms for every Skeleton inside.
SkeletonSwap.labelstring'Loading'Text announced to screen readers while loading.
...restHTMLAttributes—Other attributes, such as className and style, go to the root element.

アクセシビリティ

  • The container has aria-busy, so screen readers do not read half-loaded content during loading.
  • A permanent role="status" region announces “Loading” when loading starts; set label for something more specific.
  • All skeleton blocks are aria-hidden and never read as empty elements.
  • With reduced motion there is no sweep, only the static base colour, and the swap replaces the content without movement.

モーション

The sweep cycle is 1600ms by default (70% sweeping, 30% pause), ease-in-out, in phase across blocks. The skeleton leaves in 200ms ease-in; content enters in 360ms ease-out after 60ms, rising 8px. In the demo the bars then rise for 900ms on cubic-bezier(0.22, 1, 0.36, 1), 30ms apart, while the total counts up. Reduced motion shows static blocks and swaps without movement.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

Skeleton.jsxskeleton-shimmer.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

読み込み
「画像リビール」は Pro に含まれます。解除するとプレビューが表示されます。
「オービットローダー」は Pro に含まれます。解除するとプレビューが表示されます。