Files
gunshiz e0794822b1
CI / Verify (push) Successful in 1m18s
CI / Build immutable images and deploy (push) Successful in 1m57s
feat(i18n) : add personal languages and compact weapon exports
2026-09-14 16:44:44 +07:00

45 lines
1.4 KiB
TypeScript

"use client";
import { useTranslation } from "@/components/i18n/locale-provider";
import { Children, type ReactNode, useState } from "react";
import { ScrollableNav } from "@/components/public/scrollable-nav";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
export function ConditionSwitcher({
children,
label = "เลือก Condition",
labels,
}: {
children: ReactNode;
label?: string;
labels?: readonly string[];
}) {
const { t, e } = useTranslation();
const items = Children.toArray(children);
const [active, setActive] = useState("0");
if (items.length <= 1) return items[0] ?? null;
return (
<div className="flex min-w-0 flex-col gap-4">
<ScrollableNav ariaLabel={t(label)} className="w-full min-w-0">
<ToggleGroup aria-label={t(label)} variant="outline" value={[active]} onValueChange={(values) => {
if (values[0]) setActive(values[0]);
}}>
{items.map((_, index) => (
<ToggleGroupItem
key={index}
value={String(index)}
className="aria-pressed:bg-primary aria-pressed:text-primary-foreground"
>
{labels?.[index] || e("condition", { index: index + 1 })}
</ToggleGroupItem>
))}
</ToggleGroup>
</ScrollableNav>
{items[Number(active)]}
</div>
);
}