Skip to content

Commit 5559047

Browse files
committed
perf: uninstall classnames, install clsx
1 parent a032997 commit 5559047

File tree

6 files changed

+20
-32
lines changed

6 files changed

+20
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ yarn.lock
3131
storybook/
3232
es/
3333
package-lock.json
34+
pnpm-lock.yaml
3435
src/*.js
3536
src/*.map
3637
tslint.json

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
"dependencies": {
4848
"@ant-design/fast-color": "^3.0.0",
4949
"@rc-component/util": "^1.3.0",
50-
"classnames": "^2.2.6"
50+
"clsx": "^2.1.1"
5151
},
5252
"devDependencies": {
5353
"@rc-component/father-plugin": "^2.0.4",
5454
"@rc-component/np": "^1.0.0",
5555
"@rc-component/trigger": "^1.13.0",
5656
"@testing-library/jest-dom": "^5.16.4",
5757
"@testing-library/react": "^13.3.0",
58-
"@types/classnames": "^2.2.6",
58+
"@types/node": "^24.5.2",
5959
"@types/react": "^18.0.8",
6060
"@types/react-dom": "^18.0.3",
6161
"@types/warning": "^3.0.0",

src/ColorPicker.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { CSSProperties } from 'react';
22
import React, { forwardRef, useMemo } from 'react';
33
import { ColorPickerPrefixCls, defaultColor } from './util';
44

5-
import classNames from 'classnames';
5+
import { clsx } from 'clsx';
66
import { Color } from './color';
77
import ColorBlock from './components/ColorBlock';
88
import Picker from './components/Picker';
@@ -119,7 +119,7 @@ const ColorPicker = forwardRef<HTMLDivElement, ColorPickerProps>(
119119
};
120120

121121
// ============================ Render ============================
122-
const mergeCls = classNames(`${prefixCls}-panel`, className, {
122+
const mergeCls = clsx(`${prefixCls}-panel`, className, {
123123
[`${prefixCls}-panel-disabled`]: disabled,
124124
});
125125

@@ -138,7 +138,7 @@ const ColorPicker = forwardRef<HTMLDivElement, ColorPickerProps>(
138138
/>
139139
<div className={`${prefixCls}-slider-container`}>
140140
<div
141-
className={classNames(`${prefixCls}-slider-group`, {
141+
className={clsx(`${prefixCls}-slider-group`, {
142142
[`${prefixCls}-slider-group-disabled-alpha`]: disabledAlpha,
143143
})}
144144
>

src/components/ColorBlock.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import classNames from 'classnames';
2-
import type { FC } from 'react';
1+
import { clsx } from 'clsx';
32
import React from 'react';
43

54
export type ColorBlockProps = {
@@ -10,7 +9,7 @@ export type ColorBlockProps = {
109
onClick?: React.MouseEventHandler<HTMLDivElement>;
1110
};
1211

13-
const ColorBlock: FC<ColorBlockProps> = ({
12+
const ColorBlock: React.FC<ColorBlockProps> = ({
1413
color,
1514
prefixCls,
1615
className,
@@ -20,16 +19,11 @@ const ColorBlock: FC<ColorBlockProps> = ({
2019
const colorBlockCls = `${prefixCls}-color-block`;
2120
return (
2221
<div
23-
className={classNames(colorBlockCls, className)}
22+
className={clsx(colorBlockCls, className)}
2423
style={style}
2524
onClick={onClick}
2625
>
27-
<div
28-
className={`${colorBlockCls}-inner`}
29-
style={{
30-
background: color,
31-
}}
32-
/>
26+
<div className={`${colorBlockCls}-inner`} style={{ background: color }} />
3327
</div>
3428
);
3529
};

src/components/Handler.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import classNames from 'classnames';
2-
import type { FC } from 'react';
1+
import { clsx } from 'clsx';
32
import React from 'react';
43

54
type HandlerSize = 'default' | 'small';
65

7-
const Handler: FC<{
6+
const Handler: React.FC<{
87
size?: HandlerSize;
98
color?: string;
109
prefixCls?: string;
1110
}> = ({ size = 'default', color, prefixCls }) => {
1211
return (
1312
<div
14-
className={classNames(`${prefixCls}-handler`, {
13+
className={clsx(`${prefixCls}-handler`, {
1514
[`${prefixCls}-handler-sm`]: size === 'small',
1615
})}
17-
style={{
18-
backgroundColor: color,
19-
}}
16+
style={{ backgroundColor: color }}
2017
/>
2118
);
2219
};

src/components/Slider.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { FC } from 'react';
21
import React, { useRef } from 'react';
32
import useColorDrag from '../hooks/useColorDrag';
43
import type { HsbaColorType, TransformOffset } from '../interface';
54
import Palette from './Palette';
65

76
import { useEvent } from '@rc-component/util';
8-
import classNames from 'classnames';
7+
import { clsx } from 'clsx';
98
import { Color } from '../color';
109
import { calcOffset, calculateColor } from '../util';
1110
import Gradient from './Gradient';
@@ -25,7 +24,7 @@ export interface BaseSliderProps {
2524
color: Color;
2625
}
2726

28-
const Slider: FC<BaseSliderProps> = props => {
27+
const Slider: React.FC<BaseSliderProps> = props => {
2928
const {
3029
prefixCls,
3130
colors,
@@ -36,9 +35,9 @@ const Slider: FC<BaseSliderProps> = props => {
3635
type,
3736
} = props;
3837

39-
const sliderRef = useRef();
40-
const transformRef = useRef();
41-
const colorRef = useRef(color);
38+
const sliderRef = useRef<HTMLDivElement>(null);
39+
const transformRef = useRef<HTMLDivElement>(null);
40+
const colorRef = useRef<Color>(color);
4241

4342
const getValue = (c: Color) => {
4443
return type === 'hue' ? c.getHue() : c.a * 100;
@@ -94,10 +93,7 @@ const Slider: FC<BaseSliderProps> = props => {
9493
return (
9594
<div
9695
ref={sliderRef}
97-
className={classNames(
98-
`${prefixCls}-slider`,
99-
`${prefixCls}-slider-${type}`,
100-
)}
96+
className={clsx(`${prefixCls}-slider`, `${prefixCls}-slider-${type}`)}
10197
onMouseDown={dragStartHandle}
10298
onTouchStart={dragStartHandle}
10399
>

0 commit comments

Comments
 (0)