forked from supnate/react-tab-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab_selector_react.html
executable file
·54 lines (49 loc) · 1.52 KB
/
tab_selector_react.html
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
<!DOCTYPE html>
<html>
<head>
<script src="js/react.js"></script>
<script src="js/JSXTransformer.js"></script>
<link rel="stylesheet" tpe="text/css" href="style.css"/>
</head>
<body>
<div id="container"></div>
<script type="text/jsx">
var data = [
{name: 'Red', value: 'red'},
{name: 'Blue', value: 'blue'},
{name: 'Yellow', value: 'yellow'},
{name: 'Green', value: 'green'},
{name: 'White', value: 'White'}
];
var TabSelector = React.createClass({
getInitialState: function() {
return {selected: this.props.selected};
},
handleOnClick: function (evt) {
this.setState({'selected': evt.target.getAttribute('data-value')})
},
render: function() {
var tabs = this.props.data.map(function (item) {
var selected = item.value == this.state.selected ? 'selected' : '';
return <li data-value={item.value}
className={selected}
onClick={this.handleOnClick}
>{item.name}</li>
;
}, this);
return <div className="tab-selector">
<label>{this.props.label}</label>
<ul>
{tabs}
</ul>
</div>
;
}
});
React.render(
TabSelector({label: 'Color', data: data, selected: null}),
document.getElementById('container')
);
</script>
</body>
</html>