AccountSwitcher

Pick which signed-in account to use. One highlight stretches to the chosen row, arrow keys move the choice, and the radio semantics are real. Auth.

Open playground

Acting as Mara Okonkwo.

About

AccountSwitcher is a React component in the Auth category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { AccountSwitcher } from "@ashutoshswamy/smoui" and set accounts, value, onSwitch among its 4 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { AccountSwitcher } from "@ashutoshswamy/smoui";

<AccountSwitcher
  accounts={[
    { id: "a", name: "Mara Okonkwo", email: "mara@smoui.dev" },
    { id: "b", name: "Studio Okonkwo", email: "hello@okonkwo.studio" },
  ]}
  onSwitch={(id) => switchTo(id)}
  onAdd={() => addAccount()}
/>

Props 4

accounts

Signed-in accounts.

{ id: string; name: string; email: string; avatar?: string }[]
value / defaultValue

Controlled or initial account id.

string
onSwitch

Called when another account is chosen.

(id: string) => void
onAdd

Adds an Add another account row.

() => void