UNPKG

4.95 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9var _templateObject = _taggedTemplateLiteral([''], ['']);
10
11var _styledComponents = require('styled-components');
12
13var _styledComponents2 = _interopRequireDefault(_styledComponents);
14
15var _react = require('react');
16
17var _react2 = _interopRequireDefault(_react);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
22
23function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
27function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
28
29function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
30
31var Container = _styledComponents2.default.div(_templateObject);
32
33var Tabs = function (_Component) {
34 _inherits(Tabs, _Component);
35
36 function Tabs() {
37 var _ref;
38
39 var _temp, _this, _ret;
40
41 _classCallCheck(this, Tabs);
42
43 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
44 args[_key] = arguments[_key];
45 }
46
47 return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Tabs.__proto__ || Object.getPrototypeOf(Tabs)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
48 currentTab: 0
49 }, _this.onTabClick = function (id) {
50 _this.setState({ currentTab: id });
51 }, _temp), _possibleConstructorReturn(_this, _ret);
52 }
53 /**
54 * Define the types of props the component accepts.
55 *
56 * @type {Object}
57 */
58
59
60 /**
61 * Define the default props of the component.
62 *
63 * @type {Object}
64 */
65
66
67 /**
68 * Define the types of the child's context.
69 *
70 * @type {Object}
71 */
72
73
74 _createClass(Tabs, [{
75 key: 'getChildContext',
76 value: function getChildContext() {
77 return {
78 onTabClick: this.onTabClick,
79 currentTab: this.state.currentTab,
80 activeColor: this.props.activeColor,
81 inactiveColor: this.props.inactiveColor,
82 activeBackground: this.props.activeBackground,
83 inactiveBackground: this.props.inactiveBackground
84 };
85 }
86 }, {
87 key: 'render',
88
89
90 /**
91 * Render the component
92 *
93 * @return {ReactElement}
94 */
95 value: function render() {
96 var _props = this.props,
97 children = _props.children,
98 other = _objectWithoutProperties(_props, ['children']);
99
100 return _react2.default.createElement(
101 Container,
102 other,
103 _react.Children.map(children, function (child, key) {
104 return (0, _react.cloneElement)(child, { key: key });
105 })
106 );
107 }
108 }]);
109
110 return Tabs;
111}(_react.Component);
112
113Tabs.propTypes = {
114 children: _react.PropTypes.node.isRequired,
115 activeColor: _react.PropTypes.string,
116 inactiveColor: _react.PropTypes.string,
117 activeBackground: _react.PropTypes.string,
118 inactiveBackground: _react.PropTypes.string
119};
120Tabs.defaultProps = {
121 activeColor: 'black',
122 inactiveColor: 'white',
123 activeBackground: 'white',
124 inactiveBackground: 'black'
125};
126Tabs.childContextTypes = {
127 onTabClick: _react.PropTypes.func.isRequired,
128 currentTab: _react.PropTypes.number.isRequired,
129 activeColor: _react.PropTypes.string.isRequired,
130 inactiveColor: _react.PropTypes.string.isRequired,
131 activeBackground: _react.PropTypes.string.isRequired,
132 inactiveBackground: _react.PropTypes.string.isRequired
133};
134exports.default = Tabs;
\No newline at end of file