1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; }();
|
8 |
|
9 | var _style = require('./style.css');
|
10 |
|
11 | var _style2 = _interopRequireDefault(_style);
|
12 |
|
13 | var _each = require('lodash/each');
|
14 |
|
15 | var _each2 = _interopRequireDefault(_each);
|
16 |
|
17 | var _flag = require('../flag');
|
18 |
|
19 | var Flags = _interopRequireWildcard(_flag);
|
20 |
|
21 | var _tableItem = require('../table-item');
|
22 |
|
23 | var _tableItem2 = _interopRequireDefault(_tableItem);
|
24 |
|
25 | var _react = require('react');
|
26 |
|
27 | var _react2 = _interopRequireDefault(_react);
|
28 |
|
29 | var _reactAddonsShallowCompare = require('react-addons-shallow-compare');
|
30 |
|
31 | var _reactAddonsShallowCompare2 = _interopRequireDefault(_reactAddonsShallowCompare);
|
32 |
|
33 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
34 |
|
35 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36 |
|
37 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
38 |
|
39 | 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; }
|
40 |
|
41 | 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; }
|
42 |
|
43 | var Body = function (_Component) {
|
44 | _inherits(Body, _Component);
|
45 |
|
46 | function Body() {
|
47 | var _ref;
|
48 |
|
49 | var _temp, _this, _ret;
|
50 |
|
51 | _classCallCheck(this, Body);
|
52 |
|
53 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
54 | args[_key] = arguments[_key];
|
55 | }
|
56 |
|
57 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Body.__proto__ || Object.getPrototypeOf(Body)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
58 | headerPosition: 0
|
59 | }, _this.step = function () {
|
60 | var top = _this.refs.component.getBoundingClientRect().top;
|
61 | var offset = top > 0 ? 0 : Math.abs(top);
|
62 | (0, _each2.default)(_this.headers, function (header) {
|
63 | header.style.transform = 'translateY(' + offset + 'px)';
|
64 | });
|
65 | _this.requestId = requestAnimationFrame(_this.step);
|
66 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
67 | }
|
68 |
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | _createClass(Body, [{
|
84 | key: 'componentDidMount',
|
85 |
|
86 |
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 | value: function componentDidMount() {
|
93 | this.headers = this.refs.component.querySelectorAll('tr > th');
|
94 | this.requestId = requestAnimationFrame(this.step);
|
95 | }
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | }, {
|
106 | key: 'shouldComponentUpdate',
|
107 | value: function shouldComponentUpdate(nextProps, nextState) {
|
108 | return (0, _reactAddonsShallowCompare2.default)(this, nextProps, nextState);
|
109 | }
|
110 |
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | }, {
|
118 | key: 'componentWillUnmount',
|
119 | value: function componentWillUnmount() {
|
120 | cancelAnimationFrame(this.requestId);
|
121 | }
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | }, {
|
130 | key: 'getWidth',
|
131 | value: function getWidth() {
|
132 | return {
|
133 | scrollWidth: this.refs.component.scrollWidth,
|
134 | width: this.refs.component.getBoundingClientRect().width
|
135 | };
|
136 | }
|
137 |
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | }, {
|
145 | key: 'render',
|
146 |
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 | value: function render() {
|
154 | var _this2 = this;
|
155 |
|
156 | return _react2.default.createElement(
|
157 | 'tbody',
|
158 | { ref: 'component', className: _style2.default.body, onScroll: this.props.onScroll },
|
159 | this.props.countries.map(function (country) {
|
160 | return _react2.default.createElement(
|
161 | 'tr',
|
162 | {
|
163 | key: country,
|
164 | style: { position: 'relative' },
|
165 | className: [_style2.default.column, _style2.default.body_column].join(' ')
|
166 | },
|
167 | _react2.default.createElement(
|
168 | 'th',
|
169 | { className: _style2.default.body_header },
|
170 | _react2.default.createElement(Flags[country], { height: 20 })
|
171 | ),
|
172 | _this2.props.entries.map(function (entry) {
|
173 | return _react2.default.createElement(
|
174 | _tableItem2.default,
|
175 | {
|
176 | align: 'center',
|
177 | key: entry.id,
|
178 | className: _style2.default.body_item
|
179 | },
|
180 | entry.votes[country] || '.'
|
181 | );
|
182 | })
|
183 | );
|
184 | })
|
185 | );
|
186 | }
|
187 | }]);
|
188 |
|
189 | return Body;
|
190 | }(_react.Component);
|
191 |
|
192 | Body.propTypes = {
|
193 | onScroll: _react.PropTypes.func.isRequired,
|
194 | entries: _react.PropTypes.array.isRequired,
|
195 | countries: _react.PropTypes.array.isRequired
|
196 | };
|
197 | exports.default = Body; |
\ | No newline at end of file |