Skip to content

Commit

Permalink
Adds maxWidth prop to EuiModal (#1165)
Browse files Browse the repository at this point in the history
* add maxWidth prop to EuiModal

* switch default to true
  • Loading branch information
Ryan Keairns authored Sep 6, 2018
1 parent eff7556 commit d3fb21f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `3.9.0`.
- Added `maxWidth` prop to `EuiModal` ([#1165](https://github.com/elastic/eui/pull/1165))

## [`3.9.0`](https://github.com/elastic/eui/tree/v3.9.0)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Modal extends Component {
<EuiOverlayMask>
<EuiModal
onClose={this.closeModal}
style={{ width: '800px' }}
style={{ width: '400px' }}
>
<EuiModalHeader>
<EuiModalHeaderTitle >
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/modal/modal_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ModalExample = {
props: { EuiConfirmModal },
demo: <ConfirmModal />,
}, {
title: 'Overflow overflow test',
title: 'Overflow test',
source: [{
type: GuideSectionTypes.JS,
code: overflowTestSource,
Expand Down
1 change: 0 additions & 1 deletion src-docs/src/views/modal/overflow_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class OverflowTest extends Component {
<EuiOverlayMask>
<EuiModal
onClose={this.closeModal}
style={{ width: '800px' }}
>
<EuiModalHeader>
<EuiModalHeaderTitle >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`renders EuiConfirmModal 1`] = `
<div>
<div
aria-label="aria-label"
class="euiModal euiModal--confirmation testClass1 testClass2"
class="euiModal euiModal--maxWidth-default euiModal--confirmation testClass1 testClass2"
data-test-subj="test subject string"
tabindex="0"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/__snapshots__/modal.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`renders EuiModal 1`] = `
<div>
<div
aria-label="aria-label"
class="euiModal testClass1 testClass2"
class="euiModal euiModal--maxWidth-default testClass1 testClass2"
data-test-subj="test subject string"
tabindex="0"
>
Expand Down
4 changes: 4 additions & 0 deletions src/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
}
}

.euiModal--maxWidth-default {
max-width: map-get($euiBreakpoints, "m");
}

.euiModal--confirmation {
width: 450px;
min-width: auto;
Expand Down
30 changes: 29 additions & 1 deletion src/components/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ export class EuiModal extends Component {
className,
children,
onClose, // eslint-disable-line no-unused-vars
maxWidth,
style,
...rest
} = this.props;

const classes = classnames('euiModal', className);
let newStyle;
let widthClassName;
if (maxWidth === true) {
widthClassName = 'euiModal--maxWidth-default';
} else if (maxWidth !== false) {
const value = typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth;
newStyle = { ...style, maxWidth: value };
}

const classes = classnames('euiModal', widthClassName, className);

return (
<FocusTrap
Expand All @@ -43,6 +54,7 @@ export class EuiModal extends Component {
className={classes}
onKeyDown={this.onKeyDown}
tabIndex={0}
style={newStyle || style}
{...rest}
>
<EuiButtonIcon
Expand All @@ -65,4 +77,20 @@ EuiModal.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
onClose: PropTypes.func.isRequired,
/**
* Sets the max-width of the modal.
* Set to `true` to use the default (`euiBreakpoints 'm'`),
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
maxWidth: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number,
PropTypes.string,
]),
};

EuiModal.defaultProps = {
maxWidth: true,
};

0 comments on commit d3fb21f

Please sign in to comment.