Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(popconfirm): make title bold and add description prop #39250

Merged
merged 8 commits into from Dec 8, 2022
11 changes: 10 additions & 1 deletion components/popconfirm/PurePanel.tsx
Expand Up @@ -29,6 +29,7 @@ export interface OverlayProps
| 'okType'
| 'showCancel'
| 'title'
| 'description'
> {
prefixCls: string;
close?: Function;
Expand All @@ -42,6 +43,7 @@ export const Overlay: React.FC<OverlayProps> = (props) => {
okButtonProps,
cancelButtonProps,
title,
description,
cancelText,
okText,
okType = 'primary',
Expand All @@ -60,8 +62,15 @@ export const Overlay: React.FC<OverlayProps> = (props) => {
<div className={`${prefixCls}-inner-content`}>
<div className={`${prefixCls}-message`}>
{icon && <span className={`${prefixCls}-message-icon`}>{icon}</span>}
<div className={`${prefixCls}-message-title`}>{getRenderPropValue(title)}</div>
<div
className={classNames(`${prefixCls}-message-title`, {
[`${prefixCls}-message-title-only`]: !!description,
})}
>
{getRenderPropValue(title)}
</div>
</div>
<div className={`${prefixCls}-description`}>{getRenderPropValue(description)}</div>
<div className={`${prefixCls}-buttons`}>
{showCancel && (
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
Expand Down
1 change: 1 addition & 0 deletions components/popconfirm/demo/async.tsx
Expand Up @@ -26,6 +26,7 @@ const App: React.FC = () => {
return (
<Popconfirm
title="Title"
description="Open Popconfirm with async logic"
open={open}
onConfirm={handleOk}
okButtonProps={{ loading: confirmLoading }}
Expand Down
3 changes: 2 additions & 1 deletion components/popconfirm/demo/basic.tsx
Expand Up @@ -13,7 +13,8 @@ const cancel = (e: React.MouseEvent<HTMLElement>) => {

const App: React.FC = () => (
<Popconfirm
title="Are you sure to delete this task?"
title="删除任务"
description="Are you sure to delete this task?"
onConfirm={confirm}
onCancel={cancel}
okText="Yes"
Expand Down
3 changes: 2 additions & 1 deletion components/popconfirm/demo/dynamic-trigger.tsx
Expand Up @@ -36,7 +36,8 @@ const App: React.FC = () => {
return (
<div>
<Popconfirm
title="Are you sure delete this task?"
title="删除任务"
xhh0223 marked this conversation as resolved.
Show resolved Hide resolved
description="Are you sure delete this task?"
open={open}
onOpenChange={handleOpenChange}
onConfirm={confirm}
Expand Down
6 changes: 5 additions & 1 deletion components/popconfirm/demo/icon.tsx
Expand Up @@ -3,7 +3,11 @@ import { QuestionCircleOutlined } from '@ant-design/icons';
import { Popconfirm } from 'antd';

const App: React.FC = () => (
<Popconfirm title="Are you sure?" icon={<QuestionCircleOutlined style={{ color: 'red' }} />}>
<Popconfirm
title="删除任务"
description="Are you sure?"
icon={<QuestionCircleOutlined style={{ color: 'red' }} />}
>
<a href="#">Delete</a>
</Popconfirm>
);
Expand Down
2 changes: 1 addition & 1 deletion components/popconfirm/demo/locale.tsx
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Popconfirm } from 'antd';

const App: React.FC = () => (
<Popconfirm title="Are you sure?" okText="Yes" cancelText="No">
<Popconfirm title="删除任务" description="Are you sure?" okText="Yes" cancelText="No">
<a href="#">Delete</a>
</Popconfirm>
);
Expand Down
61 changes: 55 additions & 6 deletions components/popconfirm/demo/placement.tsx
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Button, message, Popconfirm } from 'antd';

const text = 'Are you sure to delete this task?';
const description = '删除任务';

const confirm = () => {
message.info('Clicked on Yes.');
Expand All @@ -10,15 +11,30 @@ const confirm = () => {
const App: React.FC = () => (
<div className="demo">
<div style={{ marginLeft: 70, whiteSpace: 'nowrap' }}>
<Popconfirm placement="topLeft" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="topLeft"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>TL</Button>
</Popconfirm>
<Popconfirm placement="top" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="top"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>Top</Button>
</Popconfirm>
<Popconfirm
placement="topRight"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
Expand All @@ -27,15 +43,30 @@ const App: React.FC = () => (
</Popconfirm>
</div>
<div style={{ width: 70, float: 'left' }}>
<Popconfirm placement="leftTop" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="leftTop"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>LT</Button>
</Popconfirm>
<Popconfirm placement="left" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="left"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>Left</Button>
</Popconfirm>
<Popconfirm
placement="leftBottom"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
Expand All @@ -47,18 +78,27 @@ const App: React.FC = () => (
<Popconfirm
placement="rightTop"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>RT</Button>
</Popconfirm>
<Popconfirm placement="right" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="right"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>Right</Button>
</Popconfirm>
<Popconfirm
placement="rightBottom"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
Expand All @@ -70,18 +110,27 @@ const App: React.FC = () => (
<Popconfirm
placement="bottomLeft"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>BL</Button>
</Popconfirm>
<Popconfirm placement="bottom" title={text} onConfirm={confirm} okText="Yes" cancelText="No">
<Popconfirm
placement="bottom"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
>
<Button>Bottom</Button>
</Popconfirm>
<Popconfirm
placement="bottomRight"
title={text}
description={description}
onConfirm={confirm}
okText="Yes"
cancelText="No"
Expand Down
7 changes: 6 additions & 1 deletion components/popconfirm/demo/promise.tsx
Expand Up @@ -8,7 +8,12 @@ const App: React.FC = () => {
});

return (
<Popconfirm title="Title" onConfirm={confirm} onOpenChange={() => console.log('open change')}>
<Popconfirm
title="Title"
description="Open Popconfirm with Promise"
onConfirm={confirm}
onOpenChange={() => console.log('open change')}
>
<Button type="primary">Open Popconfirm with Promise</Button>
</Popconfirm>
);
Expand Down
9 changes: 7 additions & 2 deletions components/popconfirm/demo/render-panel.tsx
Expand Up @@ -5,8 +5,13 @@ const { _InternalPanelDoNotUseOrYouWillBeFired: InternalPopconfirm } = Popconfir

const App: React.FC = () => (
<>
<InternalPopconfirm title="Are you OK?" />
<InternalPopconfirm title="Are you OK?" placement="bottomRight" style={{ width: 250 }} />
<InternalPopconfirm title="你还好吗" description="Are you OK?" />
<InternalPopconfirm
title="你还好吗"
description="Are you OK?"
placement="bottomRight"
style={{ width: 250 }}
/>
</>
);

Expand Down
1 change: 1 addition & 0 deletions components/popconfirm/index.en-US.md
Expand Up @@ -40,6 +40,7 @@ The difference with the `confirm` modal dialog is that it's more lightweight tha
| okType | Button `type` of the Confirm button | string | `primary` | |
| showCancel | Show cancel button | boolean | true | 4.18.0 |
| title | The title of the confirmation box | ReactNode \| () => ReactNode | - | |
| title | The description of the confirmation box title | ReactNode \| () => ReactNode | - | |
| onCancel | A callback of cancel | function(e) | - | |
| onConfirm | A callback of confirmation | function(e) | - | |

Expand Down
1 change: 1 addition & 0 deletions components/popconfirm/index.tsx
Expand Up @@ -15,6 +15,7 @@ import usePopconfirmStyle from './style';

export interface PopconfirmProps extends AbstractTooltipProps {
title: React.ReactNode | RenderFunction;
description?: React.ReactNode | RenderFunction;
disabled?: boolean;
onConfirm?: (e?: React.MouseEvent<HTMLElement>) => void;
onCancel?: (e?: React.MouseEvent<HTMLElement>) => void;
Expand Down
1 change: 1 addition & 0 deletions components/popconfirm/index.zh-CN.md
Expand Up @@ -41,6 +41,7 @@ demo:
| okType | 确认按钮类型 | string | `primary` | |
| showCancel | 是否显示取消按钮 | boolean | true | 4.18.0 |
| title | 确认框的描述 | ReactNode \| () => ReactNode | - | |
xhh0223 marked this conversation as resolved.
Show resolved Hide resolved
| description | 对确认框标题的描述 | ReactNode \| () => ReactNode | - | |
xhh0223 marked this conversation as resolved.
Show resolved Hide resolved
| onCancel | 点击取消的回调 | function(e) | - | |
| onConfirm | 点击确认的回调 | function(e) | - | |

Expand Down
13 changes: 13 additions & 0 deletions components/popconfirm/style/index.tsx
Expand Up @@ -17,6 +17,7 @@ const genBaseStyle: GenerateStyle<PopconfirmToken> = (token) => {
colorWarning,
marginXS,
fontSize,
fontWeightStrong,
lineHeight,
} = token;

Expand Down Expand Up @@ -49,6 +50,18 @@ const genBaseStyle: GenerateStyle<PopconfirmToken> = (token) => {
flex: 'auto',
marginInlineStart: marginXS,
},

'&-title-only': {
fontWeight: fontWeightStrong,
},
},

[`${componentCls}-description`]: {
position: 'relative',
marginInlineStart: fontSize + marginXS,
marginBottom: marginXS,
color: colorText,
fontSize,
},

[`${componentCls}-buttons`]: {
Expand Down