Skip to content

Commit 057acc8

Browse files
authored
perf: uninstall classnames, install clsx (#1370)
1 parent a887d56 commit 057acc8

File tree

16 files changed

+44
-55
lines changed

16 files changed

+44
-55
lines changed

docs/examples/animation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import CSSMotionList from 'rc-animate/lib/CSSMotionList';
3-
import classNames from 'classnames';
3+
import { clsx } from 'clsx';
44
import toArray from '@rc-component/util/lib/Children/toArray';
55
import type { TableProps } from 'rc-table';
66
import Table from 'rc-table';
@@ -27,7 +27,7 @@ const MotionBody: React.FC<MotionBodyProps> = ({ children, ...props }) => {
2727
{({ key, className }) => {
2828
const node = nodesRef.current[key];
2929
return React.cloneElement<any>(node, {
30-
className: classNames(node.props.className, className),
30+
className: clsx(node.props.className, className),
3131
});
3232
}}
3333
</CSSMotionList>

docs/examples/virtual-list-grid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import classNames from 'classnames';
2+
import { clsx } from 'clsx';
33
import { VariableSizeGrid as Grid } from 'react-window';
44
import Table from 'rc-table';
55
import '../../assets/index.less';
@@ -72,7 +72,7 @@ const Demo = () => {
7272
>
7373
{({ columnIndex, rowIndex, style }) => (
7474
<div
75-
className={classNames('virtual-cell', {
75+
className={clsx('virtual-cell', {
7676
'virtual-cell-last': columnIndex === columns.length - 1,
7777
})}
7878
style={style}

docs/examples/virtual-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import classNames from 'classnames';
2+
import { clsx } from 'clsx';
33
import { VariableSizeGrid as Grid } from 'react-window';
44
import Table from 'rc-table';
55
import '../../assets/index.less';
@@ -23,7 +23,7 @@ for (let i = 0; i < 100000; i += 1) {
2323

2424
const Cell = ({ columnIndex, rowIndex, style }) => (
2525
<div
26-
className={classNames('virtual-cell', {
26+
className={clsx('virtual-cell', {
2727
'virtual-cell-last': columnIndex === columns.length - 1,
2828
})}
2929
style={style}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@rc-component/context": "^1.4.0",
5353
"@rc-component/resize-observer": "^1.0.0",
5454
"@rc-component/util": "^1.1.0",
55-
"classnames": "^2.2.5",
55+
"clsx": "^2.1.1",
5656
"rc-virtual-list": "^3.14.2"
5757
},
5858
"devDependencies": {

src/Body/BodyRow.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cls from 'classnames';
1+
import { clsx } from 'clsx';
22
import * as React from 'react';
33
import Cell from '../Cell';
44
import { responseImmutable } from '../context/TableContext';
@@ -170,15 +170,13 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>(
170170
<RowComponent
171171
{...rowProps}
172172
data-row-key={rowKey}
173-
className={cls(
173+
className={clsx(
174174
className,
175175
`${prefixCls}-row`,
176176
`${prefixCls}-row-level-${indent}`,
177177
rowProps?.className,
178178
classNames.row,
179-
{
180-
[expandedClsName]: indent >= 1,
181-
},
179+
{ [expandedClsName]: indent >= 1 },
182180
)}
183181
style={{
184182
...style,
@@ -201,7 +199,7 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>(
201199

202200
return (
203201
<Cell<RecordType>
204-
className={cls(columnClassName, classNames.cell)}
202+
className={clsx(columnClassName, classNames.cell)}
205203
style={styles.cell}
206204
ellipsis={column.ellipsis}
207205
align={column.align}
@@ -232,7 +230,7 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>(
232230
expandRowNode = (
233231
<ExpandedRow
234232
expanded={expanded}
235-
className={cls(
233+
className={clsx(
236234
`${prefixCls}-expanded-row`,
237235
`${prefixCls}-expanded-row-level-${indent + 1}`,
238236
expandedClsName,

src/Body/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useContext } from '@rc-component/context';
22
import * as React from 'react';
3+
import { clsx } from 'clsx';
34
import type { PerfRecord } from '../context/PerfContext';
45
import PerfContext from '../context/PerfContext';
56
import TableContext, { responseImmutable } from '../context/TableContext';
@@ -9,7 +10,6 @@ import { getColumnsKey } from '../utils/valueUtil';
910
import BodyRow from './BodyRow';
1011
import ExpandedRow from './ExpandedRow';
1112
import MeasureRow from './MeasureRow';
12-
import cls from 'classnames';
1313

1414
export interface BodyProps<RecordType> {
1515
data: readonly RecordType[];
@@ -136,7 +136,7 @@ const Body = <RecordType,>(props: BodyProps<RecordType>) => {
136136
<PerfContext.Provider value={perfRef.current}>
137137
<WrapperComponent
138138
style={bodyStyles.wrapper}
139-
className={cls(`${prefixCls}-tbody`, bodyCls.wrapper)}
139+
className={clsx(`${prefixCls}-tbody`, bodyCls.wrapper)}
140140
>
141141
{/* Measure body column width with additional hidden col */}
142142
{measureColumnWidth && (

src/Cell/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from '@rc-component/context';
2-
import cls from 'classnames';
2+
import { clsx } from 'clsx';
33
import * as React from 'react';
44
import TableContext from '../context/TableContext';
55
import devRenderTimes from '../hooks/useRenderTimes';
@@ -218,7 +218,7 @@ const Cell = <RecordType,>(props: CellProps<RecordType>) => {
218218
});
219219

220220
// >>>>> ClassName
221-
const mergedClassName = cls(
221+
const mergedClassName = clsx(
222222
cellPrefixCls,
223223
className,
224224
{

src/FixedHolder/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from '@rc-component/context';
2-
import classNames from 'classnames';
2+
import { clsx } from 'clsx';
33
import { fillRef } from '@rc-component/util/lib/ref';
44
import * as React from 'react';
55
import { useMemo } from 'react';
@@ -175,7 +175,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
175175
...style,
176176
}}
177177
ref={setScrollRef}
178-
className={classNames(className, {
178+
className={clsx(className, {
179179
[stickyClassName]: !!stickyClassName,
180180
})}
181181
>

src/Header/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { clsx } from 'clsx';
23
import { useContext } from '@rc-component/context';
34
import TableContext, { responseImmutable } from '../context/TableContext';
45
import devRenderTimes from '../hooks/useRenderTimes';
@@ -11,7 +12,6 @@ import type {
1112
StickyOffsets,
1213
} from '../interface';
1314
import HeaderRow from './HeaderRow';
14-
import cls from 'classnames';
1515
import type { TableProps } from '..';
1616

1717
function parseHeaderRows<RecordType>(
@@ -33,7 +33,7 @@ function parseHeaderRows<RecordType>(
3333
const colSpans: number[] = columns.filter(Boolean).map(column => {
3434
const cell: CellType<RecordType> = {
3535
key: column.key,
36-
className: cls(column.className, classNames.cell) || '',
36+
className: clsx(column.className, classNames.cell) || '',
3737
style: styles.cell,
3838
children: column.title,
3939
column,
@@ -121,7 +121,7 @@ const Header = <RecordType extends any>(props: HeaderProps<RecordType>) => {
121121

122122
return (
123123
<WrapperComponent
124-
className={cls(`${prefixCls}-thead`, headerCls.wrapper)}
124+
className={clsx(`${prefixCls}-thead`, headerCls.wrapper)}
125125
style={headerStyles.wrapper}
126126
>
127127
{rows.map((row, rowIndex) => {

src/Table.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
import type { CompareProps } from '@rc-component/context/lib/Immutable';
28-
import cls from 'classnames';
28+
import { clsx } from 'clsx';
2929
import ResizeObserver from '@rc-component/resize-observer';
3030
import { getTargetScrollBarSize } from '@rc-component/util/lib/getScrollBarSize';
3131
import useEvent from '@rc-component/util/lib/hooks/useEvent';
@@ -779,12 +779,8 @@ const Table = <RecordType extends DefaultRecordType>(
779779
// >>>>>> Unique table
780780
groupTableNode = (
781781
<div
782-
style={{
783-
...scrollXStyle,
784-
...scrollYStyle,
785-
...styles?.content,
786-
}}
787-
className={cls(`${prefixCls}-content`, classNames?.content)}
782+
style={{ ...scrollXStyle, ...scrollYStyle, ...styles?.content }}
783+
className={clsx(`${prefixCls}-content`, classNames?.content)}
788784
onScroll={onInternalScroll}
789785
ref={scrollBodyRef}
790786
>
@@ -817,7 +813,7 @@ const Table = <RecordType extends DefaultRecordType>(
817813

818814
let fullTable = (
819815
<div
820-
className={cls(prefixCls, className, {
816+
className={clsx(prefixCls, className, {
821817
[`${prefixCls}-rtl`]: direction === 'rtl',
822818
[`${prefixCls}-fix-start-shadow`]: horizonScroll,
823819
[`${prefixCls}-fix-end-shadow`]: horizonScroll,
@@ -837,19 +833,19 @@ const Table = <RecordType extends DefaultRecordType>(
837833
{...dataProps}
838834
>
839835
{title && (
840-
<Panel className={cls(`${prefixCls}-title`, classNames?.title)} style={styles?.title}>
836+
<Panel className={clsx(`${prefixCls}-title`, classNames?.title)} style={styles?.title}>
841837
{title(mergedData)}
842838
</Panel>
843839
)}
844840
<div
845841
ref={scrollBodyContainerRef}
846-
className={cls(`${prefixCls}-container`, classNames?.section)}
842+
className={clsx(`${prefixCls}-container`, classNames?.section)}
847843
style={styles?.section}
848844
>
849845
{groupTableNode}
850846
</div>
851847
{footer && (
852-
<Panel className={cls(`${prefixCls}-footer`, classNames?.footer)} style={styles?.footer}>
848+
<Panel className={clsx(`${prefixCls}-footer`, classNames?.footer)} style={styles?.footer}>
853849
{footer(mergedData)}
854850
</Panel>
855851
)}

0 commit comments

Comments
 (0)