(null);
interface SelectProps {
value?: string;
onValueChange?: (value: string) => void;
children: React.ReactNode;
}
export function Select({ value = "", onValueChange, children }: SelectProps) {
const [open, setOpen] = React.useState(false);
const onChange = React.useCallback(
(v: string) => {
onValueChange?.(v);
setOpen(false);
},
[onValueChange]
);
return (
{children}
);
}
export function SelectTrigger({
className,
children,
}: {
className?: string;
children: React.ReactNode;
}) {
const ctx = React.useContext(SelectContext)!;
return (
);
}
export function SelectValue({ placeholder }: { placeholder?: string }) {
const ctx = React.useContext(SelectContext)!;
return {ctx.value || placeholder};
}
export function SelectContent({
children,
className,
}: {
children: React.ReactNode;
className?: string;
}) {
const ctx = React.useContext(SelectContext)!;
if (!ctx.open) return null;
return (
{children}
);
}
export function SelectItem({
value,
children,
}: {
value: string;
children: React.ReactNode;
}) {
const ctx = React.useContext(SelectContext)!;
return (
{
e.preventDefault();
ctx.onChange(value);
}}
>
{children}
);
}
// ─── Badge ───────────────────────────────────────────────────────────────────
const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default: "border-transparent bg-primary text-primary-foreground",
secondary: "border-transparent bg-secondary text-secondary-foreground",
destructive: "border-transparent bg-destructive text-destructive-foreground",
outline: "text-foreground",
success: "border-transparent bg-green-600 text-white",
},
},
defaultVariants: {
variant: "default",
},
}
);
export interface BadgeProps
extends React.HTMLAttributes,
VariantProps {}
export function Badge({ className, variant, ...props }: BadgeProps) {
return ;
}
// ─── Progress ────────────────────────────────────────────────────────────────
interface ProgressProps extends React.HTMLAttributes {
value?: number;
max?: number;
}
export function Progress({ value = 0, max = 100, className, ...props }: ProgressProps) {
const percentage = Math.min(100, Math.max(0, (value / max) * 100));
return (
);
}
// ─── RadioGroup ──────────────────────────────────────────────────────────────
interface RadioGroupContextValue {
value: string;
onValueChange: (value: string) => void;
}
const RadioGroupContext = React.createContext(null);
interface RadioGroupProps {
value: string;
onValueChange: (value: string) => void;
className?: string;
children: React.ReactNode;
}
export function RadioGroup({ value, onValueChange, className, children }: RadioGroupProps) {
return (
{children}
);
}
interface RadioGroupItemProps extends React.InputHTMLAttributes {
value: string;
}
export const RadioGroupItem = React.forwardRef(
({ value, className, ...props }, ref) => {
const ctx = React.useContext(RadioGroupContext);
if (!ctx) throw new Error("RadioGroupItem must be used within RadioGroup");
return (
ctx.onValueChange(value)}
{...props}
/>
);
}
);
RadioGroupItem.displayName = "RadioGroupItem";
export { cn };