Skip to content

Instantly share code, notes, and snippets.

@gabrielbull
Created July 26, 2016 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielbull/baac43287c19f378f89be7a45e730828 to your computer and use it in GitHub Desktop.
Save gabrielbull/baac43287c19f378f89be7a45e730828 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { NavPane, NavPaneItem, Text } from 'react-desktop/windows';
export default class Menu extends Component {
static defaultProps = {
color: '#cc7f29',
theme: 'light'
};
_isMounted = false;
constructor() {
super();
this.state = {
selected: 'Item 1'
};
}
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount() {
this._isMounted = false;
}
render() {
return (
<NavPane openLength={200} push color={this.props.color} theme={this.props.theme}>
{this.renderItem('Item 1', 'Content 1') }
{this.renderItem('Item 2', 'Content 2') }
{this.renderItem('Item 3', 'Content 3') }
</NavPane>
);
}
renderItem(title, content) {
return (
<NavPaneItem
title={title}
icon={ this.renderIcon(title) }
theme="light"
background="#ffffff"
selected={this.state.selected === title}
onSelect={ () => {if(this._isMounted){ this.setState({ selected: title }) }} }
padding="10px 20px"
push
>
<Text>{content}</Text>
</NavPaneItem>
);
}
renderIcon(name) {
const fill = this.props.theme === 'dark' ? '#ffffff' : '#000000';
switch (name) {
case 'Item 1':
return (
<svg width="16px" height="14.9px" viewBox="0 0 16 14.9">
<polygon fill={fill} points="16,5.6 10.6,4.7 8,0 5.4,4.7 0,5.7 3.8,9.6 3.1,14.9 8,12.6 13,14.8 12.3,9.5 "/>
</svg>
);
case 'Item 2':
return (
<svg width="16px" height="13.5px" viewBox="0 0 16 13.5">
<path
fill={fill}
d="M16,4.2C16,1.9,14.1,0,11.7,0c-1.4,0-2.6,0.6-3.4,1.6c0,0,0,0,0,0C8.3,1.7,8.1,1.8,8,1.8c-0.2,0-0.3-0.1-0.4-0.2c0,0,0,0,0,0C6.8,0.6,5.6,0,4.3,0C1.9,0,0,1.9,0,4.2c0,0,0,0.1,0,0.1l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