Files
accounts-manager-web/components/shared/stats-select.tsx
Your Name 0b95ca36f1 Initial project setup with Next.js accounts manager
- Set up Next.js project structure
- Added UI components and styling
- Configured package dependencies
- Added feature documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-23 01:40:14 +08:00

80 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { Input } from '@/components/ui/input';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { StatsDataItem } from '@/lib/hooks/use-stats-data';
interface StatsSelectProps {
value: string;
onValueChange: (value: string) => void;
placeholder: string;
inputPlaceholder: string;
items: StatsDataItem[];
showNoneOption?: boolean;
noneOptionLabel?: string;
className?: string;
disabled?: boolean;
}
export function StatsSelect({
value,
onValueChange,
placeholder,
inputPlaceholder,
items,
showNoneOption = false,
noneOptionLabel = "不修改",
className,
disabled = false
}: StatsSelectProps) {
const handleSelectChange = (selectedValue: string) => {
if (selectedValue === 'none') {
onValueChange('');
} else {
onValueChange(selectedValue);
}
};
// 检查当前值是否在选项列表中
const isValueInOptions = value && (
showNoneOption && value === '' ||
items.some(item => item.value === value)
);
// 为Select组件确定显示值
const selectValue = () => {
if (!value && showNoneOption) return 'none';
if (isValueInOptions) return value;
return undefined; // 如果值不在选项中不设置Select的值
};
return (
<div className={`space-y-2 ${className || ''}`}>
<Select
value={selectValue()}
onValueChange={handleSelectChange}
disabled={disabled}
>
<SelectTrigger className="w-full">
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent>
{showNoneOption && (
<SelectItem value="none">{noneOptionLabel}</SelectItem>
)}
{items.map((item) => (
<SelectItem key={item.value} value={item.value}>
{item.label} ({item.count} )
</SelectItem>
))}
</SelectContent>
</Select>
<Input
placeholder={inputPlaceholder}
value={value}
onChange={(e) => onValueChange(e.target.value)}
disabled={disabled}
/>
</div>
);
}