From a72b2f9d84ece75738602435a15fbff4c63d3941 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sun, 28 Sep 2025 11:35:41 +0800 Subject: [PATCH] perf: uninstall classnames, install clsx --- package.json | 14 +++++++------- src/PickerInput/Popup/Footer.tsx | 6 +++--- src/PickerInput/Popup/index.tsx | 6 +++--- src/PickerInput/RangePicker.tsx | 11 ++++------- src/PickerInput/Selector/Icon.tsx | 4 ++-- src/PickerInput/Selector/Input.tsx | 8 ++++---- src/PickerInput/Selector/RangeSelector.tsx | 6 +++--- .../Selector/SingleSelector/MultipleDates.tsx | 4 ++-- .../Selector/SingleSelector/index.tsx | 6 +++--- src/PickerInput/SinglePicker.tsx | 11 ++++------- src/PickerPanel/DatePanel/index.tsx | 6 +++--- src/PickerPanel/PanelBody.tsx | 8 ++++---- src/PickerPanel/PanelHeader.tsx | 18 ++++++++++++------ .../TimePanel/TimePanelBody/TimeColumn.tsx | 4 ++-- .../TimePanel/TimePanelBody/index.tsx | 4 ++-- src/PickerPanel/TimePanel/index.tsx | 12 +++--------- src/PickerPanel/WeekPanel/index.tsx | 5 ++--- src/PickerPanel/index.tsx | 6 ++---- src/PickerTrigger/index.tsx | 4 ++-- 19 files changed, 67 insertions(+), 76 deletions(-) diff --git a/package.json b/package.json index e74097a63..653996229 100644 --- a/package.json +++ b/package.json @@ -42,19 +42,16 @@ "@rc-component/resize-observer": "^1.0.0", "@rc-component/trigger": "^3.0.0", "@rc-component/util": "^1.3.0", - "classnames": "^2.2.1", + "clsx": "^2.1.1", "rc-overflow": "^1.3.2" }, - "engines": { - "node": ">=8.x" - }, - "devDependencies": { + "devDependencies": { "@rc-component/father-plugin": "^1.0.0", - "@rc-component/np":"^1.0.3", + "@rc-component/np": "^1.0.3", "@testing-library/react": "^16.0.0", - "@types/classnames": "^2.2.9", "@types/jest": "^29.4.0", "@types/luxon": "^3.2.0", + "@types/node": "^24.5.2", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.8", "coveralls": "^3.0.6", @@ -103,5 +100,8 @@ "moment": { "optional": true } + }, + "engines": { + "node": ">=8.x" } } diff --git a/src/PickerInput/Popup/Footer.tsx b/src/PickerInput/Popup/Footer.tsx index 453205a51..ba15dba3d 100644 --- a/src/PickerInput/Popup/Footer.tsx +++ b/src/PickerInput/Popup/Footer.tsx @@ -1,4 +1,4 @@ -import cls from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import type { GenerateConfig } from '../../generate'; import useTimeInfo from '../../hooks/useTimeInfo'; @@ -76,7 +76,7 @@ export default function Footer(props: FooterProps) { const presetNode = showNow && (
  • @@ -108,7 +108,7 @@ export default function Footer(props: FooterProps) { return (
    {extraNode &&
    {extraNode}
    } diff --git a/src/PickerInput/Popup/index.tsx b/src/PickerInput/Popup/index.tsx index b68fdf2af..190c56eb4 100644 --- a/src/PickerInput/Popup/index.tsx +++ b/src/PickerInput/Popup/index.tsx @@ -1,4 +1,4 @@ -import classNames from 'classnames'; +import { clsx } from 'clsx'; import ResizeObserver, { type ResizeObserverProps } from '@rc-component/resize-observer'; import * as React from 'react'; import type { @@ -213,7 +213,7 @@ export default function Popup(props: PopupProps(props: PopupProps
    diff --git a/src/PickerInput/RangePicker.tsx b/src/PickerInput/RangePicker.tsx index fc4c52472..7706fd618 100644 --- a/src/PickerInput/RangePicker.tsx +++ b/src/PickerInput/RangePicker.tsx @@ -1,5 +1,5 @@ import { useEvent, useControlledState } from '@rc-component/util'; -import cls from 'classnames'; +import { clsx } from 'clsx'; import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; import omit from '@rc-component/util/lib/omit'; import pickAttrs from '@rc-component/util/lib/pickAttrs'; @@ -777,7 +777,7 @@ function RangePicker( {...pickTriggerProps(filledProps)} popupElement={panel} popupStyle={mergedStyles.popup.root} - popupClassName={cls(rootClassName, mergedClassNames.popup.root)} + popupClassName={clsx(rootClassName, mergedClassNames.popup.root)} // Visible visible={mergedOpen} onClose={onPopupClose} @@ -790,11 +790,8 @@ function RangePicker( // Ref ref={selectorRef} // Style - className={cls(filledProps.className, rootClassName, mergedClassNames.root)} - style={{ - ...mergedStyles.root, - ...filledProps.style, - }} + className={clsx(filledProps.className, rootClassName, mergedClassNames.root)} + style={{ ...mergedStyles.root, ...filledProps.style }} // Icon suffixIcon={suffixIcon} // Active diff --git a/src/PickerInput/Selector/Icon.tsx b/src/PickerInput/Selector/Icon.tsx index 23628f4c2..a8edc0890 100644 --- a/src/PickerInput/Selector/Icon.tsx +++ b/src/PickerInput/Selector/Icon.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import PickerContext from '../context'; -import cls from 'classnames'; +import { clsx } from 'clsx'; export interface IconProps extends React.HtmlHTMLAttributes { icon?: React.ReactNode; @@ -13,7 +13,7 @@ export default function Icon(props: IconProps) { return icon ? ( diff --git a/src/PickerInput/Selector/Input.tsx b/src/PickerInput/Selector/Input.tsx index b849792e7..22051545c 100644 --- a/src/PickerInput/Selector/Input.tsx +++ b/src/PickerInput/Selector/Input.tsx @@ -1,4 +1,4 @@ -import cls from 'classnames'; +import { clsx } from 'clsx'; import { useEvent } from '@rc-component/util'; import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; import raf from '@rc-component/util/lib/raf'; @@ -95,8 +95,8 @@ const Input = React.forwardRef((props, ref) => { }, [value]); // ========================= Refs ========================= - const holderRef = React.useRef(); - const inputRef = React.useRef(); + const holderRef = React.useRef(null); + const inputRef = React.useRef(null); React.useImperativeHandle(ref, () => ({ nativeElement: holderRef.current, @@ -383,7 +383,7 @@ const Input = React.forwardRef((props, ref) => { return (
    (
    ( }} > {prefix && ( -
    +
    {prefix}
    )} diff --git a/src/PickerInput/Selector/SingleSelector/MultipleDates.tsx b/src/PickerInput/Selector/SingleSelector/MultipleDates.tsx index 670e7ba47..b2a7d8519 100644 --- a/src/PickerInput/Selector/SingleSelector/MultipleDates.tsx +++ b/src/PickerInput/Selector/SingleSelector/MultipleDates.tsx @@ -1,4 +1,4 @@ -import classNames from 'classnames'; +import { clsx } from 'clsx'; import Overflow from 'rc-overflow'; import * as React from 'react'; import type { PickerProps } from '../../SinglePicker'; @@ -36,7 +36,7 @@ export default function MultipleDates( function renderSelector(content: React.ReactNode, onClose?: React.MouseEventHandler) { return ( {content} diff --git a/src/PickerInput/Selector/SingleSelector/index.tsx b/src/PickerInput/Selector/SingleSelector/index.tsx index f8b56a832..7a373b9c0 100644 --- a/src/PickerInput/Selector/SingleSelector/index.tsx +++ b/src/PickerInput/Selector/SingleSelector/index.tsx @@ -1,4 +1,4 @@ -import cls from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import type { InternalMode, PickerRef, SelectorProps } from '../../../interface'; import { isSame } from '../../../utils/dateUtil'; @@ -201,7 +201,7 @@ function SingleSelector( return (
    ( }} > {prefix && ( -
    +
    {prefix}
    )} diff --git a/src/PickerInput/SinglePicker.tsx b/src/PickerInput/SinglePicker.tsx index 6899c52e0..d48038a0a 100644 --- a/src/PickerInput/SinglePicker.tsx +++ b/src/PickerInput/SinglePicker.tsx @@ -1,5 +1,5 @@ import { useEvent, useControlledState } from '@rc-component/util'; -import cls from 'classnames'; +import { clsx } from 'clsx'; import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; import omit from '@rc-component/util/lib/omit'; import pickAttrs from '@rc-component/util/lib/pickAttrs'; @@ -638,7 +638,7 @@ function Picker( {...pickTriggerProps(filledProps)} popupElement={panel} popupStyle={mergedStyles.popup.root} - popupClassName={cls(rootClassName, mergedClassNames.popup.root)} + popupClassName={clsx(rootClassName, mergedClassNames.popup.root)} // Visible visible={mergedOpen} onClose={onPopupClose} @@ -649,11 +649,8 @@ function Picker( // Ref ref={selectorRef} // Style - className={cls(filledProps.className, rootClassName, mergedClassNames.root)} - style={{ - ...mergedStyles.root, - ...filledProps.style, - }} + className={clsx(filledProps.className, rootClassName, mergedClassNames.root)} + style={{ ...mergedStyles.root, ...filledProps.style }} // Icon suffixIcon={suffixIcon} removeIcon={removeIcon} diff --git a/src/PickerPanel/DatePanel/index.tsx b/src/PickerPanel/DatePanel/index.tsx index e4bbe6595..42013ebff 100644 --- a/src/PickerPanel/DatePanel/index.tsx +++ b/src/PickerPanel/DatePanel/index.tsx @@ -1,4 +1,4 @@ -import classNames from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import type { PanelMode, SharedPanelProps } from '../../interface'; import { @@ -60,7 +60,7 @@ export default function DatePanel(props: DatePane return ( (props: DatePane // ========================= Render ========================= return ( -
    +
    {/* Header */} offset={(distance) => generateConfig.addMonth(pickerValue, distance)} diff --git a/src/PickerPanel/PanelBody.tsx b/src/PickerPanel/PanelBody.tsx index f202c5a85..34b6fe011 100644 --- a/src/PickerPanel/PanelBody.tsx +++ b/src/PickerPanel/PanelBody.tsx @@ -1,4 +1,4 @@ -import cls from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import type { DisabledDate } from '../interface'; import { formatValue, isInRange, isSame } from '../utils/dateUtil'; @@ -125,7 +125,7 @@ export default function PanelBody(props: PanelBod isSame(generateConfig, locale, currentDate, date, type), @@ -184,8 +184,8 @@ export default function PanelBody(props: PanelBod // ============================== Render ============================== return ( -
    - +
    +
    {headerCells && ( {headerCells} diff --git a/src/PickerPanel/PanelHeader.tsx b/src/PickerPanel/PanelHeader.tsx index 1ff81e07b..407489a59 100644 --- a/src/PickerPanel/PanelHeader.tsx +++ b/src/PickerPanel/PanelHeader.tsx @@ -1,4 +1,4 @@ -import cls from 'classnames'; +import { clsx } from 'clsx'; import * as React from 'react'; import { isSameOrAfter } from '../utils/dateUtil'; import { PickerHackContext, usePanelContext } from './context'; @@ -120,14 +120,17 @@ function PanelHeader(props: HeaderProps) { const superNextBtnCls = `${headerPrefixCls}-super-next-btn`; return ( -
    +
    {superOffset && (