Lighting the way.
Light with purpose. Interface components whose states are rendered by light: an error, a validation, a loading. At rest, nothing moves.
Get started
npm i @shader-ui/react- Frames
- 0
- Active effects
- 0
- Renderer
- none
account.ts
import "@shader-ui/core/styles.css";
import { TYPING_PAUSE, watchForm } from "@shader-ui/core";
const isTaken = (name: string) =>
new Promise<boolean>((resolve) => setTimeout(() => resolve(name === "acme"), 900));
const createAccount = () => new Promise<void>((resolve) => setTimeout(resolve, 1600));
document.body.insertAdjacentHTML(
"beforeend",
`<form id="account">
<label for="org">Organisation (try “Acme”)</label>
<input id="org" autocomplete="organization" required aria-describedby="org-hint">
<p id="org-hint" aria-live="polite"></p>
<label for="email">Email</label>
<input id="email" type="email" autocomplete="email" required aria-describedby="email-hint">
<p id="email-hint">To confirm the account.</p>
<label><input type="checkbox" required> I accept the terms of use</label>
<button type="submit">Create account</button>
</form>`,
);
const form = document.querySelector<HTMLFormElement>("#account")!;
const org = document.querySelector<HTMLInputElement>("#org")!;
const orgHint = document.querySelector("#org-hint")!;
watchForm(form, {
guide: true,
onSubmit: (event) => {
event.preventDefault();
if (org.getAttribute("aria-invalid") === "true") return;
return createAccount();
},
});
let pause: ReturnType<typeof setTimeout>;
org.addEventListener("input", () => {
clearTimeout(pause);
pause = setTimeout(async () => {
org.setAttribute("aria-busy", "true");
orgHint.textContent = "Checking…";
const taken = await isTaken(org.value.trim().toLowerCase());
org.removeAttribute("aria-busy");
orgHint.textContent = taken ? "This name is already in use." : "This name is available.";
if (taken) org.setAttribute("aria-invalid", "true");
else org.removeAttribute("aria-invalid");
}, TYPING_PAUSE);
});CreateAccount.tsx
import { Button, Checkbox, Form, Input, TYPING_PAUSE } from "@shader-ui/react";
import { useRef, useState } from "react";
const isTaken = (name: string) =>
new Promise<boolean>((resolve) => setTimeout(() => resolve(name === "acme"), 900));
const createAccount = () => new Promise<void>((resolve) => setTimeout(resolve, 1600));
export function CreateAccount() {
const [checking, setChecking] = useState(false);
const [taken, setTaken] = useState(false);
const pause = useRef<ReturnType<typeof setTimeout>>(undefined);
const check = (name: string) => {
clearTimeout(pause.current);
pause.current = setTimeout(async () => {
setChecking(true);
setTaken(await isTaken(name.trim().toLowerCase()));
setChecking(false);
}, TYPING_PAUSE);
};
return (
<Form
guide
onSubmit={(e) => {
e.preventDefault();
if (taken) return;
return createAccount();
}}
>
<label htmlFor="org">Organisation (try “Acme”)</label>
<Input
id="org"
autoComplete="organization"
required
aria-busy={checking || undefined}
aria-invalid={taken || undefined}
aria-describedby="org-hint"
onChange={(e) => check(e.target.value)}
/>
<p id="org-hint" aria-live="polite">
{checking ? "Checking…" : taken ? "This name is already in use." : ""}
</p>
<label htmlFor="email">Email</label>
<Input id="email" type="email" autoComplete="email" required aria-describedby="email-hint" />
<p id="email-hint">To confirm the account.</p>
<label>
<Checkbox required /> I accept the terms of use
</label>
<Button type="submit">Create account</Button>
</Form>
);
}The Light button
In the menu, the Light button turns off every effect on the site in one click. The meaning stays: borders, diodes, messages. It is the library's global switch, worth offering to your users too.
<ShaderProvider enabled={lightOn}>{children}</ShaderProvider>Get started
Install the library and light up your first field.
Principles
Why light, when to use it, and what it guarantees.
Components
Input, button, form, checkboxes, radios: demo, usage, accessibility.
Use cases
Create an account, place an order, subscribe: what light says in them.
Specs
The normative, versioned specification, with its conformance tests.