(null);
const [flipUpward, setFlipUpward] = React.useState(false);
React.useEffect(() => {
if (!ctx.open || !contentRef.current) return;
const rect = contentRef.current.getBoundingClientRect();
const viewportHeight = window.innerHeight;
const spaceBelow = viewportHeight - rect.bottom;
// If dropdown extends below viewport (less than 20px space), flip upward
if (spaceBelow < 20) {
setFlipUpward(true);
} else {
setFlipUpward(false);
}
}, [ctx.open]);
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 };