Cards are used to group and display content in a way that is easily readable. Supports images, actions, and multiple layout variants.
Basic Usage
Card with image, title, and action button.
await import('/components/data-display/card.js');
await import('/components/actions/button.js');
const { tags, $ } = Lightview;
const { p, Card, Button } = tags;
const card = Card({ style: 'width: 18rem;' },
Card.Figure({
src: 'https://images.unsplash.com/photo-1606107557195-0e29a4b5b4aa?w=400&h=200&fit=crop',
alt: 'Shoes'
}),
Card.Body({},
Card.Title({}, 'Nike Air Max'),
p({}, 'Premium comfort meets modern style.'),
Card.Actions({ justify: 'end' },
Button({ color: 'primary' }, 'Buy Now')
)
)
);
$('#example').content(card);
Product Card with Cart
Interactive card with add to cart functionality.
await import('/components/data-display/card.js');
await import('/components/actions/button.js');
await import('/components/data-display/badge.js');
const { signal, tags, $ } = Lightview;
const { p, span, div, Card, Button, Badge } = tags;
const inCart = signal(false);
const card = Card({ style: 'width: 18rem;' },
Card.Figure({
src: 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=400&h=200&fit=crop',
alt: 'Watch'
}),
Card.Body({},
div({ style: 'display: flex; justify-content: space-between; align-items: start;' },
Card.Title({}, 'Smart Watch'),
Badge({ color: 'success' }, 'New')
),
p({ style: 'font-size: 0.875rem; opacity: 0.7;' }, 'Track your fitness goals with precision.'),
div({ style: 'font-size: 1.25rem; font-weight: 700;' }, '$299'),
Card.Actions({ justify: 'end' },
() => inCart.value
? Button({ color: 'success', onclick: () => { inCart.value = false; } }, '✓ In Cart')
: Button({ color: 'primary', onclick: () => { inCart.value = true; } }, 'Add to Cart')
)
)
);
$('#example').content(card);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant |
string | - | 'bordered' | 'dash' | 'side' | 'compact' |
imageFull |
boolean | false | Image fills the entire card width with overlay text |
bg |
string | 'bg-base-100' | Background color class |
shadow |
string | 'shadow-sm' | Shadow class (shadow-sm, shadow-md, shadow-xl) |
Sub-components
| Component | Description |
|---|---|
Card.Body |
Content container with padding |
Card.Title |
Card heading (h2) |
Card.Actions |
Container for action buttons (props: justify) |
Card.Figure |
Image container (props: src, alt) |
Variants
Bordered
Card with a border instead of shadow.
Dash
Card with a dashed border.
Side Layout
Horizontal Card
Image on the side with content next to it.
Compact
Compact Card
Less padding for a tighter layout.
Image Overlay
Text Over Image
Content overlay on top of the image.