Skip to content

Commit

Permalink
[EuiHeader] Stacked example (#3538)
Browse files Browse the repository at this point in the history
* Added stacked header example
**Break**: EuiHeader now requires consumer to use mixin to apply padding to account for fixed position
* Adding header updates to test flyouts
* Fix styles for dark theme
  - Darker in actual dark theme
* Fix addition/removal of body classes when there are mulitple fixed headers
* Fixing shadows on flyouts.
* Change Fixed Header example and fixed separation of flyout and header
  • Loading branch information
cchaos authored Jun 4, 2020
1 parent a6e49f0 commit c134b58
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 85 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## [`master`](https://github.com/elastic/eui/tree/master)

**Bug fixes**

- Fixed `EuiKeyPadMenu` and `EuiKeyPadMenuItem` aria roles ([#3502](https://github.com/elastic/eui/pull/3502))

**Breaking changes**

- A fixed `EuiHeader` no longer automatically padding directly to the `<body>` element ([#3538](https://github.com/elastic/eui/pull/3538))
- Improved `EuiPagination`, `EuiDataGrid`, `EuiBasicTable` and `EuiInMemoryTable` accessibility, causing `EuiPaginationButton` to require a new prop `pageIndex` ([#3294](https://github.com/elastic/eui/pull/3294))

**Bug fixes**
- Fixed `EuiKeyPadMenu` and `EuiKeyPadMenuItem` aria roles ([#3502](https://github.com/elastic/eui/pull/3502))

## [`24.1.0`](https://github.com/elastic/eui/tree/v24.1.0)

Expand Down
44 changes: 30 additions & 14 deletions src-docs/src/components/guide_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
}
}

@include euiHeaderAffordForFixed;

.euiBody--headerIsFixed {
.guideSideNav {
top: $euiHeaderHeightCompensation;
}
}

.euiBody--headerIsFixed--double {
@include euiHeaderAffordForFixed($euiHeaderHeightCompensation * 2);

.guideSideNav {
top: $euiHeaderHeightCompensation * 2;
}
}

.guidePage {
padding: 0;
}
Expand Down Expand Up @@ -215,6 +231,19 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
top: 0;
}

.euiDataGridRowCell--favoriteFranchise {
background: transparentize($color: #800080, $amount: .95) !important;
}

.euiDataGridHeaderCell--favoriteFranchise {
background: transparentize($color: #800080, $amount: .9) !important;
}

.euiTreeView__nodeInnerExample {
color: $euiColorDanger;
font-weight: $euiFontWeightBold;
}

@import '../views/guidelines/index';
@import 'guide_section/index';
@import 'guide_rule/index';
Expand All @@ -229,7 +258,7 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
}

.guideSideNav {
position: relative;
position: static;
width: auto;

// This is a temporary hack till we fix how classes pass into form controls
Expand Down Expand Up @@ -263,16 +292,3 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
width: 100%;
}
}

.euiDataGridRowCell--favoriteFranchise {
background: transparentize($color: #800080, $amount: .95) !important;
}

.euiDataGridHeaderCell--favoriteFranchise {
background: transparentize($color: #800080, $amount: .9) !important;
}

.euiTreeView__nodeInnerExample {
color: $euiColorDanger;
font-weight: $euiFontWeightBold;
}
56 changes: 50 additions & 6 deletions src-docs/src/views/header/header_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import HeaderDark from './header_dark';
const headerDarkSource = require('!!raw-loader!./header_dark');
const headerDarkHtml = renderToHtml(HeaderDark);

import HeaderStacked from './header_stacked';
const headerStackedSource = require('!!raw-loader!./header_stacked');
const headerStackedHtml = renderToHtml(HeaderStacked);

const headerSnippet = `<EuiHeader>
<EuiHeaderSection grow={false}>
<EuiHeaderSectionItem border="right">
Expand Down Expand Up @@ -184,15 +188,26 @@ export const HeaderExample = {
text: (
<>
<p>
Most consumer need a header that does not scroll way with the page
contents. You can apply this display by changing{' '}
<EuiCode>position</EuiCode> to <EuiCode>fixed</EuiCode>. It will
also add the appropriate padding to the window body by applying a
class.
Most consumers need a header that does not scroll away with the page
contents. You can apply this display by applying the property{' '}
<EuiCode language="ts">{'position="fixed"'}</EuiCode>. This will
also add a class of <EuiCode>.euiBody--headerIsFixed</EuiCode> to
the window body.
</p>
<p>
You will then need to apply your own padding to this body class to
afford for the header height. EUI supplies a helper mixin that also
accounts for this height in flyouts and the collapsible nav. Simply
add{' '}
<EuiCode language="sass">@mixin euiHeaderAffordForFixed;</EuiCode>{' '}
anywhere in your SASS.
</p>
</>
),
snippet: '<EuiHeader position="fixed" />',
snippet: [
'<EuiHeader position="fixed" />',
'@mixin euiHeaderAffordForFixed;',
],
demo: <HeaderPosition />,
},
{
Expand Down Expand Up @@ -282,5 +297,34 @@ export const HeaderExample = {
snippet: headerLinksSnippet,
demo: <HeaderAlert />,
},
{
title: 'Stacked headers',
source: [
{
type: GuideSectionTypes.JS,
code: headerStackedSource,
},
{
type: GuideSectionTypes.HTML,
code: headerStackedHtml,
},
],
text: (
<p>
Stacking multiple headers provide a great way to separate global
navigation concerns. However, the{' '}
<EuiCode language="ts">{'position="fixed"'}</EuiCode> option will not
be aware of the number of headers. Therefore, if you do need fixed and
stacked headers, you will need to apply the helper mixin and pass in
the correct height to afford for.
</p>
),
snippet: [
`<EuiHeader theme="dark" />
<EuiHeader />`,
'@include euiHeaderAffordForFixed($euiHeaderHeightCompensation * 2);',
],
demo: <HeaderStacked />,
},
],
};
35 changes: 14 additions & 21 deletions src-docs/src/views/header/header_position.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@ import {
EuiHeader,
EuiHeaderLogo,
EuiSwitch,
EuiSpacer,
} from '../../../../src/components';

export default () => {
const [position, setPosition] = useState('static');

const sections = [
{
items: [
<EuiHeaderLogo
iconType="logoKibana"
href="#"
aria-label="Go to home page"
/>,
],
borders: 'none',
},
{
items: [
<div style={{ padding: 12 }}>
<EuiSwitch
label={`position: ${position}`}
checked={position === 'fixed'}
onChange={e => setPosition(e.target.checked ? 'fixed' : 'static')}
/>
</div>,
],
borders: 'none',
items: [<EuiHeaderLogo iconType="logoKibana">Kibana</EuiHeaderLogo>],
borders: 'right',
},
];

return <EuiHeader position={position} sections={sections} />;
return (
<>
<EuiSwitch
label={'Make header fixed position'}
checked={position === 'fixed'}
onChange={e => setPosition(e.target.checked ? 'fixed' : 'static')}
/>
<EuiSpacer />
<EuiHeader position={position} sections={sections} />
</>
);
};
3 changes: 3 additions & 0 deletions src-docs/src/views/header/header_sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export default () => {
items: [renderLogo, <HeaderSpacesMenu />],
borders: 'right',
breadcrumbs: breadcrumbs,
breadcrumbProps: {
'aria-label': 'Header sections breadcrumbs',
},
},
{
items: [renderSearch, <div style={{ width: 8 }} />],
Expand Down
90 changes: 90 additions & 0 deletions src-docs/src/views/header/header_stacked.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useState, useEffect } from 'react';

import {
EuiHeader,
EuiHeaderLogo,
EuiHeaderSectionItemButton,
} from '../../../../src/components/header';
import { EuiSwitch } from '../../../../src/components/form';
import { EuiSpacer } from '../../../../src/components/spacer';
import { EuiAvatar } from '../../../../src/components/avatar';
// @ts-ignore
import HeaderUpdates from './header_updates';

export default () => {
const [isFixed, setIsFixed] = useState(false);

const breadcrumbs = [
{
text: 'Management',
href: '#',
},
{
text: 'Users',
},
];

/**
* Docs Note: This additional class is needed only for docs to override the usually single header
*/
useEffect(() => {
if (isFixed) document.body.classList.add('euiBody--headerIsFixed--double');

return () => {
document.body.classList.remove('euiBody--headerIsFixed--double');
};
}, [isFixed]);

const headers = (
<>
<EuiHeader
theme="dark"
position={isFixed ? 'fixed' : 'static'}
sections={[
{
items: [
<EuiHeaderLogo iconType="logoElastic">Elastic</EuiHeaderLogo>,
],
borders: 'right',
},
{
items: [
<EuiHeaderSectionItemButton aria-label="Account menu">
<EuiAvatar name="John Username" size="s" />
</EuiHeaderSectionItemButton>,
],
},
]}
/>
<EuiHeader
position={isFixed ? 'fixed' : 'static'}
sections={[
{
items: [
<EuiHeaderSectionItemButton aria-label="Account menu">
<EuiAvatar type="space" name="Default Space" size="s" />
</EuiHeaderSectionItemButton>,
],
breadcrumbs: breadcrumbs,
borders: 'none',
},
{
items: isFixed ? [<HeaderUpdates />] : undefined,
},
]}
/>
</>
);

return (
<>
<EuiSwitch
label={'Make header fixed position'}
checked={isFixed}
onChange={e => setIsFixed(e.target.checked)}
/>
<EuiSpacer />
{headers}
</>
);
};
7 changes: 1 addition & 6 deletions src-docs/src/views/header/header_updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,13 @@ export default () => {
);

let flyout;
const flyoutStyle = {
top: '49px',
height: 'calc(100vh - 49px)',
};
if (isFlyoutVisible) {
flyout = (
<EuiFlyout
onClose={() => closeFlyout()}
size="s"
id="headerNewsFeed"
aria-labelledby="flyoutSmallTitle"
style={flyoutStyle}>
aria-labelledby="flyoutSmallTitle">
<EuiFlyoutHeader hasBorder>
<EuiTitle size="s">
<h2 id="flyoutSmallTitle">What&apos;s new</h2>
Expand Down
6 changes: 0 additions & 6 deletions src/components/flyout/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@
display: flex;
flex-direction: column;
align-items: stretch;

// When the EuiHeader is fixed, we need to account for it in the position of the flyout
.euiBody--headerIsFixed & {
top: $euiHeaderHeightCompensation;
height: calc(100% - #{$euiHeaderHeightCompensation});
}
}
16 changes: 9 additions & 7 deletions src/components/header/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
display: flex;
justify-content: space-between;
background: $euiHeaderBackgroundColor;
border-bottom: $euiBorderThin;
border-bottom: 1px solid $euiHeaderBorderColor;

&--fixed {
position: fixed;
Expand All @@ -19,20 +19,22 @@
}
}

.euiBody--headerIsFixed {
padding-top: $euiHeaderHeightCompensation;
}

.euiBody--collapsibleNavIsOpen,
.euiBody--hasFlyout {
.euiHeader--fixed {
z-index: $euiZModal + 1;
}
}

.euiHeader--fixed + .euiHeader--fixed {
top: $euiHeaderHeightCompensation;
}

.euiHeader--dark {
// Only force reverse theme if the theme is light
@if (lightness($euiTextColor) < 50) {
@include euiHeaderDarkTheme;
@include euiHeaderDarkTheme($backgroundColor: shade($euiColorDarkestShade, 28%));
} @else {
// Makes forced "dark" theme darker than the typical dark them to separate them visually
@include euiHeaderDarkTheme($backgroundColor: shade($euiColorLightestShade, 50%));
}
}
Loading

0 comments on commit c134b58

Please sign in to comment.