UNPKG

react-lite-misc

Version:
68 lines (60 loc) 1.64 kB
(function() { var React, T, cx, div, span; cx = require('classnames'); React = require('react'); div = React.createFactory('div'); span = React.createFactory('span'); T = React.PropTypes; module.exports = React.createClass({ displayName: 'switch-tabs', propTypes: { data: T.array.isRequired, onTabClick: T.func.isRequired, tab: T.string.isRequired, iconMap: T.object, getText: T.func }, onTabClick: function(tab) { return this.props.onTabClick(tab); }, renderTab: function(tab) { var className, icon, onClick, text; className = cx({ entry: true, 'is-active': this.props.tab === tab }); onClick = (function(_this) { return function() { return _this.onTabClick(tab); }; })(this); if (this.props.iconMap != null) { icon = this.props.iconMap[tab]; } else { icon = void 0; } text = this.props.getText != null ? this.props.getText(tab) : tab; return div({ key: tab, className: className, onClick: onClick }, icon ? span({ className: "ti ti-" + icon }) : void 0, span({ className: 'text' }, text)); }, render: function() { var className, classObject; classObject = { 'switch-tabs': true, 'is-decorated': this.props.iconMap != null }; classObject["col-" + this.props.data.length] = true; className = cx(classObject); return div({ className: className }, this.props.data.map(this.renderTab)); } }); }).call(this);