diff --git a/components/cascader/Panel.tsx b/components/cascader/Panel.tsx index d9f51a6f2b76..b6d3eaa27128 100644 --- a/components/cascader/Panel.tsx +++ b/components/cascader/Panel.tsx @@ -5,6 +5,7 @@ import type { PickType } from 'rc-cascader/lib/Panel'; import type { CascaderProps } from '.'; import DefaultRenderEmpty from '../config-provider/defaultRenderEmpty'; +import useCSSVarCls from '../config-provider/hooks/useCSSVarCls'; import useBase from './hooks/useBase'; import useCheckable from './hooks/useCheckable'; import useColumnIcons from './hooks/useColumnIcons'; @@ -32,6 +33,8 @@ export default function CascaderPanel(props: CascaderPanelProps) { ); const [, hashId] = useStyle(cascaderPrefixCls); + const rootCls = useCSSVarCls(prefixCls); + const cascaderRootCls = useCSSVarCls(cascaderPrefixCls); usePanelStyle(cascaderPrefixCls); const isRtl = mergedDirection === 'rtl'; @@ -54,7 +57,7 @@ export default function CascaderPanel(props: CascaderPanelProps) { {...props} checkable={checkable} prefixCls={cascaderPrefixCls} - className={classNames(className, hashId, rootClassName)} + className={classNames(className, hashId, rootClassName, rootCls, cascaderRootCls)} notFoundContent={mergedNotFoundContent} direction={mergedDirection} expandIcon={mergedExpandIcon} diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index 98c3d69b7150..0344e8a36677 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -12,6 +12,7 @@ import RcCascader from 'rc-cascader'; import type { Placement } from 'rc-select/lib/BaseSelect'; import omit from 'rc-util/lib/omit'; +import { useZIndex } from '../_util/hooks/useZIndex'; import type { SelectCommonPlacement } from '../_util/motion'; import { getTransitionName } from '../_util/motion'; import genPurePanel from '../_util/PurePanel'; @@ -21,10 +22,12 @@ import { devUseWarning } from '../_util/warning'; import { ConfigContext } from '../config-provider'; import DefaultRenderEmpty from '../config-provider/defaultRenderEmpty'; import DisabledContext from '../config-provider/DisabledContext'; +import useCSSVarCls from '../config-provider/hooks/useCSSVarCls'; import useSize from '../config-provider/hooks/useSize'; import type { SizeType } from '../config-provider/SizeContext'; import { FormItemInputContext } from '../form/context'; import useSelectStyle from '../select/style'; +import useSelectCSSVar from '../select/style/cssVar'; import useBuiltinPlacements from '../select/useBuiltinPlacements'; import useIcons from '../select/useIcons'; import useShowArrow from '../select/useShowArrow'; @@ -34,7 +37,7 @@ import useCheckable from './hooks/useCheckable'; import useColumnIcons from './hooks/useColumnIcons'; import CascaderPanel from './Panel'; import useStyle from './style'; -import { useZIndex } from '../_util/hooks/useZIndex'; +import useCSSVar from './style/cssVar'; // Align the design since we use `rc-select` in root. This help: // - List search content will show all content @@ -211,8 +214,12 @@ const Cascader = React.forwardRef>((props, ref) const rootPrefixCls = getPrefixCls(); - const [wrapSelectSSR, hashId] = useSelectStyle(prefixCls); - const [wrapCascaderSSR] = useStyle(cascaderPrefixCls); + const [, hashId] = useSelectStyle(prefixCls); + useStyle(cascaderPrefixCls); + const rootCls = useCSSVarCls(prefixCls); + const cascaderRootCls = useCSSVarCls(cascaderPrefixCls); + const wrapSelectCSSVar = useSelectCSSVar(rootCls); + const wrapCascaderCSSVar = useCSSVar(cascaderRootCls); const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction); @@ -229,6 +236,8 @@ const Cascader = React.forwardRef>((props, ref) [`${cascaderPrefixCls}-dropdown-rtl`]: mergedDirection === 'rtl', }, rootClassName, + rootCls, + cascaderRootCls, hashId, ); @@ -310,6 +319,8 @@ const Cascader = React.forwardRef>((props, ref) cascader?.className, className, rootClassName, + rootCls, + cascaderRootCls, hashId, )} disabled={mergedDisabled} @@ -339,7 +350,7 @@ const Cascader = React.forwardRef>((props, ref) /> ); - return wrapCascaderSSR(wrapSelectSSR(renderNode)); + return wrapCascaderCSSVar(wrapSelectCSSVar(renderNode)); }) as unknown as (( props: React.PropsWithChildren> & { ref?: React.Ref }, ) => React.ReactElement) & { diff --git a/components/cascader/style/columns.ts b/components/cascader/style/columns.ts index 32a5310502ce..760b08fa5a06 100644 --- a/components/cascader/style/columns.ts +++ b/components/cascader/style/columns.ts @@ -1,4 +1,4 @@ -import type { CSSInterpolation } from '@ant-design/cssinjs'; +import { unit, type CSSInterpolation } from '@ant-design/cssinjs'; import type { CascaderToken } from '.'; import { getStyle as getCheckboxStyle } from '../../checkbox/style'; @@ -59,7 +59,7 @@ const getColumnsStyle: GenerateStyle = (token: CascaderToken): CS '-ms-overflow-style': '-ms-autohiding-scrollbar', // https://github.com/ant-design/ant-design/issues/11857 '&:not(:last-child)': { - borderInlineEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`, + borderInlineEnd: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`, }, '&-item': { diff --git a/components/cascader/style/cssVar.ts b/components/cascader/style/cssVar.ts new file mode 100644 index 000000000000..0957cc1bdf0f --- /dev/null +++ b/components/cascader/style/cssVar.ts @@ -0,0 +1,4 @@ +import { prepareComponentToken } from '.'; +import { genCSSVarRegister } from '../../theme/internal'; + +export default genCSSVarRegister('Cascader', prepareComponentToken); diff --git a/components/cascader/style/panel.ts b/components/cascader/style/panel.ts index 1e12c8e0f9e0..61b3075228f2 100644 --- a/components/cascader/style/panel.ts +++ b/components/cascader/style/panel.ts @@ -1,4 +1,4 @@ -import type { CSSObject } from '@ant-design/cssinjs'; +import { unit, type CSSObject } from '@ant-design/cssinjs'; import { prepareComponentToken, type CascaderToken } from '.'; import { genComponentStyleHook, type GenerateStyle } from '../../theme/internal'; @@ -13,7 +13,7 @@ const genPanelStyle: GenerateStyle = (token: CascaderToken): CSSO getColumnsStyle(token), { display: 'inline-flex', - border: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`, + border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`, borderRadius: token.borderRadiusLG, overflowX: 'auto', maxWidth: '100%',