⌘K
Search
Search pages, pieces and blocks.
Sign in/Sign in, sign up and reset password: the mark and a list of links beside a 400 wide form, centred in the window; an error on a wrong password.
components/blocks/sign-in.tsx
"use client"
import * as React from "react"
import { AsteriskIcon } from "@/components/icons"import { BrandMark } from "@/components/ui/brand-mark"import { Button } from "@/components/ui/button"import { Field, FieldError, FieldGroup } from "@/components/ui/field"import { InputGroup, InputGroupInput } from "@/components/ui/input-group"import { Link } from "@/components/ui/link"import { NavItem } from "@/components/ui/nav-item"import { PageHeader, PageHeaderTitle } from "@/components/ui/page-header"import { PasswordInput } from "@/components/ui/password-input"import { Separator } from "@/components/ui/separator"import { Text } from "@/components/ui/text"
// Sign in: sign in, sign up and reset password on one screen, no App Shell.// Two columns 100 apart, centred in the window both ways: the Maré mark// and a list of links (the current one in the text colour), then the form,// 400 wide, under its headline. Controlled by `state` when given, else it// keeps its own; its links move between the three and tell onStateChange.// A wrong password shows the error under the field. In the demo the right// password is Ericeira2026. On a phone the form comes first, the list at// the bottom.
type SignInState = "sign-in" | "sign-up" | "reset"
const headlines: Record<SignInState, string> = { "sign-in": "Lessons, schools and bookings in one place.", "sign-up": "One account for every school and lesson.", reset: "Reset password",}
function SignInBlock({ state, onStateChange,}: { state?: SignInState onStateChange?: (state: SignInState) => void}) { const [own, setOwn] = React.useState<SignInState>("sign-in") const current = state ?? own const [wrong, setWrong] = React.useState(false) const [sent, setSent] = React.useState(false)
function go(next: SignInState) { setOwn(next) setWrong(false) setSent(false) onStateChange?.(next) }
return ( <div className="flex min-h-full w-full items-center justify-center p-6"> {/* The form comes first in the markup, so Tab reaches it first on a phone, where it sits on top; from md the links column shows on its left. */} <div className="flex w-full max-w-100 flex-col gap-12 md:w-auto md:max-w-none md:flex-row-reverse md:items-start md:gap-25"> <div className="flex w-full flex-col gap-8 md:w-100"> <PageHeader> <PageHeaderTitle size="heading" className="whitespace-normal">{headlines[current]}</PageHeaderTitle> </PageHeader>
{current === "sign-in" && ( <form className="flex flex-col" onSubmit={(event) => { event.preventDefault() const password = new FormData(event.currentTarget).get("password") setWrong(password !== "Ericeira2026") }} > <FieldGroup> <Field> <InputGroup> <InputGroupInput id="sign-in-email" label="Email" name="email" type="email" autoComplete="email" defaultValue="antonio@mare.pt" /> </InputGroup> </Field> <Field data-invalid={wrong || undefined}> <PasswordInput id="sign-in-password" label="Password" name="password" autoComplete="current-password" invalid={wrong} aria-describedby={wrong ? "sign-in-error" : undefined} onChange={() => setWrong(false)} /> {wrong && <FieldError id="sign-in-error">That password does not match this email.</FieldError>} </Field> </FieldGroup> <Button type="submit" size="lg" className="mt-6 w-full"> Sign in </Button> <Text className="mt-3 self-center"> <Link render={<button type="button" />} onClick={() => go("reset")}> Forgot password? </Link> </Text> <Button type="button" variant="secondary" size="lg" className="mt-6 w-full"> Email me a sign in link </Button> </form> )}
{current === "sign-up" && ( <form className="flex flex-col" onSubmit={(event) => event.preventDefault()}> <FieldGroup> <Field> <InputGroup> <InputGroupInput id="sign-up-name" label="Name" name="name" autoComplete="name" placeholder="Tomás Amaro" /> </InputGroup> </Field> <Field> <InputGroup> <InputGroupInput id="sign-up-email" label="Email" name="email" type="email" autoComplete="email" placeholder="tomas@mare.pt" /> </InputGroup> </Field> <Field> <PasswordInput id="sign-up-password" label="Password" name="password" autoComplete="new-password" placeholder="At least 10 characters" /> </Field> </FieldGroup> <Button type="submit" size="lg" className="mt-6 w-full"> Create account </Button> <Button type="button" variant="secondary" size="lg" className="mt-6 w-full"> Join with an invite code </Button> </form> )}
{current === "reset" && ( <form className="flex flex-col" onSubmit={(event) => { event.preventDefault() setSent(true) }} > <Field> <InputGroup> <InputGroupInput id="reset-email" label="Email" name="email" type="email" autoComplete="email" defaultValue="antonio@mare.pt" /> </InputGroup> </Field> <Button type="submit" size="lg" className="mt-6 w-full"> Send reset link </Button> <Text aria-live="polite" className="mt-3 text-center"> {sent ? "If that email has an account, the link is on its way." : ""} </Text> <Text className="mt-3 self-center"> <Link render={<button type="button" />} onClick={() => go("sign-in")}> Back to sign in </Link> </Text> </form> )} </div>
<div className="flex flex-col gap-8 md:w-40"> <BrandMark size="sm" look="plain" role="img" aria-label="Maré"> <AsteriskIcon /> </BrandMark> <nav aria-label="Maré" className="flex flex-col"> <NavItem look="text" render={<button type="button" />} active={current === "sign-in"} onClick={() => go("sign-in")}> Sign in to Maré </NavItem> <NavItem look="text" render={<button type="button" />} active={current === "sign-up"} onClick={() => go("sign-up")}> Create an account </NavItem> <NavItem look="text" href="#"> Learn more </NavItem> <Separator className="my-2 data-horizontal:w-6" /> <NavItem look="text" href="#"> Docs </NavItem> </nav> </div> </div> </div> )}
export { SignInBlock }export type { SignInState }