@moda/om 15.10.2 → 15.11.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/CHANGELOG.md +28 -0
- package/dist/components/Popover/Popover.d.ts +2 -0
- package/dist/index.cjs.js +133 -42
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +134 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +9 -9
- package/src/components/Popover/Popover.scss +24 -0
- package/src/components/Popover/Popover.stories.tsx +5 -1
- package/src/components/Popover/Popover.tsx +93 -9
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import 'focus-visible';
|
|
|
3
3
|
export declare const tokens: {
|
|
4
4
|
colors: {
|
|
5
5
|
all: {
|
|
6
|
+
coal: string;
|
|
6
7
|
ink: string;
|
|
7
8
|
cement: string;
|
|
8
9
|
fog: string;
|
|
@@ -60,6 +61,7 @@ export declare const tokens: {
|
|
|
60
61
|
"dark-fuchsia": string;
|
|
61
62
|
};
|
|
62
63
|
greyscale: {
|
|
64
|
+
coal: string;
|
|
63
65
|
ink: string;
|
|
64
66
|
cement: string;
|
|
65
67
|
fog: string;
|
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
|
|
|
@@ -327,6 +327,7 @@ colors.colors = void 0; // THIS FILE IS AUTO-GENERATED. DO NOT EDIT.
|
|
|
327
327
|
|
|
328
328
|
colors.colors = {
|
|
329
329
|
"all": {
|
|
330
|
+
"coal": "rgb(0, 0, 0)",
|
|
330
331
|
"ink": "rgb(25, 26, 27)",
|
|
331
332
|
"cement": "rgb(101, 101, 102)",
|
|
332
333
|
"fog": "rgb(151, 152, 153)",
|
|
@@ -384,6 +385,7 @@ colors.colors = {
|
|
|
384
385
|
"dark-fuchsia": "rgb(180, 60, 160)"
|
|
385
386
|
},
|
|
386
387
|
"greyscale": {
|
|
388
|
+
"coal": "rgb(0, 0, 0)",
|
|
387
389
|
"ink": "rgb(25, 26, 27)",
|
|
388
390
|
"cement": "rgb(101, 101, 102)",
|
|
389
391
|
"fog": "rgb(151, 152, 153)",
|
|
@@ -938,12 +940,14 @@ var __assign$9 = commonjsGlobal && commonjsGlobal.__assign || function () {
|
|
|
938
940
|
return __assign$9.apply(this, arguments);
|
|
939
941
|
};
|
|
940
942
|
|
|
941
|
-
var __spreadArray = commonjsGlobal && commonjsGlobal.__spreadArray || function (to, from) {
|
|
942
|
-
for (var i = 0,
|
|
943
|
-
|
|
943
|
+
var __spreadArray = commonjsGlobal && commonjsGlobal.__spreadArray || function (to, from, pack) {
|
|
944
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
945
|
+
if (ar || !(i in from)) {
|
|
946
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
947
|
+
ar[i] = from[i];
|
|
948
|
+
}
|
|
944
949
|
}
|
|
945
|
-
|
|
946
|
-
return to;
|
|
950
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
947
951
|
};
|
|
948
952
|
|
|
949
953
|
Object.defineProperty(helpers, "__esModule", {
|
|
@@ -979,7 +983,7 @@ var color = function color(name, alpha) {
|
|
|
979
983
|
var _a;
|
|
980
984
|
|
|
981
985
|
var color = colors_1.colors.all[name];
|
|
982
|
-
return alpha != null ? colorString.to.rgb(__spreadArray(__spreadArray([], ((_a = colorString.get.rgb(color)) === null || _a === void 0 ? void 0 : _a.slice(0, 3)) || []), [alpha])) : color;
|
|
986
|
+
return alpha != null ? colorString.to.rgb(__spreadArray(__spreadArray([], ((_a = colorString.get.rgb(color)) === null || _a === void 0 ? void 0 : _a.slice(0, 3)) || [], true), [alpha], false)) : color;
|
|
983
987
|
};
|
|
984
988
|
|
|
985
989
|
helpers.color = color;
|
|
@@ -2957,21 +2961,32 @@ var FocusLock = /*#__PURE__*/React$2.forwardRef(function FocusLockUI(props, pare
|
|
|
2957
2961
|
onDeactivationCallback(observed.current);
|
|
2958
2962
|
}
|
|
2959
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
|
+
}, []);
|
|
2960
2971
|
var returnFocus = React$2.useCallback(function (allowDefer) {
|
|
2961
|
-
var
|
|
2972
|
+
var returnFocusTo = originalFocusedElement.current;
|
|
2962
2973
|
|
|
2963
|
-
if (
|
|
2964
|
-
var
|
|
2965
|
-
originalFocusedElement.current = null;
|
|
2974
|
+
if (returnFocusTo && returnFocusTo.focus) {
|
|
2975
|
+
var howToReturnFocus = typeof shouldReturnFocus === 'function' ? shouldReturnFocus(returnFocusTo) : shouldReturnFocus;
|
|
2966
2976
|
|
|
2967
|
-
if (
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
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
|
+
}
|
|
2975
2990
|
}
|
|
2976
2991
|
}
|
|
2977
2992
|
}, [shouldReturnFocus]); // MEDIUM CALLBACKS
|
|
@@ -3909,13 +3924,13 @@ var onWindowBlur = function onWindowBlur() {
|
|
|
3909
3924
|
};
|
|
3910
3925
|
|
|
3911
3926
|
var attachHandler = function attachHandler() {
|
|
3912
|
-
document.addEventListener('focusin', onTrap
|
|
3927
|
+
document.addEventListener('focusin', onTrap);
|
|
3913
3928
|
document.addEventListener('focusout', onBlur);
|
|
3914
3929
|
window.addEventListener('blur', onWindowBlur);
|
|
3915
3930
|
};
|
|
3916
3931
|
|
|
3917
3932
|
var detachHandler = function detachHandler() {
|
|
3918
|
-
document.removeEventListener('focusin', onTrap
|
|
3933
|
+
document.removeEventListener('focusin', onTrap);
|
|
3919
3934
|
document.removeEventListener('focusout', onBlur);
|
|
3920
3935
|
window.removeEventListener('blur', onWindowBlur);
|
|
3921
3936
|
};
|
|
@@ -8585,30 +8600,30 @@ var useClickOutside = function useClickOutside(ref, onClickOutside) {
|
|
|
8585
8600
|
});
|
|
8586
8601
|
};
|
|
8587
8602
|
|
|
8588
|
-
var Mode;
|
|
8603
|
+
var Mode$1;
|
|
8589
8604
|
|
|
8590
8605
|
(function (Mode) {
|
|
8591
8606
|
Mode[Mode["Resting"] = 0] = "Resting";
|
|
8592
8607
|
Mode[Mode["Open"] = 1] = "Open";
|
|
8593
|
-
})(Mode || (Mode = {}));
|
|
8608
|
+
})(Mode$1 || (Mode$1 = {}));
|
|
8594
8609
|
|
|
8595
8610
|
var reducer = function reducer(state, action) {
|
|
8596
8611
|
switch (action.type) {
|
|
8597
8612
|
case 'OPEN':
|
|
8598
8613
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8599
|
-
mode: Mode.Open
|
|
8614
|
+
mode: Mode$1.Open
|
|
8600
8615
|
});
|
|
8601
8616
|
|
|
8602
8617
|
case 'CLOSE':
|
|
8603
8618
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8604
|
-
mode: Mode.Resting
|
|
8619
|
+
mode: Mode$1.Resting
|
|
8605
8620
|
});
|
|
8606
8621
|
|
|
8607
8622
|
case 'SELECT':
|
|
8608
8623
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
8609
8624
|
value: action.payload.value,
|
|
8610
8625
|
focused: undefined,
|
|
8611
|
-
mode: Mode.Resting
|
|
8626
|
+
mode: Mode$1.Resting
|
|
8612
8627
|
});
|
|
8613
8628
|
|
|
8614
8629
|
case 'FOCUS':
|
|
@@ -8627,7 +8642,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8627
8642
|
var _useReducer = useReducer(reducer, {
|
|
8628
8643
|
value: initialValue,
|
|
8629
8644
|
focused: _typeof(initialValue) == 'object' ? initialValue === null || initialValue === void 0 ? void 0 : initialValue[0] : initialValue,
|
|
8630
|
-
mode: Mode.Resting
|
|
8645
|
+
mode: Mode$1.Resting
|
|
8631
8646
|
}),
|
|
8632
8647
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
8633
8648
|
state = _useReducer2[0],
|
|
@@ -8669,7 +8684,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
8669
8684
|
return {
|
|
8670
8685
|
state: state,
|
|
8671
8686
|
dispatch: dispatch,
|
|
8672
|
-
Mode: Mode,
|
|
8687
|
+
Mode: Mode$1,
|
|
8673
8688
|
selectRef: selectRef
|
|
8674
8689
|
};
|
|
8675
8690
|
};
|
|
@@ -11237,8 +11252,19 @@ var Paginator = function Paginator(_ref) {
|
|
|
11237
11252
|
})));
|
|
11238
11253
|
};
|
|
11239
11254
|
|
|
11240
|
-
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex"];
|
|
11255
|
+
var _excluded$b = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning"];
|
|
11241
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
|
+
|
|
11242
11268
|
var Popover = function Popover(_ref) {
|
|
11243
11269
|
var className = _ref.className,
|
|
11244
11270
|
children = _ref.children,
|
|
@@ -11248,37 +11274,102 @@ var Popover = function Popover(_ref) {
|
|
|
11248
11274
|
_ref$anchor = _ref.anchor,
|
|
11249
11275
|
anchor = _ref$anchor === void 0 ? 'topLeft' : _ref$anchor,
|
|
11250
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,
|
|
11251
11281
|
rest = _objectWithoutProperties(_ref, _excluded$b);
|
|
11252
11282
|
|
|
11253
|
-
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
|
+
}),
|
|
11254
11298
|
_useState2 = _slicedToArray(_useState, 2),
|
|
11255
|
-
|
|
11256
|
-
|
|
11299
|
+
mode = _useState2[0],
|
|
11300
|
+
setMode = _useState2[1];
|
|
11257
11301
|
|
|
11258
11302
|
var timeout = useRef(null);
|
|
11259
11303
|
var handleMouseEnter = useCallback(function () {
|
|
11260
11304
|
if (!open) {
|
|
11261
11305
|
timeout.current && clearTimeout(timeout.current);
|
|
11262
|
-
|
|
11306
|
+
setMode(smoothTransitioning ? Mode.Opening : Mode.Open);
|
|
11263
11307
|
}
|
|
11264
|
-
}, [open]);
|
|
11308
|
+
}, [open, smoothTransitioning]);
|
|
11265
11309
|
var handleMouseLeave = useCallback(function () {
|
|
11266
|
-
if (
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
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]);
|
|
11342
|
+
useEffect(function () {
|
|
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]);
|
|
11272
11351
|
useEffect(function () {
|
|
11273
|
-
|
|
11274
|
-
|
|
11352
|
+
if (!open) return;
|
|
11353
|
+
|
|
11354
|
+
if (smoothTransitioning) {
|
|
11355
|
+
setMode(Mode.Opening);
|
|
11356
|
+
}
|
|
11357
|
+
|
|
11358
|
+
setMode(Mode.Open);
|
|
11359
|
+
}, [mode, open]);
|
|
11360
|
+
var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
|
|
11275
11361
|
return /*#__PURE__*/React__default.createElement("div", _extends$3({
|
|
11276
11362
|
className: classNames("Popover Popover--anchor-".concat(anchor), className),
|
|
11277
11363
|
onMouseEnter: handleMouseEnter,
|
|
11278
11364
|
onMouseLeave: handleMouseLeave
|
|
11279
11365
|
}, rest), /*#__PURE__*/React__default.createElement("span", {
|
|
11280
11366
|
className: "Popover__trigger"
|
|
11281
|
-
}, isOpen && /*#__PURE__*/React__default.createElement(
|
|
11367
|
+
}, isOpen && /*#__PURE__*/React__default.createElement("div", {
|
|
11368
|
+
className: classNames('Popover__box', {
|
|
11369
|
+
'Popover__box--opening': mode === Mode.Opening,
|
|
11370
|
+
'Popover__box--closing': mode === Mode.Closing
|
|
11371
|
+
})
|
|
11372
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
11282
11373
|
className: "Popover__caret",
|
|
11283
11374
|
style: {
|
|
11284
11375
|
zIndex: zIndex != null ? zIndex + 1 : undefined
|