@moda/om 21.6.10 → 21.6.12
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/dist/index.cjs.js +71 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +70 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/Field/FormControlContext.d.ts +6 -0
- package/dist/src/components/Field/index.d.ts +1 -0
- package/dist/src/components/Popover/Popover.d.ts +16 -0
- package/dist/src/components/Popover/Popover.stories.d.ts +53 -0
- package/package.json +1 -1
- package/src/components/Field/Field.tsx +46 -41
- package/src/components/Field/FormControlContext.tsx +11 -0
- package/src/components/Field/index.ts +1 -0
- package/src/components/Popover/Popover.stories.tsx +189 -1
- package/src/components/Popover/Popover.tsx +75 -1
- package/src/components/Select/Select.tsx +3 -1
package/dist/index.cjs.js
CHANGED
|
@@ -10011,6 +10011,13 @@ var ChevronUp12 = function ChevronUp12(_a) {
|
|
|
10011
10011
|
};
|
|
10012
10012
|
ChevronUp12.displayName = 'ChevronUp12';
|
|
10013
10013
|
|
|
10014
|
+
var FormControlContext = /*#__PURE__*/React.createContext({
|
|
10015
|
+
displaysError: false
|
|
10016
|
+
});
|
|
10017
|
+
var useFormControlContext = function useFormControlContext() {
|
|
10018
|
+
return React.useContext(FormControlContext);
|
|
10019
|
+
};
|
|
10020
|
+
|
|
10014
10021
|
var dist$1 = {};
|
|
10015
10022
|
|
|
10016
10023
|
var mapCursorToMax = {};
|
|
@@ -10844,6 +10851,8 @@ var Select = function Select(_ref) {
|
|
|
10844
10851
|
_ref$smallMobileText = _ref.smallMobileText,
|
|
10845
10852
|
smallMobileText = _ref$smallMobileText === void 0 ? false : _ref$smallMobileText,
|
|
10846
10853
|
rest = _objectWithoutProperties(_ref, _excluded$j);
|
|
10854
|
+
var _useFormControlContex = useFormControlContext(),
|
|
10855
|
+
errorDisplayedByParent = _useFormControlContex.displaysError;
|
|
10847
10856
|
var _useSelect = useSelect({
|
|
10848
10857
|
value: value,
|
|
10849
10858
|
defaultValue: defaultValue
|
|
@@ -10963,7 +10972,7 @@ var Select = function Select(_ref) {
|
|
|
10963
10972
|
type: 'CLOSE'
|
|
10964
10973
|
});
|
|
10965
10974
|
}
|
|
10966
|
-
})), typeof error === 'string' && /*#__PURE__*/React.createElement("div", {
|
|
10975
|
+
})), typeof error === 'string' && !errorDisplayedByParent && /*#__PURE__*/React.createElement("div", {
|
|
10967
10976
|
role: "status",
|
|
10968
10977
|
"aria-live": "polite",
|
|
10969
10978
|
"aria-atomic": "true",
|
|
@@ -11170,7 +11179,14 @@ var Field = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
11170
11179
|
label = _ref.label,
|
|
11171
11180
|
placeholder = _ref.placeholder,
|
|
11172
11181
|
rest = _objectWithoutProperties(_ref, _excluded$h);
|
|
11173
|
-
|
|
11182
|
+
var fieldContextValue = React.useMemo(function () {
|
|
11183
|
+
return {
|
|
11184
|
+
displaysError: Boolean(error)
|
|
11185
|
+
};
|
|
11186
|
+
}, [error]);
|
|
11187
|
+
return /*#__PURE__*/React.createElement(FormControlContext.Provider, {
|
|
11188
|
+
value: fieldContextValue
|
|
11189
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
11174
11190
|
className: classNames('Field', className)
|
|
11175
11191
|
}, label && /*#__PURE__*/React.createElement("span", {
|
|
11176
11192
|
className: "Field__label"
|
|
@@ -11193,7 +11209,7 @@ var Field = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
11193
11209
|
className: "Field__icon"
|
|
11194
11210
|
}, /*#__PURE__*/React.createElement(Warning16, null)))), error && /*#__PURE__*/React.createElement("span", {
|
|
11195
11211
|
className: "Field__error"
|
|
11196
|
-
}, error));
|
|
11212
|
+
}, error)));
|
|
11197
11213
|
});
|
|
11198
11214
|
Field.displayName = 'Field';
|
|
11199
11215
|
|
|
@@ -12335,7 +12351,7 @@ var PasswordInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
12335
12351
|
});
|
|
12336
12352
|
PasswordInput.displayName = 'PasswordInput';
|
|
12337
12353
|
|
|
12338
|
-
var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning"];
|
|
12354
|
+
var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning", "role", "aria-label", "aria-labelledby", "popoverId", "openOnFocus", "closeOnEscape", "onClose", "autoFocus"];
|
|
12339
12355
|
var POPOVER_MOUSEOUT_DELAY_MS = 200;
|
|
12340
12356
|
var THREE_QUARTER_SECOND_DELAY = 750;
|
|
12341
12357
|
var ONE_SECOND_DELAY = 1000;
|
|
@@ -12361,6 +12377,17 @@ var Popover = function Popover(_ref) {
|
|
|
12361
12377
|
autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
|
|
12362
12378
|
_ref$smoothTransition = _ref.smoothTransitioning,
|
|
12363
12379
|
smoothTransitioning = _ref$smoothTransition === void 0 ? false : _ref$smoothTransition,
|
|
12380
|
+
role = _ref.role,
|
|
12381
|
+
ariaLabel = _ref['aria-label'],
|
|
12382
|
+
ariaLabelledby = _ref['aria-labelledby'],
|
|
12383
|
+
popoverId = _ref.popoverId,
|
|
12384
|
+
_ref$openOnFocus = _ref.openOnFocus,
|
|
12385
|
+
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
12386
|
+
_ref$closeOnEscape = _ref.closeOnEscape,
|
|
12387
|
+
closeOnEscape = _ref$closeOnEscape === void 0 ? true : _ref$closeOnEscape,
|
|
12388
|
+
onClose = _ref.onClose,
|
|
12389
|
+
_ref$autoFocus = _ref.autoFocus,
|
|
12390
|
+
autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
|
|
12364
12391
|
rest = _objectWithoutProperties(_ref, _excluded$9);
|
|
12365
12392
|
var _useState = React.useState(function () {
|
|
12366
12393
|
if (open && smoothTransitioning) {
|
|
@@ -12378,6 +12405,7 @@ var Popover = function Popover(_ref) {
|
|
|
12378
12405
|
mode = _useState2[0],
|
|
12379
12406
|
setMode = _useState2[1];
|
|
12380
12407
|
var timeout = React.useRef(null);
|
|
12408
|
+
var contentRef = React.useRef(null);
|
|
12381
12409
|
var handleOpen = React.useCallback(function () {
|
|
12382
12410
|
if (smoothTransitioning) setMode(Mode.Opening);
|
|
12383
12411
|
if (!smoothTransitioning) setMode(Mode.Open);
|
|
@@ -12396,6 +12424,27 @@ var Popover = function Popover(_ref) {
|
|
|
12396
12424
|
if (open) return;
|
|
12397
12425
|
timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
|
|
12398
12426
|
}, [handleClose, open]);
|
|
12427
|
+
var handleKeyDown = React.useCallback(function (event) {
|
|
12428
|
+
if (closeOnEscape && event.key === 'Escape') {
|
|
12429
|
+
onClose === null || onClose === void 0 || onClose();
|
|
12430
|
+
handleClose();
|
|
12431
|
+
event.preventDefault();
|
|
12432
|
+
}
|
|
12433
|
+
}, [closeOnEscape, onClose, handleClose]);
|
|
12434
|
+
var handleFocus = React.useCallback(function () {
|
|
12435
|
+
if (openOnFocus && open === undefined) {
|
|
12436
|
+
if (timeout.current) clearTimeout(timeout.current);
|
|
12437
|
+
handleOpen();
|
|
12438
|
+
}
|
|
12439
|
+
}, [openOnFocus, open, handleOpen]);
|
|
12440
|
+
var handleBlur = React.useCallback(function (event) {
|
|
12441
|
+
if (openOnFocus && open === undefined) {
|
|
12442
|
+
// Only close if focus moved outside the popover entirely
|
|
12443
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
12444
|
+
timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
|
|
12445
|
+
}
|
|
12446
|
+
}
|
|
12447
|
+
}, [openOnFocus, open, handleClose]);
|
|
12399
12448
|
React.useEffect(function () {
|
|
12400
12449
|
if (mode !== Mode.Closing) return;
|
|
12401
12450
|
var closingTimeout = setTimeout(function () {
|
|
@@ -12439,10 +12488,18 @@ var Popover = function Popover(_ref) {
|
|
|
12439
12488
|
}
|
|
12440
12489
|
}, [handleClose, handleOpen, open]);
|
|
12441
12490
|
var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
|
|
12491
|
+
React.useEffect(function () {
|
|
12492
|
+
if (autoFocus && isOpen && contentRef.current) {
|
|
12493
|
+
contentRef.current.focus();
|
|
12494
|
+
}
|
|
12495
|
+
}, [autoFocus, isOpen]);
|
|
12442
12496
|
return /*#__PURE__*/React.createElement("div", _extends$1({
|
|
12443
12497
|
className: classNames("Popover Popover--anchor-".concat(anchor), className),
|
|
12444
12498
|
onMouseEnter: handleMouseEnter,
|
|
12445
|
-
onMouseLeave: handleMouseLeave
|
|
12499
|
+
onMouseLeave: handleMouseLeave,
|
|
12500
|
+
onKeyDown: handleKeyDown,
|
|
12501
|
+
onFocus: handleFocus,
|
|
12502
|
+
onBlur: handleBlur
|
|
12446
12503
|
}, rest), /*#__PURE__*/React.createElement("span", {
|
|
12447
12504
|
className: "Popover__trigger"
|
|
12448
12505
|
}, isOpen && /*#__PURE__*/React.createElement("div", {
|
|
@@ -12452,10 +12509,17 @@ var Popover = function Popover(_ref) {
|
|
|
12452
12509
|
})
|
|
12453
12510
|
}, /*#__PURE__*/React.createElement("div", {
|
|
12454
12511
|
className: "Popover__caret",
|
|
12512
|
+
"aria-hidden": "true",
|
|
12455
12513
|
style: {
|
|
12456
12514
|
zIndex: zIndex != null ? zIndex + 1 : undefined
|
|
12457
12515
|
}
|
|
12458
12516
|
}), /*#__PURE__*/React.createElement("div", {
|
|
12517
|
+
ref: contentRef,
|
|
12518
|
+
id: popoverId,
|
|
12519
|
+
role: role,
|
|
12520
|
+
"aria-label": ariaLabel,
|
|
12521
|
+
"aria-labelledby": ariaLabelledby,
|
|
12522
|
+
tabIndex: autoFocus ? -1 : undefined,
|
|
12459
12523
|
className: "Popover__content",
|
|
12460
12524
|
style: {
|
|
12461
12525
|
zIndex: zIndex
|
|
@@ -12777,6 +12841,7 @@ exports.ExceedConstrain = ExceedConstrain;
|
|
|
12777
12841
|
exports.Expandable = Expandable;
|
|
12778
12842
|
exports.Field = Field;
|
|
12779
12843
|
exports.FocusOn = FocusOn;
|
|
12844
|
+
exports.FormControlContext = FormControlContext;
|
|
12780
12845
|
exports.Input = Field;
|
|
12781
12846
|
exports.Keyhole = Keyhole;
|
|
12782
12847
|
exports.Label = Label;
|
|
@@ -12836,5 +12901,6 @@ exports.tokens = tokens;
|
|
|
12836
12901
|
exports.useBreakpoint = useBreakpoint;
|
|
12837
12902
|
exports.useClickOutside = useClickOutside;
|
|
12838
12903
|
exports.useConfirm = useConfirm;
|
|
12904
|
+
exports.useFormControlContext = useFormControlContext;
|
|
12839
12905
|
exports.useKeyboardListNavigation = useKeyboardListNavigation;
|
|
12840
12906
|
exports.useUpdateEffect = useUpdateEffect;
|