Card

GitHub
Display content in a card with a header, body and footer.

Usage

Use the header, default and footer slots to add content to the Card.

<template>
  <UCard>
    <template #header>
      <Placeholder class="h-8" />
    </template>

    <Placeholder class="h-32" />

    <template #footer>
      <Placeholder class="h-8" />
    </template>
  </UCard>
</template>

Variant

Use the variant prop to change the variant of the Card.

Size

Use the size prop to change the size of the Card.

<template>
  <UCard variant="subtle">
    <template #header>
      <Placeholder class="h-8" />
    </template>

    <Placeholder class="h-32" />

    <template #footer>
      <Placeholder class="h-8" />
    </template>
  </UCard>
</template>

API

Props

Prop Default Type
as

'div'

any

The element or component this component should render as.

variant

'outline'

"solid" | "outline" | "soft" | "subtle"

size

'md'

"md" | "xs" | "sm" | "lg" | "xl"

ui

{ root?: ClassNameValue; header?: ClassNameValue; body?: ClassNameValue; footer?: ClassNameValue; }

Slots

Slot Type
header

{}

default

{}

footer

{}

Theme

app.config.ts
export default defineAppConfig({
  ui: {
    card: {
      slots: {
        root: 'rounded-lg overflow-hidden',
        header: 'p-4 sm:px-6',
        body: 'p-4 sm:p-6',
        footer: 'p-4 sm:px-6'
      },
      variants: {
        size: {
          xs: {
            header: 'p-2 sm:px-4',
            body: 'p-2 sm:p-4',
            footer: 'p-2 sm:px-4'
          },
          sm: {
            header: 'p-3 sm:px-5',
            body: 'p-3 sm:p-5',
            footer: 'p-3 sm:px-5'
          },
          md: {
            header: 'p-4 sm:px-6',
            body: 'p-4 sm:p-6',
            footer: 'p-4 sm:px-6'
          },
          lg: {
            header: 'p-5 sm:px-7',
            body: 'p-5 sm:p-7',
            footer: 'p-5 sm:px-7'
          },
          xl: {
            header: 'p-6 sm:px-8',
            body: 'p-6 sm:p-8',
            footer: 'p-6 sm:px-8'
          }
        },
        variant: {
          solid: {
            root: 'bg-inverted text-inverted'
          },
          outline: {
            root: 'bg-default ring ring-default divide-y divide-default'
          },
          soft: {
            root: 'bg-elevated/50 divide-y divide-default'
          },
          subtle: {
            root: 'bg-elevated/50 ring ring-default divide-y divide-default'
          }
        }
      },
      defaultVariants: {
        variant: 'outline',
        size: 'md'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        card: {
          slots: {
            root: 'rounded-lg overflow-hidden',
            header: 'p-4 sm:px-6',
            body: 'p-4 sm:p-6',
            footer: 'p-4 sm:px-6'
          },
          variants: {
            size: {
              xs: {
                header: 'p-2 sm:px-4',
                body: 'p-2 sm:p-4',
                footer: 'p-2 sm:px-4'
              },
              sm: {
                header: 'p-3 sm:px-5',
                body: 'p-3 sm:p-5',
                footer: 'p-3 sm:px-5'
              },
              md: {
                header: 'p-4 sm:px-6',
                body: 'p-4 sm:p-6',
                footer: 'p-4 sm:px-6'
              },
              lg: {
                header: 'p-5 sm:px-7',
                body: 'p-5 sm:p-7',
                footer: 'p-5 sm:px-7'
              },
              xl: {
                header: 'p-6 sm:px-8',
                body: 'p-6 sm:p-8',
                footer: 'p-6 sm:px-8'
              }
            },
            variant: {
              solid: {
                root: 'bg-inverted text-inverted'
              },
              outline: {
                root: 'bg-default ring ring-default divide-y divide-default'
              },
              soft: {
                root: 'bg-elevated/50 divide-y divide-default'
              },
              subtle: {
                root: 'bg-elevated/50 ring ring-default divide-y divide-default'
              }
            }
          },
          defaultVariants: {
            variant: 'outline',
            size: 'md'
          }
        }
      }
    })
  ]
})

Changelog

5cb65 — feat: import @nuxt/ui-pro components

e6e51 — fix: class should have priority over ui prop

39c86 — fix: refactor types after @nuxt/module-builder upgrade (#3855)