diff --git a/apps/docs/content/1.component/password-strength.mdx b/apps/docs/content/1.component/password-strength.mdx new file mode 100644 index 0000000..f176ac1 --- /dev/null +++ b/apps/docs/content/1.component/password-strength.mdx @@ -0,0 +1,113 @@ +--- +title: Password Strength +description: A password field with a four-bar meter that fills as the password gets stronger and a checklist that ticks off each rule. +icon: key-round +--- + +A password field with a **four-bar strength meter** under it. As you type, +the bars **fill one after another** from the left and shift from red to teal. +The **strength word rolls in** beside the label: Weak, Fair, Good or Strong. +Below it, each requirement **draws a check** the moment it is met and erases +it when it is not. The eye button **draws a slash across itself** when the +password is shown, and **blinks** as it toggles. Driven by GSAP. + +::component-preview{name="password-strength"} +:: + +## Installation + +::tabs +:::tabs-item{label="CLI" icon="i-lucide-terminal"} + +::install-tabs{item="password-strength"} +:: + +::: +:::tabs-item{label="Manual" icon="i-lucide-clipboard"} + +::component-source{name="password-strength"} +:: + +::: +:: + +## Usage + +::tabs +:::tabs-item{label="React" icon="i-lucide-atom"} + +```tsx [app/page.tsx] +import PasswordStrength from '@/components/tweenui/password-strength'; + +export default function Page() { + return ( +
+ + + ); +} +``` + +::: +:: + +Pass your own rules to change the checklist. The meter always has four bars, +so the share of rules met is scaled to them. + +```tsx +import PasswordStrength, { defaultRules } from '@/components/tweenui/password-strength'; + + !/\s/.test(value) }]} +/>; +``` + +## How it moves + +- **Bars.** Each bar scales in from the left on a 450ms `power3.out` ease. + Bars that change are staggered 60ms apart, left to right when the score + rises and right to left when it falls. Bars already filled change colour + in place. +- **Word.** When the level changes the word slides in from below as it rises + and from above as it falls, over 350ms. +- **Checks.** The circle fills with the accent and the check draws through + `strokeDashoffset`, 100ms behind the fill. Losing a rule erases it faster. +- **Eye.** The eye blinks shut and open in 300ms while its slash draws in + 250ms. + +## Props + +| Prop | Type | Default | Description | +| --------------- | ---------------------- | --------------------- | --------------------------------------------------- | +| `label` | `string` | `"Password"` | Visible label and accessible name. | +| `placeholder` | `string` | `"Choose a password"` | Placeholder text. | +| `name` | `string` | `"password"` | Form field name. | +| `autoComplete` | `string` | `"new-password"` | Lets password managers suggest a password. | +| `rules` | `PasswordRule[]` | `defaultRules` | Each rule is `{ label, test(value) }`. | +| `value` | `string` | — | Controlled value. Pair it with `onValueChange`. | +| `defaultValue` | `string` | `""` | Starting value when uncontrolled. | +| `onValueChange` | `(value, met) => void` | — | Called on every change with the count of met rules. | +| `className` | `string` | — | Extra classes for the root. | + +The checks use `--password-accent` with the tick drawn in +`--password-on-accent`. Override them with a class, e.g. +`[--password-accent:#e11d48]`. Text, borders and the empty bars take +`currentColor`. + +## Accessibility + +::note +Under `prefers-reduced-motion: reduce` the bars, checks, word and eye change +instantly. +:: + +The input is a real `` with a `