UNPKG

3.7 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
23function _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; }
24
25function _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; }
26
27function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
28
29var Container = _styledComponents2.default.div(_templateObject);
30
31var Tabs = function (_Component) {
32 _inherits(Tabs, _Component);
33
34 function Tabs() {
35 var _ref;
36
37 var _temp, _this, _ret;
38
39 _classCallCheck(this, Tabs);
40
41 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
42 args[_key] = arguments[_key];
43 }
44
45 return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Tabs.__proto__ || Object.getPrototypeOf(Tabs)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
46 currentTab: 0
47 }, _this.onTabClick = function (id) {
48 _this.setState({ currentTab: id });
49 }, _temp), _possibleConstructorReturn(_this, _ret);
50 }
51
52 /**
53 * Define the types of props the component accepts.
54 *
55 * @type {Object}
56 */
57
58
59 _createClass(Tabs, [{
60 key: 'getChildContext',
61 value: function getChildContext() {
62 return {
63 onTabClick: this.onTabClick,
64 currentTab: this.state.currentTab
65 };
66 }
67 }, {
68 key: 'render',
69
70
71 /**
72 * Render the component
73 *
74 * @return {ReactElement}
75 */
76 value: function render() {
77 return _react2.default.createElement(
78 Container,
79 null,
80 _react.Children.map(this.props.children, function (child, key) {
81 return (0, _react.cloneElement)(child, { key: key });
82 })
83 );
84 }
85 }]);
86
87 return Tabs;
88}(_react.Component);
89
90Tabs.propTypes = {
91 children: _react.PropTypes.node.isRequired
92};
93Tabs.childContextTypes = {
94 onTabClick: _react.PropTypes.func.isRequired,
95 currentTab: _react.PropTypes.number.isRequired
96};
97exports.default = Tabs;
\No newline at end of file