Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/bui-core/src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Dialog = React.forwardRef<DialogRef, DialogProps>((props, ref) => {
type,
confirmText,
cancelText,
showCancel = true,
placeholder,
InputProps,
className,
Expand All @@ -40,13 +41,15 @@ const Dialog = React.forwardRef<DialogRef, DialogProps>((props, ref) => {
});
const footerNode = (
<div className={`${prefixCls}-body-footer`}>
<Button
variant="text"
onClick={onClose}
className={`${prefixCls}-body-button`}
>
{cancelText || cancel}
</Button>
{showCancel ? (
<Button
variant="text"
onClick={onClose}
className={`${prefixCls}-body-button`}
>
{cancelText || cancel}
</Button>
) : null}
<Button
variant="text"
color="primary"
Expand Down
4 changes: 4 additions & 0 deletions packages/bui-core/src/Dialog/Dialog.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export interface DialogProps extends ModalProps {
* 取消文本内容
*/
cancelText?: ReactNode;
/**
* 是否展示取消按钮
*/
showCancel?: boolean;
/**
* theme 主题定制
*/
Expand Down
37 changes: 27 additions & 10 deletions packages/bui-core/src/Dialog/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Stack, Button, Dialog, Toast } from '@bifrostui/react';
import React from 'react';

export default () => {
const handleClickConfirm = async () => {
const handleClickConfirm = async (showCancel) => {
const res = await Dialog({
header: '标题',
message: '这是描述内容',
Expand All @@ -47,6 +47,9 @@ export default () => {
confirm
</Button>
<Button onClick={handleClickConfirm}>等待confirm完成</Button>
<Button onClick={() => handleClickConfirm(false)}>
等待confirm完成且不展示取消按钮
</Button>
</Stack>
);
};
Expand All @@ -69,7 +72,7 @@ export default () => {
const theme = useTheme();
const [dialog, contextHolder] = Dialog.useDialog();

const handleClickConfirm = async () => {
const handleClickConfirm = async (showCancel) => {
const res = await dialog({
header: '标题',
message: '这是描述内容',
Expand Down Expand Up @@ -97,6 +100,9 @@ export default () => {
confirm
</Button>
<Button onClick={handleClickConfirm}>等待confirm完成</Button>
<Button onClick={() => handleClickConfirm(false)}>
等待confirm完成且不展示取消按钮
</Button>
</Stack>
</ThemeProvider>
);
Expand Down Expand Up @@ -218,6 +224,16 @@ export default () => {
>
自定义确认按钮文本
</Button>
<Button
onClick={() => {
dialog.confirm({
header: '不展示取消按钮',
showCancel: false,
});
}}
>
不展示取消按钮
</Button>
</Stack>
</ThemeProvider>
);
Expand Down Expand Up @@ -278,14 +294,15 @@ export default () => {

#### DialogOptions

| attribute | explain | type | Default value |
| ----------- | ----------------------- | ----------------------------------------- | ------------- |
| header | custom header | `React.ReactNode` | - |
| message | Custom message | `React.ReactNode` | - |
| confirmText | Confirm button copy | `React.ReactNode` | confirm |
| cancelText | Cancel button text | `React.ReactNode` | cancel |
| onConfirm | Confirm button callback | `(val?: string) => void \|Promise<void>;` | - |
| onCancel | Cancel button callback | `() =>void \|Promise<void>` | - |
| attribute | explain | type | Default value |
| ----------- | ------------------------------------ | ----------------------------------------- | ------------- |
| header | custom header | `React.ReactNode` | - |
| message | Custom message | `React.ReactNode` | - |
| confirmText | Confirm button copy | `React.ReactNode` | confirm |
| cancelText | Cancel button text | `React.ReactNode` | cancel |
| onConfirm | Confirm button callback | `(val?: string) => void \|Promise<void>;` | - |
| onCancel | Cancel button callback | `() =>void \|Promise<void>` | - |
| showCancel | Whether to display the cancel button | boolean | true |

The value of ConfirmOptions is the same as that of DialogOptions

Expand Down
39 changes: 29 additions & 10 deletions packages/bui-core/src/Dialog/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { Stack, Button, Dialog, Toast } from '@bifrostui/react';
import React from 'react';

export default () => {
const handleClickConfirm = async () => {
const handleClickConfirm = async (showCancel) => {
const res = await Dialog({
header: '标题',
message: '这是描述内容',
showCancel,
});
if (res) {
Toast({ message: '点击了确认', position: 'bottom' });
Expand All @@ -47,6 +48,9 @@ export default () => {
confirm
</Button>
<Button onClick={handleClickConfirm}>等待confirm完成</Button>
<Button onClick={() => handleClickConfirm(false)}>
等待confirm完成且不展示取消按钮
</Button>
</Stack>
);
};
Expand All @@ -69,10 +73,11 @@ export default () => {
const theme = useTheme();
const [dialog, contextHolder] = Dialog.useDialog();

const handleClickConfirm = async () => {
const handleClickConfirm = async (showCancel) => {
const res = await dialog({
header: '标题',
message: '这是描述内容',
showCancel,
});
if (res) {
Toast({ message: '点击了确认', position: 'bottom' });
Expand All @@ -97,6 +102,9 @@ export default () => {
confirm
</Button>
<Button onClick={handleClickConfirm}>等待confirm完成</Button>
<Button onClick={() => handleClickConfirm(false)}>
等待confirm完成且不展示取消按钮
</Button>
</Stack>
</ThemeProvider>
);
Expand Down Expand Up @@ -218,6 +226,16 @@ export default () => {
>
自定义确认按钮文本
</Button>
<Button
onClick={() => {
dialog.confirm({
header: '不展示取消按钮',
showCancel: false,
});
}}
>
不展示取消按钮
</Button>
</Stack>
</ThemeProvider>
);
Expand Down Expand Up @@ -278,14 +296,15 @@ export default () => {

#### DialogOptions

| 属性 | 说明 | 类型 | 默认值 |
| ----------- | ------------ | ------------------------------------------ | ------ |
| header | 自定义页头 | `React.ReactNode` | - |
| message | 自定义消息 | `React.ReactNode` | - |
| confirmText | 确认按钮文案 | `React.ReactNode` | 确认 |
| cancelText | 取消按钮文案 | `React.ReactNode` | 取消 |
| onConfirm | 确定按钮回调 | `(val?: string) => void \| Promise<void>;` | - |
| onCancel | 取消按钮回调 | `() =>void \| Promise<void>` | - |
| 属性 | 说明 | 类型 | 默认值 |
| ----------- | ---------------- | ------------------------------------------ | ------ |
| header | 自定义页头 | `React.ReactNode` | - |
| message | 自定义消息 | `React.ReactNode` | - |
| confirmText | 确认按钮文案 | `React.ReactNode` | 确认 |
| cancelText | 取消按钮文案 | `React.ReactNode` | 取消 |
| onConfirm | 确定按钮回调 | `(val?: string) => void \| Promise<void>;` | - |
| onCancel | 取消按钮回调 | `() =>void \| Promise<void>` | - |
| showCancel | 是否展示取消按钮 | boolean | true |

`ConfirmOptions`的取值同`DialogOptions`

Expand Down