xref: /MusicFree/src/components/dialogs/components/simpleDialog.tsx (revision 4da0658b1bf77de935d6a60ad1a26e4b92d13606)
1import React from 'react';
2import {hideDialog} from '../useDialog';
3import Dialog from './base';
4
5interface ISimpleDialogProps {
6    title: string;
7    content: string | JSX.Element;
8    okText?: string;
9    cancelText?: string;
10    onOk?: () => void;
11}
12export default function SimpleDialog(props: ISimpleDialogProps) {
13    const {title, content, onOk, okText, cancelText} = props;
14
15    const actions = onOk
16        ? [
17              {
18                  title: cancelText ?? '取消',
19                  type: 'normal',
20                  onPress: hideDialog,
21              },
22              {
23                  title: okText ?? '确认',
24                  type: 'primary',
25                  onPress() {
26                      onOk?.();
27                      hideDialog();
28                  },
29              },
30          ]
31        : ([
32              {
33                  title: okText ?? '我知道了',
34                  type: 'primary',
35                  onPress() {
36                      hideDialog();
37                  },
38              },
39          ] as any);
40
41    return (
42        <Dialog onDismiss={hideDialog}>
43            <Dialog.Title withDivider>{title}</Dialog.Title>
44            <Dialog.Content needScroll>{content}</Dialog.Content>
45            <Dialog.Actions actions={actions} />
46        </Dialog>
47    );
48}
49