1 | Object.defineProperty(exports, "__esModule", {
|
2 | value: true
|
3 | });
|
4 | exports.DIRECTIONS = undefined;
|
5 |
|
6 | var _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; }; }();
|
7 |
|
8 | var _propTypes = require('prop-types');
|
9 |
|
10 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
11 |
|
12 | var _react = require('react');
|
13 |
|
14 | var _react2 = _interopRequireDefault(_react);
|
15 |
|
16 | var _airbnbPropTypes = require('airbnb-prop-types');
|
17 |
|
18 | var _brcast = require('brcast');
|
19 |
|
20 | var _brcast2 = _interopRequireDefault(_brcast);
|
21 |
|
22 | var _brcast3 = require('./proptypes/brcast');
|
23 |
|
24 | var _brcast4 = _interopRequireDefault(_brcast3);
|
25 |
|
26 | var _direction = require('./proptypes/direction');
|
27 |
|
28 | var _direction2 = _interopRequireDefault(_direction);
|
29 |
|
30 | var _constants = require('./constants');
|
31 |
|
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
33 |
|
34 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
35 |
|
36 | function _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; }
|
37 |
|
38 | function _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; }
|
39 |
|
40 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
41 |
|
42 |
|
43 |
|
44 | var propTypes = (0, _airbnbPropTypes.forbidExtraProps)({
|
45 | children: _propTypes2['default'].node.isRequired,
|
46 | direction: _direction2['default'].isRequired
|
47 | });
|
48 |
|
49 | var childContextTypes = _defineProperty({}, _constants.CHANNEL, _brcast4['default']);
|
50 |
|
51 | exports.DIRECTIONS = _constants.DIRECTIONS;
|
52 |
|
53 | var DirectionProvider = function (_React$Component) {
|
54 | _inherits(DirectionProvider, _React$Component);
|
55 |
|
56 | function DirectionProvider(props) {
|
57 | _classCallCheck(this, DirectionProvider);
|
58 |
|
59 | var _this = _possibleConstructorReturn(this, (DirectionProvider.__proto__ || Object.getPrototypeOf(DirectionProvider)).call(this, props));
|
60 |
|
61 | _this.broadcast = (0, _brcast2['default'])(props.direction);
|
62 | return _this;
|
63 | }
|
64 |
|
65 | _createClass(DirectionProvider, [{
|
66 | key: 'getChildContext',
|
67 | value: function () {
|
68 | function getChildContext() {
|
69 | return _defineProperty({}, _constants.CHANNEL, this.broadcast);
|
70 | }
|
71 |
|
72 | return getChildContext;
|
73 | }()
|
74 | }, {
|
75 | key: 'componentWillReceiveProps',
|
76 | value: function () {
|
77 | function componentWillReceiveProps(nextProps) {
|
78 | if (this.props.direction !== nextProps.direction) {
|
79 | this.broadcast.setState(nextProps.direction);
|
80 | }
|
81 | }
|
82 |
|
83 | return componentWillReceiveProps;
|
84 | }()
|
85 | }, {
|
86 | key: 'render',
|
87 | value: function () {
|
88 | function render() {
|
89 | var _props = this.props,
|
90 | children = _props.children,
|
91 | direction = _props.direction;
|
92 |
|
93 | return _react2['default'].createElement(
|
94 | 'div',
|
95 | { dir: direction },
|
96 | _react2['default'].Children.only(children)
|
97 | );
|
98 | }
|
99 |
|
100 | return render;
|
101 | }()
|
102 | }]);
|
103 |
|
104 | return DirectionProvider;
|
105 | }(_react2['default'].Component);
|
106 |
|
107 | exports['default'] = DirectionProvider;
|
108 |
|
109 |
|
110 | DirectionProvider.propTypes = propTypes;
|
111 | DirectionProvider.childContextTypes = childContextTypes; |
\ | No newline at end of file |