Skip to content

Commit 50b9df2

Browse files
committed
refactor(ui): use clsx
1 parent 0f6e246 commit 50b9df2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ui/instructions/code.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- 不要直接用 fetch 获取资源,而是使用 ui/src/api/v1.ts 来获取数据。
22
- 使用 2 spaces 缩进。使用单引号。
33
- 在完成任务前验证是否有 Linter 或者 TypeScript 错误
4+
- 对于动态的 className,优先使用 clsx 来生成。只有遇到可能覆盖的情况下才使用 `import { cn } from '@/lib/utils'`。cn 底层用的是 twMerge,性能上会比 clsx 差一些。

ui/src/pages/main/select.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useState } from 'react';
1111
import { isSelectNet, SelectNet } from '@/api/rdp';
1212
import { useInstance } from '@/contexts/instance';
1313
import { cn } from '@/lib/utils';
14+
import { clsx } from 'clsx';
1415
import pLimit from 'p-limit';
1516
import { useLocalStorage } from '@/hooks/use-local-storage';
1617

@@ -69,10 +70,14 @@ const SelectNetItem: React.FC<SelectNetItemProps> = ({
6970
}
7071
}}
7172
>
72-
<Timer className={`h-4 w-4 ${net.list?.some(item => testingStates[item]) ? 'animate-spin' : ''}`} />
73+
<Timer className={clsx("h-4 w-4", {
74+
"animate-spin": net.list?.some(item => testingStates[item])
75+
})} />
7376
</Button>
7477
<ChevronDown
75-
className={`h-4 w-4 transition-transform duration-200 ${isOpen ? 'transform rotate-180' : ''}`}
78+
className={clsx("h-4 w-4 transition-transform duration-200", {
79+
"transform rotate-180": isOpen
80+
})}
7681
/>
7782
</div>
7883
</CollapsibleTrigger>
@@ -90,7 +95,7 @@ const SelectNetItem: React.FC<SelectNetItemProps> = ({
9095
>
9196
{item}
9297
{item in latencyResults && (
93-
<span className={cn('ml-2 text-xs', colorClass)}>
98+
<span className={cn("ml-2 text-xs", colorClass)}>
9499
{latencyText}
95100
</span>
96101
)}

0 commit comments

Comments
 (0)