Command palette

@yasinsensoy/web

Web · Components

Card

A card grouping content.

5 exports

Live example

Preview

Create account

Enter your details, it takes a few seconds.
Free

Card content goes here.

Effects (hover over them)

Lift

effect="lift"

Hover or Tab into it.

Border color

effect="border"

Hover or Tab into it.

Spinning light

effect="beam"

Hover or Tab into it.

Pointer light

effect="glow"

Hover or Tab into it.

3D tilt

effect="tilt"

Hover or Tab into it.

Shine

effect="shine"

Hover or Tab into it.

Tilt + light

effect={["tilt", "glow"]}

Like a platform, the side the pointer presses goes down.

Selected plan

effect={["beam", "lift"]} active

Always on, even without a mouse.

Custom color

--ui-card-accent

Accent color via a CSS variable.

Appearances

outline

Content

elevated

Content

filled

Content

ghost

Content

gradient

Content

glass

Content

dashed

Content

Code

import { Card, Badge, Button } from "@yasinsensoy/web";

<Card
  effect={["beam", "tilt"]}
  title="Create account"
  description="Enter your details, it takes a few seconds."
  icon="user"
  action={<Badge variant="outline">Free</Badge>}
  footer={<Button>Create</Button>}
>
  …
</Card>

Events

  1. Events appear here when you interact with the preview.

Import

import { Card } from "@yasinsensoy/web";

Card

componentServer component

A card grouping content. Title, description, icon, action and footer are given with props; children goes into the content area. A server component.

Card({ title, description, icon, action, footer, titleAs: Title, classNames, variant: variantProp, tone: toneProp, effect, active, className, children, ...props }: CardProps): JSX.Element

Examples

```tsx
<Card title="Notifications" description="You have 3 unread notifications." icon="bell"
  action={<Button size="sm" variant="ghost">All</Button>}
  footer={<Button block>Mark as read</Button>}>
  …
</Card>

<Card>Content only</Card>

<Card variant="glass" effect={["tilt", "glow"]} title="Pro">…</Card>
<Card effect="beam" tone="success" active={plan === "pro"}>…</Card>
```

Effect settings can be changed with CSS variables: `--ui-card-accent`
(color), `--ui-effect-tilt` (maximum tilt, `8deg`),
`--ui-effect-perspective` (`900px`), `--ui-effect-glow-size` (light
diameter, `18rem`), `--ui-effect-beam-speed` (one turn, `3s`).

A server component; uses the appearance settings of the nearest
{@link UIProvider} in a client tree and of the {@link defineAppearance}
registry on the server.

Card appearance.

  • outline: border and a light shadow (default).
  • elevated: no border, a pronounced shadow; it stands raised from the background.
  • filled: muted background, no border or shadow.
  • ghost: no background, border or shadow; only layout and effects.
  • gradient: a background with a light gradient flowing from the accent color.
  • glass: semi-transparent frosted glass that blurs what's behind it.
  • dashed: dashed border; for empty-state and "add new" cards.
type CardVariant = "outline" | "elevated" | "filled" | "ghost" | "gradient" | "glass" | "dashed"

Card effect. Active on hover, on keyboard focus of an element inside, or when active is given. Several effects can be combined as an array (e.g. ["tilt", "glow"]).

  • lift: the card rises slightly and its shadow grows.
  • border: the border turns the accent color at once.
  • beam: a light beam rotating around the border.
  • glow: a light following the pointer; the background and border glow where the pointer is.
  • tilt: the card tilts in 3D toward the pointer's corner; like a platform being stood on, the side the pointer presses goes down.
  • shine: a diagonal shine passes over the card on hover.

Press effects (ripple, pulse, bounce, scale) and custom effects added with defineAppearance can also be given; see BuiltinEffect for the full list.

glow and tilt work only on mouse devices; on touch screens the card stays still so it doesn't interfere with scrolling. With "reduce motion" on, tilt, lift and the rotating beam turn off; instead of the beam the border takes the accent color.

type CardEffect = EffectProp

Classes that can be given to the inner parts of Card.

NameTypeDescription
header?stringTop area holding the title, description, icon and action.
icon?stringIcon box.
title?stringTitle.
description?stringDescription.
content?stringContent area wrapping children.
footer?stringFooter area.

CardProps

interface

Props of the Card component.

Extends: Omit<ComponentProps<"div">, "title">

NameTypeDefaultDescription
title?ReactNodeCard title.
description?ReactNodeDescription below the title.
icon?IconPropIcon left of the title: a name ("chart") or an element.
action?ReactNodeAction at the top right corner (e.g. a menu or a button).
footer?ReactNodeArea at the bottom of the card; usually buttons.
titleAs?"h2" | "h3" | "h4" | "div""h3"HTML element of the title. Change it to fit the page's heading order.
classNames?CardClassNamesClasses added to the inner parts.
variant?CardVariant | CustomVariant<"card">"outline"Appearance: border, background and shadow. Custom appearances added with defineAppearance can also be given. Defaults to UIProvider appearance.defaults.card.variant.
tone?Tone"primary"Accent color of the effects and the gradient appearance. For another color pass style={{ "--ui-card-accent": "#7c3aed" }}.
effect?CardEffectEffect or effects (e.g. ["tilt", "glow"]). Defaults to UIProvider appearance.defaults.card.effect. See CardEffect.
active?booleanKeeps the effects on regardless of the pointer: the border stays highlighted, the beam rotates, the card stays raised. Useful for showing the selected card (e.g. choosing a pricing plan).