@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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [15.11.3](https://github.com/ModaOperandi/om/compare/v15.11.2...v15.11.3) (2021-12-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **popover:** fixes open & !open logic ([#2265](https://github.com/ModaOperandi/om/issues/2265)) ([21e5bc9](https://github.com/ModaOperandi/om/commit/21e5bc995297ca3eeaaf4c4e0361ddb4860bd7b7))
|
|
12
|
+
|
|
13
|
+
## [15.11.2](https://github.com/ModaOperandi/om/compare/v15.11.1...v15.11.2) (2021-12-10)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **popover smooth transitioning:** fixes problem with auto triggering ([#2260](https://github.com/ModaOperandi/om/issues/2260)) ([4700f11](https://github.com/ModaOperandi/om/commit/4700f11641478123d6220f8bef7d4a0ce81daf45))
|
|
19
|
+
|
|
20
|
+
## [15.11.1](https://github.com/ModaOperandi/om/compare/v15.11.0...v15.11.1) (2021-12-10)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **popover:** clears out props, makes smooth transitioning optional ([#2259](https://github.com/ModaOperandi/om/issues/2259)) ([9880664](https://github.com/ModaOperandi/om/commit/988066478a0f226d54db5b374dc54e1840fd9aee))
|
|
26
|
+
|
|
27
|
+
# [15.11.0](https://github.com/ModaOperandi/om/compare/v15.10.3...v15.11.0) (2021-12-10)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* **popover:** adds popover smooth animation ([#2256](https://github.com/ModaOperandi/om/issues/2256)) ([ad7562f](https://github.com/ModaOperandi/om/commit/ad7562f3256ba04b7b80a761c044ac17656f6588))
|
|
33
|
+
|
|
6
34
|
## [15.10.3](https://github.com/ModaOperandi/om/compare/v15.10.2...v15.10.3) (2021-10-27)
|
|
7
35
|
|
|
8
36
|
|
|
@@ -6,6 +6,8 @@ export declare type PopoverProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
6
6
|
open?: boolean;
|
|
7
7
|
anchor?: 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight';
|
|
8
8
|
zIndex?: number;
|
|
9
|
+
autoPreview?: boolean;
|
|
10
|
+
smoothTransitioning?: boolean;
|
|
9
11
|
};
|
|
10
12
|
export declare const POPOVER_MOUSEOUT_DELAY_MS = 200;
|
|
11
13
|
export declare const Popover: React.FC<PopoverProps>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -2988,21 +2988,32 @@ var FocusLock = /*#__PURE__*/React__namespace.forwardRef(function FocusLockUI(pr
|
|
|
2988
2988
|
onDeactivationCallback(observed.current);
|
|
2989
2989
|
}
|
|
2990
2990
|
}, [onDeactivationCallback]);
|
|
2991
|
+
React$2.useEffect(function () {
|
|
2992
|
+
if (!disabled) {
|
|
2993
|
+
// cleanup return focus on trap deactivation
|
|
2994
|
+
// sideEffect/returnFocus should happen by this time
|
|
2995
|
+
originalFocusedElement.current = null;
|
|
2996
|
+
}
|
|
2997
|
+
}, []);
|
|
2991
2998
|
var returnFocus = React__namespace.useCallback(function (allowDefer) {
|
|
2992
|
-
var
|
|
2999
|
+
var returnFocusTo = originalFocusedElement.current;
|
|
2993
3000
|
|
|
2994
|
-
if (
|
|
2995
|
-
var
|
|
2996
|
-
originalFocusedElement.current = null;
|
|
3001
|
+
if (returnFocusTo && returnFocusTo.focus) {
|
|
3002
|
+
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus;
|
|
2997
3003
|
|
|
2998
|
-
if (
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3004
|
+
if (Boolean(howToReturnFocus)) {
|
|
3005
|
+
var focusOptions = _typeof(howToReturnFocus) === 'object' ? howToReturnFocus : undefined;
|
|
3006
|
+
originalFocusedElement.current = null;
|
|
3007
|
+
|
|
3008
|
+
if (allowDefer) {
|
|
3009
|
+
// React might return focus after update
|
|
3010
|
+
// it's safer to defer the action
|
|
3011
|
+
Promise.resolve().then(function () {
|
|
3012
|
+
return returnFocusTo.focus(focusOptions);
|
|
3013
|
+
});
|
|
3014
|
+
} else {
|
|
3015
|
+
returnFocusTo.focus(focusOptions);
|
|
3016
|
+
}
|
|
3006
3017
|
}
|
|
3007
3018
|
}
|
|
3008
3019
|
}, [shouldReturnFocus]); // MEDIUM CALLBACKS
|
|
@@ -3940,13 +3951,13 @@ var onWindowBlur = function onWindowBlur() {
|
|
|
3940
3951
|
};
|
|
3941
3952
|
|
|
3942
3953
|
var attachHandler = function attachHandler() {
|
|
3943
|
-
document.addEventListener('focusin', onTrap
|
|
3954
|
+
document.addEventListener('focusin', onTrap);
|
|
3944
3955
|
document.addEventListener('focusout', onBlur);
|
|
3945
3956
|
window.addEventListener('blur', onWindowBlur);
|
|
3946
3957
|
};
|
|
3947
3958
|
|
|
3948
3959
|
var detachHandler = function detachHandler() {
|
|
3949
|
-
document.removeEventListener('focusin', onTrap
|
|
3960
|
+
document.removeEventListener('focusin', onTrap);
|
|
3950
3961
|
document.removeEventListener('focusout', onBlur);
|
|
3951
3962
|
window.removeEventListener('blur', onWindowBlur);
|
|
3952
3963
|
};
|
|
@@ -8616,30 +8627,30 @@ var useClickOutside = function useClickOutside(ref, onClickOutside) {
|
|
|
8616
8627
|
});
|
|
8617
8628
|
};
|
|
8618
8629
|
|
|
8619
|
-
var Mode;
|
|
8630
|
+
var Mode$1;
|
|
8620
8631
|
|
|
8621
8632
|
(function (Mode) {
|
|
8622
8633
|
Mode[Mode["Resting"] = 0] = "Resting";
|
|
8623
8634
|
Mode[Mode["Open"] = 1] = "Open";
|
|
8624
|
-
})(Mode || (Mode = {}));
|
|
8635
|
+
})(Mode$1 || (Mode$1 = {}));
|
|
8625
8636
|
|
|
8626
8637
|
var reducer = function reducer(state, action) {
|
|
8627
8638
|
switch (action.type) {
|
|
8628
8639
|
case 'OPEN':
|
|
8629
8640
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8630
|
-
mode: Mode.Open
|
|
8641
|
+
mode: Mode$1.Open
|
|
8631
8642
|
});
|
|
8632
8643
|
|
|
8633
8644
|
case 'CLOSE':
|
|
8634
8645
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8635
|
-
mode: Mode.Resting
|
|
8646
|
+
mode: Mode$1.Resting
|
|
8636
8647
|
});
|
|
8637
8648
|
|
|
8638
8649
|
case 'SELECT':
|
|
8639
8650
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8640
8651
|
value: action.payload.value,
|
|
8641
8652
|
focused: undefined,
|
|
8642
|
-
mode: Mode.Resting
|
|
8653
|
+
mode: Mode$1.Resting
|
|
8643
8654
|
});
|
|
8644
8655
|
|
|
8645
8656
|
case 'FOCUS':
|
|
@@ -8658,7 +8669,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8658
8669
|
var _useReducer = React$2.useReducer(reducer, {
|
|
8659
8670
|
value: initialValue,
|
|
8660
8671
|
focused: _typeof(initialValue) == 'object' ? initialValue === null || initialValue === void 0 ? void 0 : initialValue[0] : initialValue,
|
|
8661
|
-
mode: Mode.Resting
|
|
8672
|
+
mode: Mode$1.Resting
|
|
8662
8673
|
}),
|
|
8663
8674
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
8664
8675
|
state = _useReducer2[0],
|
|
@@ -8700,7 +8711,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8700
8711
|
return {
|
|
8701
8712
|
state: state,
|
|
8702
8713
|
dispatch: dispatch,
|
|
8703
|
-
Mode: Mode,
|
|
8714
|
+
Mode: Mode$1,
|
|
8704
8715
|
selectRef: selectRef
|
|
8705
8716
|
};
|
|
8706
8717
|
};
|
|
@@ -11268,8 +11279,19 @@ var Paginator = function Paginator(_ref) {
|
|
|
11268
11279
|
})));
|
|
11269
11280
|
};
|
|
11270
11281
|
|
|
11271
|
-
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex"];
|
|
11282
|
+
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning"];
|
|
11272
11283
|
var POPOVER_MOUSEOUT_DELAY_MS = 200;
|
|
11284
|
+
var Mode;
|
|
11285
|
+
|
|
11286
|
+
(function (Mode) {
|
|
11287
|
+
Mode["Opening"] = "opening";
|
|
11288
|
+
Mode["Open"] = "open";
|
|
11289
|
+
Mode["Closing"] = "closing";
|
|
11290
|
+
Mode["AutoOpening"] = "autoOpening";
|
|
11291
|
+
Mode["AutoOpen"] = "autoOpen";
|
|
11292
|
+
Mode["Closed"] = "closed";
|
|
11293
|
+
})(Mode || (Mode = {}));
|
|
11294
|
+
|
|
11273
11295
|
var Popover = function Popover(_ref) {
|
|
11274
11296
|
var className = _ref.className,
|
|
11275
11297
|
children = _ref.children,
|
|
@@ -11279,37 +11301,110 @@ var Popover = function Popover(_ref) {
|
|
|
11279
11301
|
_ref$anchor = _ref.anchor,
|
|
11280
11302
|
anchor = _ref$anchor === void 0 ? 'topLeft' : _ref$anchor,
|
|
11281
11303
|
zIndex = _ref.zIndex,
|
|
11304
|
+
_ref$autoPreview = _ref.autoPreview,
|
|
11305
|
+
autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
|
|
11306
|
+
_ref$smoothTransition = _ref.smoothTransitioning,
|
|
11307
|
+
smoothTransitioning = _ref$smoothTransition === void 0 ? false : _ref$smoothTransition,
|
|
11282
11308
|
rest = _objectWithoutProperties(_ref, _excluded$b);
|
|
11283
11309
|
|
|
11284
|
-
var _useState = React$2.useState(
|
|
11310
|
+
var _useState = React$2.useState(function () {
|
|
11311
|
+
if (open && smoothTransitioning) {
|
|
11312
|
+
return Mode.Opening;
|
|
11313
|
+
}
|
|
11314
|
+
|
|
11315
|
+
if (open && !smoothTransitioning) {
|
|
11316
|
+
return Mode.Open;
|
|
11317
|
+
}
|
|
11318
|
+
|
|
11319
|
+
if (autoPreview) {
|
|
11320
|
+
return Mode.AutoOpening;
|
|
11321
|
+
}
|
|
11322
|
+
|
|
11323
|
+
return Mode.Closed;
|
|
11324
|
+
}),
|
|
11285
11325
|
_useState2 = _slicedToArray(_useState, 2),
|
|
11286
|
-
|
|
11287
|
-
|
|
11326
|
+
mode = _useState2[0],
|
|
11327
|
+
setMode = _useState2[1];
|
|
11288
11328
|
|
|
11289
11329
|
var timeout = React$2.useRef(null);
|
|
11290
11330
|
var handleMouseEnter = React$2.useCallback(function () {
|
|
11291
11331
|
if (!open) {
|
|
11292
11332
|
timeout.current && clearTimeout(timeout.current);
|
|
11293
|
-
|
|
11333
|
+
setMode(smoothTransitioning ? Mode.Opening : Mode.Open);
|
|
11294
11334
|
}
|
|
11295
|
-
}, [open]);
|
|
11335
|
+
}, [open, smoothTransitioning]);
|
|
11296
11336
|
var handleMouseLeave = React$2.useCallback(function () {
|
|
11297
|
-
if (
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11301
|
-
|
|
11302
|
-
|
|
11337
|
+
if (open) return;
|
|
11338
|
+
timeout.current = setTimeout(function () {
|
|
11339
|
+
return setMode(smoothTransitioning ? Mode.Closing : Mode.Closed);
|
|
11340
|
+
}, POPOVER_MOUSEOUT_DELAY_MS);
|
|
11341
|
+
}, [open, smoothTransitioning]);
|
|
11342
|
+
React$2.useEffect(function () {
|
|
11343
|
+
if (mode !== Mode.Closing) return;
|
|
11344
|
+
var closingTimeout = setTimeout(function () {
|
|
11345
|
+
return setMode(Mode.Closed);
|
|
11346
|
+
}, 750);
|
|
11347
|
+
return function () {
|
|
11348
|
+
return clearTimeout(closingTimeout);
|
|
11349
|
+
};
|
|
11350
|
+
}, [mode]);
|
|
11351
|
+
React$2.useEffect(function () {
|
|
11352
|
+
if (mode !== Mode.AutoOpening) return;
|
|
11353
|
+
var openingTimeout = setTimeout(function () {
|
|
11354
|
+
return setMode(Mode.AutoOpen);
|
|
11355
|
+
}, 1000);
|
|
11356
|
+
return function () {
|
|
11357
|
+
return clearTimeout(openingTimeout);
|
|
11358
|
+
};
|
|
11359
|
+
}, [mode]);
|
|
11360
|
+
React$2.useEffect(function () {
|
|
11361
|
+
if (mode !== Mode.Opening) return;
|
|
11362
|
+
var openingTimeout = setTimeout(function () {
|
|
11363
|
+
return setMode(Mode.Open);
|
|
11364
|
+
}, 750);
|
|
11365
|
+
return function () {
|
|
11366
|
+
return clearTimeout(openingTimeout);
|
|
11367
|
+
};
|
|
11368
|
+
}, [mode]);
|
|
11303
11369
|
React$2.useEffect(function () {
|
|
11304
|
-
|
|
11305
|
-
|
|
11370
|
+
if (mode !== Mode.AutoOpen) return;
|
|
11371
|
+
var stayingTimeout = setTimeout(function () {
|
|
11372
|
+
return setMode(smoothTransitioning ? Mode.Closing : Mode.Closed);
|
|
11373
|
+
}, 5000);
|
|
11374
|
+
return function () {
|
|
11375
|
+
return clearTimeout(stayingTimeout);
|
|
11376
|
+
};
|
|
11377
|
+
}, [mode, smoothTransitioning]);
|
|
11378
|
+
React$2.useEffect(function () {
|
|
11379
|
+
if (open && smoothTransitioning) {
|
|
11380
|
+
setMode(Mode.Opening);
|
|
11381
|
+
}
|
|
11382
|
+
|
|
11383
|
+
if (open && !smoothTransitioning) {
|
|
11384
|
+
setMode(Mode.Open);
|
|
11385
|
+
}
|
|
11386
|
+
|
|
11387
|
+
if (!open && smoothTransitioning) {
|
|
11388
|
+
setMode(Mode.Closing);
|
|
11389
|
+
}
|
|
11390
|
+
|
|
11391
|
+
if (!open && !smoothTransitioning) {
|
|
11392
|
+
setMode(Mode.Closed);
|
|
11393
|
+
}
|
|
11394
|
+
}, [open, smoothTransitioning]);
|
|
11395
|
+
var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
|
|
11306
11396
|
return /*#__PURE__*/React__default["default"].createElement("div", _extends$3({
|
|
11307
11397
|
className: classNames("Popover Popover--anchor-".concat(anchor), className),
|
|
11308
11398
|
onMouseEnter: handleMouseEnter,
|
|
11309
11399
|
onMouseLeave: handleMouseLeave
|
|
11310
11400
|
}, rest), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
11311
11401
|
className: "Popover__trigger"
|
|
11312
|
-
}, isOpen && /*#__PURE__*/React__default["default"].createElement(
|
|
11402
|
+
}, isOpen && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
11403
|
+
className: classNames('Popover__box', {
|
|
11404
|
+
'Popover__box--opening': mode === Mode.Opening,
|
|
11405
|
+
'Popover__box--closing': mode === Mode.Closing
|
|
11406
|
+
})
|
|
11407
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
11313
11408
|
className: "Popover__caret",
|
|
11314
11409
|
style: {
|
|
11315
11410
|
zIndex: zIndex != null ? zIndex + 1 : undefined
|