@twreporter/react-components 8.5.0-rc.1
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 +544 -0
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/lib/bookmark-list/bookmark.js +251 -0
- package/lib/bookmark-list/bookmarks.js +93 -0
- package/lib/bookmark-list/customized-link.js +45 -0
- package/lib/bookmark-list/image-wrapper.js +119 -0
- package/lib/bookmark-list/index.js +312 -0
- package/lib/bookmark-list/redirect-to-sign-in.js +35 -0
- package/lib/bookmark-widget/index.js +259 -0
- package/lib/confirmation/index.js +125 -0
- package/lib/donation-link.js +75 -0
- package/lib/error/index.js +17 -0
- package/lib/error/message.js +567 -0
- package/lib/footer/constants/paths.js +8 -0
- package/lib/footer/constants/styles.js +81 -0
- package/lib/footer/content.js +227 -0
- package/lib/footer/icon-list.js +191 -0
- package/lib/footer/index.js +123 -0
- package/lib/footer/logo.js +92 -0
- package/lib/is-fetching-wrapper.js +126 -0
- package/lib/link-with-tracker.js +153 -0
- package/lib/listing-page/components/image.js +185 -0
- package/lib/listing-page/components/list-item.js +197 -0
- package/lib/listing-page/components/list.js +188 -0
- package/lib/listing-page/components/topics/index.js +215 -0
- package/lib/listing-page/components/topics/page-content.js +44 -0
- package/lib/listing-page/components/topics/post-item.js +139 -0
- package/lib/listing-page/components/topics/posts.js +24 -0
- package/lib/listing-page/components/topics/section.js +104 -0
- package/lib/listing-page/components/topics/topic-item.js +206 -0
- package/lib/listing-page/constants/mockup-spec.js +39 -0
- package/lib/listing-page/constants/predefined-css.js +21 -0
- package/lib/listing-page/constants/topics.js +13 -0
- package/lib/listing-page/index.js +30 -0
- package/lib/mobile-pop-up-modal.js +161 -0
- package/lib/more.js +98 -0
- package/lib/pagination/index.js +310 -0
- package/lib/podcast-link.js +73 -0
- package/lib/side-bar/index.js +317 -0
- package/lib/table-of-contents/index.js +532 -0
- package/lib/utils/link-with-params.js +27 -0
- package/package.json +33 -0
|
@@ -0,0 +1,317 @@
|
|
|
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.AnchorWrapper = AnchorWrapper;
|
|
9
|
+
exports["default"] = void 0;
|
|
10
|
+
|
|
11
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
|
+
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
|
|
15
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
16
|
+
|
|
17
|
+
var _smoothscroll = _interopRequireDefault(require("smoothscroll"));
|
|
18
|
+
|
|
19
|
+
var _reactWaypoint = require("react-waypoint");
|
|
20
|
+
|
|
21
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
22
|
+
|
|
23
|
+
var _excluded = ["children"];
|
|
24
|
+
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
26
|
+
|
|
27
|
+
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); }
|
|
28
|
+
|
|
29
|
+
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; }
|
|
30
|
+
|
|
31
|
+
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; }
|
|
32
|
+
|
|
33
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
+
|
|
35
|
+
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); } }
|
|
36
|
+
|
|
37
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
38
|
+
|
|
39
|
+
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); }
|
|
40
|
+
|
|
41
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
42
|
+
|
|
43
|
+
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); }; }
|
|
44
|
+
|
|
45
|
+
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); }
|
|
46
|
+
|
|
47
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
48
|
+
|
|
49
|
+
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; } }
|
|
50
|
+
|
|
51
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
52
|
+
|
|
53
|
+
var _ = {
|
|
54
|
+
get: _get["default"]
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Get react component display name
|
|
58
|
+
*
|
|
59
|
+
* @param {object} DecoratedComponent
|
|
60
|
+
* @returns {string} display name of react component
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
function getDisplayName(DecoratedComponent) {
|
|
64
|
+
return DecoratedComponent.displayName || DecoratedComponent.name || 'Component';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function AnchorWrapper(_ref) {
|
|
68
|
+
var children = _ref.children;
|
|
69
|
+
return _react["default"].Children.only(children);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
AnchorWrapper.defaultProps = {
|
|
73
|
+
anchorLabel: '',
|
|
74
|
+
showAnchor: false
|
|
75
|
+
};
|
|
76
|
+
AnchorWrapper.propTypes = {
|
|
77
|
+
anchorId: _propTypes["default"].string.isRequired,
|
|
78
|
+
anchorLabel: _propTypes["default"].string,
|
|
79
|
+
showAnchor: _propTypes["default"].bool,
|
|
80
|
+
children: _propTypes["default"].element.isRequired
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* `decorateSideBar`
|
|
84
|
+
* returns a High Order Component adding the side bar functionalities onto `DecoratedComponent`.
|
|
85
|
+
* It passes props such as `currentAnchorId`, `handleClickAnchor` to the `DecoratedComponent`.
|
|
86
|
+
* `DecoratedSideBar` will map the anchor ids to the sections which are passed as React children,
|
|
87
|
+
* `currentAnchorId` indicates which section is in the viewport right now.
|
|
88
|
+
* `handleClickAnchor` is a function which can be used to scroll to the certain section.
|
|
89
|
+
*
|
|
90
|
+
* For example,
|
|
91
|
+
* ```
|
|
92
|
+
* // react component to render side bar
|
|
93
|
+
* const SideBar = ({anchors, currentAnchorId, handleClickAnchor}) => {
|
|
94
|
+
* const anchorsJSX = []
|
|
95
|
+
* anchors.ForEach((anchor) => {
|
|
96
|
+
* anchorsJSX.push(
|
|
97
|
+
* <div
|
|
98
|
+
* key={anchor.id}
|
|
99
|
+
* onClick={(e) => handleClickAnchor(anchor.id, e)}
|
|
100
|
+
* style={{color: currentAnchorId === anchor.id ? 'black' : 'white'}}
|
|
101
|
+
* >
|
|
102
|
+
* {anchor.label}
|
|
103
|
+
* </div>
|
|
104
|
+
* )
|
|
105
|
+
* })
|
|
106
|
+
* return (
|
|
107
|
+
* <div>
|
|
108
|
+
* {anchorsJSX}
|
|
109
|
+
* </div>
|
|
110
|
+
* )
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* const DecoratedSideBar = decoratedSideBar(SideBar)
|
|
114
|
+
*
|
|
115
|
+
* const SideBarWithContent = () => {
|
|
116
|
+
* return (
|
|
117
|
+
* <DecoratedSideBar>
|
|
118
|
+
* <AnchorWrapper anchorId="section-1" anchorLabel="Section One">
|
|
119
|
+
* <SectionOne />
|
|
120
|
+
* </AnchorWrapper>
|
|
121
|
+
* <AnchorWrapper anchorId="section-2" anchorLabel="Section Two">
|
|
122
|
+
* <SectionTwo />
|
|
123
|
+
* </AnchorWrapper>
|
|
124
|
+
* <AnchorWrapper anchorId="section-3" anchorLabel="Section Three">
|
|
125
|
+
* <SectionThree />
|
|
126
|
+
* </AnchorWrapper>
|
|
127
|
+
* </DecoratedSideBar>
|
|
128
|
+
* )
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
*
|
|
132
|
+
* The above codes will render three sections and side bar on the same page.
|
|
133
|
+
* When the section, like `SectionTwo`, scrolls into the viewport,
|
|
134
|
+
* the anchor of that section(`Section Two`) will be black, and others will be white.
|
|
135
|
+
*
|
|
136
|
+
* And when user click the anchor, say if `Secetion Two`, the browser will auto scroll to `SectionTwo`,
|
|
137
|
+
* and anchor `Section Two` will be black.
|
|
138
|
+
*
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} DecoratedComponent A React component wants to have side bar functionality
|
|
142
|
+
* @returns {Object} A React component with side bar functionalities
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
function decorateSideBar(DecoratedComponent) {
|
|
146
|
+
var firstSection = 'first';
|
|
147
|
+
var lastSection = 'last';
|
|
148
|
+
var secondLastSection = 'second-last';
|
|
149
|
+
|
|
150
|
+
var DecoratedSideBar = /*#__PURE__*/function (_React$PureComponent) {
|
|
151
|
+
_inherits(DecoratedSideBar, _React$PureComponent);
|
|
152
|
+
|
|
153
|
+
var _super = _createSuper(DecoratedSideBar);
|
|
154
|
+
|
|
155
|
+
function DecoratedSideBar(props) {
|
|
156
|
+
var _this;
|
|
157
|
+
|
|
158
|
+
_classCallCheck(this, DecoratedSideBar);
|
|
159
|
+
|
|
160
|
+
_this = _super.call(this, props);
|
|
161
|
+
_this.state = {
|
|
162
|
+
currentSection: '',
|
|
163
|
+
previousSection: ''
|
|
164
|
+
};
|
|
165
|
+
_this.handleClickAnchor = _this._handleClickAnchor.bind(_assertThisInitialized(_this));
|
|
166
|
+
_this.handleOnEnter = _this._handleOnEnter.bind(_assertThisInitialized(_this));
|
|
167
|
+
_this.handleOnLeave = _this._handleOnLeave.bind(_assertThisInitialized(_this)); // moduleID to Module
|
|
168
|
+
|
|
169
|
+
_this.moduleMap = {};
|
|
170
|
+
return _this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_createClass(DecoratedSideBar, [{
|
|
174
|
+
key: "componentWillUnmount",
|
|
175
|
+
value: function componentWillUnmount() {
|
|
176
|
+
this.moduleMap = {};
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "_handleClickAnchor",
|
|
180
|
+
value: function _handleClickAnchor(moduleID, e) {
|
|
181
|
+
if (e) {
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
var node = this.moduleMap[moduleID];
|
|
186
|
+
|
|
187
|
+
if (node) {
|
|
188
|
+
// scroll to the section
|
|
189
|
+
return (0, _smoothscroll["default"])(node.offsetTop);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}, {
|
|
195
|
+
key: "_handleOnEnter",
|
|
196
|
+
value: function _handleOnEnter(nextSection) {
|
|
197
|
+
this.setState({
|
|
198
|
+
previousSection: this.state.currentSection,
|
|
199
|
+
currentSection: nextSection
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Function will be invoked when the section is out of viewport.
|
|
204
|
+
* Currently only handle the first section and last section.
|
|
205
|
+
* For the middle sections, except for the first and last one, could be handled by `onEnter` function.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} onLeaveSection - Section id
|
|
208
|
+
* @param {Object} props - Passed from Waypoint onLeave callback
|
|
209
|
+
* @param {string} props.currentPosition - One of `Waypoint.below`, `Waypoint.above`, `Waypoint.inside`, `Waypoint.invisible`
|
|
210
|
+
* @param {string} order - Section order, could be 'first' or 'last'
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
}, {
|
|
214
|
+
key: "_handleOnLeave",
|
|
215
|
+
value: function _handleOnLeave(onLeaveSection, props, order) {
|
|
216
|
+
if (order && onLeaveSection === this.state.currentSection) {
|
|
217
|
+
// the following conditions are for edge cases.
|
|
218
|
+
// avoid Waypoint not invoking `onEnter` function.
|
|
219
|
+
if (order === firstSection && props.currentPosition === 'above' || order === lastSection && props.currentPosition === 'below' || order === secondLastSection && props.currentPosition === 'above') {
|
|
220
|
+
return this.setState({
|
|
221
|
+
currentSection: this.state.previousSection,
|
|
222
|
+
previousSection: onLeaveSection
|
|
223
|
+
});
|
|
224
|
+
} // leave the sections controlled by side bar
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
this.setState({
|
|
228
|
+
currentSection: '',
|
|
229
|
+
previousSection: onLeaveSection
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "render",
|
|
235
|
+
value: function render() {
|
|
236
|
+
var _this2 = this;
|
|
237
|
+
|
|
238
|
+
var _this$props = this.props,
|
|
239
|
+
children = _this$props.children,
|
|
240
|
+
passThroughProps = _objectWithoutProperties(_this$props, _excluded);
|
|
241
|
+
|
|
242
|
+
var modules;
|
|
243
|
+
|
|
244
|
+
if (!children) {
|
|
245
|
+
modules = [];
|
|
246
|
+
} else if (Array.isArray(children)) {
|
|
247
|
+
modules = children;
|
|
248
|
+
} else {
|
|
249
|
+
modules = [children];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
var anchors = modules.map(function (module) {
|
|
253
|
+
var anchorObj = {
|
|
254
|
+
id: _.get(module.props, 'anchorId'),
|
|
255
|
+
label: _.get(module.props, 'anchorLabel', ''),
|
|
256
|
+
show: _.get(module.props, 'showAnchor', false)
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (anchorObj.id) {
|
|
260
|
+
return anchorObj;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
var webSiteContent = modules.map(function (module, index) {
|
|
264
|
+
var moduleID = _.get(anchors, [index, 'id'], "side_bar_module_".concat(index));
|
|
265
|
+
|
|
266
|
+
var order;
|
|
267
|
+
|
|
268
|
+
if (index === 0) {
|
|
269
|
+
order = firstSection;
|
|
270
|
+
} else if (index === modules.length - 1) {
|
|
271
|
+
order = lastSection;
|
|
272
|
+
} else if (index === modules.length - 2) {
|
|
273
|
+
order = secondLastSection;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return /*#__PURE__*/_react["default"].createElement(_reactWaypoint.Waypoint, {
|
|
277
|
+
key: moduleID,
|
|
278
|
+
onLeave: function onLeave(props) {
|
|
279
|
+
_this2.handleOnLeave(moduleID, props, order);
|
|
280
|
+
},
|
|
281
|
+
onEnter: function onEnter(props) {
|
|
282
|
+
_this2.handleOnEnter(moduleID, props);
|
|
283
|
+
},
|
|
284
|
+
fireOnRapidScroll: true,
|
|
285
|
+
topOffset: "4%",
|
|
286
|
+
bottomOffset: order === lastSection ? '50%' : '95%',
|
|
287
|
+
scrollableAncestor: "window"
|
|
288
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
289
|
+
id: moduleID,
|
|
290
|
+
ref: function ref(node) {
|
|
291
|
+
_this2.moduleMap[moduleID] = node;
|
|
292
|
+
}
|
|
293
|
+
}, module));
|
|
294
|
+
});
|
|
295
|
+
return /*#__PURE__*/_react["default"].createElement(DecoratedComponent, _extends({
|
|
296
|
+
anchors: anchors,
|
|
297
|
+
handleClickAnchor: this.handleClickAnchor,
|
|
298
|
+
currentAnchorId: this.state.currentSection
|
|
299
|
+
}, passThroughProps), webSiteContent);
|
|
300
|
+
}
|
|
301
|
+
}]);
|
|
302
|
+
|
|
303
|
+
return DecoratedSideBar;
|
|
304
|
+
}(_react["default"].PureComponent);
|
|
305
|
+
|
|
306
|
+
DecoratedSideBar.displayName = "SideBarHOC(".concat(getDisplayName(DecoratedComponent), ")");
|
|
307
|
+
DecoratedSideBar.defaultProps = {
|
|
308
|
+
children: []
|
|
309
|
+
};
|
|
310
|
+
DecoratedSideBar.propTypes = {
|
|
311
|
+
children: _propTypes["default"].arrayOf(_propTypes["default"].element)
|
|
312
|
+
};
|
|
313
|
+
return (0, _hoistNonReactStatics["default"])(DecoratedSideBar, DecoratedComponent);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var _default = decorateSideBar;
|
|
317
|
+
exports["default"] = _default;
|