Actions
SegmentedControl, ToggleGroup
One choice that is always set (SegmentedControl), or several on/off choices (ToggleGroup). In SegmentedControl the fill slides to the chosen option (no slide with reduced motion). wrap lets the options go to more rows when the row is too narrow, for a filter with many options on a phone. The fill moves to the chosen option on any row.
import { SegmentedControl, ToggleGroup } from "@percentsa/ui";Examples
Code
export function SegmentedControlExample() {
const t = useT();
const [billing, setBilling] = useState("year");
return (
<SegmentedControl
aria-label={t("Billing period", "فترة الفوترة")}
value={billing}
onValueChange={setBilling}
options={[
{ value: "month", label: t("Monthly", "شهري") },
{ value: "year", label: t("Yearly", "سنوي") },
]}
/>
);
}Code
export function SegmentedControlWrapExample() {
const t = useT();
const [kind, setKind] = useState("all");
return (
<div className="max-w-xs">
<SegmentedControl
wrap
aria-label={t("Kind", "النوع")}
value={kind}
onValueChange={setKind}
options={[
{ value: "all", label: t("All 12", "الكل 12") },
{ value: "orders", label: t("Orders 4", "الطلبات 4") },
{ value: "payments", label: t("Payments 3", "المدفوعات 3") },
{ value: "refunds", label: t("Refunds 2", "الاستردادات 2") },
{ value: "stock", label: t("Stock 2", "المخزون 2") },
{ value: "other", label: t("Other 1", "أخرى 1") },
]}
/>
</div>
);
}Code
export function ToggleGroupExample() {
const t = useT();
return (
<ToggleGroup
aria-label={t("Working days", "أيام العمل")}
defaultValue={["sun", "mon"]}
options={[
{ value: "sun", label: t("Sun", "الأحد") },
{ value: "mon", label: t("Mon", "الإثنين") },
{ value: "tue", label: t("Tue", "الثلاثاء") },
]}
/>
);
}