Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added restrictWidth to EuiPage #896

Merged
merged 5 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src-docs/src/components/guide_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
background: linear-gradient(90deg, $euiColorLightestShade 50%, $euiColorEmptyShade 50%);
}

#guide {
margin: auto;
max-width: 1240px;
}

.guidePage {
padding: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/app_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class AppView extends Component {
const { navigation } = routes;

return (
<EuiPage className="guidePage">
<EuiPage restrictWidth="1240" className="guidePage">
<EuiPageBody>
<EuiErrorBoundary>
<GuidePageChrome
Expand Down
11 changes: 10 additions & 1 deletion src/components/page/__snapshots__/page.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
exports[`EuiPage is rendered 1`] = `
<div
aria-label="aria-label"
class="euiPage testClass1 testClass2"
class="euiPage euiPage--restrictWidth-default testClass1 testClass2"
data-test-subj="test subject string"
/>
`;

exports[`EuiPage sets a max-width 1`] = `
<div
aria-label="aria-label"
class="euiPage euiPage--restrictWidth-custom testClass1 testClass2"
data-test-subj="test subject string"
style="max-width:1024px"
/>
`;
11 changes: 11 additions & 0 deletions src/components/page/_page.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
.euiPage {
padding: $euiSize;
background-color: $euiColorLightestShade;

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

&--restrictWidth-default {
max-width: 1000px;
}
}
40 changes: 38 additions & 2 deletions src/components/page/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

export const EuiPage = ({ children, className, ...rest }) => {
const classes = classNames('euiPage', className);
export const EuiPage = ({ children, className, restrictWidth, style, ...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(
'euiPage',
widthClassname,
className,
);

return (
<div
className={classes}
style={style}
{...rest}
>
{children}
Expand All @@ -18,4 +42,16 @@ export const EuiPage = ({ children, className, ...rest }) => {
EuiPage.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.any,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chandlerprall I'm not sure if this is particularly correct, but we want to accept either a bool or string, maybe a custom prop type, but that seemed excessive...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also do this to be a little more specific

restrictWidth: PropTypes.oneOfType([
  PropTypes.bool,
  PropTypes.number
]),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh perfect, I'll do that.

};

EuiPage.defaultProps = {
restrictWidth: true,
}
9 changes: 9 additions & 0 deletions src/components/page/page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ describe('EuiPage', () => {
expect(component)
.toMatchSnapshot();
});

test('sets a max-width', () => {
const component = render(
<EuiPage {...requiredProps} restrictWidth="1024" />
);

expect(component)
.toMatchSnapshot();
});
});