Card
A box of related content: a header with its title, description and action, the content, a footer. In the look of the app's style.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, email, form, required,} from '@angular/forms/signals';import { RouterLink } from '@angular/router';import { ScButton, ScCard, ScCardAction, ScCardBody, ScCardDescription, ScCardFooter, ScCardHeader, ScCardTitle, ScField, ScFieldGroup, ScInput, ScLabel, ScLink,} from '@semantic-components/ui';
@Component({ selector: 'app-card-usage-demo', imports: [ RouterLink, FormField, FormRoot, ScButton, ScCard, ScCardAction, ScCardBody, ScCardDescription, ScCardFooter, ScCardHeader, ScCardTitle, ScField, ScFieldGroup, ScInput, ScLabel, ScLink, ], template: ` <div scCard class="w-full max-w-sm"> <div scCardHeader> <h3 scCardTitle>Login to your account</h3> <p scCardDescription>Enter your email below to login to your account</p> <div scCardAction> <button scButton variant="link">Sign Up</button> </div> </div> <div scCardBody> <form id="login-form" [formRoot]="loginForm"> <div scFieldGroup> <div scField> <label scLabel>Email</label> <input scInput type="email" [formField]="loginForm.email" placeholder="m@example.com" /> </div> <div scField> <div class="flex items-center"> <label scLabel>Password</label> <a scLink routerLink="." class="ms-auto"> Forgot your password? </a> </div> <input scInput type="password" [formField]="loginForm.password" /> </div> </div> </form> </div> <div scCardFooter class="flex-col gap-2"> <button scButton type="submit" form="login-form" class="w-full"> Login </button> <button scButton variant="outline" class="w-full"> Login with Google </button> </div> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class CardUsageDemo { private readonly model = signal({ email: '', password: '' }); private readonly loginForm = form( this.model, (path) => { required(path.email); email(path.email); required(path.password); }, // Submitted from the footer's Login (form="…"); invalid, the fields are // marked and the action waits. { submission: { action: async () => undefined } }, );}Anatomy
Every part is a directive on your element. The title is the heading you choose (an h3, an h4…), at the level that fits your page.
import { ScCard, ScCardHeader, ScCardTitle, ScCardDescription, ScCardAction, ScCardBody, ScCardFooter,} from '@semantic-components/ui';<div scCard> <div scCardHeader> <h3 scCardTitle>…</h3> <p scCardDescription>…</p> <div scCardAction>…</div> </div> <div scCardBody>…</div> <div scCardFooter>…</div></div>Notes
- The spacing between the sections and the inset of every part is one variable,
--card-spacing, set by the style and bysize="sm"; change it with a class on the card. - An image as the first child sits at the top with no padding above it, in the card's corners.
- The action goes to the end of the header, beside the title and the description.
- A footer's look is the style's: a muted band with a line above in nova, a line in lyra, none in the others (add
border-tfor one).
Examples
Size
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCard, ScCardBody, ScCardDescription, ScCardFooter, ScCardHeader, ScCardTitle,} from '@semantic-components/ui';Spacing
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { ScButton, ScCard, ScCardBody, ScCardDescription, ScCardFooter, ScCardHeader, ScCardTitle, ScToggleGroup,Edge to Edge
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCard, ScCardBody, ScCardDescription, ScCardFooter, ScCardHeader, ScCardTitle,} from '@semantic-components/ui';Image
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScBadge, ScButton, ScCard, ScCardAction, ScCardDescription, ScCardFooter, ScCardHeader,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, email, form, required,} from '@angular/forms/signals';import { RouterLink } from '@angular/router';API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScCard | div[scCard] | The card. Input size: 'default' or 'sm' (less spacing, a smaller title). |
ScCardHeader | div[scCardHeader] | The title and description, the action beside them; with border-b, a line and spacing below. |
ScCardTitle | [scCardTitle] | The title, on a heading of yours. |
ScCardDescription | [scCardDescription] | Muted text under the title. |
ScCardAction | div[scCardAction] | A button or badge at the end of the header. |
ScCardBody | div[scCardBody] | The content, inset by --card-spacing. |
ScCardFooter | div[scCardFooter] | Actions at the bottom: a row; its look from the style (with border-t, a line and spacing above). |
