Skip to content

Commit 09c8190

Browse files
committed
Add dialogStyle and contentStyle props to Modal
1 parent 4f4c74c commit 09c8190

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/components/modal/Modal.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const Modal = props => {
3232
style,
3333
zindex,
3434
zIndex,
35+
dialogStyle,
36+
dialog_style,
37+
contentStyle,
38+
content_style,
3539
...otherProps
3640
} = props;
3741

@@ -45,6 +49,8 @@ const Modal = props => {
4549
<RBModal
4650
animation={fade}
4751
dialogAs={tag}
52+
dialogStyle={dialog_style || dialogStyle}
53+
contentStyle={content_style || contentStyle}
4854
dialogClassName={class_name || className}
4955
className={modal_class_name || modalClassName}
5056
contentClassName={content_class_name || contentClassName}
@@ -87,6 +93,26 @@ Modal.propTypes = {
8793
*/
8894
style: PropTypes.object,
8995

96+
/**
97+
* Inline CSS styles to apply to the dialog
98+
*/
99+
dialog_style: PropTypes.object,
100+
101+
/**
102+
* Inline CSS styles to apply to the dialog
103+
*/
104+
dialogStyle: PropTypes.object,
105+
106+
/**
107+
* Inline CSS styles to apply to the content
108+
*/
109+
content_style: PropTypes.object,
110+
111+
/**
112+
* Inline CSS styles to apply to the content
113+
*/
114+
contentStyle: PropTypes.object,
115+
90116
/**
91117
* Often used with CSS to style elements with common properties.
92118
*/

src/private/Modal.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import BaseModal from '@restart/ui/Modal';
1818
import {getSharedManager} from 'react-bootstrap/BootstrapModalManager';
1919
import Fade from 'react-bootstrap/Fade';
2020
import ModalContext from 'react-bootstrap/ModalContext';
21-
import ModalDialog from 'react-bootstrap/ModalDialog';
2221
import {useBootstrapPrefix, useIsRTL} from 'react-bootstrap/ThemeProvider';
2322

23+
import ModalDialog from './ModalDialog';
24+
2425
const defaultProps = {
2526
show: false,
2627
backdrop: true,
@@ -51,6 +52,8 @@ const Modal = React.forwardRef(
5152
dialogClassName,
5253
contentClassName,
5354
children,
55+
dialogStyle,
56+
contentStyle,
5457
dialogAs: Dialog,
5558
'data-bs-theme': dataBsTheme,
5659
'aria-labelledby': ariaLabelledby,
@@ -271,6 +274,8 @@ const Modal = React.forwardRef(
271274
onMouseDown={handleDialogMouseDown}
272275
className={dialogClassName}
273276
contentClassName={contentClassName}
277+
style={dialogStyle}
278+
contentStyle={contentStyle}
274279
>
275280
{children}
276281
</Dialog>

src/private/ModalDialog.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// vendored from React-Bootstrap to allow us to set content style
2+
// https://github.com/react-bootstrap/react-bootstrap/blob/be23c304fa40ddb209919b0faac1e5dd8cef53ad/src/ModalDialog.tsx
3+
import React from 'react';
4+
5+
import classNames from 'classnames';
6+
import {useBootstrapPrefix} from 'react-bootstrap/ThemeProvider';
7+
8+
const ModalDialog = React.forwardRef(
9+
(
10+
{
11+
bsPrefix,
12+
className,
13+
contentClassName,
14+
centered,
15+
size,
16+
fullscreen,
17+
children,
18+
scrollable,
19+
contentStyle,
20+
...props
21+
},
22+
ref
23+
) => {
24+
bsPrefix = useBootstrapPrefix(bsPrefix, 'modal');
25+
const dialogClass = `${bsPrefix}-dialog`;
26+
27+
const fullScreenClass =
28+
typeof fullscreen === 'string'
29+
? `${bsPrefix}-fullscreen-${fullscreen}`
30+
: `${bsPrefix}-fullscreen`;
31+
32+
return (
33+
<div
34+
{...props}
35+
ref={ref}
36+
className={classNames(
37+
dialogClass,
38+
className,
39+
size && `${bsPrefix}-${size}`,
40+
centered && `${dialogClass}-centered`,
41+
scrollable && `${dialogClass}-scrollable`,
42+
fullscreen && fullScreenClass
43+
)}
44+
>
45+
<div
46+
className={classNames(`${bsPrefix}-content`, contentClassName)}
47+
style={contentStyle}
48+
>
49+
{children}
50+
</div>
51+
</div>
52+
);
53+
}
54+
);
55+
56+
export default ModalDialog;

0 commit comments

Comments
 (0)