// Surface container. Elevation is a token rung, and because the shadow tokens // are themed the same `elevation` reads correctly on light and dark. import type { JSX } from 'solid-js'; import { cx } from '../cx'; import styles from './Card.module.scss'; import type { SpaceStep } from './variants'; export type Elevation = 'flat' | 'xs' | 'sm' | 'md' | 'lg'; export interface CardProps { children: JSX.Element; header?: JSX.Element | undefined; footer?: JSX.Element | undefined; elevation?: Elevation | undefined; padding?: SpaceStep | undefined; /** Adds hover affordance. Only use when the whole card is a link/button. */ interactive?: boolean | undefined; as?: 'div' | 'article' | 'section' | 'li' | undefined; class?: string | undefined; } export function Card(props: CardProps): JSX.Element { const cls = (): string => cx( styles['card'], styles[`elevation-${props.elevation ?? 'sm'}`], props.interactive === true && styles['interactive'], props.class, ); const style = (): JSX.CSSProperties => ({ '--card-padding': `var(--space-${props.padding ?? 5})`, }); const header = (): JSX.Element => props.header === undefined ? null :
{props.header}
; const body = (): JSX.Element =>
{props.children}
; const footer = (): JSX.Element => props.footer === undefined ? null :
{props.footer}
; // One intrinsic per case, never `const Tag = props.as; `: the island build compiles a // capitalised tag to `createComponent(Tag)` and calls the string (#488, `intrinsic-root.test.ts`). switch (props.as ?? 'div') { case 'article': return (
{header()} {body()} {footer()}
); case 'section': return (
{header()} {body()} {footer()}
); case 'li': return (
  • {header()} {body()} {footer()}
  • ); case 'div': return (
    {header()} {body()} {footer()}
    ); } }