@moda/om 15.10.3 → 15.11.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.
- package/CHANGELOG.md +7 -0
- package/dist/components/Popover/Popover.d.ts +1 -0
- package/dist/index.cjs.js +92 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +93 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -6
- package/src/components/Popover/Popover.scss +24 -0
- package/src/components/Popover/Popover.stories.tsx +3 -1
- package/src/components/Popover/Popover.tsx +57 -6
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React$2 from 'react';
|
|
2
|
-
import React__default, { useState, PureComponent, useRef,
|
|
2
|
+
import React__default, { useState, useEffect, PureComponent, useRef, Children, isValidElement, cloneElement, createContext, useContext, useCallback, useReducer, useMemo, forwardRef } from 'react';
|
|
3
3
|
import { Link } from 'react-router-dom';
|
|
4
4
|
import require$$1, { createPortal } from 'react-dom';
|
|
5
5
|
|
|
@@ -2961,21 +2961,32 @@ var FocusLock = /*#__PURE__*/React$2.forwardRef(function FocusLockUI(props, pare
|
|
|
2961
2961
|
onDeactivationCallback(observed.current);
|
|
2962
2962
|
}
|
|
2963
2963
|
}, [onDeactivationCallback]);
|
|
2964
|
+
useEffect(function () {
|
|
2965
|
+
if (!disabled) {
|
|
2966
|
+
// cleanup return focus on trap deactivation
|
|
2967
|
+
// sideEffect/returnFocus should happen by this time
|
|
2968
|
+
originalFocusedElement.current = null;
|
|
2969
|
+
}
|
|
2970
|
+
}, []);
|
|
2964
2971
|
var returnFocus = React$2.useCallback(function (allowDefer) {
|
|
2965
|
-
var
|
|
2972
|
+
var returnFocusTo = originalFocusedElement.current;
|
|
2966
2973
|
|
|
2967
|
-
if (
|
|
2968
|
-
var
|
|
2969
|
-
originalFocusedElement.current = null;
|
|
2974
|
+
if (returnFocusTo && returnFocusTo.focus) {
|
|
2975
|
+
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus;
|
|
2970
2976
|
|
|
2971
|
-
if (
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2977
|
+
if (Boolean(howToReturnFocus)) {
|
|
2978
|
+
var focusOptions = _typeof(howToReturnFocus) === 'object' ? howToReturnFocus : undefined;
|
|
2979
|
+
originalFocusedElement.current = null;
|
|
2980
|
+
|
|
2981
|
+
if (allowDefer) {
|
|
2982
|
+
// React might return focus after update
|
|
2983
|
+
// it's safer to defer the action
|
|
2984
|
+
Promise.resolve().then(function () {
|
|
2985
|
+
return returnFocusTo.focus(focusOptions);
|
|
2986
|
+
});
|
|
2987
|
+
} else {
|
|
2988
|
+
returnFocusTo.focus(focusOptions);
|
|
2989
|
+
}
|
|
2979
2990
|
}
|
|
2980
2991
|
}
|
|
2981
2992
|
}, [shouldReturnFocus]); // MEDIUM CALLBACKS
|
|
@@ -3913,13 +3924,13 @@ var onWindowBlur = function onWindowBlur() {
|
|
|
3913
3924
|
};
|
|
3914
3925
|
|
|
3915
3926
|
var attachHandler = function attachHandler() {
|
|
3916
|
-
document.addEventListener('focusin', onTrap
|
|
3927
|
+
document.addEventListener('focusin', onTrap);
|
|
3917
3928
|
document.addEventListener('focusout', onBlur);
|
|
3918
3929
|
window.addEventListener('blur', onWindowBlur);
|
|
3919
3930
|
};
|
|
3920
3931
|
|
|
3921
3932
|
var detachHandler = function detachHandler() {
|
|
3922
|
-
document.removeEventListener('focusin', onTrap
|
|
3933
|
+
document.removeEventListener('focusin', onTrap);
|
|
3923
3934
|
document.removeEventListener('focusout', onBlur);
|
|
3924
3935
|
window.removeEventListener('blur', onWindowBlur);
|
|
3925
3936
|
};
|
|
@@ -8589,30 +8600,30 @@ var useClickOutside = function useClickOutside(ref, onClickOutside) {
|
|
|
8589
8600
|
});
|
|
8590
8601
|
};
|
|
8591
8602
|
|
|
8592
|
-
var Mode;
|
|
8603
|
+
var Mode$1;
|
|
8593
8604
|
|
|
8594
8605
|
(function (Mode) {
|
|
8595
8606
|
Mode[Mode["Resting"] = 0] = "Resting";
|
|
8596
8607
|
Mode[Mode["Open"] = 1] = "Open";
|
|
8597
|
-
})(Mode || (Mode = {}));
|
|
8608
|
+
})(Mode$1 || (Mode$1 = {}));
|
|
8598
8609
|
|
|
8599
8610
|
var reducer = function reducer(state, action) {
|
|
8600
8611
|
switch (action.type) {
|
|
8601
8612
|
case 'OPEN':
|
|
8602
8613
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8603
|
-
mode: Mode.Open
|
|
8614
|
+
mode: Mode$1.Open
|
|
8604
8615
|
});
|
|
8605
8616
|
|
|
8606
8617
|
case 'CLOSE':
|
|
8607
8618
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8608
|
-
mode: Mode.Resting
|
|
8619
|
+
mode: Mode$1.Resting
|
|
8609
8620
|
});
|
|
8610
8621
|
|
|
8611
8622
|
case 'SELECT':
|
|
8612
8623
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8613
8624
|
value: action.payload.value,
|
|
8614
8625
|
focused: undefined,
|
|
8615
|
-
mode: Mode.Resting
|
|
8626
|
+
mode: Mode$1.Resting
|
|
8616
8627
|
});
|
|
8617
8628
|
|
|
8618
8629
|
case 'FOCUS':
|
|
@@ -8631,7 +8642,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8631
8642
|
var _useReducer = useReducer(reducer, {
|
|
8632
8643
|
value: initialValue,
|
|
8633
8644
|
focused: _typeof(initialValue) == 'object' ? initialValue === null || initialValue === void 0 ? void 0 : initialValue[0] : initialValue,
|
|
8634
|
-
mode: Mode.Resting
|
|
8645
|
+
mode: Mode$1.Resting
|
|
8635
8646
|
}),
|
|
8636
8647
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
8637
8648
|
state = _useReducer2[0],
|
|
@@ -8673,7 +8684,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8673
8684
|
return {
|
|
8674
8685
|
state: state,
|
|
8675
8686
|
dispatch: dispatch,
|
|
8676
|
-
Mode: Mode,
|
|
8687
|
+
Mode: Mode$1,
|
|
8677
8688
|
selectRef: selectRef
|
|
8678
8689
|
};
|
|
8679
8690
|
};
|
|
@@ -11241,8 +11252,18 @@ var Paginator = function Paginator(_ref) {
|
|
|
11241
11252
|
})));
|
|
11242
11253
|
};
|
|
11243
11254
|
|
|
11244
|
-
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex"];
|
|
11255
|
+
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview"];
|
|
11245
11256
|
var POPOVER_MOUSEOUT_DELAY_MS = 200;
|
|
11257
|
+
var Mode;
|
|
11258
|
+
|
|
11259
|
+
(function (Mode) {
|
|
11260
|
+
Mode["Open"] = "open";
|
|
11261
|
+
Mode["Closing"] = "closing";
|
|
11262
|
+
Mode["AutoOpening"] = "autoOpening";
|
|
11263
|
+
Mode["AutoOpen"] = "autoOpen";
|
|
11264
|
+
Mode["Closed"] = "closed";
|
|
11265
|
+
})(Mode || (Mode = {}));
|
|
11266
|
+
|
|
11246
11267
|
var Popover = function Popover(_ref) {
|
|
11247
11268
|
var className = _ref.className,
|
|
11248
11269
|
children = _ref.children,
|
|
@@ -11252,37 +11273,78 @@ var Popover = function Popover(_ref) {
|
|
|
11252
11273
|
_ref$anchor = _ref.anchor,
|
|
11253
11274
|
anchor = _ref$anchor === void 0 ? 'topLeft' : _ref$anchor,
|
|
11254
11275
|
zIndex = _ref.zIndex,
|
|
11276
|
+
_ref$autoPreview = _ref.autoPreview,
|
|
11277
|
+
autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
|
|
11255
11278
|
rest = _objectWithoutProperties(_ref, _excluded$b);
|
|
11256
11279
|
|
|
11257
|
-
var _useState = useState(
|
|
11280
|
+
var _useState = useState(function () {
|
|
11281
|
+
if (open) {
|
|
11282
|
+
return Mode.Open;
|
|
11283
|
+
}
|
|
11284
|
+
|
|
11285
|
+
if (autoPreview) {
|
|
11286
|
+
return Mode.AutoOpening;
|
|
11287
|
+
}
|
|
11288
|
+
|
|
11289
|
+
return Mode.Closed;
|
|
11290
|
+
}),
|
|
11258
11291
|
_useState2 = _slicedToArray(_useState, 2),
|
|
11259
|
-
|
|
11260
|
-
|
|
11292
|
+
mode = _useState2[0],
|
|
11293
|
+
setMode = _useState2[1];
|
|
11261
11294
|
|
|
11262
11295
|
var timeout = useRef(null);
|
|
11263
11296
|
var handleMouseEnter = useCallback(function () {
|
|
11264
11297
|
if (!open) {
|
|
11265
11298
|
timeout.current && clearTimeout(timeout.current);
|
|
11266
|
-
|
|
11299
|
+
setMode(Mode.Open);
|
|
11267
11300
|
}
|
|
11268
11301
|
}, [open]);
|
|
11269
11302
|
var handleMouseLeave = useCallback(function () {
|
|
11270
11303
|
if (!open) {
|
|
11271
11304
|
timeout.current = setTimeout(function () {
|
|
11272
|
-
return
|
|
11305
|
+
return setMode(Mode.Closing);
|
|
11273
11306
|
}, POPOVER_MOUSEOUT_DELAY_MS);
|
|
11274
11307
|
}
|
|
11275
11308
|
}, [open]);
|
|
11276
11309
|
useEffect(function () {
|
|
11277
|
-
|
|
11278
|
-
|
|
11310
|
+
if (mode !== Mode.Closing) return;
|
|
11311
|
+
var closingTimeout = setTimeout(function () {
|
|
11312
|
+
return setMode(Mode.Closed);
|
|
11313
|
+
}, 750);
|
|
11314
|
+
return function () {
|
|
11315
|
+
return clearTimeout(closingTimeout);
|
|
11316
|
+
};
|
|
11317
|
+
}, [mode]);
|
|
11318
|
+
useEffect(function () {
|
|
11319
|
+
if (mode !== Mode.AutoOpening) return;
|
|
11320
|
+
var openingTimeout = setTimeout(function () {
|
|
11321
|
+
return setMode(Mode.AutoOpen);
|
|
11322
|
+
}, 1000);
|
|
11323
|
+
return function () {
|
|
11324
|
+
return clearTimeout(openingTimeout);
|
|
11325
|
+
};
|
|
11326
|
+
}, [mode]);
|
|
11327
|
+
useEffect(function () {
|
|
11328
|
+
if (mode !== Mode.AutoOpen) return;
|
|
11329
|
+
var stayingTimeout = setTimeout(function () {
|
|
11330
|
+
return setMode(Mode.Closing);
|
|
11331
|
+
}, 5000);
|
|
11332
|
+
return function () {
|
|
11333
|
+
return clearTimeout(stayingTimeout);
|
|
11334
|
+
};
|
|
11335
|
+
}, [mode]);
|
|
11336
|
+
var isOpen = mode === Mode.AutoOpen || mode === Mode.Open || mode === Mode.Closing;
|
|
11279
11337
|
return /*#__PURE__*/React__default.createElement("div", _extends$3({
|
|
11280
11338
|
className: classNames("Popover Popover--anchor-".concat(anchor), className),
|
|
11281
11339
|
onMouseEnter: handleMouseEnter,
|
|
11282
11340
|
onMouseLeave: handleMouseLeave
|
|
11283
11341
|
}, rest), /*#__PURE__*/React__default.createElement("span", {
|
|
11284
11342
|
className: "Popover__trigger"
|
|
11285
|
-
}, isOpen && /*#__PURE__*/React__default.createElement(
|
|
11343
|
+
}, isOpen && /*#__PURE__*/React__default.createElement("div", {
|
|
11344
|
+
className: classNames('Popover__box', {
|
|
11345
|
+
'Popover__box--closing': mode === Mode.Closing
|
|
11346
|
+
})
|
|
11347
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
11286
11348
|
className: "Popover__caret",
|
|
11287
11349
|
style: {
|
|
11288
11350
|
zIndex: zIndex != null ? zIndex + 1 : undefined
|