grommet 2.25.1 → 2.25.2
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/components/Anchor/Anchor.js +14 -1
- package/components/Button/Button.js +82 -9
- package/components/Button/StyledButtonKind.js +9 -3
- package/components/Button/index.d.ts +1 -1
- package/components/Button/propTypes.js +1 -1
- package/components/DataChart/DataChart.js +11 -13
- package/components/DataChart/XAxis.js +29 -18
- package/components/DataTable/DataTable.js +13 -9
- package/components/DataTable/buildState.js +2 -2
- package/components/DataTable/index.d.ts +4 -1
- package/components/DataTable/stories/SpaceX.js +3 -1
- package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/components/Form/Form.js +72 -4
- package/components/FormField/FormField.js +4 -1
- package/components/Grommet/Grommet.js +7 -2
- package/components/Grommet/index.d.ts +1 -0
- package/components/Grommet/propTypes.js +2 -1
- package/components/Heading/Heading.js +4 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +2 -1
- package/components/Layer/LayerContainer.js +18 -0
- package/components/Menu/Menu.js +7 -4
- package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/components/Meter/Circle.js +5 -1
- package/components/PageHeader/PageHeader.js +22 -13
- package/components/PageHeader/index.d.ts +10 -1
- package/components/PageHeader/propTypes.js +1 -0
- package/components/PageHeader/stories/Size.js +55 -0
- package/components/Select/SelectContainer.js +77 -44
- package/components/Select/stories/Clear.js +7 -1
- package/components/Select/utils.js +1 -0
- package/components/Spinner/Spinner.js +1 -0
- package/components/Tab/Tab.js +1 -1
- package/components/Tabs/Tabs.js +9 -1
- package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
- package/contexts/AnalyticsContext/index.d.ts +7 -0
- package/contexts/AnalyticsContext/index.js +11 -0
- package/contexts/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +14 -2
- package/es6/components/Button/Button.js +83 -11
- package/es6/components/Button/StyledButtonKind.js +9 -3
- package/es6/components/Button/index.d.ts +1 -1
- package/es6/components/Button/propTypes.js +1 -1
- package/es6/components/DataChart/DataChart.js +11 -13
- package/es6/components/DataChart/XAxis.js +29 -19
- package/es6/components/DataTable/DataTable.js +13 -9
- package/es6/components/DataTable/buildState.js +2 -2
- package/es6/components/DataTable/index.d.ts +4 -1
- package/es6/components/DataTable/stories/SpaceX.js +3 -1
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/es6/components/Form/Form.js +70 -4
- package/es6/components/FormField/FormField.js +4 -1
- package/es6/components/Grommet/Grommet.js +6 -2
- package/es6/components/Grommet/index.d.ts +1 -0
- package/es6/components/Grommet/propTypes.js +2 -1
- package/es6/components/Heading/Heading.js +4 -2
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +2 -1
- package/es6/components/Layer/LayerContainer.js +17 -0
- package/es6/components/Menu/Menu.js +7 -4
- package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/es6/components/Meter/Circle.js +5 -1
- package/es6/components/PageHeader/PageHeader.js +24 -14
- package/es6/components/PageHeader/index.d.ts +10 -1
- package/es6/components/PageHeader/propTypes.js +1 -0
- package/es6/components/PageHeader/stories/Size.js +43 -0
- package/es6/components/Select/SelectContainer.js +76 -45
- package/es6/components/Select/stories/Clear.js +7 -1
- package/es6/components/Select/utils.js +1 -0
- package/es6/components/Spinner/Spinner.js +1 -0
- package/es6/components/Tab/Tab.js +1 -1
- package/es6/components/Tabs/Tabs.js +8 -1
- package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
- package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
- package/es6/contexts/AnalyticsContext/index.js +1 -0
- package/es6/contexts/index.js +1 -0
- package/es6/themes/base.d.ts +40 -8
- package/es6/themes/base.js +43 -0
- package/es6/utils/mixins.js +3 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +36 -30
- package/themes/base.d.ts +40 -8
- package/themes/base.js +43 -0
- package/tools/pack.js +20 -13
- package/tools/release-stable.js +2 -4
- package/utils/mixins.js +7 -1
|
@@ -27,12 +27,18 @@ var _StyledSelect = require("./StyledSelect");
|
|
|
27
27
|
|
|
28
28
|
var _utils2 = require("./utils");
|
|
29
29
|
|
|
30
|
+
var _DOM = require("../../utils/DOM");
|
|
31
|
+
|
|
32
|
+
var _excluded = ["clear", "onClear", "name", "theme"];
|
|
33
|
+
|
|
30
34
|
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); }
|
|
31
35
|
|
|
32
36
|
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; }
|
|
33
37
|
|
|
34
38
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
35
39
|
|
|
40
|
+
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; }
|
|
41
|
+
|
|
36
42
|
// position relative is so scroll can be managed correctly
|
|
37
43
|
var OptionsBox = _styledComponents["default"].div.withConfig({
|
|
38
44
|
displayName: "SelectContainer__OptionsBox",
|
|
@@ -42,26 +48,38 @@ var OptionsBox = _styledComponents["default"].div.withConfig({
|
|
|
42
48
|
var SelectOption = (0, _styledComponents["default"])(_Button.Button).withConfig({
|
|
43
49
|
displayName: "SelectContainer__SelectOption",
|
|
44
50
|
componentId: "sc-1wi0ul8-1"
|
|
45
|
-
})(["", " ", " display:block;width:100%;"], function (props) {
|
|
51
|
+
})(["", " ", " &:focus{", "}display:block;width:100%;"], function (props) {
|
|
46
52
|
return props.selected && props.textComponent && _utils.selectedStyle;
|
|
47
53
|
}, function (props) {
|
|
48
54
|
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
55
|
+
}, function (props) {
|
|
56
|
+
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
57
|
+
}); // ensure ClearButton receives visual indication of keyboard
|
|
58
|
+
|
|
59
|
+
var StyledButton = (0, _styledComponents["default"])(_Button.Button).withConfig({
|
|
60
|
+
displayName: "SelectContainer__StyledButton",
|
|
61
|
+
componentId: "sc-1wi0ul8-2"
|
|
62
|
+
})(["&:focus{", "}"], function (props) {
|
|
63
|
+
return (0, _utils.getHoverIndicatorStyle)('background', props.theme);
|
|
49
64
|
});
|
|
50
65
|
var ClearButton = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
51
66
|
var clear = _ref.clear,
|
|
52
67
|
onClear = _ref.onClear,
|
|
53
68
|
name = _ref.name,
|
|
54
|
-
theme = _ref.theme
|
|
69
|
+
theme = _ref.theme,
|
|
70
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
71
|
+
|
|
55
72
|
var label = clear.label,
|
|
56
73
|
position = clear.position;
|
|
57
74
|
var align = position !== 'bottom' ? 'start' : 'center';
|
|
58
75
|
var buttonLabel = label || "Clear " + (name || 'selection');
|
|
59
|
-
return /*#__PURE__*/_react["default"].createElement(
|
|
76
|
+
return /*#__PURE__*/_react["default"].createElement(StyledButton, _extends({
|
|
77
|
+
a11yTitle: buttonLabel + ". Or, press " + (position === 'bottom' ? 'shift tab' : 'down arrow') + " to move to select options",
|
|
60
78
|
fill: "horizontal",
|
|
61
79
|
ref: ref,
|
|
62
80
|
onClick: onClear,
|
|
63
81
|
focusIndicator: false
|
|
64
|
-
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({}, theme.select.clear.container, {
|
|
82
|
+
}, rest), /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({}, theme.select.clear.container, {
|
|
65
83
|
align: align
|
|
66
84
|
}), /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.clear.text, buttonLabel)));
|
|
67
85
|
});
|
|
@@ -98,7 +116,13 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
98
116
|
|
|
99
117
|
var theme = (0, _react.useContext)(_styledComponents.ThemeContext) || _defaultProps.defaultProps.theme;
|
|
100
118
|
|
|
101
|
-
var
|
|
119
|
+
var shouldShowClearButton = (0, _react.useCallback)(function (position) {
|
|
120
|
+
var hasValue = Boolean(multiple ? value.length : value);
|
|
121
|
+
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
122
|
+
return clear && hasValue && showAtPosition;
|
|
123
|
+
}, [clear, multiple, value]);
|
|
124
|
+
|
|
125
|
+
var _useState = (0, _react.useState)(usingKeyboard && !shouldShowClearButton('top') ? 0 : -1),
|
|
102
126
|
activeIndex = _useState[0],
|
|
103
127
|
setActiveIndex = _useState[1];
|
|
104
128
|
|
|
@@ -114,7 +138,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
114
138
|
(0, _react.useEffect)(function () {
|
|
115
139
|
var _activeRef$current;
|
|
116
140
|
|
|
117
|
-
if (activeIndex) (_activeRef$current = activeRef.current) == null ? void 0 : _activeRef$current.focus();
|
|
141
|
+
if (activeIndex >= 0) (_activeRef$current = activeRef.current) == null ? void 0 : _activeRef$current.focus();
|
|
118
142
|
}, [activeIndex]); // set initial focus
|
|
119
143
|
|
|
120
144
|
(0, _react.useEffect)(function () {
|
|
@@ -142,11 +166,11 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
142
166
|
};
|
|
143
167
|
}, [onSearch, usingKeyboard, clear]);
|
|
144
168
|
var optionLabel = (0, _react.useCallback)(function (index) {
|
|
145
|
-
return (0, _utils2.applyKey)(options[index], labelKey);
|
|
146
|
-
}, [labelKey, options]);
|
|
169
|
+
return (0, _utils2.applyKey)(options[index], labelKey || valueKey);
|
|
170
|
+
}, [labelKey, options, valueKey]);
|
|
147
171
|
var optionValue = (0, _react.useCallback)(function (index) {
|
|
148
|
-
return (0, _utils2.applyKey)(options[index], valueKey);
|
|
149
|
-
}, [options, valueKey]);
|
|
172
|
+
return (0, _utils2.applyKey)(options[index], valueKey || labelKey);
|
|
173
|
+
}, [options, valueKey, labelKey]);
|
|
150
174
|
var isDisabled = (0, _react.useCallback)(function (index) {
|
|
151
175
|
var option = options[index];
|
|
152
176
|
var result;
|
|
@@ -238,7 +262,6 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
238
262
|
var onNextOption = (0, _react.useCallback)(function (event) {
|
|
239
263
|
event.preventDefault();
|
|
240
264
|
var nextActiveIndex = activeIndex + 1;
|
|
241
|
-
var clearButton = clearRef.current;
|
|
242
265
|
|
|
243
266
|
while (nextActiveIndex < options.length && isDisabled(nextActiveIndex)) {
|
|
244
267
|
nextActiveIndex += 1;
|
|
@@ -248,21 +271,19 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
248
271
|
setActiveIndex(nextActiveIndex);
|
|
249
272
|
setKeyboardNavigation(true);
|
|
250
273
|
}
|
|
251
|
-
|
|
252
|
-
if (clear && clear.position === 'bottom' && clearButton && nextActiveIndex >= options.length) {
|
|
253
|
-
setActiveIndex(options.length);
|
|
254
|
-
(0, _utils.setFocusWithoutScroll)(clearButton);
|
|
255
|
-
}
|
|
256
|
-
}, [activeIndex, isDisabled, options, clear]);
|
|
274
|
+
}, [activeIndex, isDisabled, options]);
|
|
257
275
|
var onPreviousOption = (0, _react.useCallback)(function (event) {
|
|
258
276
|
event.preventDefault();
|
|
259
277
|
var nextActiveIndex = activeIndex - 1;
|
|
260
|
-
var clearButton = clearRef.current;
|
|
261
278
|
|
|
262
279
|
if (nextActiveIndex === -1) {
|
|
263
280
|
var searchInput = searchRef.current;
|
|
281
|
+
var clearButton = clearRef.current;
|
|
264
282
|
|
|
265
|
-
if (
|
|
283
|
+
if (clearButton && clearButton.focus && shouldShowClearButton('top')) {
|
|
284
|
+
setActiveIndex(nextActiveIndex);
|
|
285
|
+
(0, _utils.setFocusWithoutScroll)(clearButton);
|
|
286
|
+
} else if (searchInput && searchInput.focus) {
|
|
266
287
|
setActiveIndex(nextActiveIndex);
|
|
267
288
|
(0, _utils.setFocusWithoutScroll)(searchInput);
|
|
268
289
|
}
|
|
@@ -276,11 +297,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
276
297
|
setActiveIndex(nextActiveIndex);
|
|
277
298
|
setKeyboardNavigation(true);
|
|
278
299
|
}
|
|
279
|
-
|
|
280
|
-
if (clear && clear.position !== 'bottom' && clearButton && activeIndex === 0) {
|
|
281
|
-
setActiveIndex(-1);
|
|
282
|
-
}
|
|
283
|
-
}, [activeIndex, isDisabled, clear]);
|
|
300
|
+
}, [activeIndex, isDisabled, shouldShowClearButton]);
|
|
284
301
|
var onKeyDownOption = (0, _react.useCallback)(function (event) {
|
|
285
302
|
if (!onSearch) {
|
|
286
303
|
var nextActiveIndex = options.findIndex(function (e, index) {
|
|
@@ -312,19 +329,18 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
312
329
|
};
|
|
313
330
|
}, [keyboardNavigation]);
|
|
314
331
|
var onSelectOption = (0, _react.useCallback)(function (event) {
|
|
315
|
-
if (
|
|
332
|
+
if ((shouldShowClearButton('bottom') || shouldShowClearButton('top')) && (0, _DOM.containsFocus)(clearRef.current)) {
|
|
333
|
+
onChange(event, {
|
|
334
|
+
option: undefined,
|
|
335
|
+
value: '',
|
|
336
|
+
selected: ''
|
|
337
|
+
});
|
|
338
|
+
} else if (activeIndex >= 0 && activeIndex < options.length) {
|
|
316
339
|
event.preventDefault(); // prevent submitting forms
|
|
317
340
|
|
|
318
341
|
selectOption(activeIndex)(event);
|
|
319
342
|
}
|
|
320
|
-
}, [activeIndex, selectOption, options]);
|
|
321
|
-
|
|
322
|
-
var shouldShowClearButton = function shouldShowClearButton(position) {
|
|
323
|
-
var hasValue = Boolean(multiple ? value.length : value);
|
|
324
|
-
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
325
|
-
return clear && hasValue && showAtPosition;
|
|
326
|
-
};
|
|
327
|
-
|
|
343
|
+
}, [activeIndex, selectOption, options, onChange, shouldShowClearButton]);
|
|
328
344
|
var customSearchInput = theme.select.searchInput;
|
|
329
345
|
var SelectTextInput = customSearchInput || _TextInput.TextInput;
|
|
330
346
|
var selectOptionsStyle = theme.select.options ? _extends({}, theme.select.options.box, theme.select.options.container) : {};
|
|
@@ -355,7 +371,19 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
355
371
|
setActiveIndex(-1);
|
|
356
372
|
onSearch(nextSearch);
|
|
357
373
|
}
|
|
358
|
-
})), /*#__PURE__*/_react["default"].createElement(
|
|
374
|
+
})), shouldShowClearButton('top') && /*#__PURE__*/_react["default"].createElement(ClearButton, {
|
|
375
|
+
ref: clearRef,
|
|
376
|
+
clear: clear,
|
|
377
|
+
name: name,
|
|
378
|
+
onClear: onClear,
|
|
379
|
+
onFocus: function onFocus() {
|
|
380
|
+
return setActiveIndex(-1);
|
|
381
|
+
},
|
|
382
|
+
onMouseOver: function onMouseOver() {
|
|
383
|
+
return setActiveIndex(-1);
|
|
384
|
+
},
|
|
385
|
+
theme: theme
|
|
386
|
+
}), /*#__PURE__*/_react["default"].createElement(OptionsBox, {
|
|
359
387
|
role: "listbox",
|
|
360
388
|
tabIndex: "-1",
|
|
361
389
|
ref: optionsRef,
|
|
@@ -363,13 +391,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
363
391
|
onMouseMove: function onMouseMove() {
|
|
364
392
|
return setKeyboardNavigation(false);
|
|
365
393
|
}
|
|
366
|
-
},
|
|
367
|
-
ref: clearRef,
|
|
368
|
-
clear: clear,
|
|
369
|
-
name: name,
|
|
370
|
-
onClear: onClear,
|
|
371
|
-
theme: theme
|
|
372
|
-
}), options.length > 0 ? /*#__PURE__*/_react["default"].createElement(_InfiniteScroll.InfiniteScroll, {
|
|
394
|
+
}, options.length > 0 ? /*#__PURE__*/_react["default"].createElement(_InfiniteScroll.InfiniteScroll, {
|
|
373
395
|
items: options,
|
|
374
396
|
step: theme.select.step,
|
|
375
397
|
onMore: onMore,
|
|
@@ -419,7 +441,12 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
419
441
|
label: !child ? optionLabel(index) : undefined,
|
|
420
442
|
disabled: optionDisabled || undefined,
|
|
421
443
|
active: optionActive,
|
|
422
|
-
selected: optionSelected
|
|
444
|
+
selected: optionSelected // allow keyboard navigation to start from
|
|
445
|
+
// selected option after tabbing to it
|
|
446
|
+
,
|
|
447
|
+
onFocus: function onFocus() {
|
|
448
|
+
return setActiveIndex(index);
|
|
449
|
+
},
|
|
423
450
|
onMouseOver: !optionDisabled ? onActiveOption(index) : undefined,
|
|
424
451
|
onClick: !optionDisabled ? selectOption(index) : undefined,
|
|
425
452
|
textComponent: textComponent
|
|
@@ -430,12 +457,18 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
430
457
|
role: "menuitem",
|
|
431
458
|
hoverIndicator: "background",
|
|
432
459
|
disabled: true
|
|
433
|
-
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, selectOptionsStyle, /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.container.text, emptySearchMessage))), shouldShowClearButton('bottom') && /*#__PURE__*/_react["default"].createElement(ClearButton, {
|
|
460
|
+
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, selectOptionsStyle, /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.container.text, emptySearchMessage)))), shouldShowClearButton('bottom') && /*#__PURE__*/_react["default"].createElement(ClearButton, {
|
|
434
461
|
ref: clearRef,
|
|
435
462
|
clear: clear,
|
|
436
463
|
name: name,
|
|
437
464
|
onClear: onClear,
|
|
465
|
+
onFocus: function onFocus() {
|
|
466
|
+
return setActiveIndex(-1);
|
|
467
|
+
},
|
|
468
|
+
onMouseOver: function onMouseOver() {
|
|
469
|
+
return setActiveIndex(-1);
|
|
470
|
+
},
|
|
438
471
|
theme: theme
|
|
439
|
-
})))
|
|
472
|
+
})));
|
|
440
473
|
});
|
|
441
474
|
exports.SelectContainer = SelectContainer;
|
|
@@ -11,7 +11,11 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
|
|
12
12
|
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; }
|
|
13
13
|
|
|
14
|
-
var options = [
|
|
14
|
+
var options = [];
|
|
15
|
+
|
|
16
|
+
for (var i = 0; i < 500; i += 1) {
|
|
17
|
+
options.push("Number " + i);
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
var ClearTop = function ClearTop() {
|
|
17
21
|
var _useState = (0, _react.useState)(),
|
|
@@ -32,6 +36,7 @@ var ClearTop = function ClearTop() {
|
|
|
32
36
|
var nextValue = _ref.value;
|
|
33
37
|
return setValue(nextValue);
|
|
34
38
|
},
|
|
39
|
+
dropHeight: "large",
|
|
35
40
|
clear: true
|
|
36
41
|
}));
|
|
37
42
|
};
|
|
@@ -55,6 +60,7 @@ var ClearBottom = function ClearBottom() {
|
|
|
55
60
|
var nextValue = _ref2.value;
|
|
56
61
|
return setValue(nextValue);
|
|
57
62
|
},
|
|
63
|
+
dropHeight: "large",
|
|
58
64
|
clear: {
|
|
59
65
|
position: 'bottom'
|
|
60
66
|
}
|
|
@@ -8,6 +8,7 @@ var applyKey = function applyKey(option, key) {
|
|
|
8
8
|
if (typeof key === 'object') return applyKey(option, key.key);
|
|
9
9
|
if (typeof key === 'function') return key(option);
|
|
10
10
|
if (key !== undefined) return option[key];
|
|
11
|
+
if (typeof option === 'object' && Object.keys(option)) return option[Object.keys(option)[0]];
|
|
11
12
|
return option;
|
|
12
13
|
};
|
|
13
14
|
|
package/components/Tab/Tab.js
CHANGED
|
@@ -70,7 +70,7 @@ var Tab = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
70
70
|
var tabStyles = {};
|
|
71
71
|
var tabRef = (0, _utils.useForwardedRef)(ref);
|
|
72
72
|
(0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
|
|
73
|
-
if (tabRef.current) {
|
|
73
|
+
if (tabRef.current && tabsContextRef) {
|
|
74
74
|
tabsContextRef.current = tabRef.current;
|
|
75
75
|
}
|
|
76
76
|
});
|
package/components/Tabs/Tabs.js
CHANGED
|
@@ -31,6 +31,8 @@ var _MessageContext = require("../../contexts/MessageContext");
|
|
|
31
31
|
|
|
32
32
|
var _propTypes = require("./propTypes");
|
|
33
33
|
|
|
34
|
+
var _AnalyticsContext = require("../../contexts/AnalyticsContext/AnalyticsContext");
|
|
35
|
+
|
|
34
36
|
var _excluded = ["alignControls", "children", "flex", "justify", "messages", "responsive"];
|
|
35
37
|
|
|
36
38
|
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); }
|
|
@@ -90,6 +92,7 @@ var Tabs = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
90
92
|
|
|
91
93
|
var headerRef = (0, _react.useRef)();
|
|
92
94
|
var size = (0, _react.useContext)(_ResponsiveContext.ResponsiveContext);
|
|
95
|
+
var sendAnalytics = (0, _AnalyticsContext.useAnalytics)();
|
|
93
96
|
|
|
94
97
|
if (activeIndex !== propsActiveIndex && propsActiveIndex !== undefined) {
|
|
95
98
|
setActiveIndex(propsActiveIndex);
|
|
@@ -256,6 +259,11 @@ var Tabs = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
256
259
|
}, [tabRefs, disableLeftArrow, disableRightArrow, activeIndex, headerRef, overflow, updateArrowState]);
|
|
257
260
|
var getTabsContext = (0, _react.useCallback)(function (index) {
|
|
258
261
|
var activateTab = function activateTab(nextIndex) {
|
|
262
|
+
sendAnalytics({
|
|
263
|
+
type: 'activateTab',
|
|
264
|
+
element: tabRefs[nextIndex].current
|
|
265
|
+
});
|
|
266
|
+
|
|
259
267
|
if (propsActiveIndex === undefined) {
|
|
260
268
|
setActiveIndex(nextIndex);
|
|
261
269
|
}
|
|
@@ -277,7 +285,7 @@ var Tabs = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
277
285
|
setActiveTitle: setActiveTitle,
|
|
278
286
|
setFocusIndex: setFocusIndex
|
|
279
287
|
};
|
|
280
|
-
}, [activeIndex, onActive, propsActiveIndex, tabRefs]);
|
|
288
|
+
}, [activeIndex, onActive, propsActiveIndex, sendAnalytics, tabRefs]);
|
|
281
289
|
|
|
282
290
|
var tabs = _react["default"].Children.map(children, function (child, index) {
|
|
283
291
|
return /*#__PURE__*/_react["default"].createElement(_TabsContext.TabsContext.Provider, {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.useAnalytics = exports.AnalyticsProvider = exports.AnalyticsContext = void 0;
|
|
5
|
+
|
|
6
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
7
|
+
|
|
8
|
+
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); }
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
var AnalyticsContext = /*#__PURE__*/_react["default"].createContext(function () {});
|
|
13
|
+
|
|
14
|
+
exports.AnalyticsContext = AnalyticsContext;
|
|
15
|
+
|
|
16
|
+
var useAnalytics = function useAnalytics() {
|
|
17
|
+
return (0, _react.useContext)(AnalyticsContext);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.useAnalytics = useAnalytics;
|
|
21
|
+
|
|
22
|
+
var AnalyticsProvider = function AnalyticsProvider(_ref) {
|
|
23
|
+
var onAnalytics = _ref.onAnalytics,
|
|
24
|
+
children = _ref.children;
|
|
25
|
+
var lastUrlRef = (0, _react.useRef)();
|
|
26
|
+
var sendAnalytics = (0, _react.useCallback)(function (data) {
|
|
27
|
+
return onAnalytics && onAnalytics(data);
|
|
28
|
+
}, [onAnalytics]);
|
|
29
|
+
(0, _react.useEffect)(function () {
|
|
30
|
+
var observer;
|
|
31
|
+
|
|
32
|
+
if (onAnalytics) {
|
|
33
|
+
observer = new window.MutationObserver(function () {
|
|
34
|
+
var _window, _window$location;
|
|
35
|
+
|
|
36
|
+
var url = (_window = window) == null ? void 0 : (_window$location = _window.location) == null ? void 0 : _window$location.href;
|
|
37
|
+
var previousUrl = lastUrlRef.current;
|
|
38
|
+
|
|
39
|
+
if (url !== previousUrl) {
|
|
40
|
+
lastUrlRef.current = url;
|
|
41
|
+
sendAnalytics({
|
|
42
|
+
type: 'pageView',
|
|
43
|
+
url: url,
|
|
44
|
+
previousUrl: previousUrl
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
observer.observe(document, {
|
|
49
|
+
subtree: true,
|
|
50
|
+
childList: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return function () {
|
|
55
|
+
var _observer;
|
|
56
|
+
|
|
57
|
+
return (_observer = observer) == null ? void 0 : _observer.disconnect();
|
|
58
|
+
};
|
|
59
|
+
}, [sendAnalytics, onAnalytics]);
|
|
60
|
+
return /*#__PURE__*/_react["default"].createElement(AnalyticsContext.Provider, {
|
|
61
|
+
value: sendAnalytics
|
|
62
|
+
}, children);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.AnalyticsProvider = AnalyticsProvider;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
|
|
5
|
+
var _AnalyticsContext = require("./AnalyticsContext");
|
|
6
|
+
|
|
7
|
+
Object.keys(_AnalyticsContext).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _AnalyticsContext[key]) return;
|
|
10
|
+
exports[key] = _AnalyticsContext[key];
|
|
11
|
+
});
|
package/contexts/index.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
+
var _AnalyticsContext = require("./AnalyticsContext");
|
|
6
|
+
|
|
7
|
+
Object.keys(_AnalyticsContext).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _AnalyticsContext[key]) return;
|
|
10
|
+
exports[key] = _AnalyticsContext[key];
|
|
11
|
+
});
|
|
12
|
+
|
|
5
13
|
var _AnnounceContext = require("./AnnounceContext");
|
|
6
14
|
|
|
7
15
|
Object.keys(_AnnounceContext).forEach(function (key) {
|
|
@@ -4,13 +4,14 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
-
import React, { cloneElement, forwardRef, useContext, useEffect, useState } from 'react';
|
|
7
|
+
import React, { cloneElement, forwardRef, useCallback, useContext, useEffect, useState } from 'react';
|
|
8
8
|
import { ThemeContext } from 'styled-components';
|
|
9
9
|
import { defaultProps } from '../../default-props';
|
|
10
10
|
import { normalizeColor } from '../../utils';
|
|
11
11
|
import { Box } from '../Box';
|
|
12
12
|
import { StyledAnchor } from './StyledAnchor';
|
|
13
13
|
import { AnchorPropTypes } from './propTypes';
|
|
14
|
+
import { useAnalytics } from '../../contexts/AnalyticsContext';
|
|
14
15
|
var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
15
16
|
var a11yTitle = _ref.a11yTitle,
|
|
16
17
|
ariaLabel = _ref['aria-label'],
|
|
@@ -22,7 +23,7 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
22
23
|
icon = _ref.icon,
|
|
23
24
|
label = _ref.label,
|
|
24
25
|
_onBlur = _ref.onBlur,
|
|
25
|
-
|
|
26
|
+
onClickProp = _ref.onClick,
|
|
26
27
|
_onFocus = _ref.onFocus,
|
|
27
28
|
reverse = _ref.reverse,
|
|
28
29
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
@@ -33,6 +34,17 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
33
34
|
focus = _useState[0],
|
|
34
35
|
setFocus = _useState[1];
|
|
35
36
|
|
|
37
|
+
var sendAnalytics = useAnalytics();
|
|
38
|
+
var onClick = useCallback(function (event) {
|
|
39
|
+
sendAnalytics({
|
|
40
|
+
type: 'anchorClick',
|
|
41
|
+
element: event.target,
|
|
42
|
+
event: event,
|
|
43
|
+
href: href,
|
|
44
|
+
label: typeof label === 'string' ? label : undefined
|
|
45
|
+
});
|
|
46
|
+
if (onClickProp) onClickProp(event);
|
|
47
|
+
}, [onClickProp, sendAnalytics, label, href]);
|
|
36
48
|
useEffect(function () {
|
|
37
49
|
if ((icon || label) && children) {
|
|
38
50
|
console.warn('Anchor should not have children if icon or label is provided');
|