Skip to main content

Overview

The Card component provides a flexible container for displaying related content in a visually distinct panel. Cards can include headers, footers, images, and actions, making them ideal for presenting information in a structured and scannable format.

Basic usage

Import the Card component and use it in your Angular templates:
import { CardComponent } from '@flowx/angular-ui-toolkit';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [CardComponent],
  template: `
    <flx-card
      [title]="'Card Title'"
      [subtitle]="'Card subtitle'">
      <p>Your card content goes here</p>
    </flx-card>
  `
})
export class ExampleComponent {}

Component selector

<flx-card></flx-card>

Properties

title
string
The main title displayed in the card header.
subtitle
string
Secondary text displayed below the title in the card header.
elevation
number
default:"1"
Shadow depth of the card. Valid values are 0 (no shadow) through 5 (maximum shadow).
variant
'default' | 'outlined' | 'elevated'
default:"'default'"
Visual style variant of the card:
  • default: Standard card with subtle border
  • outlined: Card with prominent border
  • elevated: Card with shadow elevation
clickable
boolean
default:"false"
When true, applies hover effects and cursor pointer to indicate the card is interactive.
disabled
boolean
default:"false"
When true, applies a disabled visual state and prevents interaction.
loading
boolean
default:"false"
When true, displays a loading skeleton or spinner overlay.
padding
'none' | 'small' | 'medium' | 'large'
default:"'medium'"
Controls the internal padding of the card content area.

Events

cardClick
EventEmitter<MouseEvent>
Emitted when the card is clicked. Only fires when clickable is true.

Content projection

The Card component supports multiple content projection slots:

Default content slot

<flx-card [title]="'Simple Card'">
  <!-- This content goes in the main content area -->
  <p>Main card content</p>
</flx-card>

Named slots

<flx-card>
  <div slot="header">
    <h3>Custom Header</h3>
    <button>Action</button>
  </div>
  <p>Card content</p>
</flx-card>

Examples

Simple card with title, content, and actions:
@Component({
  template: `
    <flx-card
      [title]="'User Profile'"
      [subtitle]="'Member since 2024'"
      [elevation]="2">
      <div class="profile-content">
        <p><strong>Email:</strong> user@example.com</p>
        <p><strong>Role:</strong> Administrator</p>
      </div>
      <div slot="footer">
        <button (click)="editProfile()">Edit</button>
        <button (click)="deleteProfile()">Delete</button>
      </div>
    </flx-card>
  `
})
export class ProfileCardComponent {
  editProfile() {
    console.log('Edit profile');
  }
  
  deleteProfile() {
    console.log('Delete profile');
  }
}
When using the clickable property, ensure you provide appropriate visual feedback and handle keyboard navigation for accessibility.

Accessibility

The Card component includes accessibility features:
  • Semantic HTML structure with proper heading hierarchy
  • Keyboard navigation support for clickable cards
  • ARIA attributes for interactive states
  • Screen reader announcements for loading states
Avoid using cards for critical navigation elements. While clickable cards are convenient, important navigation should use proper link or button elements.

Styling

Customize card appearance using CSS custom properties:
flx-card {
  --card-background: #ffffff;
  --card-border-color: #e0e0e0;
  --card-border-radius: 8px;
  --card-padding: 16px;
  --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --card-header-color: #333333;
  --card-subtitle-color: #666666;
}

Common use cases

  • Product listings: Display products with images, descriptions, and actions
  • Dashboard widgets: Show statistics and metrics in card format
  • User profiles: Present user information in organized cards
  • Content previews: Provide summaries with links to full content
  • Settings panels: Group related settings in separate cards
  • Notification cards: Display notifications or alerts with actions

Build docs developers (and LLMs) love