MCPcopy
hub / github.com/graphif/project-graph / EnumQuickSettingControl

Function EnumQuickSettingControl

app/src/components/right-toolbar.tsx:58–100  ·  view source on GitHub ↗

* Enum 类型的快捷设置项(下拉菜单)

({
  settingKey,
  isHovered,
}: {
  settingKey: keyof typeof settingsSchema.shape;
  isHovered: boolean;
})

Source from the content-addressed store, hash-verified

56 * Enum 类型的快捷设置项(下拉菜单)
57 */
58function EnumQuickSettingControl({
59 settingKey,
60 isHovered,
61}: {
62 settingKey: keyof typeof settingsSchema.shape;
63 isHovered: boolean;
64}) {
65 const { t } = useTranslation("settings");
66 const [value, setValue] = useState<string>(Settings[settingKey] as string);
67 const options = QuickSettingsManager.getEnumOptions(settingKey as string);
68
69 useEffect(() => {
70 const unwatch = Settings.watch(settingKey, (newValue) => {
71 if (typeof newValue === "string") setValue(newValue);
72 });
73 return unwatch;
74 }, [settingKey]);
75
76 const handleChange = (newValue: string) => {
77 setValue(newValue);
78 // @ts-expect-error 设置值
79 Settings[settingKey] = newValue;
80 };
81
82 return (
83 <div
84 className={cn("overflow-hidden transition-all duration-200", isHovered ? "w-28 opacity-100" : "w-0 opacity-0")}
85 >
86 <Select value={value} onValueChange={handleChange}>
87 <SelectTrigger size="sm" className="h-7 w-28 text-xs">
88 <SelectValue />
89 </SelectTrigger>
90 <SelectContent>
91 {options.map((opt) => (
92 <SelectItem key={opt} value={opt} className="text-xs">
93 {t(`${settingKey as string}.options.${opt}`, { defaultValue: opt })}
94 </SelectItem>
95 ))}
96 </SelectContent>
97 </Select>
98 </div>
99 );
100}
101
102/**
103 * Number 类型的快捷设置项(滑块 或 数字输入框)

Callers

nothing calls this directly

Calls 1

cnFunction · 0.90

Tested by

no test coverage detected