Skip to main content

Overview

The Card component (mt-card) provides a structured container for organizing content with optional header, toolbar, tabs, and footer sections. It supports various slots for customization and includes features like loading states, context menus, and inheritance toggles.

Import

import MtCard from '@/components/layout/mt-card/mt-card.vue';

Props

title
string
default:"undefined"
The main title displayed in the card header
subtitle
string
default:"undefined"
The subtitle displayed below the title in the card header
isLoading
boolean
default:"false"
When true, displays a loading indicator over the card content
large
boolean
default:"false"
Deprecated in v4.0.0 - Makes the card wider (max-width: 83.125rem)
inheritance
boolean
default:"undefined"
Controls the inheritance toggle button visibility. When defined, shows a link icon that can be toggled

Events

update:inheritance
(value: boolean) => void
Emitted when the inheritance toggle button is clicked. Returns the new inheritance state

Slots

default
slot
The main content area of the card
title
slot
Alternative slot to the title property for custom title rendering
subtitle
slot
Alternative slot to the subtitle property for custom subtitle rendering
avatar
slot
Slot for displaying an avatar or logo in the card header
headerRight
slot
Slot for adding content to the right side of the card header
toolbar
slot
Slot for adding toolbar functionality like search bars, buttons, etc.
tabs
slot
Slot for adding a tab bar (typically used with mt-tabs component)
Slot for adding footer content at the bottom of the card
context-actions
slot
Slot for adding mt-context-menu-item components to render a context menu
grid
slot
Slot for rendering a data grid within the card

Usage Examples

Basic Card

<template>
  <mt-card title="Basic Card" subtitle="This is a subtitle">
    <p>Card content goes here</p>
  </mt-card>
</template>

<script setup>
import MtCard from '@/components/layout/mt-card/mt-card.vue';
</script>
<template>
  <mt-card title="Products" subtitle="Manage your products">
    <template #toolbar>
      <mt-button variant="primary">Add Product</mt-button>
      <mt-button variant="secondary">Import</mt-button>
    </template>

    <p>Product list content...</p>

    <template #footer>
      <span>Total: 42 products</span>
    </template>
  </mt-card>
</template>

Card with Context Menu

<template>
  <mt-card title="Settings">
    <template #context-actions>
      <mt-context-menu-item label="Edit" />
      <mt-context-menu-item label="Duplicate" />
      <mt-context-menu-item label="Delete" type="critical" />
    </template>

    <p>Settings content...</p>
  </mt-card>
</template>

Card with Tabs

<template>
  <mt-card title="Configuration">
    <template #tabs>
      <mt-tabs
        :items="tabItems"
        :default-item="activeTab"
        @new-item-active="handleTabChange"
      />
    </template>

    <p>Content for: {{ activeTab }}</p>
  </mt-card>
</template>

<script setup>
import { ref } from 'vue';

const activeTab = ref('general');
const tabItems = [
  { name: 'general', label: 'General' },
  { name: 'advanced', label: 'Advanced' },
  { name: 'permissions', label: 'Permissions' }
];

const handleTabChange = (tabName) => {
  activeTab.value = tabName;
};
</script>

Card with Inheritance Toggle

<template>
  <mt-card
    title="Inherited Settings"
    :inheritance="isInherited"
    @update:inheritance="isInherited = $event"
  >
    <p>These settings are {{ isInherited ? 'inherited' : 'custom' }}</p>
  </mt-card>
</template>

<script setup>
import { ref } from 'vue';

const isInherited = ref(true);
</script>

Loading State

<template>
  <mt-card title="Loading Data" :is-loading="isLoading">
    <p v-if="!isLoading">Data loaded successfully</p>
  </mt-card>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const isLoading = ref(true);

onMounted(async () => {
  await fetchData();
  isLoading.value = false;
});
</script>

Source

View the component source at /home/daytona/workspace/source/packages/component-library/src/components/layout/mt-card/mt-card.vue:1

Build docs developers (and LLMs) love