Skip to content

Commit c2dc268

Browse files
authored
perf: uninstall classnames, install clsx (#1164)
* perf: uninstall classnames, install clsx * perf: uninstall classnames, install clsx
1 parent eac8428 commit c2dc268

File tree

10 files changed

+23
-24
lines changed

10 files changed

+23
-24
lines changed

.gitignore

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
"react-dom": "*"
5050
},
5151
"dependencies": {
52-
"@rc-component/trigger": "^3.0.0",
5352
"@rc-component/motion": "^1.1.4",
53+
"@rc-component/trigger": "^3.0.0",
5454
"@rc-component/util": "^1.3.0",
55-
"classnames": "2.x",
55+
"clsx": "^2.1.1",
5656
"rc-overflow": "^1.4.0",
5757
"rc-virtual-list": "^3.5.2"
5858
},
@@ -62,6 +62,7 @@
6262
"@testing-library/jest-dom": "^6.4.5",
6363
"@testing-library/react": "^15.0.6",
6464
"@types/jest": "^29.5.12",
65+
"@types/node": "^24.5.2",
6566
"@types/react": "^18.3.0",
6667
"@types/react-dom": "^18.3.0",
6768
"babel-jest": "^29.6.1",

src/BaseSelect/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface';
2-
import cls from 'classnames';
2+
import { clsx } from 'clsx';
33
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
44
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
55
import isMobile from '@rc-component/util/lib/isMobile';
@@ -732,7 +732,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
732732
if (showSuffixIcon) {
733733
arrowNode = (
734734
<TransBtn
735-
className={cls(`${prefixCls}-arrow`, classNames?.suffix, {
735+
className={clsx(`${prefixCls}-arrow`, classNames?.suffix, {
736736
[`${prefixCls}-arrow-loading`]: loading,
737737
})}
738738
style={styles?.suffix}
@@ -776,7 +776,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
776776
const optionList = <OptionList ref={listRef} />;
777777

778778
// ============================= Select =============================
779-
const mergedClassName = cls(prefixCls, className, {
779+
const mergedClassName = clsx(prefixCls, className, {
780780
[`${prefixCls}-focused`]: mockFocused,
781781
[`${prefixCls}-multiple`]: multiple,
782782
[`${prefixCls}-single`]: !multiple,

src/OptionList.tsx

Lines changed: 4 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 KeyCode from '@rc-component/util/lib/KeyCode';
33
import useMemo from '@rc-component/util/lib/hooks/useMemo';
44
import omit from '@rc-component/util/lib/omit';
@@ -351,7 +351,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
351351

352352
return (
353353
<div
354-
className={classNames(itemPrefixCls, `${itemPrefixCls}-group`, data.className)}
354+
className={clsx(itemPrefixCls, `${itemPrefixCls}-group`, data.className)}
355355
title={groupTitle}
356356
>
357357
{label !== undefined ? label : key}
@@ -368,7 +368,8 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
368368
const mergedDisabled = disabled || (!selected && overMaxCount);
369369

370370
const optionPrefixCls = `${itemPrefixCls}-option`;
371-
const optionClassName = classNames(
371+
372+
const optionClassName = clsx(
372373
itemPrefixCls,
373374
optionPrefixCls,
374375
className,

src/SelectTrigger.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Trigger, { type TriggerRef } from '@rc-component/trigger';
22
import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface';
3-
import classNames from 'classnames';
3+
import { clsx } from 'clsx';
44
import * as React from 'react';
55
import type { Placement, RenderDOMFunc } from './BaseSelect';
66

@@ -168,9 +168,7 @@ const SelectTrigger: React.ForwardRefRenderFunction<RefTriggerProps, SelectTrigg
168168
popupAlign={popupAlign}
169169
popupVisible={visible}
170170
getPopupContainer={getPopupContainer}
171-
popupClassName={classNames(popupClassName, {
172-
[`${popupPrefixCls}-empty`]: empty,
173-
})}
171+
popupClassName={clsx(popupClassName, { [`${popupPrefixCls}-empty`]: empty })}
174172
popupStyle={mergedPopupStyle}
175173
onPopupVisibleChange={onPopupVisibleChange}
176174
>

src/Selector/Input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import classNames from 'classnames';
2+
import { clsx } from 'clsx';
33
import { composeRef } from '@rc-component/util/lib/ref';
44
import { warning } from '@rc-component/util/lib/warning';
55
import composeProps from '@rc-component/util/lib/composeProps';
@@ -70,7 +70,7 @@ const Input: React.ForwardRefRenderFunction<InputRef, InputProps> = (props, ref)
7070
ref: composeRef(ref, originRef as any),
7171
autoComplete: autoComplete || 'off',
7272

73-
className: classNames(
73+
className: clsx(
7474
`${prefixCls}-selection-search-input`,
7575
originProps.className,
7676
contextClassNames?.input,

src/Selector/MultipleSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { useState } from 'react';
3-
import classNames from 'classnames';
3+
import { clsx } from 'clsx';
44
import pickAttrs from '@rc-component/util/lib/pickAttrs';
55
import Overflow from 'rc-overflow';
66
import TransBtn from '../TransBtn';
@@ -107,7 +107,7 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
107107
) => (
108108
<span
109109
title={getTitle(item)}
110-
className={classNames(`${selectionPrefixCls}-item`, {
110+
className={clsx(`${selectionPrefixCls}-item`, {
111111
[`${selectionPrefixCls}-item-disabled`]: itemDisabled,
112112
})}
113113
>

src/Selector/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import useLock from '../hooks/useLock';
1717
import { isValidateOpenKey } from '../utils/keyUtil';
1818
import MultipleSelector from './MultipleSelector';
1919
import SingleSelector from './SingleSelector';
20-
import classNames from 'classnames';
20+
import { clsx } from 'clsx';
2121

2222
export interface InnerSelectorProps {
2323
prefixCls: string;
@@ -293,7 +293,7 @@ const Selector: React.ForwardRefRenderFunction<RefSelectorProps, SelectorProps>
293293
onMouseDown={onMouseDown}
294294
>
295295
{prefix && (
296-
<div className={classNames(`${prefixCls}-prefix`, prefixClassName)} style={prefixStyle}>
296+
<div className={clsx(`${prefixCls}-prefix`, prefixClassName)} style={prefixStyle}>
297297
{prefix}
298298
</div>
299299
)}

src/TransBtn.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import classNames from 'classnames';
2+
import { clsx } from 'clsx';
33
import type { RenderNode } from './BaseSelect';
44

55
export interface TransBtnProps {
@@ -34,9 +34,7 @@ const TransBtn: React.FC<TransBtnProps> = (props) => {
3434
{icon !== undefined ? (
3535
icon
3636
) : (
37-
<span className={classNames(className.split(/\s+/).map((cls) => `${cls}-icon`))}>
38-
{children}
39-
</span>
37+
<span className={clsx(className.split(/\s+/).map((cls) => `${cls}-icon`))}>{children}</span>
4038
)}
4139
</span>
4240
);

tests/Tags.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createEvent, fireEvent, render } from '@testing-library/react';
22
import KeyCode from '@rc-component/util/lib/KeyCode';
3-
import classNames from 'classnames';
3+
import { clsx } from 'clsx';
44
import * as React from 'react';
55
import Select, { BaseSelect, OptGroup, Option } from '../src';
66
import allowClearTest from './shared/allowClearTest';
@@ -279,7 +279,7 @@ describe('Select.Tags', () => {
279279
const { label } = props;
280280
onTagRender(label);
281281
return (
282-
<span className={classNames(label, 'customize-tag')}>
282+
<span className={clsx(label, 'customize-tag')}>
283283
{label}
284284
{label}
285285
</span>

0 commit comments

Comments
 (0)