Components
Password input
NativeA password field with an explicit reveal button, Caps Lock warning and optional guidance.
Installation
npx nook-ui@latest add password-inputPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Password input" component to this project, exactly as Nook ships it.
A password field with an explicit reveal button, Caps Lock warning and optional guidance.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add password-input`. It writes `components/ui/password-input.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/password-input.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { PasswordInput, PASSWORD_REQUIREMENTS } from "@/components/ui/password-input";
import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
export default function PasswordInputDefault() {
const [password, setPassword] = React.useState("");
const [confirmation, setConfirmation] = React.useState("");
const [saved, setSaved] = React.useState(false);
const id = React.useId();
const matches = !!password && password === confirmation;
const requirementsMet = PASSWORD_REQUIREMENTS.every((rule) => rule.test(password));
return <form className="grid w-full max-w-sm gap-5" onSubmit={(event) => { event.preventDefault(); if (matches && requirementsMet) setSaved(true); }}>
<div><h3 className="font-semibold">Keep your account yours</h3><p className="mt-1 text-xs text-muted-foreground">Create a unique password for your workspace.</p></div>
<div className="grid gap-2"><Label htmlFor={`${id}-new`}>Create password</Label><PasswordInput id={`${id}-new`} name="password" value={password} onValueChange={(next) => { setPassword(next); setSaved(false); }} autoComplete="new-password" strength requirements={PASSWORD_REQUIREMENTS} required /></div>
<div className="grid gap-2"><Label htmlFor={`${id}-confirm`}>Confirm password</Label><PasswordInput id={`${id}-confirm`} name="confirmation" value={confirmation} onValueChange={(next) => { setConfirmation(next); setSaved(false); }} autoComplete="new-password" aria-describedby={`${id}-match`} aria-invalid={confirmation && !matches ? true : undefined} required /><p id={`${id}-match`} role="status" className="text-xs text-muted-foreground">{confirmation ? matches ? "Passwords match." : "The passwords don’t match yet. Check both fields." : "Enter the same password again."}</p></div>
<Button type="submit" disabled={!matches || !requirementsMet}>Create account</Button><p role="status" className="text-xs text-muted-foreground">{saved ? "Your password is ready. This demo does not create an account." : ""}</p>
</form>;
}
```
API
- `PasswordInput`: Uses InputGroup. The strength meter estimates length and character variety only; it does not check breaches or predictability and is a hint, not a security guarantee.
- `value, defaultValue, onValueChange` (`string, string, (password: string) => void`): Controlled or initial password; native onChange also works.
- `autoComplete` (`string`, default current-password): Use new-password when creating or confirming a password.
- `strength` (`boolean`, default false): Show four square meter segments with Weak, Fair, Good or Strong in words.
- `requirements` (`PasswordRequirement[]`): Rules with id, label and test(password). PASSWORD_REQUIREMENTS exports a length, number, case and symbol checklist.
- `...props` (`React.InputHTMLAttributes<HTMLInputElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Hidden by default. Show/hide exposes aria-pressed; Caps Lock and requirement changes are announced politely. Label the input using id and Label or aria-label. The ref points to the input and native password-manager attributes are preserved.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { PasswordInput, PASSWORD_REQUIREMENTS } from "@/components/ui/password-input";
import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
export default function PasswordInputDefault() {
const [password, setPassword] = React.useState("");
const [confirmation, setConfirmation] = React.useState("");
const [saved, setSaved] = React.useState(false);
const id = React.useId();
const matches = !!password && password === confirmation;
const requirementsMet = PASSWORD_REQUIREMENTS.every((rule) => rule.test(password));
return <form className="grid w-full max-w-sm gap-5" onSubmit={(event) => { event.preventDefault(); if (matches && requirementsMet) setSaved(true); }}>
<div><h3 className="font-semibold">Keep your account yours</h3><p className="mt-1 text-xs text-muted-foreground">Create a unique password for your workspace.</p></div>
<div className="grid gap-2"><Label htmlFor={`${id}-new`}>Create password</Label><PasswordInput id={`${id}-new`} name="password" value={password} onValueChange={(next) => { setPassword(next); setSaved(false); }} autoComplete="new-password" strength requirements={PASSWORD_REQUIREMENTS} required /></div>
<div className="grid gap-2"><Label htmlFor={`${id}-confirm`}>Confirm password</Label><PasswordInput id={`${id}-confirm`} name="confirmation" value={confirmation} onValueChange={(next) => { setConfirmation(next); setSaved(false); }} autoComplete="new-password" aria-describedby={`${id}-match`} aria-invalid={confirmation && !matches ? true : undefined} required /><p id={`${id}-match`} role="status" className="text-xs text-muted-foreground">{confirmation ? matches ? "Passwords match." : "The passwords don’t match yet. Check both fields." : "Enter the same password again."}</p></div>
<Button type="submit" disabled={!matches || !requirementsMet}>Create account</Button><p role="status" className="text-xs text-muted-foreground">{saved ? "Your password is ready. This demo does not create an account." : ""}</p>
</form>;
}Examples
With strength hint
A hint based on length and variety, not a guarantee of security. Use a unique password.
With a checklist
Each rule ticks off as it is met.
- Not met: At least 8 characters
- Not met: A number
- Not met: An uppercase and a lowercase letter
- Not met: A symbol
Invalid
That password does not match this account. Try again or reset it.
Disabled
You sign in with Google, so there is no password to change.
Props
PasswordInput
Uses InputGroup. The strength meter estimates length and character variety only; it does not check breaches or predictability and is a hint, not a security guarantee.
| Prop | Type | Default | Description |
|---|---|---|---|
| value, defaultValue, onValueChange | string, string, (password: string) => void | – | Controlled or initial password; native onChange also works. |
| autoComplete | string | current-password | Use new-password when creating or confirming a password. |
| strength | boolean | false | Show four square meter segments with Weak, Fair, Good or Strong in words. |
| requirements | PasswordRequirement[] | – | Rules with id, label and test(password). PASSWORD_REQUIREMENTS exports a length, number, case and symbol checklist. |
| ...props | React.InputHTMLAttributes<HTMLInputElement> | – | Everything the native element accepts, such as `id`, `aria-*` and event handlers. |
Accessibility
Hidden by default. Show/hide exposes aria-pressed; Caps Lock and requirement changes are announced politely. Label the input using id and Label or aria-label. The ref points to the input and native password-manager attributes are preserved.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.