This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathModal.tsx
171 lines (165 loc) · 4.19 KB
/
Modal.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* eslint react/prop-types: 0 */
import { ReactNode, CSSProperties } from 'react'
import BootstrapModal from 'react-bootstrap/Modal'
import { Button, ButtonProps } from '../Button'
import { ButtonsAlignment } from './interfaces'
interface Props {
/** Defines if the modal should be visible. */
show: boolean
/** Toggles the modal visibility. */
toggle(): void
/** Defines the title of the modal. */
title?: string
/** Defines the body of the modal. */
body?: ReactNode
/**
* Renders a close button in modal header.
* @default true
* */
showHeaderCloseButton?: boolean
/**
* Defines if the modal should be vertically centered.
* @default false
* */
verticallyCentered?: boolean
/**
* Defines the buttons alignment.
* @default "edges"
* */
buttonsAlignment?: ButtonsAlignment
/**
* Optional close button properties.
* */
closeButton?: ButtonProps
/**
* Optional middle button properties.
* */
middleButton?: ButtonProps
/**
* Optional success button properties.
* */
successButton?: ButtonProps
/**
* Styling through CSS classes
*/
className?: string
/**
* Styilng through inline CSSProperties
*/
style?: CSSProperties
/**
* Include a backdrop component. Specify 'static' for a backdrop that doesn't trigger an "onHide" when clicked. Default = true
*/
backdrop?: true | false | 'static'
/**
* Callback fired before the Modal transitions in
* @param node
*/
onEnter?(node: HTMLElement): any
/**
* Callback fired after the Modal finishes transitioning in
* @param node
*/
onEntered?(node: HTMLElement): any
/**
* Callback fired as the Modal begins to transition in
* @param node
*/
onEntering?(node: HTMLElement): any
/**
* Callback fired right before the Modal transitions out
* @param node
*/
onExit?(node: HTMLElement): any
/**
* Callback fired after the Modal finishes transitioning out
* @param node
*/
onExited?(node: HTMLElement): any
/**
* Callback fired as the Modal begins to transition out
* @param node
*/
onExiting?(node: HTMLElement): any
}
/**
* Add dialogs for lightboxes, user notifications, or completely custom content.
*/
const Modal = (props: Props) => {
const {
show,
toggle,
title,
body,
verticallyCentered,
buttonsAlignment,
showHeaderCloseButton,
closeButton,
middleButton,
successButton,
className,
style,
backdrop,
onEnter,
onEntered,
onEntering,
onExit,
onExited,
onExiting,
} = props
return (
<BootstrapModal
dialogClassName={className}
show={show}
style={style}
autoFocus
centered={verticallyCentered}
keyboard
restoreFocus
onHide={() => toggle()}
backdrop={backdrop || true}
onEnter={onEnter}
onEntered={onEntered}
onEntering={onEntering}
onExit={onExit}
onExited={onExited}
onExiting={onExiting}
>
{(showHeaderCloseButton === false ? title : true) && (
<BootstrapModal.Header closeButton={showHeaderCloseButton !== false}>
{title && <BootstrapModal.Title>{title}</BootstrapModal.Title>}
</BootstrapModal.Header>
)}
{body && <BootstrapModal.Body>{body}</BootstrapModal.Body>}
<BootstrapModal.Footer
style={{
justifyContent:
buttonsAlignment === 'left'
? 'flex-start'
: buttonsAlignment === 'right'
? 'flex-end'
: buttonsAlignment === 'center'
? 'center'
: 'space-between',
}}
>
{closeButton && (
<Button {...closeButton} color={closeButton.color || 'secondary'}>
{closeButton.children || 'Close'}
</Button>
)}
{middleButton && (
<Button {...middleButton} color={middleButton.color || 'info'}>
{middleButton.children || 'Retry'}
</Button>
)}
{successButton && (
<Button {...successButton} color={successButton.color || 'primary'}>
{successButton.children || 'Confirm'}
</Button>
)}
</BootstrapModal.Footer>
</BootstrapModal>
)
}
export { Modal }