@hanzo/ui

Choicebox

import { Choicebox } from '@hanzo/ui'

Default

One plan at a time; clicking a card never clears the choice.

export function Default() {
  return (
    <YStack maxW={420} width="100%">
      <Choicebox options={plans} defaultValue="team" />
    </YStack>
  )
}

Multiple

`multiple` turns each card into its own checkbox, so any number can be on.

export function Multiple() {
  const notifications = [
    { value: "email", label: "Email", description: "A digest every morning." },
    { value: "push", label: "Push", description: "As soon as it happens." },
    { value: "sms", label: "SMS", description: "Only for incidents." },
  ]
  return (
    <YStack maxW={420} width="100%">
      <Choicebox options={notifications} defaultValue="email,push" multiple />
    </YStack>
  )
}

Controlled

`value` and `onChange` hand the choice to you, as a plain string.

You picked starter.

export function Controlled() {
  const [plan, setPlan] = useState("starter")
  return (
    <YStack gap="$3" maxW={420} width="100%">
      <Choicebox options={plans} value={plan} onChange={setPlan} />
      <Paragraph color="$quiet">You picked {plan}.</Paragraph>
    </YStack>
  )
}

Without a description

The label alone is enough for a short list of options.

export function LabelOnly() {
  const sizes = [
    { value: "s", label: "Small" },
    { value: "m", label: "Medium" },
    { value: "l", label: "Large" },
  ]
  return (
    <YStack maxW={280} width="100%">
      <Choicebox options={sizes} defaultValue="m" />
    </YStack>
  )
}

Types

export type ChoiceboxOption = {
  value: string
  label: ReactNode
  description?: ReactNode
}
export type ChoiceboxProps = Omit<
  ComponentProps<typeof GuiToggleGroup>,
  'type' | 'value' | 'defaultValue' | 'onValueChange' | 'onChange' | 'children'
> & {
  options: ChoiceboxOption[]
  value?: string
  defaultValue?: string
  onChange?: (value: string) => void
  multiple?: boolean
}

Exports

Choiceboxtype ChoiceboxOptiontype ChoiceboxProps