This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Example.jsx
101 lines (91 loc) · 2.54 KB
/
Example.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';
import Options from './Options';
import DropdownMenu, { NestedDropdownMenu } from 'react-dd-menu';
class Example extends Component {
render() {
return (
<div className="example">
<header><h1>React Dropdown Menu Example</h1></header>
<main>
{Options.map(opts => {
return <Menu {...opts} key={opts.text} />;
})}
</main>
<footer>
<a href="http://github.com/mlaursen/react-dd-menu">
<span className="fa fa-github fa-4x" />
</a>
</footer>
</div>
);
}
}
export default Example;
class Menu extends Component {
constructor(props) {
super(props);
this.state = { isOpen: false };
}
toggleMenu = () => {
this.setState({ isOpen: !this.state.isOpen });
};
closeMenu = () => {
this.setState({ isOpen: false });
};
static propTypes = {
text: PropTypes.string,
additionalItems: PropTypes.node,
nestedProps: PropTypes.object,
};
render() {
const { isOpen } = this.state;
const { text, additionalItems, nestedProps, ...props } = this.props;
const opts = {
close: this.closeMenu,
isOpen: isOpen,
toggle: (
<div className={classnames('tab', { 'active': isOpen })}>
<button type="button" onClick={this.toggleMenu}>{text}</button>
</div>
),
};
let toggle = null;
if(nestedProps) {
let nested = null;
switch(nestedProps.nested) {
case 'left':
case 'right':
nested = nestedProps.nested;
break;
case 'inherit':
nested = props.align;
break;
default:
nested = props.align === 'left' ? 'right' : 'left';
}
const icon = <span className={`fa fa-chevron-${nested}`} />;
toggle = (
<button type="button">
{nested === 'left' && icon}
Hover for Nested menu
{nested === 'right' && icon}
</button>
);
}
return (
<DropdownMenu {...props} {...opts}>
<li><a href="#">Link Example</a></li>
<li><button type="button" onClick={this.onClick}>Button Example</button></li>
{additionalItems}
{nestedProps &&
<NestedDropdownMenu toggle={toggle} {...nestedProps}>
<li><a href="#">Woop Woop</a></li>
<li><a href="#">Thats the Sound of</a></li>
<li><a href="#">The Police</a></li>
</NestedDropdownMenu>
}
</DropdownMenu>
);
}
}