Settings

Sections of rows in one column

5 min readWritten for your agentMarkdown

This recipe draws SettingsPage arrangement="column"; the others (agent/layout-chooser.md) take the same slots. Your page fits another? Change the one prop:

  • sections (sections: many): subNav a link to each section; sections many.
  • mode (sections: app-wide; Trail draws it as sections): subNav every settings area.
  • tabs (sections: few): subNav two to five tabs.

Copy the file below whole (src/screens/settings.tsx, say) beside frame.tsx (docs/screen-frame.md) and swap the sections and rows for your settings; keep the parts and their props. SettingsPage: the heading, then each section's heading over a card of Field rows, a control at each row's end (under its label on a phone). Each section is a <section> put straight in sections: the page spaces them in every arrangement, so write no wrapper or margin between them. A switch takes effect at once; a field keeps what is typed. Light, dark, phone and desktop are the parts' own: add no class for them.

Each kind of setting has its part ([settings.parts]), never a control of your own:

  • an order the person sets (steps, stages, pinned views): SortableList, its own rows under the section's heading;
  • a colour (a label's, a stage's, a team's): ColorPicker variant="field" in its row (beside a name, the quiet swatch);
  • a limit or an approximate amount: Slider (an exact number is a NumberInput);
  • an address, a unit or a prefix inside the field (https://, kg, a copy button): InputGroup;
  • a key: a read-only TextInput with a CopyButton at its end; a command or a request to copy: CodeBlock;
  • options few people open: an Accordion of blocks (one block alone: Collapsible);
  • a delete, or anything that cannot be undone: last on the page, a DestructiveButton that asks in an AlertDialog (what can be undone runs at once and offers Undo in its toast).
Show the code273 lines
TSX
// src/screens/settings.tsx: the settings page
import { type ReactNode, useState } from 'react';
import { SettingsPage } from '@/components/goop/patterns/settings-page';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/goop/accordion';
import {
  AlertDialog,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogDestructiveAction,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from '@/components/ui/goop/alert-dialog';
import { Card } from '@/components/ui/goop/card';
import { CodeBlock } from '@/components/ui/goop/code-block';
import { ColorPicker } from '@/components/ui/goop/color-picker';
import { CopyButton } from '@/components/ui/goop/copy-button';
import { DestructiveButton } from '@/components/ui/goop/destructive-button';
import { Field } from '@/components/ui/goop/field';
import {
  InputGroup,
  InputGroupAddon,
  InputGroupIconButton,
  InputGroupInput,
  InputGroupText,
} from '@/components/ui/goop/input-group';
import {
  PageHeader,
  PageHeaderContent,
  PageHeaderDescription,
  PageHeaderTitle,
} from '@/components/ui/goop/page-header';
import {
  Select,
  SelectContent,
  SelectIcon,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/goop/select';
import { Slider } from '@/components/ui/goop/slider';
import { SortableList } from '@/components/ui/goop/sortable-list';
import { Switch } from '@/components/ui/goop/switch';
import { TextInput } from '@/components/ui/goop/text-input';
import { SAMPLE_BRAND } from '@/lib/goop/trail/sample-brand';
import { ScreenFrame, ScreenTopBar } from './frame';

// ---- the sample data: swap it for yours
const KEEP_FOR = [
  { value: '90', words: 'After 90 days' },
  { value: '365', words: 'After a year' },
];
const STEPS = [
  { id: 'screener', label: 'Screener survey', length: '5 min' },
  { id: 'consent', label: 'Consent form', length: '2 min' },
  { id: 'interview', label: 'First interview', length: '45 min' },
];
const LABELS = [
  { id: 'follow-up', name: 'Follow-up', colour: '#eb5757' },
  { id: 'quote', name: 'Good quote', colour: '#4cb782' },
];
const API_KEY = 'fw_key_4Rt8Nc2Lm9Qx7Vb3Hp6s';
const ADD_NOTE = `curl https://api.fieldwork.example/v1/notes \\
  -H "X-Api-Key: ${API_KEY}" \\
  -d study=screener -d text="Wants exports by email"`;

/** A section: its heading over its rows. */
function Section({ id, title, line, children }: { id: string; title: string; line: string; children: ReactNode }) {
  return (
    <section aria-labelledby={`${id}-title`}>
      <PageHeader>
        <PageHeaderContent>
          <PageHeaderTitle asChild>
            <h2 id={`${id}-title`}>{title}</h2>
          </PageHeaderTitle>
          <PageHeaderDescription>{line}</PageHeaderDescription>
        </PageHeaderContent>
      </PageHeader>
      {children}
    </section>
  );
}

export default function SettingsScreen() {
  const [address, setAddress] = useState('fieldwork');
  const [steps, setSteps] = useState(STEPS);
  const [keepFor, setKeepFor] = useState('90');
  const [warnAt, setWarnAt] = useState(80);
  const [recordings, setRecordings] = useState(128);
  const [colours, setColours] = useState(() => Object.fromEntries(LABELS.map((l) => [l.id, l.colour])));
  const [digest, setDigest] = useState(true);
  return (
    <ScreenFrame current="/settings">
      <SettingsPage
        arrangement="column"
        header={<ScreenTopBar title="Settings" />}
        heading={
          <PageHeader>
            <PageHeaderContent>
              <PageHeaderTitle asChild>
                <h1>Workspace settings</h1>
              </PageHeaderTitle>
              <PageHeaderDescription>
                How the workspace is named, runs its studies, keeps recordings and reminds you.
              </PageHeaderDescription>
            </PageHeaderContent>
          </PageHeader>
        }
        sections={
          <>
            <Section id="workspace" title="Workspace" line="What everyone in it sees.">
              <Card variant="outline" asChild>
                <ul>
                  <Field as="li" label="Name">
                    <TextInput name="workspace" defaultValue={SAMPLE_BRAND.name} />
                  </Field>
                  <Field as="li" label="Web address">
                    <InputGroup>
                      <InputGroupAddon>
                        <InputGroupText>fieldwork.example/</InputGroupText>
                      </InputGroupAddon>
                      <InputGroupInput value={address} onChange={(e) => setAddress(e.currentTarget.value)} />
                      <InputGroupAddon side="end">
                        <InputGroupIconButton
                          copy={`https://fieldwork.example/${address}`}
                          icon="copy"
                          aria-label="Copy link"
                        />
                      </InputGroupAddon>
                    </InputGroup>
                  </Field>
                </ul>
              </Card>
            </Section>
            <Section id="steps" title="Study steps" line="Every new study starts with these, in this order.">
              <SortableList
                aria-label="Study steps"
                value={steps}
                onReorder={setSteps}
                renderItem={(step) => (
                  <span className="flex items-center gap-2">
                    <span className="min-w-0 flex-1 truncate">{step.label}</span>
                    <span className="text-muted-foreground">{step.length}</span>
                  </span>
                )}
              />
            </Section>
            <Section id="recordings" title="Recordings" line="Each study can change this in its own settings.">
              <Card variant="outline" asChild>
                <ul>
                  <Field as="li" label="Delete recordings" description="Transcripts and notes stay">
                    {(control) => (
                      <Select value={keepFor} onValueChange={setKeepFor}>
                        <SelectTrigger {...control}>
                          <SelectValue />
                          <SelectIcon />
                        </SelectTrigger>
                        <SelectContent aria-label="Delete recordings" search={false}>
                          {KEEP_FOR.map((option) => (
                            <SelectItem key={option.value} value={option.value}>
                              {option.words}
                            </SelectItem>
                          ))}
                        </SelectContent>
                      </Select>
                    )}
                  </Field>
                  <Field as="li" label="Warn me at" description="Of the plan’s storage">
                    {(control) => (
                      <Slider
                        aria-label="Warn me at"
                        aria-describedby={control['aria-describedby']}
                        min={50}
                        max={95}
                        step={5}
                        value={warnAt}
                        onValueChange={setWarnAt}
                        format={(value) => `${value}%`}
                      />
                    )}
                  </Field>
                </ul>
              </Card>
            </Section>
            <Section id="labels" title="Labels" line="The colour a note’s label wears.">
              <Card variant="outline" asChild>
                <ul>
                  {LABELS.map((label) => (
                    <Field key={label.id} as="li" label={label.name}>
                      {(control) => (
                        <ColorPicker
                          {...control}
                          variant="field"
                          label={`${label.name} colour`}
                          value={colours[label.id] ?? ''}
                          onValueChange={(colour) => setColours({ ...colours, [label.id]: colour })}
                        />
                      )}
                    </Field>
                  ))}
                </ul>
              </Card>
            </Section>
            <Section id="notices" title="Notifications" line="What reaches you outside the app.">
              <Card variant="outline" asChild>
                <ul>
                  <Field as="li" label="Weekly digest" description="A summary every Monday">
                    {(control) => <Switch {...control} checked={digest} onCheckedChange={setDigest} />}
                  </Field>
                </ul>
              </Card>
            </Section>
            <Section id="advanced" title="Advanced" line="Notes sent from your own tools.">
              <Accordion type="single" collapsible>
                <AccordionItem value="key">
                  <AccordionTrigger>API key</AccordionTrigger>
                  <AccordionContent>
                    <div className="flex w-full items-center gap-2">
                      <TextInput
                        aria-label="API key"
                        readOnly
                        value={API_KEY}
                        className="min-w-0 flex-1 text-ellipsis"
                      />
                      <CopyButton value={API_KEY} label="Copy key" variant="outline" size="lg" />
                    </div>
                  </AccordionContent>
                </AccordionItem>
                <AccordionItem value="request">
                  <AccordionTrigger>Send a note from a script</AccordionTrigger>
                  <AccordionContent>
                    <CodeBlock code={ADD_NOTE} language="bash" />
                  </AccordionContent>
                </AccordionItem>
              </Accordion>
            </Section>
            <Section id="danger" title="Delete recordings now" line="Gone for good: transcripts and notes stay.">
              <Card variant="outline" asChild>
                <ul>
                  <Field as="li" label="Recordings" description={`${recordings} kept`}>
                    {(control) => (
                      <AlertDialog>
                        <AlertDialogTrigger asChild>
                          <DestructiveButton aria-describedby={control['aria-describedby']} disabled={recordings === 0}>
                            Delete every recording
                          </DestructiveButton>
                        </AlertDialogTrigger>
                        <AlertDialogContent>
                          <AlertDialogHeader>
                            <AlertDialogTitle>{`Delete ${recordings} recordings?`}</AlertDialogTitle>
                            <AlertDialogDescription>They cannot be brought back.</AlertDialogDescription>
                          </AlertDialogHeader>
                          <AlertDialogFooter>
                            <AlertDialogCancel>Keep them</AlertDialogCancel>
                            <AlertDialogDestructiveAction onClick={() => setRecordings(0)}>
                              Delete every recording
                            </AlertDialogDestructiveAction>
                          </AlertDialogFooter>
                        </AlertDialogContent>
                      </AlertDialog>
                    )}
                  </Field>
                </ul>
              </Card>
            </Section>
          </>
        }
      />
    </ScreenFrame>
  );
}

Where would you like to start?

Free · now

The Goop plugin

A design system for your AI coding agent, so screen ten matches screen one.

/plugin marketplace add goop-so/skillsthen /plugin install goop@goopCodex, Cursor, ChatGPT, the Claude app and more: Connect Goop
FreePro

The components

Every part live, with its props, its keys and what an agent sees. Whole page and app templates, working with sample data.