-
Notifications
You must be signed in to change notification settings - Fork 72
/
ShowPopupDemo.tsx
82 lines (80 loc) · 1.83 KB
/
ShowPopupDemo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Button, Form, Input, Typography } from 'antd';
import { FC, useState } from 'react';
import {
ShowPopupParams,
useShowPopup,
} from '@vkruglikov/react-telegram-web-app';
const ShowPopupDemo: FC = () => {
const showPopup = useShowPopup();
const [popupState, setPopupState] = useState<
Pick<ShowPopupParams, 'title' | 'message'>
>({
title: 'title',
message: 'message',
});
const onFinish = (values: any) => {
setPopupState(values);
showPopup({
...values,
buttons: [
{
type: 'ok',
},
{
type: 'close',
},
{
type: 'destructive',
text: 'destructive',
},
],
}).catch(e => {
showPopup({
title: 'error',
message: e,
});
});
};
return (
<>
<Typography.Title level={3}>useShowPopup</Typography.Title>
<Form
labelCol={{ span: 6 }}
name="ShowPopupDemo"
layout="horizontal"
initialValues={popupState}
onFinish={onFinish}
autoComplete="off"
>
<Form.Item label="title" name="title">
<Input />
</Form.Item>
<Form.Item label="message" name="message">
<Input />
</Form.Item>
<Form.Item label="buttons" name="buttons">
<Typography.Text>
{JSON.stringify([
{
type: 'ok',
},
{
type: 'close',
},
{
type: 'destructive',
text: 'destructive',
},
])}
</Typography.Text>
</Form.Item>
<Form.Item>
<Button block type="primary" htmlType="submit">
Show popup
</Button>
</Form.Item>
</Form>
</>
);
};
export default ShowPopupDemo;