@twreporter/universal-header 2.6.0 → 2.6.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,420 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _CSSTransition = _interopRequireDefault(require("react-transition-group/CSSTransition"));
15
-
16
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
17
-
18
- var _headerContext = _interopRequireDefault(require("../contexts/header-context"));
19
-
20
- var _themeOld = _interopRequireDefault(require("../utils/theme-old"));
21
-
22
- var _propTypesOld = _interopRequireDefault(require("../constants/prop-types-old"));
23
-
24
- var _channelsOld = require("../constants/channels-old");
25
-
26
- var _fonts = _interopRequireDefault(require("../constants/fonts"));
27
-
28
- var _dropDownMenu = _interopRequireDefault(require("./drop-down-menu"));
29
-
30
- var _customizedLink = _interopRequireDefault(require("./customized-link"));
31
-
32
- var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
33
-
34
- var _css = require("@twreporter/core/lib/utils/css");
35
-
36
- var _color = require("@twreporter/core/lib/constants/color");
37
-
38
- var _get = _interopRequireDefault(require("lodash/get"));
39
-
40
- var _map = _interopRequireDefault(require("lodash/map"));
41
-
42
- var _templateObject;
43
-
44
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
45
-
46
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47
-
48
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
49
-
50
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
51
-
52
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
53
-
54
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
55
-
56
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
57
-
58
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
59
-
60
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
61
-
62
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
63
-
64
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
65
-
66
- 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); } }
67
-
68
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
69
-
70
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
71
-
72
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
73
-
74
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
75
-
76
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
77
-
78
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
79
-
80
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
81
-
82
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
83
-
84
- 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; }
85
-
86
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
87
-
88
- var _ = {
89
- get: _get["default"],
90
- map: _map["default"]
91
- };
92
- var styles = {
93
- itemMargin: {
94
- desktop: 0
95
- },
96
- itemPadding: {
97
- row: [8, 16],
98
- // px
99
- column: [20, 32] // px
100
-
101
- },
102
- itemWidth: {
103
- row: 'initial',
104
- column: '100%'
105
- },
106
- itemBorderWidth: {
107
- row: [0, 0, 0, 1],
108
- column: [0, 0, 1, 0]
109
- },
110
- itemBorderWidthFirstChild: {
111
- row: [0, 0, 0, 0],
112
- column: [1, 0, 1, 0]
113
- },
114
- dropdownPosition: {
115
- row: 'absolute',
116
- column: 'relative'
117
- },
118
- dropdownTop: {
119
- row: "calc(100% + 1px)",
120
- column: 0
121
- }
122
- };
123
- var dropDownMenuEffectCSS = /*#__PURE__*/(0, _styledComponents.css)([".effect-enter{max-height:0;}.effect-enter-active{max-height:400px;transition:max-height 400ms ease-in 100ms;}"]);
124
-
125
- var DropDownMenuWrapper = /*#__PURE__*/_styledComponents["default"].div.withConfig({
126
- displayName: "channels-old__DropDownMenuWrapper",
127
- componentId: "sc-69i48b-0"
128
- })(["position:", ";z-index:999;width:100%;left:0;top:", ";", ""], function (props) {
129
- return styles.dropdownPosition[props.direction];
130
- }, function (props) {
131
- return styles.dropdownTop[props.direction];
132
- }, dropDownMenuEffectCSS);
133
-
134
- var Box = /*#__PURE__*/_styledComponents["default"].div.withConfig({
135
- displayName: "channels-old__Box",
136
- componentId: "sc-69i48b-1"
137
- })(["width:100%;height:100%;"]);
138
-
139
- var List = /*#__PURE__*/_styledComponents["default"].ul.withConfig({
140
- displayName: "channels-old__List",
141
- componentId: "sc-69i48b-2"
142
- })(["height:100%;justify-content:space-between;background-color:", ";user-select:none;box-sizing:border-box;display:flex;flex-direction:", ";flex-wrap:nowrap;align-items:center;list-style-type:none;margin:auto;padding-inline-start:0;border-color:", ";border-width:", ";border-style:solid;"], function (props) {
143
- return props.bgColor || 'white';
144
- }, function (props) {
145
- return props.direction;
146
- }, function (props) {
147
- return props.borderColor || _color.colorGrayscale.gray200;
148
- }, function (props) {
149
- return (0, _css.arrayToCssShorthand)(props.borderWidth);
150
- });
151
-
152
- var ListItem = /*#__PURE__*/_styledComponents["default"].li.withConfig({
153
- displayName: "channels-old__ListItem",
154
- componentId: "sc-69i48b-3"
155
- })(["display:flex;flex-direction:", ";position:relative;width:", ";height:100%;font-size:", ";letter-spacing:0.5px;margin:", ";flex:1;text-shadow:", ";border-style:solid;border-color:inherit;border-width:", ";&:first-child{border-width:", ";}a,a:link,a:visited{display:flex;justify-content:space-between;align-items:center;font-size:", ";font-weight:", ";padding:", ";width:100%;color:", ";border:0;line-height:18px;&:hover{background-color:", ";color:", ";}", "}"], function (props) {
156
- return props.direction;
157
- }, function (props) {
158
- return styles.itemWidth[props.direction];
159
- }, _fonts["default"].size.base, (0, _css.arrayToCssShorthand)(styles.itemMargin.desktop), function (props) {
160
- return props.textShadow;
161
- }, function (props) {
162
- return (0, _css.arrayToCssShorthand)(styles.itemBorderWidth[props.direction]);
163
- }, function (props) {
164
- return (0, _css.arrayToCssShorthand)(styles.itemBorderWidthFirstChild[props.direction]);
165
- }, _fonts["default"].size.base, _fonts["default"].weight.bold, function (props) {
166
- return (0, _css.arrayToCssShorthand)(styles.itemPadding[props.direction]);
167
- }, function (props) {
168
- return props.fontColor;
169
- }, function (props) {
170
- return props.hoverBgColor;
171
- }, function (props) {
172
- return props.hoverFontColor;
173
- }, _mediaQuery["default"].tabletAndBelow(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: default;\n "]))));
174
-
175
- var ShowOnHover = /*#__PURE__*/_styledComponents["default"].div.withConfig({
176
- displayName: "channels-old__ShowOnHover",
177
- componentId: "sc-69i48b-4"
178
- })(["display:none;", ":hover &{display:flex;}"], ListItem);
179
-
180
- var HideOnHover = /*#__PURE__*/_styledComponents["default"].div.withConfig({
181
- displayName: "channels-old__HideOnHover",
182
- componentId: "sc-69i48b-5"
183
- })(["display:flex;", ":hover &{display:none;}"], ListItem);
184
-
185
- var invalidDataIndex = -1;
186
- var dropDownMenuKey = 'dropDownMenu';
187
-
188
- var Channels = /*#__PURE__*/function (_React$PureComponent) {
189
- _inherits(Channels, _React$PureComponent);
190
-
191
- var _super = _createSuper(Channels);
192
-
193
- function Channels(props) {
194
- var _this;
195
-
196
- _classCallCheck(this, Channels);
197
-
198
- _this = _super.call(this, props);
199
- _this.state = {
200
- activeDataIndex: _this._checkWhichChannelActive(props.currentPathname),
201
- activeDropdownIndex: invalidDataIndex
202
- };
203
- _this.handleDropDownChannelClick = _this._handleDropDownChannelClick.bind(_assertThisInitialized(_this));
204
- _this.handleNormalChannelClick = _this._handleNormalChannelClick.bind(_assertThisInitialized(_this));
205
- _this.handleDropDownMenuClick = _this._handleDropDownMenuClick.bind(_assertThisInitialized(_this));
206
- _this.callback = _this._callback.bind(_assertThisInitialized(_this));
207
- return _this;
208
- }
209
-
210
- _createClass(Channels, [{
211
- key: "componentDidUpdate",
212
- value: function componentDidUpdate() {
213
- if (this.context.hideHeader) {
214
- this.setState({
215
- activeDropdownIndex: invalidDataIndex
216
- });
217
- }
218
- }
219
- }, {
220
- key: "_checkWhichChannelActive",
221
- value: function _checkWhichChannelActive(currentPathname) {
222
- var data = this.props.data;
223
- var activeChannelIndex = invalidDataIndex;
224
-
225
- for (var channelIndex = 0; channelIndex < data.length; channelIndex += 1) {
226
- var channelItem = data[channelIndex];
227
-
228
- if (currentPathname === channelItem.pathname) {
229
- activeChannelIndex = channelIndex;
230
- break;
231
- }
232
-
233
- if (channelItem.hasOwnProperty(dropDownMenuKey)) {
234
- var dropDownMenuArr = channelItem[dropDownMenuKey];
235
-
236
- for (var dropDownIndex = 0; dropDownIndex < dropDownMenuArr.length; dropDownIndex += 1) {
237
- if (dropDownMenuArr[dropDownIndex].pathname === currentPathname) {
238
- activeChannelIndex = channelIndex;
239
- break;
240
- }
241
- }
242
-
243
- if (activeChannelIndex !== invalidDataIndex) {
244
- break;
245
- }
246
- }
247
- }
248
-
249
- return activeChannelIndex;
250
- }
251
- }, {
252
- key: "_handleDropDownChannelClick",
253
- value: function _handleDropDownChannelClick(e, channelIndex) {
254
- e.preventDefault();
255
- var activeDropdownIndex = this.state.activeDropdownIndex;
256
- var nextActiveDropdownIndex = channelIndex === activeDropdownIndex ? invalidDataIndex : channelIndex;
257
- this.setState({
258
- activeDropdownIndex: nextActiveDropdownIndex
259
- });
260
- }
261
- }, {
262
- key: "_handleNormalChannelClick",
263
- value: function _handleNormalChannelClick(channelIndex) {
264
- this.setState({
265
- activeDataIndex: channelIndex,
266
- activeDropdownIndex: invalidDataIndex
267
- });
268
- this.callback(channelIndex);
269
- }
270
- }, {
271
- key: "_handleDropDownMenuClick",
272
- value: function _handleDropDownMenuClick(parentIndex) {
273
- this.setState({
274
- activeDataIndex: parentIndex,
275
- activeDropdownIndex: invalidDataIndex
276
- });
277
- this.callback(parentIndex);
278
- }
279
- }, {
280
- key: "_callback",
281
- value: function _callback(dataIndex) {
282
- var currentActivePathname = dataIndex === invalidDataIndex ? '' : this.props.data[dataIndex].pathname;
283
- this.props.callback(currentActivePathname);
284
- }
285
- }, {
286
- key: "_prepareChannelItemJSX",
287
- value: function _prepareChannelItemJSX(channelItem, dataIndex, theme) {
288
- var _this2 = this;
289
-
290
- var channelLabel = channelItem.label;
291
- var channelType = channelItem.type;
292
- var channelLink = channelItem.link;
293
-
294
- if (channelType === _channelsOld.channelDropDownType) {
295
- var _this$props = this.props,
296
- data = _this$props.data,
297
- direction = _this$props.direction;
298
- var activeDropdownIndex = this.state.activeDropdownIndex;
299
- var toShowDropdownMenu = activeDropdownIndex === dataIndex;
300
-
301
- var dropdownMenuData = _.get(data, [dataIndex, dropDownMenuKey], []);
302
-
303
- var dropdownMenuJSX = /*#__PURE__*/_react["default"].createElement(DropDownMenuWrapper, {
304
- direction: direction
305
- }, /*#__PURE__*/_react["default"].createElement(_CSSTransition["default"], {
306
- "in": toShowDropdownMenu,
307
- classNames: "effect",
308
- timeout: 400,
309
- exit: false,
310
- mountOnEnter: true,
311
- unmountOnExit: true
312
- }, /*#__PURE__*/_react["default"].createElement(_dropDownMenu["default"], {
313
- data: dropdownMenuData,
314
- onClick: function onClick(e) {
315
- return _this2.handleDropDownMenuClick(dataIndex);
316
- }
317
- })));
318
-
319
- var status = toShowDropdownMenu ? 'collapse' : 'expand';
320
-
321
- var _themeUtils$selectIco = _slicedToArray(_themeOld["default"].selectIcons(theme)[status], 2),
322
- StatusIcon = _themeUtils$selectIco[0],
323
- StatusHoverIcon = _themeUtils$selectIco[1];
324
-
325
- var statusIconJSX = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(HideOnHover, null, /*#__PURE__*/_react["default"].createElement(StatusIcon, null)), /*#__PURE__*/_react["default"].createElement(ShowOnHover, null, /*#__PURE__*/_react["default"].createElement(StatusHoverIcon, null)));
326
-
327
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_customizedLink["default"], _extends({
328
- onClick: function onClick(e) {
329
- return _this2.handleDropDownChannelClick(e, dataIndex);
330
- }
331
- }, channelLink), channelLabel, statusIconJSX), dropdownMenuJSX);
332
- } else {
333
- return /*#__PURE__*/_react["default"].createElement(_customizedLink["default"], _extends({
334
- onClick: function onClick() {
335
- return _this2.handleNormalChannelClick(dataIndex);
336
- }
337
- }, channelLink), channelLabel);
338
- }
339
- }
340
- }, {
341
- key: "render",
342
- value: function render() {
343
- var _this3 = this;
344
-
345
- var _this$props2 = this.props,
346
- data = _this$props2.data,
347
- direction = _this$props2.direction,
348
- borderWidth = _this$props2.borderWidth,
349
- themeFunction = _this$props2.themeFunction;
350
-
351
- var channelsJSX = _.map(data, function (channelItem, dataIndex) {
352
- return /*#__PURE__*/_react["default"].createElement(_headerContext["default"].Consumer, {
353
- key: channelItem.key
354
- }, function (_ref) {
355
- var theme = _ref.theme;
356
-
357
- var _themeFunction = themeFunction(theme),
358
- fontColor = _themeFunction.fontColor,
359
- hoverFontColor = _themeFunction.hoverFontColor,
360
- hoverBgColor = _themeFunction.hoverBgColor;
361
-
362
- var channelItemJSX = _this3._prepareChannelItemJSX(channelItem, dataIndex, theme);
363
-
364
- return /*#__PURE__*/_react["default"].createElement(ListItem, {
365
- direction: direction,
366
- onClick: _this3.handleClickChannel,
367
- fontColor: fontColor,
368
- hoverFontColor: hoverFontColor,
369
- hoverBgColor: hoverBgColor
370
- }, channelItemJSX);
371
- });
372
- });
373
-
374
- return /*#__PURE__*/_react["default"].createElement(Box, null, /*#__PURE__*/_react["default"].createElement(_headerContext["default"].Consumer, null, function (_ref2) {
375
- var theme = _ref2.theme;
376
-
377
- var _themeFunction2 = themeFunction(theme),
378
- bgColor = _themeFunction2.bgColor,
379
- borderColor = _themeFunction2.borderColor;
380
-
381
- return /*#__PURE__*/_react["default"].createElement(List, {
382
- bgColor: bgColor,
383
- direction: direction,
384
- borderColor: borderColor,
385
- borderWidth: borderWidth
386
- }, channelsJSX);
387
- }));
388
- }
389
- }]);
390
-
391
- return Channels;
392
- }(_react["default"].PureComponent);
393
-
394
- _defineProperty(Channels, "propTypes", {
395
- currentPathname: _propTypes["default"].string.isRequired,
396
- data: _propTypes["default"].arrayOf(_propTypes["default"].shape(_defineProperty({
397
- key: _propTypes["default"].string,
398
- label: _propTypes["default"].string,
399
- link: _propTypes["default"].shape(_propTypesOld["default"].link.propTypes),
400
- pathname: _propTypes["default"].string,
401
- type: _propTypes["default"].oneOf([_channelsOld.channelDropDownType, _channelsOld.channelLinkType])
402
- }, dropDownMenuKey, _dropDownMenu["default"].propTypes.data))),
403
- direction: _propTypes["default"].string,
404
- borderWidth: _propTypes["default"].array,
405
- themeFunction: _propTypes["default"].func,
406
- callback: _propTypes["default"].func
407
- });
408
-
409
- _defineProperty(Channels, "defaultProps", {
410
- data: [],
411
- direction: 'row',
412
- borderWidth: [0, 0, 0, 0],
413
- themeFunction: _themeOld["default"].selectChannelTheme,
414
- callback: function callback() {}
415
- });
416
-
417
- _defineProperty(Channels, "contextType", _headerContext["default"]);
418
-
419
- var _default = Channels;
420
- exports["default"] = _default;