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

Responsive refactors and addition of helpers #909

Merged
merged 12 commits into from
Jun 8, 2018
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- Added multiple style-only adjustments to `EuiFormControlLayout` buttons/icons ([#894](https://github.com/elastic/eui/pull/894))
- Shifted `readOnly` inputs to not have left padding unless it has an icon ([#894](https://github.com/elastic/eui/pull/894))
- Added more customization options to `EuiAvatar` ([#903](https://github.com/elastic/eui/pull/903))
- Added responsive helpers in the form of `EuiShowFor` and `EuiHideFor` components and corresponding CSS classes. ([#909](https://github.com/elastic/eui/pull/909))

**Deprecations**

- Replaced `$breakpoints` in favor of better named `$euiBreakpoints` ([#909](https://github.com/elastic/eui/pull/909))
- Replaced the following mixin `screenXSmall()`, `screenSmall()`, `screenMedium()`, `screenLarge()`, `screenSmallMediumLarge()` in favor of a single `euiBreakpoint()`. ([#909](https://github.com/elastic/eui/pull/909))

**Bug fixes**

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/components/guide_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
@import "guide_section/index";
@import "guide_rule/index";

@include screenXSmall {
@include euiBreakpoint('xs','s') {

.guideBody {
background: none;
Expand Down
4 changes: 4 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ import { PortalExample }
import { ProgressExample }
from './views/progress/progress_example';

import { ResponsiveExample }
from './views/responsive/responsive_example';

import { SearchBarExample }
from './views/search_bar/search_bar_example';

Expand Down Expand Up @@ -341,6 +344,7 @@ const navigation = [{
name: 'Utilities',
items: [
AccessibilityExample,
ResponsiveExample,
DelayHideExample,
ErrorBoundaryExample,
HighlightExample,
Expand Down
46 changes: 46 additions & 0 deletions src-docs/src/views/responsive/responsive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';

import {
EuiCode,
EuiHideFor,
EuiShowFor,
} from '../../../../src/components';

export default () => (
<div>
<EuiHideFor sizes={['xs']}>
Hiding from <EuiCode>xs</EuiCode> screens only
</EuiHideFor>
<br/>
<EuiHideFor sizes={['xs','s']}>
Hiding from <EuiCode>xs, s</EuiCode> screens
</EuiHideFor>
<br/>
<EuiHideFor sizes={['xs','s','m', 'l']}>
Hiding from <EuiCode>xs, s, m, l</EuiCode> screens
</EuiHideFor>
<br/>
<EuiHideFor sizes={['xl']}>
Hiding from <EuiCode>xl</EuiCode> screens only
</EuiHideFor>

<br/>
<br/>

<EuiShowFor sizes={['xs']}>
Showing for <EuiCode>xs</EuiCode> screens only
</EuiShowFor>
<br/>
<EuiShowFor sizes={['xs','s']}>
Showing for <EuiCode>xs, s</EuiCode> screens
</EuiShowFor>
<br/>
<EuiShowFor sizes={['xs','s','m', 'l']}>
Showing for <EuiCode>xs, s, m, l</EuiCode> screens
</EuiShowFor>
<br/>
<EuiShowFor sizes={['xl']}>
Showing for <EuiCode>xl</EuiCode> screen only
</EuiShowFor>
</div>
);
68 changes: 68 additions & 0 deletions src-docs/src/views/responsive/responsive_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';

import { renderToHtml } from '../../services';
import sizes from '!!sass-vars-to-js-loader!../../../../src/global_styling/variables/_responsive.scss';

import {
GuideSectionTypes,
} from '../../components';

import {
EuiCode,
EuiShowFor,
EuiHideFor,
EuiCodeBlock,
} from '../../../../src/components';

import Responsive from './responsive';
const responsiveSource = require('!!raw-loader!./responsive');
const responsiveHtml = renderToHtml(Responsive);

function renderSizes(size, index) {
let code = `'${size}': ${sizes.euiBreakpoints[size]}px`;

if (index < sizes.euiBreakpointKeys.length - 1) {
code += ` - ${(sizes.euiBreakpoints[sizes.euiBreakpointKeys[index+1]] - 1)}px`;
} else {
code += ` +`;
}

return (
<div key={index}>
{code}
</div>
)
}

export const ResponsiveExample = {
title: 'Responsive',
sections: [{
title: 'EuiShowFor and EuiHideFor',
source: [{
type: GuideSectionTypes.JS,
code: responsiveSource,
}, {
type: GuideSectionTypes.HTML,
code: responsiveHtml,
}],
text: (
<div>
<p>
Pass an array of named breakpoints to either
the <EuiCode>EuiShowFor</EuiCode> or <EuiCode>EuiHideFor</EuiCode> components
to make them responsive.
</p>

<p><strong>The sizing correlates with our <EuiCode>$euiBreakpoints</EuiCode> SASS map.</strong></p>

<EuiCodeBlock language="scss" paddingSize="s">
{sizes.euiBreakpointKeys.map(function (size, index) {
return renderSizes(size, index);
})}
</EuiCodeBlock>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would love to see this using our "blue" wrapper boxes to show people the actual sizing. It might help visualize the sizing more quickly. Even possibly listing out the more common scenarios (tablet and below is... size={xs,s}...etc.

Don't think it needs to be for this PR, and I'm happy to set it up after you merge since you did all the leg work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I can do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snide Here's the problem I'm running into with your suggestion. The screen and especially that side of the page never gets large enough to show the full width of anything above size 's'. Unless I'm just not understanding what you mean.

screen shot 2018-06-08 at 10 09 51 am

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't think about this. One thing we could do is make some page outlines that were fixed positon, or just take these bars and fix them to the bottom of the page (maybe make them thinner).

Always something we can do a bit later. Don't want to hold up your PR on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, ok, I'll push this idea off for later.

</div>
),
props: { EuiShowFor, EuiHideFor },
demo: <Responsive />,
}],
};
25 changes: 25 additions & 0 deletions src-docs/src/views/utility_classes/utility_classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,30 @@ export default () => (

<EuiCode className="eui-displayInlineBlock">.eui-displayInlineBlock</EuiCode>

<h4>Responsive</h4>

<EuiCode className="euiHideFor--xs">.euiHideFor--xs</EuiCode>
<EuiSpacer />
<EuiCode className="euiHideFor--s">.euiHideFor--s</EuiCode>
<EuiSpacer />
<EuiCode className="euiHideFor--m">.euiHideFor--m</EuiCode>
<EuiSpacer />
<EuiCode className="euiHideFor--l">.euiHideFor--l</EuiCode>
<EuiSpacer />
<EuiCode className="euiHideFor--xl">.euiHideFor--xl</EuiCode>

<EuiSpacer />

<EuiCode className="euiShowFor--xs">.euiShowFor--xs</EuiCode>
<EuiSpacer />
<EuiCode className="euiShowFor--s">.euiShowFor--s</EuiCode>
<EuiSpacer />
<EuiCode className="euiShowFor--m">.euiShowFor--m</EuiCode>
<EuiSpacer />
<EuiCode className="euiShowFor--l">.euiShowFor--l</EuiCode>
<EuiSpacer />
<EuiCode className="euiShowFor--xl">.euiShowFor--xl</EuiCode>


</EuiText>
);
6 changes: 3 additions & 3 deletions src/components/breadcrumbs/_breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

.euiBreadcrumbs--responsive {
// Laptop
@include screenMedium {
@include euiBreakpoint('l') {
.euiBreadcrumbSeparator,
.euiBreadcrumb {
display: none;
Expand All @@ -43,7 +43,7 @@
}

// Tablets
@include screenSmall {
@include euiBreakpoint('m') {
.euiBreadcrumbSeparator,
.euiBreadcrumb {
display: none;
Expand All @@ -56,7 +56,7 @@
}

// Mobile
@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiBreadcrumbSeparator,
.euiBreadcrumb {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/button_group/_button_group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
border-bottom-right-radius: $euiBorderRadius;
}

@include screenXSmall(){
@include euiBreakpoint('xs','s'){
flex: 1;
min-width: 0;

Expand Down
2 changes: 1 addition & 1 deletion src/components/date_picker/_date_picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@
}

// We drop the time picker on mobile. They can still type in the time directly.
@include screenXSmall {
@include euiBreakpoint('xs','s') {
.react-datepicker__time-container {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/flex/_flex_group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $gutterTypes: (
flex-wrap: wrap;
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiFlexGroup--responsive {
flex-wrap: wrap;
margin-left: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/flex/_flex_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

// On mobile we force them to stack and act the same.
@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiFlexGroup--responsive > .euiFlexItem,
.euiFlexGrid > .euiFlexItem {
width: 100% !important;
Expand Down
8 changes: 4 additions & 4 deletions src/components/flyout/_flyout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ $euiFlyoutBorderColor: tintOrShade($euiShadowColorLarge, 50%, 0%) !default; // m
*/
$flyoutSizes: (
"small": (
min: map-get($breakpoints, "small") * .5, /* 1 */
min: map-get($euiBreakpoints, "m") * .5, /* 1 */
width: 25vw
),
"medium": (
min: map-get($breakpoints, "small") * .7, /* 1 */
min: map-get($euiBreakpoints, "m") * .7, /* 1 */
width: 50vw
),
"large": (
min: map-get($breakpoints, "small") * .9, /* 1 */
min: map-get($euiBreakpoints, "m") * .9, /* 1 */
width: 75vw
)
);
Expand All @@ -52,7 +52,7 @@ $flyoutSizes: (
}
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiFlyout:not(.euiFlyout--small) { /* 2 */
left: 0;
min-width: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiDescribedFormGroup__fields {
padding-top: 0;

Expand Down
2 changes: 1 addition & 1 deletion src/components/header/_header_logo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
padding-left: $euiSize;
font-weight: $euiFontWeightLight;

@include screenXSmall() {
@include euiBreakpoint('xs','s') {
@include euiTitle("xxs");
font-weight: $euiFontWeightLight;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/header_links/_header_links.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
white-space: nowrap;
overflow: hidden;

@include screenXSmall(){
@include euiBreakpoint('xs','s'){
display: none;
}
}
Expand All @@ -21,7 +21,7 @@
position: absolute !important; // override popover relative
right: 0;

@include screenXSmall(){
@include euiBreakpoint('xs','s'){
display: block !important;
}
}
6 changes: 6 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,9 @@ export {
EuiIconTip,
EuiToolTip,
} from './tool_tip';

export {
EuiHideFor,
EuiShowFor,
} from './responsive';

2 changes: 1 addition & 1 deletion src/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $euiModalBorderColor: tintOrShade($euiShadowColorLarge, 50%, 0%) !default; // ma
}

// On mobile we fix modals as a takeover.
@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiModal {
position: fixed;
width: calc(100vw + 2px);
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_body/_page_body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
min-height: 400px; // Temporary till we have a better doc system.
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiPageBody {
flex-direction: column;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_content/_page_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}


@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiPageContent {
border-radius: 0;
border: none;
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_content/_page_content_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
align-items: center;
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiPageContentHeader {
flex-direction: column;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {

.euiPageContentHeaderSection {
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_header/_page_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
align-items: center;
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiPageHeader {
flex-direction: column;
padding: 0 $euiSize;
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_header/_page_header_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
margin-left: $euiSizeXL;
}
}
@include screenXSmall {
@include euiBreakpoint('xs','s') {

.euiPageHeaderSection {
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/page_side_bar/_page_side_bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
margin-right: $euiSizeL;
}

@include screenXSmall {
@include euiBreakpoint('xs','s') {
.euiPageSideBar {
width: 100%;
}
Expand Down
Loading