Settings shell
Workspace settings in five sections: a NavList beside the panel on wide screens and a Select above it on narrow ones, with Field, Switch, Table and Card in the panels and a Modal that asks for the workspace name before deleting it.
Fernhill Labs
Workspace settings
Settings section
General
Source · recipes/settings-shell.tsx
'use client'
import {
Badge,
Body,
BodySmall,
Button,
Card,
Field,
Heading,
Input,
Label,
Link,
Modal,
NavList,
Select,
Separator,
Stack,
Switch,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableHeader,
TableRow,
Text,
toastSuccess,
} from '@blocks/design-system'
import { Building2, CreditCard, Plug, TriangleAlert, Users } from 'lucide-react'
import { type FormEvent, type ReactNode, useId, useRef, useState } from 'react'
import styles from './settings-shell.module.css'
const sections = [
{ value: 'general', label: 'General', icon: Building2 },
{ value: 'members', label: 'Members', icon: Users },
{ value: 'billing', label: 'Billing', icon: CreditCard },
{ value: 'integrations', label: 'Integrations', icon: Plug },
{ value: 'danger', label: 'Danger zone', icon: TriangleAlert },
]
// App settings: a NavList beside the panel on wide containers, a Select above
// it on narrow ones. Both drive the same piece of state.
export default function SettingsShell() {
const [section, setSection] = useState('general')
const [workspace, setWorkspace] = useState('Fernhill Labs')
const id = useId()
const label = sections.find((item) => item.value === section)?.label
return (
<section aria-labelledby={`${id}-title`} className={styles.shell}>
<div className={styles.layout}>
<header className={styles.header}>
<span className={styles.avatar} aria-hidden>
{initials(workspace)}
</span>
<Stack gap="none">
<Heading as="h3" id={`${id}-title`} fontSize="md">
{workspace}
</Heading>
<BodySmall margin="none" color="text-muted">
Workspace settings
</BodySmall>
</Stack>
</header>
<NavList aria-label="Settings sections" dangerouslySetClassName={styles.nav}>
{sections.map((item) => (
<NavList.Item
key={item.value}
as="button"
type="button"
active={item.value === section}
onClick={() => setSection(item.value)}
dangerouslySetClassName={styles.navItem}
>
<item.icon aria-hidden size={16} />
{item.label}
</NavList.Item>
))}
</NavList>
<div className={styles.picker}>
<Select items={sections} value={section} onValueChange={(value) => value && setSection(value)}>
<Select.Label>Settings section</Select.Label>
<Select.Trigger />
<Select.Content>
{sections.map((item) => (
<Select.Item key={item.value} value={item.value}>
{item.label}
</Select.Item>
))}
</Select.Content>
</Select>
</div>
<section aria-labelledby={`${id}-panel`} className={styles.panel}>
<Heading as="h4" id={`${id}-panel`} fontSize="lg" marginBottom="lg">
{label}
</Heading>
{section === 'general' && <General workspace={workspace} onRename={setWorkspace} />}
{section === 'members' && <Members />}
{section === 'billing' && <Billing />}
{section === 'integrations' && <Integrations />}
{section === 'danger' && <DangerZone workspace={workspace} />}
</section>
</div>
</section>
)
}
function initials(name: string) {
return name
.split(/\s+/)
.map((word) => word[0])
.join('')
.slice(0, 2)
.toUpperCase()
}
const timeZones = [
{ value: 'America/Los_Angeles', label: 'Pacific time (UTC−8)' },
{ value: 'America/Denver', label: 'Mountain time (UTC−7)' },
{ value: 'America/New_York', label: 'Eastern time (UTC−5)' },
{ value: 'Europe/Berlin', label: 'Central European time (UTC+1)' },
]
function General({ workspace, onRename }: { workspace: string; onRename: (name: string) => void }) {
function save(event: FormEvent<HTMLFormElement>) {
event.preventDefault()
const name = String(new FormData(event.currentTarget).get('name')).trim()
onRename(name)
toastSuccess('Workspace settings saved')
}
return (
<Stack as="form" gap="lg" onSubmit={save}>
<Field name="name">
<Field.Label>Workspace name</Field.Label>
<Field.Control defaultValue={workspace} required maxLength={40} />
<Field.Error match="valueMissing">Give the workspace a name.</Field.Error>
</Field>
<Field name="slug">
<Field.Label>Workspace URL</Field.Label>
<Field.Control defaultValue="fernhill" required pattern="[a-z0-9\-]+" />
<Field.Description>harbor.app/fernhill · lowercase letters, numbers and dashes</Field.Description>
<Field.Error match="valueMissing">Choose a URL.</Field.Error>
<Field.Error match="patternMismatch">Use only lowercase letters, numbers and dashes.</Field.Error>
</Field>
{/* Field's wrapper gives the Select the same label spacing as the inputs. */}
<Field>
<Select name="timeZone" items={timeZones} defaultValue="America/Los_Angeles">
<Select.Label>Time zone</Select.Label>
<Select.Trigger />
<Select.Content>
{timeZones.map((zone) => (
<Select.Item key={zone.value} value={zone.value}>
{zone.label}
</Select.Item>
))}
</Select.Content>
</Select>
</Field>
<Switch name="digest" defaultChecked>
Email a weekly digest to admins
</Switch>
<Stack direction="row" justify="end">
<Button type="submit" variant="primary">
Save changes
</Button>
</Stack>
</Stack>
)
}
const roles = [
{ value: 'admin', label: 'Admin' },
{ value: 'editor', label: 'Editor' },
{ value: 'viewer', label: 'Viewer' },
]
interface Member {
name: string
email: string
role: string
invited?: boolean
}
function Members() {
const [members, setMembers] = useState<Member[]>([
{ name: 'Ines Halvorsen', email: 'ines@fernhill.dev', role: 'owner' },
{ name: 'Tobias Mbeki', email: 'tobias@fernhill.dev', role: 'admin' },
{ name: 'Ruth Alcántara', email: 'ruth@fernhill.dev', role: 'editor' },
{ name: 'Kenji Moreau', email: 'kenji@fernhill.dev', role: 'viewer' },
])
function invite(event: FormEvent<HTMLFormElement>) {
event.preventDefault()
const form = event.currentTarget
const email = String(new FormData(form).get('email')).trim()
setMembers([...members, { name: email.split('@')[0] ?? email, email, role: 'viewer', invited: true }])
toastSuccess(`Invite sent to ${email}`)
form.reset()
}
function changeRole(email: string, role: string) {
setMembers(members.map((member) => (member.email === email ? { ...member, role } : member)))
}
return (
<Stack gap="lg">
<ul className={styles.rows}>
{members.map((member) => (
<li key={member.email} className={styles.row}>
<span className={styles.avatar} data-size="sm" aria-hidden>
{initials(member.name)}
</span>
<Stack gap="none" flex="1" dangerouslySetClassName={styles.truncate}>
<Text fontWeight="medium">{member.name}</Text>
<Text fontSize="sm" color="text-muted">
{member.email}
</Text>
</Stack>
{member.invited && <Badge tone="info">Invited</Badge>}
{member.role === 'owner' ? (
<Badge>Owner</Badge>
) : (
<Select
items={roles}
value={member.role}
onValueChange={(role) => role && changeRole(member.email, role)}
>
<Select.Trigger size="sm" aria-label={`Role for ${member.name}`} />
<Select.Content>
{roles.map((role) => (
<Select.Item key={role.value} value={role.value}>
{role.label}
</Select.Item>
))}
</Select.Content>
</Select>
)}
</li>
))}
</ul>
<Stack as="form" direction="row" align="end" gap="sm" wrap="wrap" onSubmit={invite} aria-label="Invite a member">
<Field
name="email"
dangerouslySetClassName={styles.grow}
validate={(value) =>
members.some((member) => member.email === String(value).trim()) ? 'They’re already a member.' : null
}
>
<Field.Label>Invite by email</Field.Label>
<Field.Control type="email" placeholder="name@company.com" required />
<Field.Error match="valueMissing">Enter an email address.</Field.Error>
<Field.Error match="typeMismatch">That doesn’t look like an email address.</Field.Error>
<Field.Error match="customError" />
</Field>
<Button type="submit">Send invite</Button>
</Stack>
</Stack>
)
}
const invoices = [
{ date: 'Dec 1, 2026', number: 'FH-0012', amount: '$72.00' },
{ date: 'Nov 1, 2026', number: 'FH-0011', amount: '$60.00' },
{ date: 'Oct 1, 2026', number: 'FH-0010', amount: '$60.00' },
]
function Billing() {
const id = useId()
return (
<Stack gap="lg">
<Card padding="lg" backgroundColor="bg-subtle">
<Stack direction="row" justify="space-between" align="start" gap="md" wrap="wrap">
<Stack gap="xs">
<Stack direction="row" gap="sm" align="center">
<Text fontWeight="semibold">Team plan</Text>
<Badge tone="accent">Annual</Badge>
</Stack>
<Text fontSize="sm" color="text-muted">
6 seats × $12 per month · renews Jan 1, 2027
</Text>
</Stack>
<Text fontSize="xl" fontWeight="semibold">
$72<Text fontSize="sm" color="text-muted">/mo</Text>
</Text>
</Stack>
<Separator dangerouslySetClassName={styles.separator} />
<Stack direction="row" justify="space-between" align="center" gap="md" wrap="wrap">
<Text fontSize="sm">
<CreditCard aria-hidden size={16} className={styles.inlineIcon} /> Card ending 4417, expires 08/28
</Text>
<Stack direction="row" gap="sm">
<Button type="button" size="sm" variant="ghost">
Update card
</Button>
<Button type="button" size="sm">
Change plan
</Button>
</Stack>
</Stack>
</Card>
<TableContainer tabIndex={0} role="region" aria-labelledby={`${id}-invoices`}>
<Table>
<caption id={`${id}-invoices`}>Invoices</caption>
<TableHeader>
<TableRow>
<TableHead scope="col">Date</TableHead>
<TableHead scope="col">Invoice</TableHead>
<TableHead scope="col">Amount</TableHead>
<TableHead scope="col">Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.number}>
<TableHead scope="row">{invoice.date}</TableHead>
<TableCell>
<Link href={`#invoice-${invoice.number}`}>{invoice.number}</Link>
</TableCell>
<TableCell>{invoice.amount}</TableCell>
<TableCell>
<Badge tone="success">Paid</Badge>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Stack>
)
}
const apps = [
{ name: 'Pagerline', summary: 'Page the on-call engineer when an alert fires.', on: true },
{ name: 'Kitepost', summary: 'Post dashboard snapshots to team channels.', on: true },
{ name: 'Driftwood', summary: 'Sync query results to your warehouse nightly.', on: false },
{ name: 'Tallybook', summary: 'Send invoices to your accounting ledger.', on: false },
]
function Integrations() {
return (
<ul className={styles.rows}>
{apps.map((app) => (
<li key={app.name} className={styles.row}>
<span className={styles.appMark} aria-hidden>
{app.name[0]}
</span>
<Stack gap="none" flex="1">
<Text fontWeight="medium">{app.name}</Text>
<Text fontSize="sm" color="text-muted">
{app.summary}
</Text>
</Stack>
<Switch
aria-label={`Connect ${app.name}`}
defaultChecked={app.on}
onCheckedChange={(on) => toastSuccess(on ? `${app.name} connected` : `${app.name} disconnected`)}
/>
</li>
))}
</ul>
)
}
function DangerZone({ workspace }: { workspace: string }) {
const [open, setOpen] = useState(false)
const [confirmation, setConfirmation] = useState('')
const confirmInput = useRef<HTMLInputElement>(null)
const id = useId()
const matches = confirmation === workspace
function remove(event: FormEvent<HTMLFormElement>) {
event.preventDefault()
if (!open || !matches) return
setOpen(false)
setConfirmation('')
toastSuccess(`${workspace} is scheduled for deletion`, { description: 'You have 14 days to restore it.' })
}
return (
<Card padding="none" borderColor="danger">
<DangerRow
title="Export all data"
summary="Download every dashboard, query and member list as a ZIP archive."
action={
<Button type="button" size="sm" variant="ghost" onClick={() => toastSuccess('Export started')}>
Export
</Button>
}
/>
<Separator />
<DangerRow
title="Delete workspace"
summary="Removes dashboards, sources and members for everyone. This can’t be undone after 14 days."
action={
<Modal
open={open}
onOpenChange={(next) => {
setOpen(next)
if (!next) setConfirmation('')
}}
>
<Modal.Trigger render={<Button type="button" size="sm" variant="primary" dangerouslySetClassName={styles.destructive} />}>
Delete workspace
</Modal.Trigger>
<Modal.Content initialFocus={confirmInput}>
<Modal.Header>Delete {workspace}?</Modal.Header>
<Stack as="form" gap="md" onSubmit={remove}>
<Modal.Body>
<Body margin="none">
All 4 members lose access immediately. Dashboards, sources and alerts are deleted after 14 days.
</Body>
</Modal.Body>
<Stack gap="xs">
<Label htmlFor={`${id}-confirm`} fontWeight="body">
Type <strong>{workspace}</strong> to confirm
</Label>
<Input
id={`${id}-confirm`}
ref={confirmInput}
value={confirmation}
onChange={(event) => setConfirmation(event.target.value)}
autoComplete="off"
spellCheck={false}
/>
</Stack>
<Modal.Footer>
<Modal.Close render={<Button type="button" variant="ghost" />}>Cancel</Modal.Close>
<Button type="submit" variant="primary" disabled={!matches} dangerouslySetClassName={styles.destructive}>
Delete workspace
</Button>
</Modal.Footer>
</Stack>
</Modal.Content>
</Modal>
}
/>
</Card>
)
}
function DangerRow({ title, summary, action }: { title: string; summary: string; action: ReactNode }) {
return (
<Stack direction="row" justify="space-between" align="center" gap="md" padding="lg" wrap="wrap">
<Stack gap="xs" dangerouslySetClassName={styles.grow}>
<Text fontWeight="medium">{title}</Text>
<Text fontSize="sm" color="text-muted">
{summary}
</Text>
</Stack>
{action}
</Stack>
)
}How it works
- The NavList items render as buttons (
as="button") andactivemarks the current section witharia-current. The phoneSelectsets the same state, so switching between widths never loses your place. - The shell swaps the NavList for the Select with a container query on its own width, so it adapts to the column it sits in rather than the viewport.
- Forms validate on submit with
Field.Error: a pattern for the workspace URL,type="email"plus avalidatefunction that rejects existing members for invites. Saving renames the workspace everywhere, including the confirmation phrase in the Danger zone. - The destructive button is the primary
Buttonwith--ds-color-accentre-pointed at--ds-color-dangerfor that one element. Delete stays disabled until the typed name matches exactly, and closing the dialog clears what was typed.
App-owned CSS
/* The shell answers to its own width, not the viewport's. */
.shell {
container-type: inline-size;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr);
overflow: hidden;
background-color: var(--ds-color-bg);
border: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
border-radius: var(--ds-border-radius-xl);
}
.header {
display: flex;
align-items: center;
gap: var(--ds-space-md);
padding: var(--ds-space-lg);
border-bottom: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
}
.nav {
display: none;
}
.picker {
padding: var(--ds-space-lg) var(--ds-space-lg) 0;
}
.panel {
min-width: 0;
padding: var(--ds-space-lg);
}
@container (min-width: 34rem) {
.layout {
grid-template-columns: calc(var(--ds-space-xxl) * 2.5) minmax(0, 1fr);
}
.header {
grid-column: 1 / -1;
}
.nav {
display: block;
padding: var(--ds-space-md);
background-color: var(--ds-color-bg-subtle);
border-right: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
}
.picker {
display: none;
}
.panel {
padding: var(--ds-space-lg) var(--ds-space-xl) var(--ds-space-xl);
}
}
.navItem {
gap: var(--ds-space-md);
padding-block: var(--ds-space-sm);
}
.avatar {
display: grid;
flex-shrink: 0;
place-items: center;
width: var(--ds-control-height-lg);
aspect-ratio: 1;
font-size: var(--ds-font-size-sm);
font-weight: var(--ds-font-weight-semibold);
color: var(--ds-color-accent-fg);
background-color: var(--ds-color-accent);
border-radius: var(--ds-border-radius-md);
&[data-size="sm"] {
width: var(--ds-control-height-md);
font-size: var(--ds-font-size-xs);
color: var(--ds-color-accent-text);
background-color: var(--ds-color-accent-subtle);
border-radius: var(--ds-border-radius-circle);
}
}
.appMark {
display: grid;
flex-shrink: 0;
place-items: center;
width: var(--ds-control-height-md);
aspect-ratio: 1;
font-weight: var(--ds-font-weight-bold);
color: var(--ds-color-text-muted);
background-color: var(--ds-color-surface);
border: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
border-radius: var(--ds-border-radius-md);
}
.rows {
margin: 0;
padding: 0;
list-style: none;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--ds-space-md);
padding-block: var(--ds-space-md);
& + & {
border-top: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
}
}
.truncate {
min-width: 0;
& > * {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.grow {
flex: 1;
min-width: calc(var(--ds-space-xxxl) * 1.5);
}
.separator {
margin-block: var(--ds-space-lg);
}
.inlineIcon {
vertical-align: text-bottom;
color: var(--ds-color-text-muted);
}
/* A destructive action: the primary button with its accent pointed at danger. */
.destructive {
--ds-color-accent: var(--ds-color-danger);
--ds-color-accent-hover: var(--ds-color-danger-hover);
--ds-color-accent-fg: var(--ds-color-danger-fg);
}