Command Palette

Search for a command to run...

2.4KGitHub stars
Components

Cover Flow

Row of covers that turn in 3D as you scroll, inspired by Cover Flow on iOS 6.

Loading…
Dependencies (1)

Features

  • Drag with a mouse; a flick coasts and lands on a cover.
  • The value changes as each cover passes the center, so a caption keeps up while scrolling.

Installation

pnpm dlx shadcn@latest add @ncdai/cover-flow

Usage

import {
  CoverFlow,
  CoverFlowCover,
  CoverFlowItem,
  CoverFlowReflection,
} from "@/components/cover-flow"
<CoverFlow aria-label="Albums">
  <CoverFlowItem value="album">
    <CoverFlowCover>
      <img src="/album.jpg" alt="Album" />
      <CoverFlowReflection>
        <img src="/album.jpg" alt="" />
      </CoverFlowReflection>
    </CoverFlowCover>
  </CoverFlowItem>
</CoverFlow>

CoverFlowReflection is optional and needs the same content as the cover.

Composition

Use the following composition to build a CoverFlow

CoverFlow
└── CoverFlowItem
    └── CoverFlowCover
        └── CoverFlowReflection

API reference

CoverFlow

Prop

Type

CoverFlowItem

Prop

Type

CSS variables

Set them on CoverFlow, for example className="[--cover-flow-size:--spacing(56)]".

VariableDefaultDescription
--cover-flow-size--spacing(48)Width and height of a cover.
--cover-flow-angle70degHow far the side covers turn.
--cover-flow-firstsize * 0.64Gap between the center and the next cover.
--cover-flow-stepsize * 0.26Gap between the stacked side covers.
--cover-flow-depthsize * -0.75How far the side covers sit back.

Data attributes

AttributeElementPresent when
data-selectedCoverFlowItem, CoverFlowCoverThe cover is at the center.

Accessibility

  • The row is a listbox and the centered cover its selected option. Name the row with aria-label and each cover with its image's alt.
  • ArrowLeft and ArrowRight step through the covers, Home and End jump to the ends.
  • With prefers-reduced-motion, clicks and keys jump to the cover instead of gliding.

Credits

References

License and usage

  • Free to use and modify in both personal and commercial projects.
  • Attribution is appreciated but not required.
  • Released under the MIT License.

Was this helpful?

Command Palette

Search for a command to run...