App patterns
PinPad
A short numeric code on screen with large keys: a device lock on a shared phone or tablet, a cashier switch at a till. Masked dots and a 3 × 4 key grid that keep left-to-right order in Arabic, like a phone keypad. onComplete gets the code once, when the last digit is typed; while its promise runs the keys are off, then the pad clears. error shows under the dots and clears them; onStart fires at the first digit of a new entry. The keys are buttons; digits and Backspace on a hardware keyboard work too (not while a text field has the focus). Screen readers hear a count (“2 of 4”), never the digits. For a code that comes by SMS use OtpInput.
import { PinPad } from "@percentsa/ui";Examples
Enter the lock code
Code
export function PinPadExample() {
const t = useT();
const [tries, setTries] = useState(3);
const [open, setOpen] = useState(false);
return (
<Stack gap={4} className="w-full max-w-xs items-center">
<Text tone="muted">{open ? t("Unlocked", "تم الفتح") : t("Enter the lock code", "أدخل رمز القفل")}</Text>
<PinPad
label={t("Enter the lock code", "أدخل رمز القفل")}
disabled={open}
error={tries < 3 && !open ? (tries > 0 ? t(`Wrong code. ${tries} tries left`, `رمز غير صحيح، بقيت ${tries} محاولات`) : t("Locked. Ask the office.", "مقفل. تواصل مع المكتب.")) : undefined}
onStart={() => undefined}
onComplete={(pin) => {
if (pin === "1234") setOpen(true);
else setTries((n) => Math.max(0, n - 1));
}}
/>
{open && (
<Button variant="secondary" size="sm" onClick={() => (setOpen(false), setTries(3))}>
{t("Lock again", "قفل مرة أخرى")}
</Button>
)}
</Stack>
);
}
/** Six digits, a slow check (the keys are off while it runs), and a note that drops at the first digit. */Code
export function PinPadCashierExample() {
const t = useT();
const [note, setNote] = useState<string | null>(null);
return (
<div className="w-full max-w-xs">
<PinPad
length={6}
label={t("Cashier code", "رمز الكاشير")}
error={note}
onStart={() => setNote(null)}
onComplete={async () => {
await new Promise((r) => setTimeout(r, 900));
setNote(t("This code is not a cashier code", "هذا الرمز ليس رمز كاشير"));
}}
/>
</div>
);
}
/** Blocked: the button stays, disabled, with the reason above it. Danger and cancelLabel for a destructive sheet from the bottom. */