Skip to content

Commit

Permalink
Fixing EuiPageContent layout (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos authored Jul 18, 2018
1 parent a539e49 commit f2312b5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `3.0.1`.
- Added `restrictWidth` option to `EuiPageBody` ([#1024](https://github.com/elastic/eui/pull/1024))

**Bug fixes**

- Fixed `EuiPageContent` centered layouts ([#1024](https://github.com/elastic/eui/pull/1024))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiPageBody is rendered 1`] = `
<div
aria-label="aria-label"
class="euiPageBody testClass1 testClass2"
class="euiPageBody euiPage--widthIsNotRestricted testClass1 testClass2"
data-test-subj="test subject string"
/>
`;
10 changes: 10 additions & 0 deletions src/components/page/page_body/_page_body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
flex-direction: column;
align-items: stretch;
flex: 1 1 0%;

&--restrictWidth-default,
&--restrictWidth-custom {
margin-left: auto;
margin-right: auto;
}

&--restrictWidth-default {
max-width: 1000px;
}
}

39 changes: 37 additions & 2 deletions src/components/page/page_body/page_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

export const EuiPageBody = ({ children, className, ...rest }) => {
const classes = classNames('euiPageBody', className);
export const EuiPageBody = ({ children, restrictWidth, style, className, ...rest }) => {

let widthClassname;
if (restrictWidth === true) {
widthClassname = 'euiPage--restrictWidth-default';
} else if (restrictWidth === false) {
widthClassname = 'euiPage--widthIsNotRestricted';
} else {
widthClassname = 'euiPage--restrictWidth-custom';

// if style has been passed as a prop, add to it
if (style) {
style.maxWidth = `${restrictWidth}px`;
}
// otherwise create a new object
else {
style = { maxWidth: `${restrictWidth}px` };
}
}

const classes = classNames('euiPageBody', widthClassname, className);

return (
<div
className={classes}
style={style}
{...rest}
>
{children}
Expand All @@ -18,4 +38,19 @@ export const EuiPageBody = ({ children, className, ...rest }) => {
EuiPageBody.propTypes = {
children: PropTypes.node,
className: PropTypes.string,

/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width.
*/
restrictWidth: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number
]),
};

EuiPageBody.defaultProps = {
restrictWidth: false,
};
11 changes: 8 additions & 3 deletions src/components/page/page_content/_page_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@

&.euiPageContent--verticalCenter {
align-self: center;
margin-top: auto;
margin-bottom: auto;
flex-grow: 0;
}

&.euiPageContent--horizontalCenter {
width: auto;
max-width: 100%; // Fixes IE
margin: auto;
margin-left: auto;
margin-right: auto;
flex-grow: 0; // Offsets the properties of .euiPanel within flexboxes
}

/** TEMPORARILY REMOVING
// At small screens, the content extends edge to edge, so remove the side borders and shadow
@include euiBreakpoint('xs', 's') {
&.euiPanel:not(.euiPageContent--horizontalCenter) { // Override panel styles without the need for !important
// Temporarily removing
.euiPanel:not(.euiPageContent--horizontalCenter) { // Override panel styles without the need for !important
// border-radius: 0;
// border-left: none;
// border-right: none;
// box-shadow: none;
}
}
**/
}

0 comments on commit f2312b5

Please sign in to comment.