# Rokkit Card Component > Data-driven card component with field mapping and link support. The Card component displays content in a card format, supporting icons, titles, descriptions, and optional link behavior through field mapping. ## Quick Start ```svelte ``` ## Core Concepts ### Data-Driven Design Card adapts to your data structure through field mapping: ```svelte ``` ### Link Behavior When the data includes an `href` field, Card renders as a link: ```svelte openSettings()} /> ``` ### Custom Rendering Use the `child` snippet for custom card content: ```svelte {#snippet child(proxy)}

{proxy.get('title')}

{proxy.get('description')}

${proxy.value.price}
{/snippet}
``` ## Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `value` | `object` | `undefined` | Card data object (use `bind:value`) | | `fields` | `object` | `{}` | Field mapping configuration | | `class` | `string` | `''` | CSS class names | | `child` | `Snippet` | `undefined` | Custom content renderer | | `children` | `Snippet` | `undefined` | Alternative content | | `onClick` | `function` | `undefined` | Click handler (when no href) | ## Field Mapping Map your data fields to card expectations: | Field | Default | Description | |-------|---------|-------------| | `icon` | `'icon'` | Icon class or name | | `title` | `'title'` | Card title | | `description` | `'description'` | Card description | | `href` | `'href'` | Link URL (makes card clickable) | ### Field Mapping Example ```svelte ``` ## Component Structure ``` ├── // Icon container │ └── // Icon element ├──

// Title └──

// Description
├── │ └── ├──

└──

``` ## Data Attributes for Styling | Attribute | Element | Purpose | |-----------|---------|---------| | `data-card-root` | a/div | Main card element | ### Styling Example ```css [data-card-root] { display: flex; flex-direction: column; padding: 24px; background: var(--surface-100); border: 1px solid var(--border-color); border-radius: 12px; text-decoration: none; color: inherit; transition: transform 0.2s, box-shadow 0.2s; } [data-card-root]:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1); } [data-card-root] icon { display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; background: var(--primary-100); color: var(--primary-600); border-radius: 12px; margin-bottom: 16px; } [data-card-root] h1 { font-size: 1.25rem; font-weight: 600; margin: 0 0 8px 0; } [data-card-root] h2 { font-size: 0.875rem; color: var(--text-muted); margin: 0; font-weight: normal; } ``` ## Accessibility - Renders as `` when href is present for proper link semantics - Keyboard accessible via Enter key (for div variant) - `role="button"` and `tabindex` for non-link cards ## Import ```javascript // Named import import { Card } from '@rokkit/ui' // Default import import Card from '@rokkit/ui/card' ``` ## TypeScript Types ```typescript interface CardProps { value?: any fields?: FieldMapping class?: string child?: Snippet<[Proxy]> children?: Snippet onClick?: () => void } interface FieldMapping { icon?: string title?: string description?: string href?: string [key: string]: string | undefined } ``` ## Examples ### Basic Card ```svelte ``` ### Link Card ```svelte ``` ### Card Grid ```svelte
{#each features as feature} {/each}
``` ### Custom Card Content ```svelte {#snippet child(proxy)} {proxy.get('title')}

{proxy.get('title')}

${proxy.value.price}
★ {proxy.value.rating}
{/snippet}
``` ### Action Card ```svelte ``` ### Using Children Snippet ```svelte

Custom Title

Completely custom content without data binding.

``` ## Related Components - **Panel** - Structured container with header/body/footer - **Item** - Simpler item display - **List** - Display multiple items