feat : update
This commit is contained in:
@@ -4,7 +4,15 @@ import { Children, type ReactNode, useState } from "react";
|
||||
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
|
||||
export function ConditionSwitcher({ children, label = "เลือก Condition" }: { children: ReactNode; label?: string }) {
|
||||
export function ConditionSwitcher({
|
||||
children,
|
||||
label = "เลือก Condition",
|
||||
labels,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
label?: string;
|
||||
labels?: readonly string[];
|
||||
}) {
|
||||
const items = Children.toArray(children);
|
||||
const [active, setActive] = useState("0");
|
||||
|
||||
@@ -15,7 +23,15 @@ export function ConditionSwitcher({ children, label = "เลือก Condition
|
||||
<ToggleGroup aria-label={label} variant="outline" value={[active]} onValueChange={(values) => {
|
||||
if (values[0]) setActive(values[0]);
|
||||
}}>
|
||||
{items.map((_, index) => <ToggleGroupItem key={index} value={String(index)}>Condition {index + 1}</ToggleGroupItem>)}
|
||||
{items.map((_, index) => (
|
||||
<ToggleGroupItem
|
||||
key={index}
|
||||
value={String(index)}
|
||||
className="aria-pressed:bg-primary aria-pressed:text-primary-foreground"
|
||||
>
|
||||
{labels?.[index] || `Condition ${index + 1}`}
|
||||
</ToggleGroupItem>
|
||||
))}
|
||||
</ToggleGroup>
|
||||
{items[Number(active)]}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user