Skip to Content

Account Screens

Profile, devices and API keys: the settings sections of a signed-in account.

Profile

AV
Name
Asha Verma
Email
[email protected]
Phone
+91 98765 43210
import { Button } from "@dapplelight/signet-ui/components/button"
import { ProfileCard } from "@dapplelight/signet-ui/screens/account-screens"
import { useState } from "react"

export function ProfileCardDemo() {
  const [name, setName] = useState("Asha Verma")
  return (
    <div className="w-full max-w-md">
      <ProfileCard
        profile={{ name, email: "[email protected]", phone: "+91 98765 43210" }}
        onSave={async (patch) => setName(patch.name)}
        action={<Button variant="outline" size="sm">Change photo</Button>}
      />
    </div>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import { ProfileCard, SessionsList, SessionItem, ApiKeysManager, ApiKeyReveal, AccountSection, AccountSectionHeader } from "@dapplelight/signet-ui/screens/account-screens"
import { sessions, revoke, revokeOthers } from "./sessions"

<SessionsList sessions={sessions} onRevoke={revoke} onRevokeOthers={revokeOthers} />

Examples

ProfileCard

Profile

AV
Name
Asha Verma
Email
[email protected]
Phone
+91 98765 43210
import { Button } from "@dapplelight/signet-ui/components/button"
import { ProfileCard } from "@dapplelight/signet-ui/screens/account-screens"
import { useState } from "react"

export function ProfileCardDemo() {
  const [name, setName] = useState("Asha Verma")
  return (
    <div className="w-full max-w-md">
      <ProfileCard
        profile={{ name, email: "[email protected]", phone: "+91 98765 43210" }}
        onSave={async (patch) => setName(patch.name)}
        action={<Button variant="outline" size="sm">Change photo</Button>}
      />
    </div>
  )
}

SessionsList

Devices

  • Chrome on macOSThis device103.21.4.18 · Active just now
  • Safari on iPhone49.36.12.7 · Active 3 hours ago
  • Firefox on Windows122.172.9.40 · Active 3 days ago
import { type SessionRow, SessionsList } from "@dapplelight/signet-ui/screens/account-screens"
import { useState } from "react"

const hoursAgo = (h: number) => Date.now() - h * 3600_000

const initialSessions: SessionRow[] = [
  { id: "s1", device: "Chrome on macOS", ip: "103.21.4.18", lastSeenAt: Date.now(), current: true },
  { id: "s2", device: "Safari on iPhone", ip: "49.36.12.7", lastSeenAt: hoursAgo(3) },
  { id: "s3", device: "Firefox on Windows", ip: "122.172.9.40", lastSeenAt: hoursAgo(72) },
]

export function SessionsListDemo() {
  const [sessions, setSessions] = useState(initialSessions)
  return (
    <div className="w-full max-w-md">
      <SessionsList
        sessions={sessions}
        onRevoke={(s) => setSessions((list) => list.filter((x) => x.id !== s.id))}
        onRevokeOthers={() => setSessions((list) => list.filter((x) => x.current))}
      />
    </div>
  )
}

SessionItem

  • Safari on iPhone49.36.12.7 · Active 3 hours ago
import { SessionItem, type SessionRow } from "@dapplelight/signet-ui/screens/account-screens"

const hoursAgo = (h: number) => Date.now() - h * 3600_000

const initialSessions: SessionRow[] = [
  { id: "s1", device: "Chrome on macOS", ip: "103.21.4.18", lastSeenAt: Date.now(), current: true },
  { id: "s2", device: "Safari on iPhone", ip: "49.36.12.7", lastSeenAt: hoursAgo(3) },
  { id: "s3", device: "Firefox on Windows", ip: "122.172.9.40", lastSeenAt: hoursAgo(72) },
]

export function SessionItemDemo() {
  return (
    <ul className="w-full max-w-md list-none p-0">
      <SessionItem session={initialSessions[1] as SessionRow} onRevoke={() => undefined} />
    </ul>
  )
}

ApiKeysManager

API keys

  • CI deployapp_1a2b3c… · Used 2 hours ago
  • Analytics exportapp_9f8e7d… · Never used
import { type ApiKeyRow, ApiKeysManager } from "@dapplelight/signet-ui/screens/account-screens"
import { useState } from "react"

const hoursAgo = (h: number) => Date.now() - h * 3600_000

const initialKeys: ApiKeyRow[] = [
  { id: "k1", name: "CI deploy", start: "app_1a2b3c", createdAt: hoursAgo(24 * 30), lastUsedAt: hoursAgo(2) },
  { id: "k2", name: "Analytics export", start: "app_9f8e7d", createdAt: hoursAgo(24 * 90), lastUsedAt: null },
]

export function ApiKeysManagerDemo() {
  const [keys, setKeys] = useState(initialKeys)
  return (
    <div className="w-full max-w-md">
      <ApiKeysManager
        keys={keys}
        onCreate={({ name }) => {
          const token = `app_${Math.random().toString(36).slice(2, 10)}${Math.random().toString(36).slice(2, 18)}`
          setKeys((list) => [
            ...list,
            { id: token, name, start: token.slice(0, 10), createdAt: Date.now(), lastUsedAt: null },
          ])
          return { token }
        }}
        onRevoke={(key) => setKeys((list) => list.filter((k) => k.id !== key.id))}
      />
    </div>
  )
}

ApiKeyReveal

import { ApiKeyReveal } from "@dapplelight/signet-ui/screens/account-screens"

export function ApiKeyRevealDemo() {
  return (
    <div className="w-full max-w-md">
      <ApiKeyReveal token="app_1a2b3c4d5e6f7g8h9i0jklmnopqrstuv" />
    </div>
  )
}

AccountSection and AccountSectionHeader

Notifications

Weekly digest and billing emails go to [email protected].

import { Button } from "@dapplelight/signet-ui/components/button"
import { AccountSection, AccountSectionHeader } from "@dapplelight/signet-ui/screens/account-screens"

export function AccountSectionDemo() {
  return (
    <div className="w-full max-w-md">
      <AccountSection>
        <AccountSectionHeader title="Notifications" action={<Button size="sm" variant="outline">Edit</Button>} />
        <p className="text-neutral-500">Weekly digest and billing emails go to [email protected].</p>
      </AccountSection>
    </div>
  )
}

API Reference

ProfileCard

PropTypeDefaultDescription
profileProfile—name, email, phone, image.
onSave(patch: { name: string }) => unknown—Save a new name. Without it the name is read-only.
actionReactNode—Shown beside the details, e.g. a Change photo button.
labelsPartial<AccountLabels>—Every string, in English by default. Spread DEFAULT_ACCOUNT_LABELS to translate.
classNamestring—Class for the root.
classNamesPartial<Record<"avatar" | "details" | "form", string>>—Classes per part.

SessionsList

PropTypeDefaultDescription
sessionsreadonly SessionRow[]—Rows of sessionRoutes GET; current marks this device.
onRevoke(session: SessionRow) => unknown—Sign out one device.
onRevokeOthers() => unknown—Sign out everywhere else. Confirms first.
localestringbrowserFor relative times.
labelsPartial<AccountLabels>—Every string, in English by default. Spread DEFAULT_ACCOUNT_LABELS to translate.
classNamesPartial<Record<"header" | "list" | "item", string>>—Classes per part.

SessionItem

PropTypeDefaultDescription
sessionSessionRow—The device row.
onRevoke(session: SessionRow) => unknown—Shows a sign-out button.
localestringbrowserFor relative times.
labelsPartial<AccountLabels>—Every string, in English by default. Spread DEFAULT_ACCOUNT_LABELS to translate.

ApiKeysManager

PropTypeDefaultDescription
keysreadonly ApiKeyRow[]—Keys without their secrets.
onCreate(input: { name: string }) => Promise<{ token: string }> | { token: string }—Mint a key. The token is shown once, then dropped.
onRevoke(key: ApiKeyRow) => unknown—Revoke a key. Confirms first.
localestringbrowserFor relative times.
labelsPartial<AccountLabels>—Every string, in English by default. Spread DEFAULT_ACCOUNT_LABELS to translate.
classNamesPartial<Record<"header" | "list" | "item" | "empty" | "dialog", string>>—Classes per part.

ApiKeyReveal

PropTypeDefaultDescription
tokenstring—The new key: read-only, selected on focus, with a copy button.
labelsPartial<AccountLabels>—Every string, in English by default. Spread DEFAULT_ACCOUNT_LABELS to translate.

AccountSection

PropTypeDefaultDescription
renderReactElement | (props, state) => ReactElement—Swaps the <section> element.
classNamestring—Merged over the card styles.

AccountSectionHeader

PropTypeDefaultDescription
titleReactNode—The section heading.
actionReactNode—Shown on the right.
idstring—Id of the heading, for aria-labelledby.