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

[EuiHeader] Added sections and position props #2928

Merged
merged 8 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `sections` and `position` props to `EuiHeader` ([#2928](https://github.com/elastic/eui/pull/2928))

**Bug Fixes**

- Fixed `EuiDataGrid`'s sort popover to behave properly on mobile screens ([#2979](https://github.com/elastic/eui/pull/2979))
Expand Down
108 changes: 104 additions & 4 deletions src-docs/src/views/header/header_example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { Link } from 'react-router';

import { renderToHtml } from '../../services';

Expand All @@ -17,10 +18,20 @@ import {
EuiHeaderLink,
} from '../../../../src/components';

import { EuiHeaderSectionsProp } from './props';

import Header from './header';
const headerSource = require('!!raw-loader!./header');
const headerHtml = renderToHtml(Header);

import HeaderSections from './header_sections';
const headerSectionsSource = require('!!raw-loader!./header_sections');
const headerSectionsHtml = renderToHtml(HeaderSections);

import HeaderPosition from './header_position';
const headerPositionSource = require('!!raw-loader!./header_position');
const headerPositionHtml = renderToHtml(HeaderPosition);

import HeaderAlert from './header_alert';
const headerAlertSource = require('!!raw-loader!./header_alert');
const headerAlertHtml = renderToHtml(HeaderAlert);
Expand All @@ -45,10 +56,27 @@ const headerSnippet = `<EuiHeader>
</EuiHeaderSection>
</EuiHeader>`;

const headerSectionsSnippet = `<EuiHeader
sections={[
{
items: [...],
borders: 'right',
breadcrumbs: [...],
},
{
items: [...],
borders: 'none',
},
{
items: [...],
},
]}
/>`;

const headerLinksSnippet = `<EuiHeader>
<EuiHeaderSectionItem border="right">
<EuiHeaderLogo
iconType="iconName"
iconType="iconName"
href="#"
/>
</EuiHeaderSectionItem>
Expand Down Expand Up @@ -78,20 +106,92 @@ export const HeaderExample = {
code: headerHtml,
},
],
text: <p>The header is made up of several individual components.</p>,
text: (
<p>
The header is made up of <strong>many</strong> individual components.
</p>
),
props: {
EuiHeader,
EuiHeaderBreadcrumbs,
EuiHeaderSection,
EuiHeaderSectionItem,
EuiHeaderSectionItemButton,
EuiHeaderLogo,
EuiHeaderSectionsProp,
},
snippet: headerSnippet,
demo: <Header />,
},
{
title: 'Links',
title: 'Sections',
source: [
{
type: GuideSectionTypes.JS,
code: headerSectionsSource,
},
{
type: GuideSectionTypes.HTML,
code: headerSectionsHtml,
},
],
text: (
<>
<p>
Alternatively, you can pass an array objects to the{' '}
<EuiCode>sections</EuiCode> props that takes a key of{' '}
<EuiCode>items</EuiCode> (array of children to wrap in an{' '}
<strong>EuiHeaderSectionItem</strong>) and/or{' '}
<EuiCode>breadcrumbs</EuiCode> (array of{' '}
<Link to="/navigation/breadcrumbs">breadcrumb</Link> objects). Each
item in the array will be wrapped in an{' '}
<strong>EuiHeaderSection</strong>.
</p>
<p>
<strong>Note:</strong> Passing <EuiCode>sections</EuiCode> and{' '}
<EuiCode>children</EuiCode> will disregard the{' '}
<EuiCode>children</EuiCode> as it is not easily interpreted at what
location the children should be placed.
</p>
</>
),
props: {
EuiHeader,
EuiHeaderSectionsProp,
EuiHeaderSection,
EuiHeaderSectionItem,
},
snippet: headerSectionsSnippet,
demo: <HeaderSections />,
},
{
title: 'Fixed header',
source: [
{
type: GuideSectionTypes.JS,
code: headerPositionSource,
},
{
type: GuideSectionTypes.HTML,
code: headerPositionHtml,
},
],
text: (
<>
<p>
Most consumer need a header that does not scroll way with the page
cchaos marked this conversation as resolved.
Show resolved Hide resolved
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.
</p>
</>
),
snippet: '<EuiHeader position="fixed" />',
demo: <HeaderPosition />,
},
{
title: 'Header links',
source: [
{
type: GuideSectionTypes.JS,
Expand All @@ -117,7 +217,7 @@ export const HeaderExample = {
demo: <HeaderLinks />,
},
{
title: 'Display header alerts',
title: 'Alerts in the header',
source: [
{
type: GuideSectionTypes.JS,
Expand Down
38 changes: 38 additions & 0 deletions src-docs/src/views/header/header_position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useState } from 'react';

import {
EuiHeader,
EuiHeaderLogo,
EuiSwitch,
} 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: 16 }}>
<EuiSwitch
label={`position: ${position}`}
checked={position === 'fixed'}
onChange={e => setPosition(e.target.checked ? 'fixed' : 'static')}
/>
</div>,
],
borders: 'none',
},
];

return <EuiHeader position={position} sections={sections} />;
};
82 changes: 82 additions & 0 deletions src-docs/src/views/header/header_sections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';

import {
EuiHeader,
EuiFieldSearch,
EuiHeaderLogo,
} from '../../../../src/components';

import HeaderAppMenu from './header_app_menu';
import HeaderUserMenu from './header_user_menu';
import HeaderSpacesMenu from './header_spaces_menu';

export default () => {
const renderLogo = (
<EuiHeaderLogo
iconType="logoKibana"
href="#"
aria-label="Go to home page"
/>
);

const breadcrumbs = [
{
text: 'Management',
href: '#',
onClick: e => {
e.preventDefault();
console.log('You clicked management');
},
'data-test-subj': 'breadcrumbsAnimals',
className: 'customClass',
},
{
text: 'Truncation test is here for a really long item',
href: '#',
onClick: e => {
e.preventDefault();
console.log('You clicked truncation test');
},
},
{
text: 'hidden',
href: '#',
onClick: e => {
e.preventDefault();
console.log('You clicked hidden');
},
},
{
text: 'Users',
href: '#',
onClick: e => {
e.preventDefault();
console.log('You clicked users');
},
},
{
text: 'Create',
},
];

const renderSearch = (
<EuiFieldSearch placeholder="Search for anything" compressed />
);

const sections = [
{
items: [renderLogo, <HeaderSpacesMenu />],
borders: 'right',
breadcrumbs: breadcrumbs,
},
{
items: [renderSearch, <div style={{ width: 8 }} />],
borders: 'none',
},
{
items: [<HeaderUserMenu />, <HeaderAppMenu />],
},
];

return <EuiHeader sections={sections} />;
};
7 changes: 7 additions & 0 deletions src-docs/src/views/header/props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { FunctionComponent } from 'react';

import { EuiHeaderSections } from '../../../../src/components/header';

export const EuiHeaderSectionsProp: FunctionComponent<
EuiHeaderSections
> = () => <div />;
Loading