import React from 'react'; import { cn } from '@/lib/utils'; // 1. 引入标准的 shadcn 工具函数 export interface SwitchOption { value: T; label: React.ReactNode; } // 2. 移除内联 sx,继承标准 HTML 属性,并使用标准的类名注入机制 export interface SwitchButtonGroupProps extends Omit< React.HTMLAttributes, 'onChange' > { value: T; options: SwitchOption[]; onChange: (value: T) => void; size?: 'small' | 'medium' | 'large'; buttonClassName?: string; // 替换原有的 buttonSx } export default function SwitchButtonGroup({ value, options, onChange, size = 'medium', className, buttonClassName, ...props }: SwitchButtonGroupProps) { // 3. 将尺寸和高度、内边距等整体对齐,保证按钮和背景容器成比例缩放 const sizeClasses = { small: 'text-xs h-8 px-2 py-1 rounded-md', medium: 'text-sm h-9 px-3 py-1.5 rounded-md', large: 'text-base h-11 px-4 py-2 rounded-lg', }; return (
{options.map((option) => { const isSelected = value === option.value; return ( ); })}
); }