From d140218dd943feaa52d7cd868e145ec525bc4b22 Mon Sep 17 00:00:00 2001 From: moshiur01 Date: Sun, 22 Nov 2026 12:08:24 +0600 Subject: [PATCH] feat(registry): add the password strength component A password field with a four-bar strength meter driven by GSAP. The bars scale in one after another and shift from red to teal as more rules pass, the strength word slides in, and each rule draws a check when it is met. The eye blinks and draws a slash to show or hide the password. A hidden password shows asterisks through a tiny inline font limited to the mask characters, so selection, the caret and password managers behave like a native field. Includes gallery preview media. Co-Authored-By: Claude Opus 5.5 --- .../content/1.component/password-strength.mdx | 113 +++++++ .../components/password-strength-poster.webp | Bin 0 -> 8238 bytes .../components/password-strength-preview.mp4 | Bin 0 -> 75210 bytes .../docs/public/r/password-strength-demo.json | 22 ++ apps/docs/public/r/password-strength.json | 24 ++ apps/docs/public/r/registry.json | 28 ++ apps/docs/registry/__index__.generated.tsx | 1 + apps/docs/registry/__media__.generated.ts | 1 + apps/docs/registry/__sources__.generated.ts | 12 + .../docs/registry/demos/password-strength.tsx | 13 + apps/docs/registry/registry-ui.ts | 37 ++ .../registry/tweenui/password-strength.tsx | 318 ++++++++++++++++++ apps/docs/tests/password-strength.test.tsx | 102 ++++++ 13 files changed, 671 insertions(+) create mode 100644 apps/docs/content/1.component/password-strength.mdx create mode 100644 apps/docs/public/media/components/password-strength-poster.webp create mode 100644 apps/docs/public/media/components/password-strength-preview.mp4 create mode 100644 apps/docs/public/r/password-strength-demo.json create mode 100644 apps/docs/public/r/password-strength.json create mode 100644 apps/docs/registry/demos/password-strength.tsx create mode 100644 apps/docs/registry/tweenui/password-strength.tsx create mode 100644 apps/docs/tests/password-strength.test.tsx 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 `