Skip to content
Get started

Components

SourceCard

Unstable: where an AI answer came from, a web page or a file, as one link with its domain, title and number. A web source opens in a new tab and says so. Import it from @nizivo/react/unstable/source-card.

Server component, no client JSUnstable

Examples

Basic

Two types under an answer: a web page (opens in a new tab) and a file.

import type { JSX } from 'react';
import { SourceCard } from '@nizivo/react/unstable/source-card';

export function SourceCardExample(): JSX.Element {
  return (
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 17.5rem)', gap: 16 }}>
      <SourceCard
        href="https://example.com/autumn-restock"
        domain="mossandkiln.com"
        title="Autumn restock: what sold out first"
        number={1}
      />
      <SourceCard
        href="/files/sales-report.pdf"
        type="file"
        domain="Sales report, October"
        title="Moss & Kiln sales report"
        number={2}
      />
    </div>
  );
}

Import

import { SourceCard } from '@nizivo/react/unstable/source-card';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/source-card.css';

Static or interactive

Server. No client JavaScript: it is a link. How to choose.

Web or file

type="web" (the default) shows a globe and opens in a new tab, with a visually hidden "(opens in a new tab)" after the title; type="file" shows a document and opens in place. newTab overrides either. domain is where it lives and title the card's main line. number repeats the Citation that points here; it is decorative, since the citation already names the source.

Layout

The card fills the width you give it: lay several out in a grid under the answer. The domain is cut short with an ellipsis when it does not fit; the title wraps.

Props

Server component Renders data-slot="source-card" with the class nz-source-card. Props: SourceCardProps. Source: src/unstable/source-card/source-card.tsx.

NameTypeDefaultDescription
domainrequiredstring–

Where it lives: a domain (mossandkiln.com) or a file's name or folder.

hrefrequiredstring–
labelsPartial<SourceCardLabels>–
localestring'en-US'

BCP 47 tag for the number.

newTabbooleantype === 'web'

Opens in a new tab (target="_blank", rel="noopener noreferrer").

numbernumber–

The source's number, as the answer's Citations show it.

renderRenderProp<Record<string, never>>–

Must render an <a>, for example a router's link.

titlerequiredstring–

The source's title, the card's main line.

type"web" | "file"'web'

The kind of source: a web page or a file.

  • Also takes every attribute of <a> except children, title; href, type are redeclared above. (Omit<ComponentPropsWithRef<"a">, "children" | "title">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

SourceCardLabels type

import type { SourceCardLabels } from '@nizivo/react/unstable/source-card'

SourceCard's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
newTabrequiredstring'(opens in a new tab)'

Read after the title when the card opens in a new tab.

SourceCardProps type

import type { SourceCardProps } from '@nizivo/react/unstable/source-card'

The props of SourceCard, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
source-card
.nz-source-card
SourceCard
root (takes render); interactive, focus: self
  • data-variant: "web""file"
    The variant prop; values in each component manifest
source-card-domain
.nz-source-card-domain
SourceCard
inner element (CSS only)
none
source-card-title
.nz-source-card-title
SourceCard
inner element (CSS only)
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

HookDefaultRead as
--nz-source-card-bg--nz-bg-surface
  • background on .nz-source-card
--nz-source-card-radius--nz-radius-lg
  • border-radius on .nz-source-card

Layers: nz.components. Classes: .nz-source-card, .nz-source-card-domain, .nz-source-card-header, .nz-source-card-icon, .nz-source-card-number, .nz-source-card-title.

Tokens this stylesheet reads (20)

--nz-bg-brand-subtle, --nz-bg-hover, --nz-bg-muted, --nz-bg-surface, --nz-border-default, --nz-border-subtle, --nz-border-width-default, --nz-font-body-s, --nz-font-label-m-strong, --nz-font-label-s, --nz-icon-brand, --nz-radius-lg, --nz-radius-xs, --nz-space-0-5, --nz-space-1-5, --nz-space-2, --nz-space-3, --nz-space-5, --nz-text-primary, --nz-text-secondary

Accessibility

These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:

  • source-card: draws the focus outline itself on keyboard focus.

Keyboard

To be written.

On this page