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.
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.
| Name | Type | Default | Description |
|---|---|---|---|
domainrequired | string | – | Where it lives: a domain ( |
hrefrequired | string | – | |
labels | Partial<SourceCardLabels> | – | |
locale | string | 'en-US' | BCP 47 tag for the number. |
newTab | boolean | type === 'web' | Opens in a new tab ( |
number | number | – | The source's number, as the answer's Citations show it. |
render | RenderProp<Record<string, never>> | – | Must render an |
titlerequired | string | – | 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>exceptchildren,title;href,typeare 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
SourceCardLabelstypeimport type { SourceCardLabels } from '@nizivo/react/unstable/source-card'SourceCard's own strings (§16.4): serialisable, English defaults.
Name Type Default Description newTabrequiredstring'(opens in a new tab)'Read after the title when the card opens in a new tab.
SourceCardPropstypeimport 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.
| Slot | Rendered by | Data attributes |
|---|---|---|
source-card.nz-source-card | SourceCardroot (takes render); interactive, focus: self |
|
source-card-domain.nz-source-card-domain | SourceCardinner element (CSS only) | none |
source-card-title.nz-source-card-title | SourceCardinner 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.
| Hook | Default | Read as |
|---|---|---|
--nz-source-card-bg | --nz-bg-surface |
|
--nz-source-card-radius | --nz-radius-lg |
|
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.
Slider
Unstable: a value in a range on a native range input, its name and value written out above the track. Import it from @nizivo/react/unstable/slider.
Split
A main column and an aside, side by side while there is room and stacked below that, by the Split's own width, with no breakpoint and no script.