Skip to content

Commit

Permalink
Add ability to force open EuiSideNav items.
Browse files Browse the repository at this point in the history
  • Loading branch information
arkwright committed Mar 14, 2018
1 parent 0606825 commit 81843fb
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 132 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- New icons for `logoGithub` and `logoSketch` ([#494](https://github.com/elastic/eui/pull/494))
- `EuiCard` now has an `href` and `isClickable` prop for better handling hover animations. ([#494](https://github.com/elastic/eui/pull/494))
- Added `calculateContrast` and `rgbToHex` to services ([#494](https://github.com/elastic/eui/pull/494))
- Add ability to force `EuiSideNav` items open by setting `item.forceOpen`. ([#497](https://github.com/elastic/eui/pull/515))

**Bug fixes**

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/side_nav/side_nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class extends Component {
name: 'Saved Objects',
id: 3,
onClick: () => { window.alert('Saved Objects'); },
isSelected: true,
isSelected: false,
}, {
name: 'Reporting',
id: 4,
Expand Down
23 changes: 21 additions & 2 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 @@ -34,12 +38,12 @@ export const SideNavExample = {
<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.
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: 'Lion stuff',
};
}

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 }}
/>
);
}
}
Loading

0 comments on commit 81843fb

Please sign in to comment.