-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathbasic_usage.tsx
More file actions
75 lines (68 loc) · 1.86 KB
/
Copy pathbasic_usage.tsx
File metadata and controls
75 lines (68 loc) · 1.86 KB
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
import Button from '@semcore/ui/button';
import Modal from '@semcore/ui/modal';
import type { NSModal } from '@semcore/ui/modal';
import { Text } from '@semcore/ui/typography';
import React from 'react';
type BasicModalProps = NSModal.Props & {
title?: string;
content?: string;
showCloseButton?: boolean;
};
const Demo = (props: BasicModalProps) => {
const {
title = 'Modal Title',
content = 'Modal content goes here',
showCloseButton = true,
duration = 200,
closable = true,
disablePreventScroll = false,
ghost = false,
w,
locale,
...restProps
} = props;
const [visible, setVisible] = React.useState(false);
const handleOpen = React.useCallback(() => setVisible(true), []);
const handleClose = React.useCallback(() => setVisible(false), []);
const modalTabIndex = !closable && !showCloseButton ? 0 : undefined;
return (
<React.Fragment>
<Button onClick={handleOpen}>Open modal</Button>
<Modal
visible={visible}
onClose={handleClose}
duration={duration}
closable={closable}
disablePreventScroll={disablePreventScroll}
ghost={ghost}
w={w}
locale={locale}
tabIndex={modalTabIndex}
{...restProps}
>
<Modal.Title>{title}</Modal.Title>
<Text size={200} mb={4} tag='p'>
{content}
</Text>
{showCloseButton && (
<Button use='primary' theme='success' size='l' onClick={handleClose}>
Close
</Button>
)}
</Modal>
</React.Fragment>
);
};
export const defaultProps: BasicModalProps = {
title: 'Modal Title',
content: 'Modal content goes here',
showCloseButton: true,
duration: 200,
closable: true,
disablePreventScroll: false,
ghost: false,
w: undefined,
locale: undefined,
};
Demo.defaultProps = defaultProps;
export default Demo;