Actions
Button
Primary (one per view), secondary, ghost, danger and link. Loading keeps the width. Icon-only buttons need aria-label (a type error without it). size="sm" (and the small icon button, Toggle, SegmentedControl items, the NumberInput step buttons and menu rows) follows --p-control-h-xs: 32 px as before, and 44 px inside data-density="touch" on a touch screen. blocked keeps the button visible but refuses the press, and shows the reason on hover, focus and tap.
import { Button } from "@percentsa/ui";Examples
Code
export function ButtonVariants() {
const t = useT();
return (
<Inline gap={3}>
<Button>{t("Start a project", "ابدأ مشروعًا")}</Button>
<Button variant="secondary">{t("See our work", "شاهد أعمالنا")}</Button>
<Button variant="ghost">{t("Cancel", "إلغاء")}</Button>
<Button variant="danger">
<Trash2 aria-hidden />
{t("Delete", "حذف")}
</Button>
<Button variant="link">{t("Read more", "اقرأ المزيد")}</Button>
</Inline>
);
}Code
export function ButtonSizes() {
const t = useT();
return (
<Inline gap={3}>
<Button size="sm">{t("Small", "صغير")}</Button>
<Button>{t("Medium", "متوسط")}</Button>
<Button size="lg">{t("Large", "كبير")}</Button>
</Inline>
);
}
/** `data-density="touch"` on a counter tablet: on a touch screen the small controls grow to 44 px (a mouse keeps the compact sizes). */Code
export function ButtonTouchExample() {
const t = useT();
return (
<Stack gap={3} data-density="touch" className="w-full">
<Inline gap={3}>
<Button size="sm">{t("Hold", "تعليق")}</Button>
<Button size="sm" variant="secondary">
{t("Discount", "خصم")}
</Button>
<Button size="sm" variant="ghost" iconOnly aria-label={t("Add", "إضافة")}>
<Plus aria-hidden />
</Button>
<Toggle aria-label={t("Bold", "عريض")}>
<Bold aria-hidden />
</Toggle>
<SegmentedControl
aria-label={t("Price list", "قائمة الأسعار")}
value="retail"
onValueChange={() => {}}
options={[
{ value: "retail", label: t("Retail", "مفرد") },
{ value: "wholesale", label: t("Wholesale", "جملة") },
]}
/>
</Inline>
</Stack>
);
}Code
export function ButtonStates() {
const t = useT();
const [loading, setLoading] = useState(false);
return (
<Inline gap={3}>
<Button loading={loading} onClick={() => (setLoading(true), setTimeout(() => setLoading(false), 1500))}>
{t("Send message", "أرسل الرسالة")}
</Button>
<Button disabled>{t("Disabled", "معطّل")}</Button>
<Button variant="secondary" iconOnly aria-label={t("Add", "إضافة")}>
<Plus aria-hidden />
</Button>
<Button asChild variant="secondary">
<a href="#contact">
{t("Talk to us", "تحدّث معنا")}
<ArrowRight aria-hidden className="rtl:-scale-x-100" />
</a>
</Button>
</Inline>
);
}Code
export function ButtonBlockedExample() {
const t = useT();
return <Button blocked={t("A backup runs now.", "نسخة احتياطية قيد التشغيل الآن.")}>{t("Back up now", "انسخ احتياطيًا الآن")}</Button>;
}