Skip to content
Get started

Components

ModelSelector

Unstable: which model answers, as a trade-off in plain words (Fast, Balanced, Deep), in a pill that opens a list describing each one. Import it from @nizivo/react/unstable/model-selector.

Tier: clientUnstable

Examples

Basic

Three trade-offs, named in words, with Balanced chosen.

Model
import type { JSX } from 'react';
import { ModelSelector } from '@nizivo/react/unstable/model-selector';

const MODELS = [
  { value: 'fast', label: 'Fast', description: 'Quick answers for simple tasks' },
  { value: 'balanced', label: 'Balanced', description: 'Good for most work' },
  { value: 'deep', label: 'Deep', description: 'Slower, more careful reasoning' },
];

export function ModelSelectorExample(): JSX.Element {
  return <ModelSelector models={MODELS} defaultValue="balanced" />;
}

Import

import { ModelSelector } from '@nizivo/react/unstable/model-selector';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css and @nizivo/react/css/popover.css and @nizivo/react/css/select.css
import '@nizivo/react/css/model-selector.css';

Static or interactive

Client. It is a Select: the same keyboard, typeahead and hidden native <select> for forms. How to choose.

Models

models lists the choices, each with a value, a label that names the trade-off ("Balanced", never a version number) and a description that says it in words ("Good for most work"). value, defaultValue (the first model by default) and onValueChange hold the choice. The trigger shows the chosen name only; its accessible name ends with labels.label ("Balanced Model").

Props

Client component Renders data-slot="model-selector" with the class nz-model-selector. Props: ModelSelectorProps. Source: src/unstable/model-selector/model-selector.client.tsx.

NameTypeDefaultDescription
classNamestring–
defaultValuestringthe first model

The model at first (uncontrolled).

disabledboolean–
labelsPartial<ModelSelectorLabels>–
modelsrequiredreadonly ModelOption[]–
namestring–

Submitted with a form, as Select's hidden native <select>.

onValueChange(value: string, details: ChangeDetails<SelectValueReason>) => void–
valuestring–

The chosen model (controlled).

Other exports

ModelOption type

import type { ModelOption } from '@nizivo/react/unstable/model-selector'

One choice.

NameTypeDefaultDescription
descriptionstring–

What it trades, in words: "Good for most work".

disabledboolean–
labelrequiredstring–

The trade-off's name: "Balanced".

valuerequiredstring–
ModelSelectorLabels type

import type { ModelSelectorLabels } from '@nizivo/react/unstable/model-selector'

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

NameTypeDefaultDescription
labelrequiredstring'Model'

Names the trigger, after the chosen model ("Balanced Model"), as every Select reads.

ModelSelectorProps type

import type { ModelSelectorProps } from '@nizivo/react/unstable/model-selector'

The props of ModelSelector, 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
model-selector
.nz-model-selector
ModelSelector
root (no render)
none
model-selector-item
.nz-model-selector-item
ModelSelector
inner element (CSS only); interactive, focus: engine
none
model-selector-trigger
.nz-model-selector-trigger
ModelSelector
inner element (CSS only); interactive, focus: self
none
model-selector-value
.nz-model-selector-value
ModelSelector
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.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-model-selector, .nz-model-selector-chevron, .nz-model-selector-description, .nz-model-selector-item, .nz-model-selector-name, .nz-model-selector-popup, .nz-model-selector-text, .nz-model-selector-trigger, .nz-model-selector-value, .nz-select-chevron, .nz-select-icon, .nz-select-item, .nz-select-popup, .nz-select-trigger.

Tokens this stylesheet reads (15)

--nz-border-default, --nz-font-body-s, --nz-font-label-m, --nz-font-label-m-strong, --nz-icon-brand, --nz-radius-full, --nz-radius-sm, --nz-space-0-5, --nz-space-1-5, --nz-space-10, --nz-space-2, --nz-space-3, --nz-space-8, --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:

  • model-selector-item: draws the focus outline when the engine reports keyboard focus, not on pointer hover.
  • model-selector-trigger: draws the focus outline itself on keyboard focus.

Keyboard

To be written.

On this page