Skip to content

Commit

Permalink
refactor: popconfirm support css var (ant-design#45840)
Browse files Browse the repository at this point in the history
* refactor: popconfirm support css var

* Apply suggestions from code review

Signed-off-by: MadCcc <[email protected]>

* Apply suggestions from code review

Signed-off-by: MadCcc <[email protected]>

* fix: 补充遗漏的useStyle

---------

Signed-off-by: MadCcc <[email protected]>
Signed-off-by: MadCcc <[email protected]>
Co-authored-by: MadCcc <[email protected]>
Co-authored-by: MadCcc <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2023
1 parent 5224c05 commit 308d7ca
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
6 changes: 4 additions & 2 deletions components/popconfirm/PurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useLocale } from '../locale';
import defaultLocale from '../locale/en_US';
import PopoverPurePanel from '../popover/PurePanel';
import useStyle from './style';
import useCSSVar from './style/cssVar';

export interface PopconfirmLocale {
okText: string;
Expand Down Expand Up @@ -108,9 +109,10 @@ const PurePanel: React.FC<PurePanelProps> = (props) => {

const { getPrefixCls } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('popconfirm', customizePrefixCls);
const [wrapSSR] = useStyle(prefixCls);
useStyle(prefixCls);
const wrapCSSVar = useCSSVar(prefixCls);

return wrapSSR(
return wrapCSSVar(
<PopoverPurePanel
placement={placement}
className={classNames(prefixCls, className)}
Expand Down
6 changes: 4 additions & 2 deletions components/popconfirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Popover from '../popover';
import type { AbstractTooltipProps, TooltipRef } from '../tooltip';
import PurePanel, { Overlay } from './PurePanel';
import usePopconfirmStyle from './style';
import useCSSVar from './style/cssVar';

export interface PopconfirmProps extends AbstractTooltipProps {
title: React.ReactNode | RenderFunction;
Expand Down Expand Up @@ -95,9 +96,10 @@ const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) =>
const prefixCls = getPrefixCls('popconfirm', customizePrefixCls);
const overlayClassNames = classNames(prefixCls, overlayClassName);

const [wrapSSR] = usePopconfirmStyle(prefixCls);
usePopconfirmStyle(prefixCls);
const wrapCSSVar = useCSSVar(prefixCls);

return wrapSSR(
return wrapCSSVar(
<Popover
{...omit(restProps, ['title'])}
trigger={trigger}
Expand Down
4 changes: 4 additions & 0 deletions components/popconfirm/style/cssVar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { genCSSVarRegister } from '../../theme/internal';
import { prepareComponentToken } from '.';

export default genCSSVarRegister('Popconfirm', prepareComponentToken);
18 changes: 10 additions & 8 deletions components/popconfirm/style/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FullToken, GenerateStyle } from '../../theme/internal';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';

export interface ComponentToken {
Expand Down Expand Up @@ -76,16 +76,18 @@ const genBaseStyle: GenerateStyle<PopconfirmToken> = (token) => {
};

// ============================== Export ==============================
export const prepareComponentToken: GetDefaultToken<'Popconfirm'> = (token) => {
const { zIndexPopupBase } = token;

return {
zIndexPopup: zIndexPopupBase + 60,
};
};

export default genComponentStyleHook(
'Popconfirm',
(token) => genBaseStyle(token),
(token) => {
const { zIndexPopupBase } = token;

return {
zIndexPopup: zIndexPopupBase + 60,
};
},
prepareComponentToken,
{
resetStyle: false,
},
Expand Down
1 change: 0 additions & 1 deletion scripts/check-cssinjs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function checkCSSVar() {
'message',
'notification',
'pagination',
'popconfirm',
'progress',
'qr-code',
'radio',
Expand Down

0 comments on commit 308d7ca

Please sign in to comment.