Enter a password and reveal it when checking for a typo. The optional meter gives an estimate as you type.
Password input example
Example.jsx
import { PasswordInput } from "./ui/password-input";
import "./example.css";
export default function Example() {
return (
<section class="sample">
<header>
<h2>Protect a proof link</h2>
<p>Choose a passphrase for the editorial review copy.</p>
</header>
<PasswordInput label="Review passphrase" placeholder="Enter a passphrase" />
</section>
);
}
example.css
@media screen and (prefers-reduced-motion: no-preference) {
#example button:is(.v-primary, .v-secondary):enabled {
transition: transform 120ms ease-out;
}
#example button:is(.v-primary, .v-secondary):enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button:is(.v-primary, .v-secondary):enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
--example-seed: var(--aster-primary);
--example-secondary-text: var(--aster-on-surface-subtle);
}
body {
--aster-primary: color-mix(in srgb, var(--example-seed) 84%, var(--aster-on-surface));
--aster-on-surface-subtle: color-mix(in srgb, var(--example-secondary-text) 84%, var(--aster-on-surface));
--aster-input-border: color-mix(in srgb, var(--aster-on-surface) 55%, var(--aster-surface));
margin: 0;
padding: clamp(0.8rem, 4vw, 1.5rem);
color: var(--aster-on-surface);
background: var(--aster-surface-muted);
font: 1rem/1.5 var(--aster-font-sans);
}
#example {
display: grid;
gap: 0.8rem;
min-width: 0;
align-content: start;
}
#example > button,
.sample > button {
justify-self: start;
}
.sample,
.tile {
background: var(--aster-surface);
border: 1px solid var(--aster-border);
border-radius: var(--aster-radius-lg);
}
.sample {
display: grid;
gap: 0.8rem;
padding: clamp(0.85rem, 3vw, 1.35rem);
box-shadow: var(--aster-shadow-xs);
min-width: 0;
}
.tile {
padding: 1rem;
min-width: 0;
}
h2,
h3,
p,
dl,
ul {
margin-block: 0;
}
h2,
h3 {
letter-spacing: -0.025em;
line-height: 1.2;
}
h2 {
font-size: 1.25rem;
}
h3 {
font-size: 1rem;
}
.sample > header,
.identity > div,
.receipt {
display: grid;
gap: 0.25rem;
}
.sample > header p,
.tile p,
small {
color: var(--aster-on-surface-muted);
}
small {
font-size: 0.82rem;
}
.split,
.actions,
.identity {
display: flex;
align-items: center;
gap: 0.65rem;
flex-wrap: wrap;
}
.split {
justify-content: space-between;
padding-block: 0.4rem;
border-bottom: 1px solid var(--aster-border);
}
.split:last-child {
border-bottom: 0;
}
.metric {
font-size: 2rem;
letter-spacing: -0.06em;
}
.facts {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.45rem 1rem;
}
.facts dt {
color: var(--aster-on-surface-muted);
}
.facts dd {
margin: 0;
font-weight: 600;
}
.type-sample {
font:
2rem/1.2 Georgia,
serif;
}
.listing {
padding-inline-start: 1.25rem;
}
.ink-strip {
height: 1.2rem;
background: var(--aster-primary);
border-radius: var(--aster-radius-sm);
}
.ink-proof {
display: grid;
gap: 0.15rem;
border-left: 0.6rem solid;
padding-left: 0.8rem;
}
.ink-proof strong {
font-size: 1.25rem;
letter-spacing: 0.06em;
}
.glyph {
display: inline-grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: var(--aster-radius-sm);
color: var(--aster-on-primary-subtle);
background: var(--aster-primary-subtle);
}
.cover-box {
width: min(100%, 18rem);
}
.cover {
display: flex;
min-height: 7.5rem;
height: 100%;
padding: 1rem 1.25rem;
flex-direction: column;
justify-content: space-between;
gap: 1.6rem;
color: #fff;
background: repeating-linear-gradient(150deg, transparent 0 8px, #fff2 8px 9px), #204a48;
}
.cover strong {
font:
italic 2.45rem/1 Georgia,
serif;
}
.cover span {
font: 0.78rem var(--aster-font-mono);
}
.cover.grove {
background-color: #3d4b27;
}
.cover.dune {
background-color: #7c4428;
}
button:not([class]),
.entry {
font: inherit;
font-size: 0.875rem;
padding: 0.45rem 0.8rem;
border: 1px solid var(--aster-border-strong);
border-radius: var(--aster-radius-control);
background: var(--aster-surface);
color: var(--aster-on-surface);
}
button:not([class]) {
cursor: pointer;
font-weight: 600;
}
button:not([class]):hover:enabled {
background: var(--aster-primary-subtle);
}
button:disabled {
cursor: default;
}
:focus-visible {
outline: 2px solid var(--aster-primary);
outline-offset: 3px;
}
output:not(:empty) {
display: block;
color: var(--aster-on-primary-subtle);
font-weight: 600;
font-size: 0.9rem;
}
Site-owned component source and scoped styles
src/ui/password-input
import './theme.css';
import { Eye, EyeOff } from '@lucide/icons';
import { scope, type Ctx } from '@fierst/aster';
import { Icon } from './icon';
const pwScope = scope`
:scope { display: grid; gap: 0.375rem; font-family: var(--aster-font-sans); }
.pw-label { font-size: 0.84rem; font-weight: 500; color: var(--aster-on-surface); }
.pw-wrap {
display: flex;
align-items: center;
gap: 0.4rem;
padding: 0 0.45rem 0 0.75rem;
min-height: var(--aster-control-md);
border-radius: var(--aster-radius-control);
border: 1px solid var(--aster-input-border);
background: var(--aster-surface);
box-shadow: var(--aster-shadow-xs);
transition: border-color var(--aster-dur-fast), box-shadow var(--aster-dur-fast);
}
.pw-wrap:focus-within { border-color: var(--aster-primary); box-shadow: var(--aster-focus-ring); }
.pw-wrap.is-invalid { border-color: var(--aster-danger); }
input {
flex: 1;
min-width: 0;
border: none;
outline: none;
background: transparent;
color: var(--aster-on-surface);
font: inherit;
font-size: 1rem;
}
@media (min-width: 640px) { input { font-size: 0.875rem; } }
.eye-btn {
width: 28px;
height: 28px;
border: none;
border-radius: var(--aster-radius-xs);
background: transparent;
color: var(--aster-on-surface-muted);
display: inline-grid;
place-items: center;
cursor: pointer;
}
.eye-btn:hover { background: var(--aster-surface-muted); color: var(--aster-on-surface); }
.bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 2px; }
.bar { height: 4px; border-radius: 9999px; background: var(--aster-surface-accent); transition: background-color var(--aster-dur-fast); }
.bar.s-1 { background: var(--aster-danger); }
.bar.s-2 { background: var(--aster-warning); }
.bar.s-3 { background: var(--aster-primary); }
.bar.s-4 { background: var(--aster-success); }
.pw-meta { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--aster-on-surface-muted); }
.pw-err { font-size: 0.78rem; color: var(--aster-danger); font-weight: 500; }
`;
function scorePassword(val: string): number {
if (!val) return 0;
let score = 0;
if (val.length >= 8) score++;
if (/[A-Z]/.test(val) && /[a-z]/.test(val)) score++;
if (/\d/.test(val)) score++;
if (/[^A-Za-z0-9]/.test(val)) score++;
return Math.max(1, score);
}
const LABELS = ['', 'Weak', 'Fair', 'Good', 'Strong'];
let pwSeq = 0;
export function* PasswordInput(
props: {
id?: string;
label?: string;
value?: string;
defaultValue?: string;
placeholder?: string;
showStrength?: boolean;
error?: string | null;
onChange?: (val: string) => void;
class?: string;
},
ctx: Ctx,
) {
const uid = props.id ?? `aster-pw-${++pwSeq}`;
let internal = props.defaultValue ?? '';
let revealed = false;
for (props of ctx) {
const isControlled = props.value !== undefined;
const current = isControlled ? props.value! : internal;
const score = props.showStrength ? scorePassword(current) : 0;
yield (
<div class={[pwScope, props.class].filter(Boolean).join(' ')}>
{props.label ? (
<label class="pw-label" for={uid}>
{props.label}
</label>
) : null}
<div class="pw-wrap" class:is-invalid={Boolean(props.error)}>
<input
id={uid}
type={revealed ? 'text' : 'password'}
value={current}
placeholder={props.placeholder ?? 'Enter password…'}
aria-invalid={Boolean(props.error)}
onInput={(e: Event) => {
const next = (e.target as HTMLInputElement).value;
if (!isControlled) internal = next;
props.onChange?.(next);
}}
/>
<button
type="button"
class="eye-btn"
aria-label={revealed ? 'Hide password' : 'Show password'}
onClick={() => (revealed = !revealed)}
>
<Icon icon={revealed ? EyeOff : Eye} size={15} />
</button>
</div>
{props.showStrength ? (
<>
<div class="bars" aria-hidden="true">
{[1, 2, 3, 4].map((lvl) => (
<span
key={lvl}
class={['bar', lvl <= score ? `s-${score}` : ''].filter(Boolean).join(' ')}
/>
))}
</div>
{current ? (
<div class="pw-meta">
<span>Password strength</span>
<span>{LABELS[score]}</span>
</div>
) : null}
</>
) : null}
{props.error ? (
<span class="pw-err" role="alert">
{props.error}
</span>
) : null}
</div>
);
}
}
Install
sh
npx @fierst/ui@1.0.2 add password-inputRegistry dependencies: theme, icon. Package dependencies: @lucide/icons.
Exports from ./ui/password-input: PasswordInput.
Download the registry source for password-input 1.0.2.
API contracts
ts
export function* PasswordInput(
props: {
id?: string;
label?: string;
value?: string;
defaultValue?: string;
placeholder?: string;
showStrength?: boolean;
error?: string | null;
onChange?: (val: string) => void;
class?: string;
},
ctx: Ctx,
)