'use client';
import { useId, type ReactNode } from 'react';
export function Lab({
children,
controls,
caption,
}: {
children: ReactNode;
controls: ReactNode;
caption?: ReactNode;
}) {
return (
{children}
{controls}
{caption && (
{caption}
)}
);
}
export function Slider({
label,
value,
min,
max,
step = 1,
onChange,
format,
}: {
label: string;
value: number;
min: number;
max: number;
step?: number;
onChange: (value: number) => void;
format?: (value: number) => string;
}) {
const id = useId();
return (
onChange(Number(event.target.value))}
className="accent-fd-primary h-1 min-w-0 flex-1 cursor-pointer"
/>
{format ? format(value) : value}
);
}
const chip =
'focus-visible:ring-fd-ring rounded-md px-2.5 py-1 text-[0.75rem] transition-colors outline-none focus-visible:ring-2';
export function Segmented({
label,
value,
options,
onChange,
}: {
label: string;
value: T;
options: { value: T; label: string }[];
onChange: (value: T) => void;
}) {
return (
{label}
{options.map((option) => (
))}
);
}
export function Toggle({
label,
checked,
onChange,
}: {
label: string;
checked: boolean;
onChange: (checked: boolean) => void;
}) {
return (
);
}
export function TextInput({
label,
value,
onChange,
maxLength = 40,
}: {
label: string;
value: string;
onChange: (value: string) => void;
maxLength?: number;
}) {
const id = useId();
return (
onChange(event.target.value)}
className="border-fd-border bg-fd-background focus-visible:ring-fd-ring min-w-0 flex-1 rounded-md border px-2.5 py-1 font-mono text-[0.75rem] outline-none focus-visible:ring-2"
/>
);
}
export function Legend({
items,
}: {
items: { color: string; label: string }[];
}) {
return (
{items.map((item) => (
{item.label}
))}
);
}
export function LabSkeleton({ height }: { height: string }) {
return (
);
}