OTP Input
A one-time code field: one real input drawn as cells. Digits rise into place, paste and SMS autofill just work, and the cells turn to ink once complete.
View codeA password field with an eye that crosses itself out, a meter that fills as it gets stronger, a verdict that rolls and rules that tick themselves off.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Use the Kodza Password field in my signup form.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-password">
<div class="kodza-password__field">
<label class="kodza-password__box">
<input class="kodza-password__input" type="password" name="password" placeholder=" " autocomplete="new-password" minlength="8" required>
<span class="kodza-password__label">Password</span>
</label>
<button class="kodza-password__toggle" type="button" aria-label="Show the password" aria-pressed="false">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M1.8 10S5 4.5 10 4.5 18.2 10 18.2 10 15 15.5 10 15.5 1.8 10 1.8 10Z"/><circle cx="10" cy="10" r="2.6"/><path class="kodza-password__slash" d="M3.5 3.5l13 13" pathLength="1"/></svg>
</button>
</div>
<div class="kodza-password__meter" aria-hidden="true"><span></span><span></span><span></span><span></span></div>
<p class="kodza-password__status"><span class="kodza-password__word">Type something</span></p>
<ul class="kodza-password__rules">
<li class="kodza-password__rule" data-rule="length"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>At least 8 characters</li>
<li class="kodza-password__rule" data-rule="digit"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>A number</li>
<li class="kodza-password__rule" data-rule="symbol"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>A symbol, like ! or #</li>
</ul>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Password
A password field with everything around it: an eye to show it (a stroke crosses the eye
while it is visible), a four-step meter that fills as it gets stronger with its word rolling
to the new verdict, and rules that tick themselves off one by one.
Same box as Text Field. Everything is tuned with the --kz-pass-* variables. */
.kodza-password {
--kz-pass-bg: #ffffff;
--kz-pass-fg: #0a0a0a;
--kz-pass-muted: rgba(10, 10, 10, 0.6);
--kz-pass-line: rgba(10, 10, 10, 0.14);
--kz-pass-line-hover: rgba(10, 10, 10, 0.3);
--kz-pass-soft: rgba(10, 10, 10, 0.06);
--kz-pass-height: 56px;
--kz-pass-radius: 12px;
--kz-pass-pad: 16px;
--kz-pass-ease: cubic-bezier(0.22, 1, 0.36, 1);
display: grid;
gap: 12px;
width: 100%;
max-width: 420px;
color: var(--kz-pass-fg);
}
.kodza-password__field {
position: relative;
}
.kodza-password__box {
position: relative;
display: flex;
align-items: flex-end;
box-sizing: border-box;
height: var(--kz-pass-height);
padding: 0 56px 9px var(--kz-pass-pad);
border-radius: var(--kz-pass-radius);
background: var(--kz-pass-bg);
box-shadow: inset 0 0 0 1px var(--kz-pass-line);
cursor: text;
transition: box-shadow 0.25s ease;
}
.kodza-password__box:hover {
box-shadow: inset 0 0 0 1px var(--kz-pass-line-hover);
}
.kodza-password__box:focus-within {
box-shadow: inset 0 0 0 1.5px var(--kz-pass-fg), 0 0 0 4px var(--kz-pass-soft);
}
.kodza-password__input {
flex: 1;
min-width: 0;
height: 22px;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 15px;
line-height: 22px;
letter-spacing: 0.02em;
outline: none;
}
.kodza-password__label {
position: absolute;
top: 50%;
left: var(--kz-pass-pad);
color: var(--kz-pass-muted);
font-size: 15px;
line-height: 1;
pointer-events: none;
transform: translateY(-50%);
transform-origin: left top;
transition: transform 0.35s var(--kz-pass-ease);
}
.kodza-password__box:focus-within .kodza-password__label,
.kodza-password__input:not(:placeholder-shown) ~ .kodza-password__label {
transform: translateY(-18px) scale(0.8);
}
/* The eye: a stroke draws across it while the password is visible */
.kodza-password__toggle {
position: absolute;
top: calc(var(--kz-pass-height) / 2 - 18px);
right: 10px;
display: grid;
place-items: center;
width: 36px;
height: 36px;
padding: 0;
border: 0;
border-radius: 50%;
background: none;
color: var(--kz-pass-muted);
white-space: nowrap;
cursor: pointer;
transition: background-color 0.2s ease, color 0.2s ease;
}
.kodza-password__toggle:hover {
background: var(--kz-pass-soft);
color: var(--kz-pass-fg);
}
.kodza-password__toggle:focus-visible {
outline: 2px solid var(--kz-pass-fg);
outline-offset: 1px;
}
.kodza-password__toggle svg {
width: 20px;
height: 20px;
fill: none;
stroke: currentColor;
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
}
.kodza-password__slash {
stroke-dasharray: 1;
stroke-dashoffset: 1;
transition: stroke-dashoffset 0.35s var(--kz-pass-ease);
}
.kodza-password__toggle[aria-pressed="true"] .kodza-password__slash {
stroke-dashoffset: 0;
}
/* The meter: four steps, each filling from the left in turn */
.kodza-password__meter {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.kodza-password__meter span {
height: 3px;
overflow: hidden;
border-radius: 3px;
background: var(--kz-pass-soft);
}
.kodza-password__meter span::after {
content: "";
display: block;
height: 100%;
background: var(--kz-pass-fg);
transform: scaleX(0);
transform-origin: left;
transition: transform 0.45s var(--kz-pass-ease) var(--d, 0ms);
}
.kodza-password__meter span.is-on::after {
transform: none;
}
/* The verdict rolls to its new word */
.kodza-password__status {
display: flex;
margin: -4px 0 0;
font-family: ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
color: var(--kz-pass-muted);
}
.kodza-password__word {
display: inline-grid;
overflow: hidden;
}
.kodza-password__word > span {
grid-area: 1 / 1;
}
/* The rules tick themselves off */
.kodza-password__rules {
display: grid;
gap: 6px;
margin: 4px 0 0;
padding: 0;
list-style: none;
font-size: 13px;
color: var(--kz-pass-muted);
}
.kodza-password__rule {
display: flex;
align-items: center;
gap: 8px;
transition: color 0.3s ease;
}
.kodza-password__rule svg {
flex: none;
width: 16px;
height: 16px;
padding: 2px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px var(--kz-pass-line);
box-sizing: border-box;
fill: none;
stroke: var(--kz-pass-bg);
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
stroke-dashoffset: 1;
transition: background-color 0.25s ease, box-shadow 0.25s ease, stroke-dashoffset 0.4s var(--kz-pass-ease) 0.1s;
}
.kodza-password__rule.is-met {
color: var(--kz-pass-fg);
}
.kodza-password__rule.is-met svg {
background: var(--kz-pass-fg);
box-shadow: none;
stroke-dashoffset: 0;
}
@media (prefers-reduced-motion: reduce) {
.kodza-password__box,
.kodza-password__label,
.kodza-password__slash,
.kodza-password__meter span::after,
.kodza-password__rule,
.kodza-password__rule svg {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
/* Theming example — on a dark background:
.dark-section .kodza-password {
--kz-pass-bg: #161616;
--kz-pass-fg: #f2f2f0;
--kz-pass-muted: rgba(242, 242, 240, 0.62);
--kz-pass-line: rgba(255, 255, 255, 0.14);
--kz-pass-line-hover: rgba(255, 255, 255, 0.3);
--kz-pass-soft: rgba(255, 255, 255, 0.08);
}
*/
/* kodza-guard afcfd265234b — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */
:where(.kodza-password__toggle):not(#_) {
outline: revert;
outline-offset: revert;
}
:where(.kodza-password__rule):not(#_) {
color: revert;
}
:where(.kodza-password__rule svg:where(:not([class*="kodza-"]))):not(#_) {
background-color: revert;
background-image: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-password:not(#_),
.kodza-password__field:not(#_),
.kodza-password__label:not(#_),
.kodza-password__slash:not(#_),
.kodza-password__meter:not(#_),
.kodza-password__word:not(#_),
.kodza-password__meter span:where(:not([class*="kodza-"])):not(#_),
.kodza-password__word span:where(:not([class*="kodza-"])):not(#_) {
box-sizing: revert;
}
.kodza-password__box:not(#_) {
border: revert;
margin: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
float: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__input:not(#_) {
margin: revert;
border-radius: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
white-space: revert;
min-height: revert;
}
.kodza-password__toggle:not(#_) {
margin: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
min-height: revert;
}
.kodza-password__status:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__rules:not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__rule:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__toggle svg:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__rule svg:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
float: revert;
position: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-password__input:not(#_):where(:not([hidden])),
.kodza-password__toggle svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])),
.kodza-password__rule svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-password__input:not(#_):where([hidden]),
.kodza-password__toggle svg:where(:not([class*="kodza-"])):not(#_):where([hidden]),
.kodza-password__rule svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
display: none;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-password:not(#_) {
width: min(100%, 420px);
}
.kodza-password__box:not(#_) {
position: relative;
display: flex;
box-sizing: border-box;
padding: 0 56px 9px var(--kz-pass-pad);
border-radius: var(--kz-pass-radius);
background: var(--kz-pass-bg);
box-shadow: inset 0 0 0 1px var(--kz-pass-line);
transition: box-shadow 0.25s ease;
}
.kodza-password__box:hover:not(#_) {
box-shadow: inset 0 0 0 1px var(--kz-pass-line-hover);
}
.kodza-password__box:focus-within:not(#_) {
box-shadow: inset 0 0 0 1.5px var(--kz-pass-fg), 0 0 0 4px var(--kz-pass-soft);
}
.kodza-password__input:not(#_) {
flex: 1;
min-width: 0;
height: 22px;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 15px;
line-height: 22px;
letter-spacing: 0.02em;
outline: none;
}
.kodza-password__toggle:not(#_) {
position: absolute;
top: calc(var(--kz-pass-height) / 2 - 18px);
right: 10px;
display: grid;
place-items: center;
width: 36px;
height: 36px;
padding: 0;
border: 0;
border-radius: 50%;
background: none;
color: var(--kz-pass-muted);
white-space: nowrap;
cursor: pointer;
transition: background-color 0.2s ease, color 0.2s ease;
}
.kodza-password__toggle:hover:not(#_) {
background: var(--kz-pass-soft);
color: var(--kz-pass-fg);
}
.kodza-password__toggle:focus-visible:not(#_) {
outline: 2px solid var(--kz-pass-fg);
outline-offset: 1px;
}
.kodza-password__status:not(#_) {
display: flex;
margin: -4px 0 0;
font-family: ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
color: var(--kz-pass-muted);
}
.kodza-password__rules:not(#_) {
display: grid;
margin: 4px 0 0;
padding: 0;
list-style: none;
font-size: 13px;
color: var(--kz-pass-muted);
}
.kodza-password__rule:not(#_) {
display: flex;
transition: color 0.3s ease;
}
.kodza-password__rule svg:not(#_) {
padding: 2px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px var(--kz-pass-line);
box-sizing: border-box;
transition: background-color 0.25s ease, box-shadow 0.25s ease, stroke-dashoffset 0.4s var(--kz-pass-ease) 0.1s;
}
.kodza-password__rule.is-met:not(#_) {
color: var(--kz-pass-fg);
}
.kodza-password__rule.is-met svg:not(#_) {
background: var(--kz-pass-fg);
box-shadow: none;
}
@media (prefers-reduced-motion: reduce) {
.kodza-password__box:not(#_),
.kodza-password__rule:not(#_),
.kodza-password__rule svg:not(#_) {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Password
// Shows or hides the password (keeping the caret where it was), scores it as you type (length,
// mixed case, digits, symbols), fills the meter, rolls the verdict and ticks the rules.
// The verdict is also read out to screen readers. Fires "kodza:strength" with { score } (0–4).
(() => {
const SELECTOR = '.kodza-password';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const WORDS = ['Type something', 'Too easy', 'Getting there', 'Solid', 'Very solid'];
const RULES = {
length: (value) => value.length >= 8,
digit: (value) => /\d/.test(value),
symbol: (value) => /[^A-Za-z0-9\s]/.test(value),
};
let uid = 0;
const score = (value) => {
if (!value) return 0;
let points = 0;
if (value.length >= 8) points++;
if (value.length >= 14) points++;
if (/[a-z]/.test(value) && /[A-Z]/.test(value)) points++;
if (/\d/.test(value)) points++;
if (/[^A-Za-z0-9\s]/.test(value)) points++;
return Math.max(1, Math.min(4, points));
};
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const input = root.querySelector('.kodza-password__input');
const toggle = root.querySelector('.kodza-password__toggle');
const bars = [...root.querySelectorAll('.kodza-password__meter span')];
const word = root.querySelector('.kodza-password__word');
const status = root.querySelector('.kodza-password__status');
const rules = [...root.querySelectorAll('.kodza-password__rule')];
if (!input) return;
if (status) {
status.id = `kodza-password-${++uid}`;
status.setAttribute('aria-live', 'polite');
input.setAttribute('aria-describedby', status.id);
}
if (word) word.replaceChildren(Object.assign(document.createElement('span'), { textContent: word.textContent.trim() }));
// The verdict rolls up when it gets better, down when it gets worse
const roll = (text, dir) => {
const prev = word.lastElementChild;
if (prev.textContent === text) return;
const span = Object.assign(document.createElement('span'), { textContent: text });
word.append(span);
if (reduceMotion) return prev.remove();
const timing = { duration: 400, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
prev.animate([{ transform: 'none' }, { transform: `translateY(${dir * -110}%)` }], { ...timing, fill: 'forwards' }).finished.then(() => prev.remove());
span.animate([{ transform: `translateY(${dir * 110}%)` }, { transform: 'none' }], timing);
};
let last = 0;
const update = () => {
const value = input.value;
const points = score(value);
// Filling up goes left to right, emptying right to left, one step after the other
bars.forEach((bar, i) => {
const delay = points > last ? i - last : last - 1 - i;
bar.style.setProperty('--d', `${Math.max(0, delay) * 60}ms`);
bar.classList.toggle('is-on', i < points);
});
if (word) roll(WORDS[points], points >= last ? 1 : -1);
rules.forEach((rule) => rule.classList.toggle('is-met', !!RULES[rule.dataset.rule]?.(value)));
if (points !== last) root.dispatchEvent(new CustomEvent('kodza:strength', { detail: { score: points }, bubbles: true }));
last = points;
};
input.addEventListener('input', update, { signal });
toggle?.addEventListener('click', () => {
const show = input.type === 'password';
const { selectionStart, selectionEnd } = input;
input.type = show ? 'text' : 'password';
toggle.setAttribute('aria-pressed', String(show));
toggle.setAttribute('aria-label', show ? 'Hide the password' : 'Show the password');
input.focus();
try {
input.setSelectionRange(selectionStart, selectionEnd);
} catch {
/* some types refuse selections */
}
}, { signal });
update();
}
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load.
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const init = (scope) => find(scope).forEach((root) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.controller.abort();
[...root.attributes].forEach((a) => root.removeAttribute(a.name));
instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
root.innerHTML = instance.html;
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Password, for React. From https://kodza.dev/components/password-field/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: password-field.css and password-field.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './password-field.css';
export type PasswordProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "onStrength"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** default: #ffffff */
"--kz-pass-bg"?: string | number;
/** default: #0a0a0a */
"--kz-pass-fg"?: string | number;
/** default: rgba(10, 10, 10, 0.6) */
"--kz-pass-muted"?: string | number;
/** default: rgba(10, 10, 10, 0.14) */
"--kz-pass-line"?: string | number;
/** default: rgba(10, 10, 10, 0.3) */
"--kz-pass-line-hover"?: string | number;
/** default: rgba(10, 10, 10, 0.06) */
"--kz-pass-soft"?: string | number;
/** default: 56px */
"--kz-pass-height"?: string | number;
/** default: 12px */
"--kz-pass-radius"?: string | number;
/** default: 16px */
"--kz-pass-pad"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-pass-ease"?: string | number;
};
/** "kodza:strength", fired by the script (bubbles from the root) */
onStrength?: (event: CustomEvent) => void;
className?: string;
};
export function Password({ vars, onStrength, className, style, ...rest }: PasswordProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-password", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./password-field.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
useEffect(() => {
const root = ref.current;
if (!root || !onStrength) return;
const listener = (event: Event) => onStrength(event as CustomEvent);
root.addEventListener("kodza:strength", listener);
return () => root.removeEventListener("kodza:strength", listener);
}, [onStrength, key]);
return (
<div key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<div className="kodza-password__field">
<label className="kodza-password__box">
<input className="kodza-password__input" type="password" name="password" placeholder=" " autoComplete="new-password" minLength={8} required />
{' '}
<span className="kodza-password__label">Password</span>
</label>
{' '}
<button className="kodza-password__toggle" type="button" aria-label="Show the password" aria-pressed="false">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M1.8 10S5 4.5 10 4.5 18.2 10 18.2 10 15 15.5 10 15.5 1.8 10 1.8 10Z" />
<circle cx="10" cy="10" r="2.6" />
<path className="kodza-password__slash" d="M3.5 3.5l13 13" pathLength="1" />
</svg>
</button>
</div>
<div className="kodza-password__meter" aria-hidden="true">
<span />
<span />
<span />
<span />
</div>
<p className="kodza-password__status">
<span className="kodza-password__word">Type something</span>
</p>
<ul className="kodza-password__rules">
<li className="kodza-password__rule" data-rule="length"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>At least 8 characters</li>
<li className="kodza-password__rule" data-rule="digit"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>A number</li>
<li className="kodza-password__rule" data-rule="symbol"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>A symbol, like ! or #</li>
</ul>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.