Components › Components

On this page

Card

A box with a header, a body and a footer.

Team plan

For up to ten people.

Shared projects, roles, and one invoice.

Usage #

tscl
@import uiCard from './card.tscl'
@import uiButton from './button.tscl'

<div class="demo">
  <uiCard>
    @slot('header') {
      <h2>Team plan</h2>
      <p>For up to ten people.</p>
    }
    <p>Shared projects, roles, and one invoice.</p>
    @slot('footer') {
      <uiButton variant="outline">Compare</uiButton>
      <uiButton>Choose</uiButton>
    }
  </uiCard>
</div>

<style scoped>
  :scope {
    display: grid;
    gap: 12px;
    padding: 24px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    background: var(--ui-bg);
    color: var(--ui-fg);
  }
</style>

Source #

Copy it into your components folder (next to the others) as card.tscl.

tscl
{{-- Card: an <article> with a header, a body and a footer; a header or footer you don't fill is hidden. parts takes
     attributes (class, style, data-*) for each piece: header, body, footer. --}}
@input parts: { header?: Record<string, string | boolean>; body?: Record<string, string | boolean>; footer?: Record<string, string | boolean> } = {}

<article data-part="card">
  <header [...]="parts.header ?? {}" data-part="card-header"><slot name="header" /></header>
  <div [...]="parts.body ?? {}" data-part="card-body"><slot /></div>
  <footer [...]="parts.footer ?? {}" data-part="card-footer"><slot name="footer" /></footer>
</article>

<style scoped>
  @layer theme, base, components, utilities;
  @layer components {
    :where(:scope) {
      display: grid;
      gap: 16px;
      padding: 20px;
      border: 1px solid var(--ui-border);
      border-radius: calc(var(--ui-radius) * 1.5);
      background: var(--ui-card);
      color: var(--ui-card-fg);
      font-family: var(--ui-font);
    }
    :where([data-part='card-header'] :is(h1), :where(h2), :where(h3), :where(h4)) {
      margin: 0;
      font-size: calc(var(--ui-font-size) + 4px);
    }
    :where([data-part='card-header'] p) {
      margin: 4px 0 0;
      color: var(--ui-muted);
      font-size: var(--ui-font-size);
    }
    :where([data-part='card-footer']) {
      display: flex;
      gap: 8px;
      justify-content: flex-end;
    }
    :where([data-part='card-header']:empty),
    :where([data-part='card-footer']:empty) {
      display: none;
    }
  }
</style>

Styling #

Needs #