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
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.
Designing for reduced motion
Keep interfaces calm without losing feedback. Drag the card, press the arrow keys, or use the buttons.
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.---
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>import { SwipeCard } from '@santi020k/lumen-react'
export const Example = () => (
<>
<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>
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-swipe-card
label="Suggested article"
start-action={{ label: 'Skip', announcement: 'Skipped' }}
end-action={{ 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>
</lumen-swipe-card>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let mut card = use_signal(|| 0_u32);
rsx! {
SwipeCard {
key: "{card}",
label: "Recipe suggestion",
on_swipe: move |_| card += 1,
"Recipe {card}"
}
}
}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.
pnpm add @santi020k/lumen-astrolumen add SwipeCardpnpm add @santi020k/lumen-reactlumen add SwipeCard --target reactpnpm add @santi020k/lumen-elementslumen add SwipeCard --target elementsAPI 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.
| Attribute | Values | Default | Description |
|---|---|---|---|
| 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 slot | card content | - | The content of the draggable card. |
| label | string | - | Names the card group. |
| hint | string | gesture and keyboard hint | Visually 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, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML 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.
.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.
| Hook | Values | Default | Contract |
|---|---|---|---|
| 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, className | string | "" | 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.
| Key | Action |
|---|---|
| ArrowLeft, ArrowRight on the focused card | Choose the action on that side. Start and end follow the writing direction, so ArrowLeft chooses the end action in RTL. |
| Tab | Move to the visible action buttons below the card. |
| Enter, Space on an action button | Choose that action, the same as swiping. |