Skip to content

Commit d5540a7

Browse files
authored
perf: uninstall classnames, install clsx (#457)
1 parent 607cb16 commit d5540a7

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
"tsc": "bunx tsc --noEmit"
4141
},
4242
"dependencies": {
43-
"@rc-component/portal": "^2.0.0",
4443
"@rc-component/motion": "^1.0.0",
44+
"@rc-component/portal": "^2.0.0",
4545
"@rc-component/util": "^1.3.0",
46-
"classnames": "^2.2.6"
46+
"clsx": "^2.1.1"
4747
},
4848
"devDependencies": {
4949
"@ant-design/icons": "^5.0.1",
5050
"@rc-component/father-plugin": "^2.0.2",
5151
"@rc-component/np": "^1.0.0",
5252
"@testing-library/jest-dom": "^6.4.0",
5353
"@testing-library/react": "^15.0.6",
54-
"@types/classnames": "^2.2.10",
5554
"@types/jest": "^29.5.11",
55+
"@types/node": "^24.5.2",
5656
"@types/react": "^18.0.0",
5757
"@types/react-dom": "^18.0.0",
5858
"@umijs/fabric": "^4.0.1",

src/Image.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
2-
import classnames from 'classnames';
2+
import { clsx } from 'clsx';
33
import * as React from 'react';
44
import { useContext, useMemo, useState } from 'react';
55
import type { InternalPreviewConfig, PreviewSemanticName, ToolbarRenderInfoType } from './Preview';
@@ -208,7 +208,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
208208
<>
209209
<div
210210
{...otherProps}
211-
className={classnames(prefixCls, rootClassName, classNames.root, {
211+
className={clsx(prefixCls, rootClassName, classNames.root, {
212212
[`${prefixCls}-error`]: status === 'error',
213213
})}
214214
onClick={canPreview ? onPreview : onClick}
@@ -220,7 +220,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
220220
>
221221
<img
222222
{...imgCommonProps}
223-
className={classnames(
223+
className={clsx(
224224
`${prefixCls}-img`,
225225
{
226226
[`${prefixCls}-img-placeholder`]: placeholder === true,
@@ -249,7 +249,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
249249
{/* Preview Click Mask */}
250250
{cover !== false && canPreview && (
251251
<div
252-
className={classnames(
252+
className={clsx(
253253
`${prefixCls}-cover`,
254254
classNames.cover,
255255
`${prefixCls}-cover-${coverPlacement}`,
@@ -278,7 +278,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
278278
{...restProps}
279279
classNames={classNames?.popup}
280280
styles={styles?.popup}
281-
rootClassName={classnames(previewRootClassName, rootClassName)}
281+
rootClassName={clsx(previewRootClassName, rootClassName)}
282282
/>
283283
)}
284284
</>

src/Preview/Footer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import classnames from 'classnames';
1+
import { clsx } from 'clsx';
22
import * as React from 'react';
33
import type { Actions, PreviewProps } from '.';
44
import type { ImgInfo } from '../Image';
@@ -97,7 +97,7 @@ export default function Footer(props: FooterProps) {
9797
return (
9898
<div
9999
key={type}
100-
className={classnames(actionCls, `${actionCls}-${type}`, {
100+
className={clsx(actionCls, `${actionCls}-${type}`, {
101101
[`${actionCls}-disabled`]: !!disabled,
102102
})}
103103
onClick={onClick}
@@ -164,7 +164,7 @@ export default function Footer(props: FooterProps) {
164164
});
165165

166166
const actionsNode = (
167-
<div className={classnames(`${prefixCls}-actions`, classNames.actions)} style={styles.actions}>
167+
<div className={clsx(`${prefixCls}-actions`, classNames.actions)} style={styles.actions}>
168168
{flipYNode}
169169
{flipXNode}
170170
{rotateLeftNode}
@@ -176,7 +176,7 @@ export default function Footer(props: FooterProps) {
176176

177177
// >>>>> Render
178178
return (
179-
<div className={classnames(`${prefixCls}-footer`, classNames.footer)} style={styles.footer}>
179+
<div className={clsx(`${prefixCls}-footer`, classNames.footer)} style={styles.footer}>
180180
{progressNode}
181181
{actionsRender
182182
? actionsRender(actionsNode, {

src/Preview/PrevNext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import classNames from 'classnames';
1+
import { clsx } from 'clsx';
22
import * as React from 'react';
33
import type { OperationIcons } from '.';
44

@@ -24,15 +24,15 @@ export default function PrevNext(props: PrevNextProps) {
2424
return (
2525
<>
2626
<div
27-
className={classNames(switchCls, `${switchCls}-prev`, {
27+
className={clsx(switchCls, `${switchCls}-prev`, {
2828
[`${switchCls}-disabled`]: current === 0,
2929
})}
3030
onClick={() => onActive(-1)}
3131
>
3232
{prev ?? left}
3333
</div>
3434
<div
35-
className={classNames(switchCls, `${switchCls}-next`, {
35+
className={clsx(switchCls, `${switchCls}-next`, {
3636
[`${switchCls}-disabled`]: current === count - 1,
3737
})}
3838
onClick={() => onActive(1)}

src/Preview/index.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Portal, { type PortalProps } from '@rc-component/portal';
33
import { useEvent } from '@rc-component/util';
44
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
55
import KeyCode from '@rc-component/util/lib/KeyCode';
6-
import classnames from 'classnames';
6+
import { clsx } from 'clsx';
77
import React, { useContext, useEffect, useRef, useState } from 'react';
88
import { PreviewGroupContext } from '../context';
99
import type { TransformAction, TransformType } from '../hooks/useImageTransform';
@@ -410,27 +410,23 @@ const Preview: React.FC<PreviewProps> = props => {
410410

411411
return (
412412
<div
413-
className={classnames(prefixCls, rootClassName, classNames.root, motionClassName, {
413+
className={clsx(prefixCls, rootClassName, classNames.root, motionClassName, {
414414
[`${prefixCls}-moving`]: isMoving,
415415
})}
416416
style={mergedStyle}
417417
>
418418
{/* Mask */}
419419
<div
420-
className={classnames(`${prefixCls}-mask`, classNames.mask)}
420+
className={clsx(`${prefixCls}-mask`, classNames.mask)}
421421
style={styles.mask}
422422
onClick={onClose}
423423
/>
424424

425425
{/* Body */}
426-
<div className={classnames(`${prefixCls}-body`, classNames.body)} style={bodyStyle}>
426+
<div className={clsx(`${prefixCls}-body`, classNames.body)} style={bodyStyle}>
427427
{/* Preview Image */}
428428
{imageRender
429-
? imageRender(imgNode, {
430-
transform,
431-
image,
432-
...(groupContext ? { current } : {}),
433-
})
429+
? imageRender(imgNode, { transform, image, ...(groupContext ? { current } : {}) })
434430
: imgNode}
435431
</div>
436432

0 commit comments

Comments
 (0)