@twreporter/universal-header 2.2.0-rc.5
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.
- package/CHANGELOG.md +302 -0
- package/LICENSE +21 -0
- package/README.md +223 -0
- package/lib/actions/auth.js +105 -0
- package/lib/actions/error-action-creators.js +162 -0
- package/lib/components/action-button.js +216 -0
- package/lib/components/channels.js +420 -0
- package/lib/components/customized-link.js +49 -0
- package/lib/components/drop-down-menu.js +138 -0
- package/lib/components/hamburger-icons.js +270 -0
- package/lib/components/hamburger-menu.js +152 -0
- package/lib/components/header.js +233 -0
- package/lib/components/icons.js +276 -0
- package/lib/components/mobile-header.js +264 -0
- package/lib/components/search-box.js +214 -0
- package/lib/components/slogan.js +57 -0
- package/lib/constants/action-types.js +14 -0
- package/lib/constants/actions.js +35 -0
- package/lib/constants/categories.js +32 -0
- package/lib/constants/channels.js +41 -0
- package/lib/constants/colors.js +17 -0
- package/lib/constants/external-links.js +13 -0
- package/lib/constants/fonts.js +32 -0
- package/lib/constants/prop-types.js +46 -0
- package/lib/constants/services.js +31 -0
- package/lib/constants/slogan.js +9 -0
- package/lib/constants/theme.js +13 -0
- package/lib/containers/header.js +375 -0
- package/lib/contexts/header-context.js +17 -0
- package/lib/index.js +18 -0
- package/lib/reducers/auth.js +109 -0
- package/lib/reducers/index.js +22 -0
- package/lib/standalone-header.js +110 -0
- package/lib/utils/animations.js +32 -0
- package/lib/utils/icon.js +905 -0
- package/lib/utils/jwt.js +37 -0
- package/lib/utils/links.js +177 -0
- package/lib/utils/theme.js +415 -0
- package/package.json +38 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
9
|
+
|
|
10
|
+
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
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); }
|
|
15
|
+
|
|
16
|
+
var _ = {
|
|
17
|
+
get: _get["default"],
|
|
18
|
+
merge: _merge["default"]
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Refine Axios config to remain the infomative properties.
|
|
22
|
+
* @param {Object} axiosConfig - config provied by Axios
|
|
23
|
+
* @return {Object} - empty object or the object containing the following properties
|
|
24
|
+
* 'url',
|
|
25
|
+
* 'method' ,
|
|
26
|
+
* 'baseURL',
|
|
27
|
+
* 'headers',
|
|
28
|
+
* 'params',
|
|
29
|
+
* 'timeout',
|
|
30
|
+
* 'withCredentials',
|
|
31
|
+
* 'auth',
|
|
32
|
+
* 'responseType',
|
|
33
|
+
* 'responseEncoding',
|
|
34
|
+
* 'maxContentLength',
|
|
35
|
+
* 'proxy'
|
|
36
|
+
*
|
|
37
|
+
* For other removed properties,
|
|
38
|
+
* see https://github.com/axios/axios#request-config
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
function refineAxiosConfig(axiosConfig) {
|
|
42
|
+
if (_typeof(axiosConfig) === 'object' && axiosConfig !== null) {
|
|
43
|
+
return {
|
|
44
|
+
// request url
|
|
45
|
+
url: axiosConfig.url,
|
|
46
|
+
// requst method
|
|
47
|
+
method: axiosConfig.method,
|
|
48
|
+
// request baseURL
|
|
49
|
+
baseURL: axiosConfig.baseURL,
|
|
50
|
+
// request headers
|
|
51
|
+
headers: axiosConfig.headers,
|
|
52
|
+
// request query params
|
|
53
|
+
params: axiosConfig.params,
|
|
54
|
+
// request data
|
|
55
|
+
data: axiosConfig.data,
|
|
56
|
+
// request timeout
|
|
57
|
+
timeout: axiosConfig.timeout,
|
|
58
|
+
withCredentials: axiosConfig.withCredentials,
|
|
59
|
+
auth: axiosConfig.auth,
|
|
60
|
+
responseType: axiosConfig.responseType,
|
|
61
|
+
responseEncoding: axiosConfig.responseEncoding,
|
|
62
|
+
maxContentLength: axiosConfig.maxContentLength,
|
|
63
|
+
proxy: axiosConfig.proxy
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Axios Error object
|
|
71
|
+
* @typedef {Error} AxiosError
|
|
72
|
+
* @property {Function} toJSON
|
|
73
|
+
* @property {Object} config - Axios config
|
|
74
|
+
* @property {Object} request - Axios request
|
|
75
|
+
* @property {Object} response- Axios response
|
|
76
|
+
* @property {bool} isAxiosError
|
|
77
|
+
* @property {string} message - Error message
|
|
78
|
+
* @property {string} stack - Error stack
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Refined Axios error object type definition
|
|
83
|
+
* We only pick certain properties of Axios error to log
|
|
84
|
+
* because of the record size limitation (250kb) of
|
|
85
|
+
* Stackdriver logging system.
|
|
86
|
+
* @typedef {Error} RefinedAxiosError
|
|
87
|
+
* @property {Object} config - Refined Axios config object
|
|
88
|
+
* @property {Object} data - Server response body
|
|
89
|
+
* @property {Object} headers - Server response headers
|
|
90
|
+
* @property {number} statusCode - Response status code
|
|
91
|
+
* @property {string} message - Error message
|
|
92
|
+
* @property {string} name - Error name
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Error rejected from Axios contains many details
|
|
97
|
+
* which we might not need.
|
|
98
|
+
* Therefore, we need to remove those properties
|
|
99
|
+
* to maintain a neat and informative object.
|
|
100
|
+
*
|
|
101
|
+
* @param {AxiosError} err - Axios Error object
|
|
102
|
+
* @return {RefinedAxiosError}
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
function refineAxiosError(err) {
|
|
107
|
+
var config = refineAxiosConfig(_.get(err, 'config'));
|
|
108
|
+
var data = null;
|
|
109
|
+
var statusCode = 500; // internal server error
|
|
110
|
+
|
|
111
|
+
var headers = null;
|
|
112
|
+
|
|
113
|
+
var message = _.get(err, 'message');
|
|
114
|
+
|
|
115
|
+
if (err.response) {
|
|
116
|
+
data = _.get(err, 'response.data');
|
|
117
|
+
statusCode = _.get(err, 'response.status');
|
|
118
|
+
headers = _.get(err, 'response.headers');
|
|
119
|
+
} else if (err.request) {
|
|
120
|
+
message = 'A request was made but no response was received: ' + message;
|
|
121
|
+
} else {
|
|
122
|
+
message = 'An error occured when setting up the request: ' + message;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var refinedErr = new Error(message);
|
|
126
|
+
refinedErr.name = 'AxiosError';
|
|
127
|
+
refinedErr.data = data;
|
|
128
|
+
refinedErr.statusCode = statusCode;
|
|
129
|
+
refinedErr.headers = headers;
|
|
130
|
+
refinedErr.config = config;
|
|
131
|
+
return refinedErr;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* error action type definition
|
|
135
|
+
* @typedef {Object} ErrorAction
|
|
136
|
+
* @property {string} type - Action error type
|
|
137
|
+
* @property {RefinedAxiosError} payload
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create an action which carefully records the details about the error.
|
|
142
|
+
* @param {AxiosError} [err={}] - Axios Error
|
|
143
|
+
* @param {string} failActionType
|
|
144
|
+
* @returns {ErrorAction}
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
function createAxiosErrorAction() {
|
|
149
|
+
var err = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
150
|
+
var failActionType = arguments.length > 1 ? arguments[1] : undefined;
|
|
151
|
+
return {
|
|
152
|
+
type: failActionType,
|
|
153
|
+
payload: {
|
|
154
|
+
error: refineAxiosError(err)
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var _default = {
|
|
160
|
+
axios: createAxiosErrorAction
|
|
161
|
+
};
|
|
162
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
+
|
|
14
|
+
var _css = require("@twreporter/core/lib/utils/css");
|
|
15
|
+
|
|
16
|
+
var _headerContext = _interopRequireDefault(require("../contexts/header-context"));
|
|
17
|
+
|
|
18
|
+
var _fonts = _interopRequireDefault(require("../constants/fonts"));
|
|
19
|
+
|
|
20
|
+
var _colors = _interopRequireDefault(require("../constants/colors"));
|
|
21
|
+
|
|
22
|
+
var _actions = _interopRequireDefault(require("../constants/actions"));
|
|
23
|
+
|
|
24
|
+
var _links = _interopRequireDefault(require("../utils/links"));
|
|
25
|
+
|
|
26
|
+
var _theme = _interopRequireDefault(require("../utils/theme"));
|
|
27
|
+
|
|
28
|
+
var _customizedLink = _interopRequireDefault(require("./customized-link"));
|
|
29
|
+
|
|
30
|
+
var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
|
|
31
|
+
|
|
32
|
+
var _map = _interopRequireDefault(require("lodash/map"));
|
|
33
|
+
|
|
34
|
+
var _excluded = ["actions", "direction"];
|
|
35
|
+
|
|
36
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
37
|
+
|
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
39
|
+
|
|
40
|
+
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); }
|
|
41
|
+
|
|
42
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
43
|
+
|
|
44
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
45
|
+
|
|
46
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
47
|
+
|
|
48
|
+
var _ = {
|
|
49
|
+
map: _map["default"]
|
|
50
|
+
};
|
|
51
|
+
var styles = {
|
|
52
|
+
itemWidth: {
|
|
53
|
+
mobile: {
|
|
54
|
+
row: '48px',
|
|
55
|
+
column: '100%'
|
|
56
|
+
},
|
|
57
|
+
tablet: {
|
|
58
|
+
row: '70px',
|
|
59
|
+
column: '100%'
|
|
60
|
+
},
|
|
61
|
+
desktop: '70px'
|
|
62
|
+
},
|
|
63
|
+
itemHeight: {
|
|
64
|
+
mobile: {
|
|
65
|
+
row: 24,
|
|
66
|
+
// px
|
|
67
|
+
column: 40 // px
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
tablet: {
|
|
71
|
+
row: 30,
|
|
72
|
+
// px
|
|
73
|
+
column: 40 // px
|
|
74
|
+
|
|
75
|
+
},
|
|
76
|
+
desktop: 30 // px
|
|
77
|
+
|
|
78
|
+
},
|
|
79
|
+
itemMargin: {
|
|
80
|
+
row: [0, 0, 0, 10],
|
|
81
|
+
// px
|
|
82
|
+
column: [7, 0, 0, 0] // px
|
|
83
|
+
|
|
84
|
+
},
|
|
85
|
+
fontSize: {
|
|
86
|
+
mobile: {
|
|
87
|
+
row: _fonts["default"].size.small,
|
|
88
|
+
column: _fonts["default"].size.medium
|
|
89
|
+
},
|
|
90
|
+
tablet: {
|
|
91
|
+
row: _fonts["default"].size.base,
|
|
92
|
+
column: _fonts["default"].size.medium
|
|
93
|
+
},
|
|
94
|
+
desktop: _fonts["default"].size.base
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var ActionsContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
99
|
+
displayName: "action-button__ActionsContainer",
|
|
100
|
+
componentId: "sc-4wc24t-0"
|
|
101
|
+
})(["display:flex;align-items:center;flex-direction:", ";width:100%;"], function (props) {
|
|
102
|
+
return props.direction;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
var ActionContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
106
|
+
displayName: "action-button__ActionContainer",
|
|
107
|
+
componentId: "sc-4wc24t-1"
|
|
108
|
+
})(["transition:opacity 0.3s;transition-delay:400ms;opacity:", ";margin:", ";width:100%;&:first-child{margin-top:0;margin-left:0;}a,a:link,a:visited{color:", ";font-size:", ";font-weight:", ";", " ", "}"], function (props) {
|
|
109
|
+
return props.isActive ? 1 : 0;
|
|
110
|
+
}, function (props) {
|
|
111
|
+
return (0, _css.arrayToCssShorthand)(styles.itemMargin[props.direction]);
|
|
112
|
+
}, function (props) {
|
|
113
|
+
return props.color || _colors["default"].white;
|
|
114
|
+
}, styles.fontSize.desktop, _fonts["default"].weight.bold, _mediaQuery["default"].tabletOnly(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-size: ", ";\n "])), function (props) {
|
|
115
|
+
return styles.fontSize.tablet[props.direction];
|
|
116
|
+
}), _mediaQuery["default"].mobileOnly(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n font-size: ", ";\n "])), function (props) {
|
|
117
|
+
return styles.fontSize.mobile[props.direction];
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
var ActionItem = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
121
|
+
displayName: "action-button__ActionItem",
|
|
122
|
+
componentId: "sc-4wc24t-2"
|
|
123
|
+
})(["background-color:", ";width:", ";max-width:316px;height:", "px;border-radius:50px;display:flex;align-items:center;justify-content:center;margin:0 auto;&:hover{background-color:", ";}", " ", ""], function (props) {
|
|
124
|
+
return props.bgColor || _colors["default"].red;
|
|
125
|
+
}, styles.itemWidth.desktop, styles.itemHeight.desktop, function (props) {
|
|
126
|
+
return props.hoverBgColor || _colors["default"].red;
|
|
127
|
+
}, _mediaQuery["default"].tabletOnly(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n height: ", "px;\n width: ", ";\n "])), function (props) {
|
|
128
|
+
return styles.itemHeight.tablet[props.direction];
|
|
129
|
+
}, function (props) {
|
|
130
|
+
return styles.itemWidth.tablet[props.direction];
|
|
131
|
+
}), _mediaQuery["default"].mobileOnly(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n height: ", "px;\n width: ", ";\n "])), function (props) {
|
|
132
|
+
return styles.itemHeight.mobile[props.direction];
|
|
133
|
+
}, function (props) {
|
|
134
|
+
return styles.itemWidth.mobile[props.direction];
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
var ActionButtonItem = function ActionButtonItem(_ref) {
|
|
138
|
+
var _action$active;
|
|
139
|
+
|
|
140
|
+
var action = _ref.action,
|
|
141
|
+
direction = _ref.direction,
|
|
142
|
+
themeFunction = _ref.themeFunction,
|
|
143
|
+
callback = _ref.callback;
|
|
144
|
+
var actionKey = action.key;
|
|
145
|
+
var isActive = (_action$active = action.active) !== null && _action$active !== void 0 ? _action$active : true;
|
|
146
|
+
var actionLabel = _actions["default"].actionLabels[actionKey];
|
|
147
|
+
|
|
148
|
+
var actionLink = _links["default"].getActionLinks()[actionKey];
|
|
149
|
+
|
|
150
|
+
return /*#__PURE__*/_react["default"].createElement(_headerContext["default"].Consumer, null, function (_ref2) {
|
|
151
|
+
var theme = _ref2.theme;
|
|
152
|
+
|
|
153
|
+
var _themeFunction = themeFunction(theme),
|
|
154
|
+
color = _themeFunction.color,
|
|
155
|
+
bgColor = _themeFunction.bgColor,
|
|
156
|
+
hoverBgColor = _themeFunction.hoverBgColor;
|
|
157
|
+
|
|
158
|
+
return /*#__PURE__*/_react["default"].createElement(ActionContainer, {
|
|
159
|
+
color: color,
|
|
160
|
+
direction: direction,
|
|
161
|
+
isActive: isActive,
|
|
162
|
+
onClick: callback
|
|
163
|
+
}, /*#__PURE__*/_react["default"].createElement(_customizedLink["default"], actionLink, /*#__PURE__*/_react["default"].createElement(ActionItem, {
|
|
164
|
+
direction: direction,
|
|
165
|
+
bgColor: bgColor,
|
|
166
|
+
hoverBgColor: hoverBgColor
|
|
167
|
+
}, actionLabel)));
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
ActionButtonItem.propTypes = {
|
|
172
|
+
action: _propTypes["default"].shape({
|
|
173
|
+
key: _propTypes["default"].string,
|
|
174
|
+
active: _propTypes["default"]["boolean"]
|
|
175
|
+
}),
|
|
176
|
+
direction: _propTypes["default"].string,
|
|
177
|
+
themeFunction: _propTypes["default"].func,
|
|
178
|
+
callback: _propTypes["default"].func
|
|
179
|
+
};
|
|
180
|
+
ActionButtonItem.defaultProps = {
|
|
181
|
+
action: {},
|
|
182
|
+
direction: 'row',
|
|
183
|
+
themeFunction: _theme["default"].selectActionButtonTheme,
|
|
184
|
+
callback: function callback() {}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
var ActionButton = function ActionButton(_ref3) {
|
|
188
|
+
var actions = _ref3.actions,
|
|
189
|
+
direction = _ref3.direction,
|
|
190
|
+
rest = _objectWithoutProperties(_ref3, _excluded);
|
|
191
|
+
|
|
192
|
+
return /*#__PURE__*/_react["default"].createElement(ActionsContainer, {
|
|
193
|
+
direction: direction
|
|
194
|
+
}, _.map(actions, function (action) {
|
|
195
|
+
return /*#__PURE__*/_react["default"].createElement(ActionButtonItem, _extends({
|
|
196
|
+
action: action,
|
|
197
|
+
direction: direction,
|
|
198
|
+
key: action.key
|
|
199
|
+
}, rest));
|
|
200
|
+
}));
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
ActionButton.propTypes = {
|
|
204
|
+
actions: _propTypes["default"].arrayOf(_propTypes["default"].shape(ActionButtonItem.propTypes)),
|
|
205
|
+
direction: _propTypes["default"].string,
|
|
206
|
+
themeFunction: _propTypes["default"].func,
|
|
207
|
+
callback: _propTypes["default"].func
|
|
208
|
+
};
|
|
209
|
+
ActionButton.defaultProps = {
|
|
210
|
+
actions: [],
|
|
211
|
+
direction: 'row',
|
|
212
|
+
themeFunction: _theme["default"].selectActionButtonTheme,
|
|
213
|
+
callback: function callback() {}
|
|
214
|
+
};
|
|
215
|
+
var _default = ActionButton;
|
|
216
|
+
exports["default"] = _default;
|