Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Templates

Settings

Free

Account settings in tabs: a profile form, notification switches and a password change.

Open full screen

The download follows the framework picked above the code. Unzip it and run npm install, then npm run dev.

Live preview

Preview width

Code

tsx
import { useState, type FormEvent } from "react";
import {
  Avatar,
  Button,
  Card,
  Container,
  Field,
  Flex,
  Heading,
  Input,
  Navbar,
  PasswordInput,
  Select,
  Stack,
  Switch,
  Tabs,
  Text,
  Textarea,
} from "@vjdesigns/vjdesigns-ui";

/** Account settings in tabs: a profile form, notification switches and a password change. Each tab saves on its own and confirms with a status message. */
export function SettingsPage() {
  const [saved, setSaved] = useState("");
  const save = (what: string) => (event: FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    setSaved(`${what} saved.`);
  };

  return (
    <>
      <Navbar position="sticky" collapseBelow="md" menuTitle="Acme">
        <Navbar.Brand href="#home">Acme</Navbar.Brand>
        <Navbar.Nav aria-label="Main">
          <Navbar.Link href="#projects">Projects</Navbar.Link>
          <Navbar.Link href="#team">Team</Navbar.Link>
          <Navbar.Link href="#settings" active>
            Settings
          </Navbar.Link>
        </Navbar.Nav>
        <Navbar.Actions>
          <Avatar name="Jordan Lee" size="sm" colorFromName />
        </Navbar.Actions>
      </Navbar>

      <Container as="main" size="md" gutter="responsive" py={10}>
        <Stack gap={6}>
          <Stack gap={2}>
            <Heading level={1} size="3xl">
              Settings
            </Heading>
            <Text tone="muted">Manage your profile, notifications and password.</Text>
          </Stack>

          <Tabs defaultValue="profile" onValueChange={() => setSaved("")}>
            <Tabs.List aria-label="Settings">
              <Tabs.Tab value="profile">Profile</Tabs.Tab>
              <Tabs.Tab value="notifications">Notifications</Tabs.Tab>
              <Tabs.Tab value="security">Security</Tabs.Tab>
            </Tabs.List>

            <Tabs.Panel value="profile">
              <Card padding="lg" style={{ marginTop: "1.5rem" }}>
                <form onSubmit={save("Profile")}>
                  <Stack gap={4}>
                    <Flex align="center" gap={4} wrap="wrap">
                      <Avatar name="Jordan Lee" size="lg" colorFromName />
                      <Button variant="outline" tone="neutral" size="sm">
                        Change photo
                      </Button>
                    </Flex>
                    <Field label="Full name">
                      <Input name="name" autoComplete="name" defaultValue="Jordan Lee" fullWidth />
                    </Field>
                    <Field label="Email" hint="We'll send a link to confirm a new address.">
                      <Input name="email" type="email" autoComplete="email" defaultValue="jordan@example.com" fullWidth />
                    </Field>
                    <Field label="Time zone">
                      <Select
                        name="timezone"
                        defaultValue="america-new-york"
                        options={[
                          { value: "america-los-angeles", label: "Pacific Time (Los Angeles)" },
                          { value: "america-new-york", label: "Eastern Time (New York)" },
                          { value: "europe-london", label: "London" },
                          { value: "asia-tokyo", label: "Tokyo" },
                        ]}
                      />
                    </Field>
                    <Field label="Bio" hint="A sentence or two for your profile.">
                      <Textarea name="bio" rows={3} />
                    </Field>
                    <Flex justify="end">
                      <Button type="submit" tone="primary">
                        Save profile
                      </Button>
                    </Flex>
                  </Stack>
                </form>
              </Card>
            </Tabs.Panel>

            <Tabs.Panel value="notifications">
              <Card padding="lg" style={{ marginTop: "1.5rem" }}>
                <form onSubmit={save("Notification settings")}>
                  <Stack gap={5}>
                    <Switch name="mentions" label="Mentions and replies" description="When someone mentions you or replies to you." labelPosition="between" defaultChecked />
                    <Switch name="weekly" label="Weekly summary" description="A Monday email with last week's activity." labelPosition="between" defaultChecked />
                    <Switch name="product" label="Product news" description="New features and tips, about once a month." labelPosition="between" />
                    <Flex justify="end">
                      <Button type="submit" tone="primary">
                        Save notifications
                      </Button>
                    </Flex>
                  </Stack>
                </form>
              </Card>
            </Tabs.Panel>

            <Tabs.Panel value="security">
              <Card padding="lg" style={{ marginTop: "1.5rem" }}>
                <form onSubmit={save("Password")}>
                  <Stack gap={4}>
                    <Field label="Current password">
                      <PasswordInput name="current" autoComplete="current-password" fullWidth />
                    </Field>
                    <Field label="New password">
                      <PasswordInput
                        name="new"
                        autoComplete="new-password"
                        fullWidth
                        strength
                        requirements={[
                          { id: "length", label: "At least 12 characters", test: (p) => p.length >= 12 },
                          { id: "number", label: "A number", test: (p) => /\d/.test(p) },
                        ]}
                      />
                    </Field>
                    <Flex justify="end">
                      <Button type="submit" tone="primary">
                        Change password
                      </Button>
                    </Flex>
                  </Stack>
                </form>
              </Card>
            </Tabs.Panel>
          </Tabs>

          <Text role="status" weight="semibold">
            {saved}
          </Text>
        </Stack>
      </Container>
    </>
  );
}