Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Actions

SwipeCard

Lets people swipe a card toward the start or end to choose one of two actions, with matching buttons and arrow keys.

Frameworks
Astro · React · Elements · Dioxus
Registry
lumen add SwipeCard
Interaction
Enhanced runtime
01

See it and copy it

Framework example

Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro

Designing for reduced motion

Keep interfaces calm without losing feedback. Drag the card, press the arrow keys, or use the buttons.

Swipe the card, press the left or right arrow key, or use the buttons below.
View SwipeCard code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.
astro
---
import { SwipeCard } from '@santi020k/lumen-astro'
---

<SwipeCard
  label="Suggested article"
  startAction={{ label: 'Skip', announcement: 'Skipped' }}
  endAction={{ label: 'Save', tone: 'brand', announcement: 'Saved for later' }}
>
  <h3>Designing for reduced motion</h3>
  <p>Keep interfaces calm without losing feedback. Drag the card, press the arrow keys, or use the buttons.</p>
</SwipeCard>
Edit SwipeCard in browser
02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add SwipeCard

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
startAction, endAction{ label: string; tone?: "neutral" | "brand" | "success" | "warning" | "danger"; announcement?: string }{ label: "Skip" }, { label: "Save" }The two choices; pass localized labels. start is chosen by swiping toward the inline start (left in LTR); end by swiping toward the inline end. label names the button and the cue; announcement is read after the commit and defaults to label. Elements use start-label, start-tone, start-announcement and the end-* equivalents.
children / default slotcard content-The content of the draggable card.
labelstring-Names the card group.
hintstringgesture and keyboard hintVisually hidden description of the swipe, arrow keys, and buttons, attached to the card.
onSwipe / ui:swipe(direction: "start" | "end") => void | CustomEvent<{ direction; source }>-Fires once per commit from a swipe, arrow key, or button. Astro and Elements dispatch a bubbling ui:swipe event; React calls onSwipe. The card then stays dismissed: it becomes inert, leaving the tab order and the accessibility tree, and its action buttons get aria-disabled="true" while staying focusable. Move focus in the handler to the next card (or a heading or summary when none remain). In React, render the next item with a new key so it mounts fresh, then focus its card part from an effect; in Astro and Elements, replace the markup or call reset() on the element, which makes the card reachable again.
data-state"idle" | "dragging" | "swiped"-Set by the script on the root. A drag commits past 35% of the card width or on a quick flick, otherwise it springs back. Reduced motion commits without the fly-out.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Customize SwipeCard

Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.

cssScoped theme overrides
.product-swipe-card {
  --surface: 0 0% 100%;
  --ink: 220 20% 15%;
  --line: 220 15% 82%;
}

Apply product-swipe-card through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.

HookValuesDefaultContract
data-state"idle" | "dragging" | "swiped"-Set by the script on the root. A drag commits past 35% of the card width or on a quick flick, otherwise it springs back. Reduced motion commits without the fly-out.
class, classNamestring""Merges custom classes with the generated ui-* root classes.

Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope

Keyboard interactions

Keyboard behavior provided by the Astro UIPrimitives runtime for this component.

KeyAction
ArrowLeft, ArrowRight on the focused cardChoose the action on that side. Start and end follow the writing direction, so ArrowLeft chooses the end action in RTL.
TabMove to the visible action buttons below the card.
Enter, Space on an action buttonChoose that action, the same as swiping.

Web docsFull catalog