Skip to content

Commit

Permalink
Add ability to force open EuiSideNav items. (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkwright authored Mar 16, 2018
1 parent 55e4f91 commit ab57f00
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 133 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `0.0.29`.
- Add ability to force `EuiSideNav` items open by setting `item.forceOpen`. ([#515](https://github.com/elastic/eui/pull/515))

# [`0.0.29`](https://github.com/elastic/eui/tree/v0.0.29)

Expand Down
25 changes: 22 additions & 3 deletions src-docs/src/views/side_nav/side_nav_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import SideNavComplex from './side_nav_complex';
const sideNavComplexSource = require('!!raw-loader!./side_nav_complex');
const sideNavComplexHtml = renderToHtml(SideNavComplex);

import SideNavForceOpen from './side_nav_force_open';
const sideNavForceOpenSource = require('!!raw-loader!./side_nav_force_open');
const sideNavForceOpenHtml = renderToHtml(SideNavForceOpen);

export const SideNavExample = {
title: 'Side Nav',
sections: [{
Expand All @@ -33,13 +37,13 @@ export const SideNavExample = {
<div>
<p>
<EuiCode>SideNav</EuiCode> is a responsive menu system that usually sits on the left side of a page layout.
It will exapand to the width of its container. This is the menu that is used on the left side of the
page you are looking at.
It will expand to the width of its container. This is the menu that is used on the left side of the
page you are currently looking at.
</p>

<p>
Configure the content of a <EuiCode>SideNav</EuiCode> by passing in an <EuiCode>items</EuiCode> prop.
Referring to the source code for an example of this data structure&rsquo;s anatomy.
Refer to the source code for an example of this data structure&rsquo;s anatomy.
</p>
</div>
),
Expand All @@ -60,5 +64,20 @@ export const SideNavExample = {
</p>
),
demo: <SideNavComplex />,
}, {
title: 'Forced open side nav',
source: [{
type: GuideSectionTypes.JS,
code: sideNavForceOpenSource,
}, {
type: GuideSectionTypes.HTML,
code: sideNavForceOpenHtml,
}],
text: (
<p>
<EuiCode>SideNav</EuiCode> items can be forced open by setting <EuiCode>items[n].forceOpen = true</EuiCode>
</p>
),
demo: <SideNavForceOpen />,
}],
};
94 changes: 94 additions & 0 deletions src-docs/src/views/side_nav/side_nav_force_open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, {
Component,
} from 'react';

import {
EuiIcon,
EuiSideNav,
} from '../../../../src/components';

export default class extends Component {
constructor(props) {
super(props);

this.state = {
isSideNavOpenOnMobile: false,
selectedItemName: null,
};
}

toggleOpenOnMobile = () => {
this.setState({
isSideNavOpenOnMobile: !this.state.isSideNavOpenOnMobile,
});
};

selectItem = name => {
this.setState({
selectedItemName: name,
});
};

createItem = (name, data = {}) => {
// NOTE: Duplicate `name` values will cause `id` collisions.
return {
...data,
id: name,
name,
isSelected: this.state.selectedItemName === name,
onClick: () => this.selectItem(name),
};
};

render() {
const sideNav = [
this.createItem('Kibana', {
icon: <EuiIcon type="logoKibana" />,
items: [
this.createItem('Has normal children', {
items: [
this.createItem('Without forceOpen', {
items: [
this.createItem('Child 1'),
this.createItem('Child 2'),
],
}),
],
}),
this.createItem('Normally not open', {
items: [
this.createItem('Has forceOpen:true', {
forceOpen: true,
items: [
this.createItem('Child 3'),
this.createItem('Child 4'),
],
}),
],
}),
this.createItem('With forceOpen:true', {
forceOpen: true,
items: [
this.createItem('Normal child', {
items: [
this.createItem('Child 5'),
this.createItem('Child 6'),
],
}),
],
}),
],
}),
];

return (
<EuiSideNav
mobileTitle="Navigate within $APP_NAME"
toggleOpenOnMobile={this.toggleOpenOnMobile}
isOpenOnMobile={this.state.isSideNavOpenOnMobile}
items={sideNav}
style={{ width: 192 }}
/>
);
}
}
164 changes: 150 additions & 14 deletions src/components/side_nav/__snapshots__/side_nav.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports[`EuiSideNav is rendered 1`] = `
</nav>
`;

exports[`EuiSideNav isOpenOnMobile defaults to false 1`] = `
exports[`EuiSideNav props isOpenOnMobile defaults to false 1`] = `
<nav
class="euiSideNav"
>
Expand Down Expand Up @@ -84,7 +84,7 @@ exports[`EuiSideNav isOpenOnMobile defaults to false 1`] = `
</nav>
`;

exports[`EuiSideNav isOpenOnMobile is rendered when specified as true 1`] = `
exports[`EuiSideNav props isOpenOnMobile is rendered when specified as true 1`] = `
<nav
class="euiSideNav euiSideNav-isOpenMobile"
>
Expand Down Expand Up @@ -125,7 +125,7 @@ exports[`EuiSideNav isOpenOnMobile is rendered when specified as true 1`] = `
</nav>
`;

exports[`EuiSideNav items is rendered 1`] = `
exports[`EuiSideNav props items is rendered 1`] = `
<nav
class="euiSideNav"
>
Expand Down Expand Up @@ -164,7 +164,7 @@ exports[`EuiSideNav items is rendered 1`] = `
class="euiSideNav__content"
>
<div
class="euiSideNavItem euiSideNavItem--root"
class="euiSideNavItem euiSideNavItem--root euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton"
Expand Down Expand Up @@ -241,7 +241,7 @@ exports[`EuiSideNav items is rendered 1`] = `
</nav>
`;

exports[`EuiSideNav items renders items using a specified callback 1`] = `
exports[`EuiSideNav props items renders items having { forceOpen: true } in open state, and automatically opens parent items 1`] = `
<nav
class="euiSideNav"
>
Expand Down Expand Up @@ -280,7 +280,146 @@ exports[`EuiSideNav items renders items using a specified callback 1`] = `
class="euiSideNav__content"
>
<div
class="euiSideNavItem euiSideNavItem--root"
class="euiSideNavItem euiSideNavItem--root euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton"
>
<span
class="euiSideNavItemButton__content"
>
<span
class="euiSideNavItemButton__label"
>
A
</span>
</span>
</div>
<div
class="euiSideNavItem__items"
>
<div
class="euiSideNavItem euiSideNavItem--trunk"
>
<div
class="euiSideNavItemButton"
>
<span
class="euiSideNavItemButton__content"
>
<span
class="euiSideNavItemButton__label"
>
B
</span>
</span>
</div>
</div>
<div
class="euiSideNavItem euiSideNavItem--trunk euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton euiSideNavItemButton-isOpen"
>
<span
class="euiSideNavItemButton__content"
>
<span
class="euiSideNavItemButton__label"
>
C
</span>
</span>
</div>
<div
class="euiSideNavItem__items"
>
<div
class="euiSideNavItem euiSideNavItem--branch euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton euiSideNavItemButton-isOpen"
>
<span
class="euiSideNavItemButton__content"
>
<span
class="euiSideNavItemButton__label"
>
D
</span>
</span>
</div>
<div
class="euiSideNavItem__items"
>
<div
class="euiSideNavItem euiSideNavItem--branch"
>
<div
class="euiSideNavItemButton"
>
<span
class="euiSideNavItemButton__content"
>
<span
class="euiSideNavItemButton__label"
>
E
</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
`;

exports[`EuiSideNav props items renders items using a specified callback 1`] = `
<nav
class="euiSideNav"
>
<button
class="euiSideNav__mobileToggle euiLink"
type="button"
>
<span
class="euiSideNav__mobileWrap"
>
<span
class="euiSideNav__mobileTitle"
/>
<svg
aria-hidden="true"
class="euiIcon euiSideNav__mobileIcon euiIcon--medium"
height="16"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<path
d="M2 4V2h2v2H2zm5 0V2h2v2H7zm5 0V2h2v2h-2zM2 9V7h2v2H2zm5 0V7h2v2H7zm5 0V7h2v2h-2zM2 14v-2h2v2H2zm5 0v-2h2v2H7zm5 0v-2h2v2h-2z"
id="apps-a"
/>
</defs>
<use
href="#apps-a"
/>
</svg>
</span>
</button>
<div
class="euiSideNav__content"
>
<div
class="euiSideNavItem euiSideNavItem--root euiSideNavItem--hasChildItems"
>
<a
class="euiSideNavItemButton euiSideNavItemButton--isClickable"
Expand Down Expand Up @@ -324,7 +463,7 @@ exports[`EuiSideNav items renders items using a specified callback 1`] = `
</nav>
`;

exports[`EuiSideNav items renders items which are links 1`] = `
exports[`EuiSideNav props items renders items which are links 1`] = `
<nav
class="euiSideNav"
>
Expand Down Expand Up @@ -363,7 +502,7 @@ exports[`EuiSideNav items renders items which are links 1`] = `
class="euiSideNav__content"
>
<div
class="euiSideNavItem euiSideNavItem--root"
class="euiSideNavItem euiSideNavItem--root euiSideNavItem--hasChildItems"
>
<a
class="euiSideNavItemButton euiSideNavItemButton--isClickable"
Expand Down Expand Up @@ -441,7 +580,7 @@ exports[`EuiSideNav items renders items which are links 1`] = `
</nav>
`;

exports[`EuiSideNav items renders selected item and automatically opens parent items 1`] = `
exports[`EuiSideNav props items renders selected item and automatically opens parent items 1`] = `
<nav
class="euiSideNav"
>
Expand Down Expand Up @@ -480,7 +619,7 @@ exports[`EuiSideNav items renders selected item and automatically opens parent i
class="euiSideNav__content"
>
<div
class="euiSideNavItem euiSideNavItem--root"
class="euiSideNavItem euiSideNavItem--root euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton"
Expand Down Expand Up @@ -516,7 +655,7 @@ exports[`EuiSideNav items renders selected item and automatically opens parent i
</div>
</div>
<div
class="euiSideNavItem euiSideNavItem--trunk"
class="euiSideNavItem euiSideNavItem--trunk euiSideNavItem--hasChildItems"
>
<div
class="euiSideNavItemButton euiSideNavItemButton-isOpen"
Expand Down Expand Up @@ -550,9 +689,6 @@ exports[`EuiSideNav items renders selected item and automatically opens parent i
</span>
</span>
</div>
<div
class="euiSideNavItem__items"
/>
</div>
<div
class="euiSideNavItem euiSideNavItem--branch"
Expand Down
Loading

0 comments on commit ab57f00

Please sign in to comment.