-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to force open EuiSideNav items.
- Loading branch information
Showing
8 changed files
with
455 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.