@moda/om 15.10.3 → 15.11.3
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 +28 -0
- package/dist/components/Popover/Popover.d.ts +2 -0
- package/dist/index.cjs.js +131 -36
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +132 -37
- 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 +5 -1
- package/src/components/Popover/Popover.tsx +101 -9
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,19 @@ 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", "smoothTransitioning"];
|
|
11245
11256
|
var POPOVER_MOUSEOUT_DELAY_MS = 200;
|
|
11257
|
+
var Mode;
|
|
11258
|
+
|
|
11259
|
+
(function (Mode) {
|
|
11260
|
+
Mode["Opening"] = "opening";
|
|
11261
|
+
Mode["Open"] = "open";
|
|
11262
|
+
Mode["Closing"] = "closing";
|
|
11263
|
+
Mode["AutoOpening"] = "autoOpening";
|
|
11264
|
+
Mode["AutoOpen"] = "autoOpen";
|
|
11265
|
+
Mode["Closed"] = "closed";
|
|
11266
|
+
})(Mode || (Mode = {}));
|
|
11267
|
+
|
|
11246
11268
|
var Popover = function Popover(_ref) {
|
|
11247
11269
|
var className = _ref.className,
|
|
11248
11270
|
children = _ref.children,
|
|
@@ -11252,37 +11274,110 @@ var Popover = function Popover(_ref) {
|
|
|
11252
11274
|
_ref$anchor = _ref.anchor,
|
|
11253
11275
|
anchor = _ref$anchor === void 0 ? 'topLeft' : _ref$anchor,
|
|
11254
11276
|
zIndex = _ref.zIndex,
|
|
11277
|
+
_ref$autoPreview = _ref.autoPreview,
|
|
11278
|
+
autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
|
|
11279
|
+
_ref$smoothTransition = _ref.smoothTransitioning,
|
|
11280
|
+
smoothTransitioning = _ref$smoothTransition === void 0 ? false : _ref$smoothTransition,
|
|
11255
11281
|
rest = _objectWithoutProperties(_ref, _excluded$b);
|
|
11256
11282
|
|
|
11257
|
-
var _useState = useState(
|
|
11283
|
+
var _useState = useState(function () {
|
|
11284
|
+
if (open && smoothTransitioning) {
|
|
11285
|
+
return Mode.Opening;
|
|
11286
|
+
}
|
|
11287
|
+
|
|
11288
|
+
if (open && !smoothTransitioning) {
|
|
11289
|
+
return Mode.Open;
|
|
11290
|
+
}
|
|
11291
|
+
|
|
11292
|
+
if (autoPreview) {
|
|
11293
|
+
return Mode.AutoOpening;
|
|
11294
|
+
}
|
|
11295
|
+
|
|
11296
|
+
return Mode.Closed;
|
|
11297
|
+
}),
|
|
11258
11298
|
_useState2 = _slicedToArray(_useState, 2),
|
|
11259
|
-
|
|
11260
|
-
|
|
11299
|
+
mode = _useState2[0],
|
|
11300
|
+
setMode = _useState2[1];
|
|
11261
11301
|
|
|
11262
11302
|
var timeout = useRef(null);
|
|
11263
11303
|
var handleMouseEnter = useCallback(function () {
|
|
11264
11304
|
if (!open) {
|
|
11265
11305
|
timeout.current && clearTimeout(timeout.current);
|
|
11266
|
-
|
|
11306
|
+
setMode(smoothTransitioning ? Mode.Opening : Mode.Open);
|
|
11267
11307
|
}
|
|
11268
|
-
}, [open]);
|
|
11308
|
+
}, [open, smoothTransitioning]);
|
|
11269
11309
|
var handleMouseLeave = useCallback(function () {
|
|
11270
|
-
if (
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
|
|
11310
|
+
if (open) return;
|
|
11311
|
+
timeout.current = setTimeout(function () {
|
|
11312
|
+
return setMode(smoothTransitioning ? Mode.Closing : Mode.Closed);
|
|
11313
|
+
}, POPOVER_MOUSEOUT_DELAY_MS);
|
|
11314
|
+
}, [open, smoothTransitioning]);
|
|
11315
|
+
useEffect(function () {
|
|
11316
|
+
if (mode !== Mode.Closing) return;
|
|
11317
|
+
var closingTimeout = setTimeout(function () {
|
|
11318
|
+
return setMode(Mode.Closed);
|
|
11319
|
+
}, 750);
|
|
11320
|
+
return function () {
|
|
11321
|
+
return clearTimeout(closingTimeout);
|
|
11322
|
+
};
|
|
11323
|
+
}, [mode]);
|
|
11324
|
+
useEffect(function () {
|
|
11325
|
+
if (mode !== Mode.AutoOpening) return;
|
|
11326
|
+
var openingTimeout = setTimeout(function () {
|
|
11327
|
+
return setMode(Mode.AutoOpen);
|
|
11328
|
+
}, 1000);
|
|
11329
|
+
return function () {
|
|
11330
|
+
return clearTimeout(openingTimeout);
|
|
11331
|
+
};
|
|
11332
|
+
}, [mode]);
|
|
11333
|
+
useEffect(function () {
|
|
11334
|
+
if (mode !== Mode.Opening) return;
|
|
11335
|
+
var openingTimeout = setTimeout(function () {
|
|
11336
|
+
return setMode(Mode.Open);
|
|
11337
|
+
}, 750);
|
|
11338
|
+
return function () {
|
|
11339
|
+
return clearTimeout(openingTimeout);
|
|
11340
|
+
};
|
|
11341
|
+
}, [mode]);
|
|
11276
11342
|
useEffect(function () {
|
|
11277
|
-
|
|
11278
|
-
|
|
11343
|
+
if (mode !== Mode.AutoOpen) return;
|
|
11344
|
+
var stayingTimeout = setTimeout(function () {
|
|
11345
|
+
return setMode(smoothTransitioning ? Mode.Closing : Mode.Closed);
|
|
11346
|
+
}, 5000);
|
|
11347
|
+
return function () {
|
|
11348
|
+
return clearTimeout(stayingTimeout);
|
|
11349
|
+
};
|
|
11350
|
+
}, [mode, smoothTransitioning]);
|
|
11351
|
+
useEffect(function () {
|
|
11352
|
+
if (open && smoothTransitioning) {
|
|
11353
|
+
setMode(Mode.Opening);
|
|
11354
|
+
}
|
|
11355
|
+
|
|
11356
|
+
if (open && !smoothTransitioning) {
|
|
11357
|
+
setMode(Mode.Open);
|
|
11358
|
+
}
|
|
11359
|
+
|
|
11360
|
+
if (!open && smoothTransitioning) {
|
|
11361
|
+
setMode(Mode.Closing);
|
|
11362
|
+
}
|
|
11363
|
+
|
|
11364
|
+
if (!open && !smoothTransitioning) {
|
|
11365
|
+
setMode(Mode.Closed);
|
|
11366
|
+
}
|
|
11367
|
+
}, [open, smoothTransitioning]);
|
|
11368
|
+
var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
|
|
11279
11369
|
return /*#__PURE__*/React__default.createElement("div", _extends$3({
|
|
11280
11370
|
className: classNames("Popover Popover--anchor-".concat(anchor), className),
|
|
11281
11371
|
onMouseEnter: handleMouseEnter,
|
|
11282
11372
|
onMouseLeave: handleMouseLeave
|
|
11283
11373
|
}, rest), /*#__PURE__*/React__default.createElement("span", {
|
|
11284
11374
|
className: "Popover__trigger"
|
|
11285
|
-
}, isOpen && /*#__PURE__*/React__default.createElement(
|
|
11375
|
+
}, isOpen && /*#__PURE__*/React__default.createElement("div", {
|
|
11376
|
+
className: classNames('Popover__box', {
|
|
11377
|
+
'Popover__box--opening': mode === Mode.Opening,
|
|
11378
|
+
'Popover__box--closing': mode === Mode.Closing
|
|
11379
|
+
})
|
|
11380
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
11286
11381
|
className: "Popover__caret",
|
|
11287
11382
|
style: {
|
|
11288
11383
|
zIndex: zIndex != null ? zIndex + 1 : undefined
|