@alfalab/core-components-base-modal
Advanced tools
Comparing version 5.1.3 to 5.2.0
@@ -87,2 +87,7 @@ /// <reference types="react-transition-group" /> | ||
/** | ||
* Рендерить ли в контейнер через портал. | ||
* @default true | ||
*/ | ||
usePortal?: boolean; | ||
/** | ||
* Обработчик события нажатия на бэкдроп | ||
@@ -89,0 +94,0 @@ */ |
@@ -26,3 +26,3 @@ 'use strict'; | ||
var styles = {"component":"base-modal__component_7v143","wrapper":"base-modal__wrapper_7v143","content":"base-modal__content_7v143","hidden":"base-modal__hidden_7v143","backdrop":"base-modal__backdrop_7v143","appear":"base-modal__appear_7v143","enter":"base-modal__enter_7v143","appearActive":"base-modal__appearActive_7v143","enterActive":"base-modal__enterActive_7v143","exit":"base-modal__exit_7v143","exitActive":"base-modal__exitActive_7v143","exitDone":"base-modal__exitDone_7v143"}; | ||
var styles = {"component":"base-modal__component_1n9jh","wrapper":"base-modal__wrapper_1n9jh","content":"base-modal__content_1n9jh","hidden":"base-modal__hidden_1n9jh","backdrop":"base-modal__backdrop_1n9jh","appear":"base-modal__appear_1n9jh","enter":"base-modal__enter_1n9jh","appearActive":"base-modal__appearActive_1n9jh","enterActive":"base-modal__enterActive_1n9jh","exit":"base-modal__exit_1n9jh","exitActive":"base-modal__exitActive_1n9jh","exitDone":"base-modal__exitDone_1n9jh"}; | ||
require('./index.css') | ||
@@ -47,10 +47,10 @@ | ||
var BaseModal = React.forwardRef(function (_a, ref) { | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop = _c === void 0 ? coreComponentsBackdrop.Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? coreComponentsStack.stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o; | ||
var _p = React.useState(null), exited = _p[0], setExited = _p[1]; | ||
var _q = React.useState(false), hasScroll = _q[0], setHasScroll = _q[1]; | ||
var _r = React.useState(false), hasHeader = _r[0], setHasHeader = _r[1]; | ||
var _s = React.useState(false), hasFooter = _s[0], setHasFooter = _s[1]; | ||
var _t = React.useState(false), headerHighlighted = _t[0], setHeaderHighlighted = _t[1]; | ||
var _u = React.useState(false), footerHighlighted = _u[0], setFooterHighlighted = _u[1]; | ||
var _v = React.useState(0), headerOffset = _v[0], setHeaderOffset = _v[1]; | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop = _c === void 0 ? coreComponentsBackdrop.Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? coreComponentsStack.stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o, _p = _a.usePortal, usePortal = _p === void 0 ? true : _p; | ||
var _q = React.useState(null), exited = _q[0], setExited = _q[1]; | ||
var _r = React.useState(false), hasScroll = _r[0], setHasScroll = _r[1]; | ||
var _s = React.useState(false), hasHeader = _s[0], setHasHeader = _s[1]; | ||
var _t = React.useState(false), hasFooter = _t[0], setHasFooter = _t[1]; | ||
var _u = React.useState(false), headerHighlighted = _u[0], setHeaderHighlighted = _u[1]; | ||
var _v = React.useState(false), footerHighlighted = _v[0], setFooterHighlighted = _v[1]; | ||
var _w = React.useState(0), headerOffset = _w[0], setHeaderOffset = _w[1]; | ||
var componentNodeRef = React.useRef(null); | ||
@@ -238,23 +238,23 @@ var wrapperRef = React.useRef(null); | ||
]); | ||
var renderContent = function () { return (React__default.default.createElement(coreComponentsStack.Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React__default.default.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React__default.default.createElement(FocusLock__default.default, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop && (React__default.default.createElement(Backdrop, tslib.__assign({}, backdropProps, { className: cn__default.default(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React__default.default.createElement("div", { role: 'dialog', className: cn__default.default(styles.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs__default.default([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React__default.default.createElement(reactTransitionGroup.CSSTransition, tslib.__assign({ appear: true, timeout: 200, classNames: styles }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React__default.default.createElement("div", { className: cn__default.default(styles.component, className), ref: mergeRefs__default.default([componentRef, componentNodeRef]) }, | ||
React__default.default.createElement("div", { className: cn__default.default(styles.content, contentClassName) }, children))))))); | ||
})); }; | ||
if (!shouldRender) | ||
return null; | ||
return (React__default.default.createElement(coreComponentsStack.Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React__default.default.createElement(coreComponentsPortal.Portal, { getPortalContainer: container, immediateMount: true }, | ||
React__default.default.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React__default.default.createElement(FocusLock__default.default, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop && (React__default.default.createElement(Backdrop, tslib.__assign({}, backdropProps, { className: cn__default.default(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React__default.default.createElement("div", { role: 'dialog', className: cn__default.default(styles.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs__default.default([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React__default.default.createElement(reactTransitionGroup.CSSTransition, tslib.__assign({ appear: true, timeout: 200, classNames: styles }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React__default.default.createElement("div", { className: cn__default.default(styles.component, className), ref: mergeRefs__default.default([componentRef, componentNodeRef]) }, | ||
React__default.default.createElement("div", { className: cn__default.default(styles.content, contentClassName) }, children)))))))); | ||
})); | ||
return usePortal ? (React__default.default.createElement(coreComponentsPortal.Portal, { getPortalContainer: container, immediateMount: true }, renderContent())) : (renderContent()); | ||
}); | ||
@@ -261,0 +261,0 @@ |
@@ -87,2 +87,7 @@ /// <reference types="react-transition-group" /> | ||
/** | ||
* Рендерить ли в контейнер через портал. | ||
* @default true | ||
*/ | ||
usePortal?: boolean; | ||
/** | ||
* Обработчик события нажатия на бэкдроп | ||
@@ -89,0 +94,0 @@ */ |
@@ -45,10 +45,10 @@ 'use strict'; | ||
var BaseModal = React.forwardRef(function (_a, ref) { | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop = _c === void 0 ? coreComponentsBackdrop.Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? coreComponentsStack.stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o; | ||
var _p = React.useState(null), exited = _p[0], setExited = _p[1]; | ||
var _q = React.useState(false), hasScroll = _q[0], setHasScroll = _q[1]; | ||
var _r = React.useState(false), hasHeader = _r[0], setHasHeader = _r[1]; | ||
var _s = React.useState(false), hasFooter = _s[0], setHasFooter = _s[1]; | ||
var _t = React.useState(false), headerHighlighted = _t[0], setHeaderHighlighted = _t[1]; | ||
var _u = React.useState(false), footerHighlighted = _u[0], setFooterHighlighted = _u[1]; | ||
var _v = React.useState(0), headerOffset = _v[0], setHeaderOffset = _v[1]; | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop = _c === void 0 ? coreComponentsBackdrop.Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? coreComponentsStack.stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o, _p = _a.usePortal, usePortal = _p === void 0 ? true : _p; | ||
var _q = React.useState(null), exited = _q[0], setExited = _q[1]; | ||
var _r = React.useState(false), hasScroll = _r[0], setHasScroll = _r[1]; | ||
var _s = React.useState(false), hasHeader = _s[0], setHasHeader = _s[1]; | ||
var _t = React.useState(false), hasFooter = _t[0], setHasFooter = _t[1]; | ||
var _u = React.useState(false), headerHighlighted = _u[0], setHeaderHighlighted = _u[1]; | ||
var _v = React.useState(false), footerHighlighted = _v[0], setFooterHighlighted = _v[1]; | ||
var _w = React.useState(0), headerOffset = _w[0], setHeaderOffset = _w[1]; | ||
var componentNodeRef = React.useRef(null); | ||
@@ -236,23 +236,23 @@ var wrapperRef = React.useRef(null); | ||
]); | ||
var renderContent = function () { return (React__default.default.createElement(coreComponentsStack.Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React__default.default.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React__default.default.createElement(FocusLock__default.default, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop && (React__default.default.createElement(Backdrop, tslib.__assign({}, backdropProps, { className: cn__default.default(backdropProps.className, styles__default.default.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React__default.default.createElement("div", { role: 'dialog', className: cn__default.default(styles__default.default.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles__default.default.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs__default.default([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React__default.default.createElement(reactTransitionGroup.CSSTransition, tslib.__assign({ appear: true, timeout: 200, classNames: styles__default.default }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React__default.default.createElement("div", { className: cn__default.default(styles__default.default.component, className), ref: mergeRefs__default.default([componentRef, componentNodeRef]) }, | ||
React__default.default.createElement("div", { className: cn__default.default(styles__default.default.content, contentClassName) }, children))))))); | ||
})); }; | ||
if (!shouldRender) | ||
return null; | ||
return (React__default.default.createElement(coreComponentsStack.Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React__default.default.createElement(coreComponentsPortal.Portal, { getPortalContainer: container, immediateMount: true }, | ||
React__default.default.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React__default.default.createElement(FocusLock__default.default, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop && (React__default.default.createElement(Backdrop, tslib.__assign({}, backdropProps, { className: cn__default.default(backdropProps.className, styles__default.default.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React__default.default.createElement("div", { role: 'dialog', className: cn__default.default(styles__default.default.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles__default.default.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs__default.default([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React__default.default.createElement(reactTransitionGroup.CSSTransition, tslib.__assign({ appear: true, timeout: 200, classNames: styles__default.default }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React__default.default.createElement("div", { className: cn__default.default(styles__default.default.component, className), ref: mergeRefs__default.default([componentRef, componentNodeRef]) }, | ||
React__default.default.createElement("div", { className: cn__default.default(styles__default.default.content, contentClassName) }, children)))))))); | ||
})); | ||
return usePortal ? (React__default.default.createElement(coreComponentsPortal.Portal, { getPortalContainer: container, immediateMount: true }, renderContent())) : (renderContent()); | ||
}); | ||
@@ -259,0 +259,0 @@ |
@@ -87,2 +87,7 @@ /// <reference types="react-transition-group" /> | ||
/** | ||
* Рендерить ли в контейнер через портал. | ||
* @default true | ||
*/ | ||
usePortal?: boolean; | ||
/** | ||
* Обработчик события нажатия на бэкдроп | ||
@@ -89,0 +94,0 @@ */ |
@@ -15,3 +15,3 @@ import { __assign } from 'tslib'; | ||
var styles = {"component":"base-modal__component_7v143","wrapper":"base-modal__wrapper_7v143","content":"base-modal__content_7v143","hidden":"base-modal__hidden_7v143","backdrop":"base-modal__backdrop_7v143","appear":"base-modal__appear_7v143","enter":"base-modal__enter_7v143","appearActive":"base-modal__appearActive_7v143","enterActive":"base-modal__enterActive_7v143","exit":"base-modal__exit_7v143","exitActive":"base-modal__exitActive_7v143","exitDone":"base-modal__exitDone_7v143"}; | ||
var styles = {"component":"base-modal__component_1n9jh","wrapper":"base-modal__wrapper_1n9jh","content":"base-modal__content_1n9jh","hidden":"base-modal__hidden_1n9jh","backdrop":"base-modal__backdrop_1n9jh","appear":"base-modal__appear_1n9jh","enter":"base-modal__enter_1n9jh","appearActive":"base-modal__appearActive_1n9jh","enterActive":"base-modal__enterActive_1n9jh","exit":"base-modal__exit_1n9jh","exitActive":"base-modal__exitActive_1n9jh","exitDone":"base-modal__exitDone_1n9jh"}; | ||
require('./index.css') | ||
@@ -36,10 +36,10 @@ | ||
var BaseModal = forwardRef(function (_a, ref) { | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop$1 = _c === void 0 ? Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o; | ||
var _p = useState(null), exited = _p[0], setExited = _p[1]; | ||
var _q = useState(false), hasScroll = _q[0], setHasScroll = _q[1]; | ||
var _r = useState(false), hasHeader = _r[0], setHasHeader = _r[1]; | ||
var _s = useState(false), hasFooter = _s[0], setHasFooter = _s[1]; | ||
var _t = useState(false), headerHighlighted = _t[0], setHeaderHighlighted = _t[1]; | ||
var _u = useState(false), footerHighlighted = _u[0], setFooterHighlighted = _u[1]; | ||
var _v = useState(0), headerOffset = _v[0], setHeaderOffset = _v[1]; | ||
var open = _a.open, container = _a.container, children = _a.children, _b = _a.scrollHandler, scrollHandler = _b === void 0 ? 'wrapper' : _b, _c = _a.Backdrop, Backdrop$1 = _c === void 0 ? Backdrop : _c, _d = _a.backdropProps, backdropProps = _d === void 0 ? {} : _d, _e = _a.transitionProps, transitionProps = _e === void 0 ? {} : _e, disableBackdropClick = _a.disableBackdropClick, _f = _a.disableAutoFocus, disableAutoFocus = _f === void 0 ? false : _f, _g = _a.disableFocusLock, disableFocusLock = _g === void 0 ? false : _g, _h = _a.disableEscapeKeyDown, disableEscapeKeyDown = _h === void 0 ? false : _h, _j = _a.disableRestoreFocus, disableRestoreFocus = _j === void 0 ? false : _j, _k = _a.disableBlockingScroll, disableBlockingScroll = _k === void 0 ? false : _k, _l = _a.keepMounted, keepMounted = _l === void 0 ? false : _l, className = _a.className, contentClassName = _a.contentClassName, wrapperClassName = _a.wrapperClassName, onBackdropClick = _a.onBackdropClick, onClose = _a.onClose, onEscapeKeyDown = _a.onEscapeKeyDown, onMount = _a.onMount, onUnmount = _a.onUnmount, dataTestId = _a.dataTestId, _m = _a.zIndex, zIndex = _m === void 0 ? stackingOrder.MODAL : _m, _o = _a.componentRef, componentRef = _o === void 0 ? null : _o, _p = _a.usePortal, usePortal = _p === void 0 ? true : _p; | ||
var _q = useState(null), exited = _q[0], setExited = _q[1]; | ||
var _r = useState(false), hasScroll = _r[0], setHasScroll = _r[1]; | ||
var _s = useState(false), hasHeader = _s[0], setHasHeader = _s[1]; | ||
var _t = useState(false), hasFooter = _t[0], setHasFooter = _t[1]; | ||
var _u = useState(false), headerHighlighted = _u[0], setHeaderHighlighted = _u[1]; | ||
var _v = useState(false), footerHighlighted = _v[0], setFooterHighlighted = _v[1]; | ||
var _w = useState(0), headerOffset = _w[0], setHeaderOffset = _w[1]; | ||
var componentNodeRef = useRef(null); | ||
@@ -227,25 +227,25 @@ var wrapperRef = useRef(null); | ||
]); | ||
var renderContent = function () { return (React.createElement(Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React.createElement(FocusLock, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop$1 && (React.createElement(Backdrop$1, __assign({}, backdropProps, { className: cn(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React.createElement("div", { role: 'dialog', className: cn(styles.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React.createElement(CSSTransition, __assign({ appear: true, timeout: 200, classNames: styles }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React.createElement("div", { className: cn(styles.component, className), ref: mergeRefs([componentRef, componentNodeRef]) }, | ||
React.createElement("div", { className: cn(styles.content, contentClassName) }, children))))))); | ||
})); }; | ||
if (!shouldRender) | ||
return null; | ||
return (React.createElement(Stack, { value: zIndex }, function (computedZIndex) { | ||
var _a; | ||
return (React.createElement(Portal, { getPortalContainer: container, immediateMount: true }, | ||
React.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React.createElement(FocusLock, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop$1 && (React.createElement(Backdrop$1, __assign({}, backdropProps, { className: cn(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} }))), | ||
React.createElement("div", { role: 'dialog', className: cn(styles.wrapper, wrapperClassName, (_a = {}, | ||
_a[styles.hidden] = !open && isExited, | ||
_a)), ref: mergeRefs([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React.createElement(CSSTransition, __assign({ appear: true, timeout: 200, classNames: styles }, transitionProps, { in: open, onEntered: handleEntered, onExited: handleExited }), | ||
React.createElement("div", { className: cn(styles.component, className), ref: mergeRefs([componentRef, componentNodeRef]) }, | ||
React.createElement("div", { className: cn(styles.content, contentClassName) }, children)))))))); | ||
})); | ||
return usePortal ? (React.createElement(Portal, { getPortalContainer: container, immediateMount: true }, renderContent())) : (renderContent()); | ||
}); | ||
export { BaseModal, BaseModalContext }; |
@@ -87,2 +87,7 @@ /// <reference types="react-transition-group" /> | ||
/** | ||
* Рендерить ли в контейнер через портал. | ||
* @default true | ||
*/ | ||
usePortal?: boolean; | ||
/** | ||
* Обработчик события нажатия на бэкдроп | ||
@@ -89,0 +94,0 @@ */ |
@@ -9,3 +9,3 @@ import React, { forwardRef, useState, useRef, useCallback, useEffect, useMemo } from 'react'; | ||
import { Portal } from '@alfalab/core-components-portal/modern'; | ||
import { Stack, stackingOrder } from '@alfalab/core-components-stack/modern'; | ||
import { stackingOrder, Stack } from '@alfalab/core-components-stack/modern'; | ||
import { isScrolledToTop, isScrolledToBottom, handleContainer, restoreContainerStyles, hasScrollbar, getScrollbarSize } from './utils.js'; | ||
@@ -15,3 +15,3 @@ import './matches-polyfill.js'; | ||
const styles = {"component":"base-modal__component_7v143","wrapper":"base-modal__wrapper_7v143","content":"base-modal__content_7v143","hidden":"base-modal__hidden_7v143","backdrop":"base-modal__backdrop_7v143","appear":"base-modal__appear_7v143","enter":"base-modal__enter_7v143","appearActive":"base-modal__appearActive_7v143","enterActive":"base-modal__enterActive_7v143","exit":"base-modal__exit_7v143","exitActive":"base-modal__exitActive_7v143","exitDone":"base-modal__exitDone_7v143"}; | ||
const styles = {"component":"base-modal__component_1n9jh","wrapper":"base-modal__wrapper_1n9jh","content":"base-modal__content_1n9jh","hidden":"base-modal__hidden_1n9jh","backdrop":"base-modal__backdrop_1n9jh","appear":"base-modal__appear_1n9jh","enter":"base-modal__enter_1n9jh","appearActive":"base-modal__appearActive_1n9jh","enterActive":"base-modal__enterActive_1n9jh","exit":"base-modal__exit_1n9jh","exitActive":"base-modal__exitActive_1n9jh","exitDone":"base-modal__exitDone_1n9jh"}; | ||
require('./index.css') | ||
@@ -36,3 +36,3 @@ | ||
}); | ||
const BaseModal = forwardRef(({ open, container, children, scrollHandler = 'wrapper', Backdrop: Backdrop$1 = Backdrop, backdropProps = {}, transitionProps = {}, disableBackdropClick, disableAutoFocus = false, disableFocusLock = false, disableEscapeKeyDown = false, disableRestoreFocus = false, disableBlockingScroll = false, keepMounted = false, className, contentClassName, wrapperClassName, onBackdropClick, onClose, onEscapeKeyDown, onMount, onUnmount, dataTestId, zIndex = stackingOrder.MODAL, componentRef = null, }, ref) => { | ||
const BaseModal = forwardRef(({ open, container, children, scrollHandler = 'wrapper', Backdrop: Backdrop$1 = Backdrop, backdropProps = {}, transitionProps = {}, disableBackdropClick, disableAutoFocus = false, disableFocusLock = false, disableEscapeKeyDown = false, disableRestoreFocus = false, disableBlockingScroll = false, keepMounted = false, className, contentClassName, wrapperClassName, onBackdropClick, onClose, onEscapeKeyDown, onMount, onUnmount, dataTestId, zIndex = stackingOrder.MODAL, componentRef = null, usePortal = true, }, ref) => { | ||
const [exited, setExited] = useState(null); | ||
@@ -226,22 +226,22 @@ const [hasScroll, setHasScroll] = useState(false); | ||
]); | ||
const renderContent = () => (React.createElement(Stack, { value: zIndex }, (computedZIndex) => (React.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React.createElement(FocusLock, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop$1 && (React.createElement(Backdrop$1, { ...backdropProps, className: cn(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} })), | ||
React.createElement("div", { role: 'dialog', className: cn(styles.wrapper, wrapperClassName, { | ||
[styles.hidden]: !open && isExited, | ||
}), ref: mergeRefs([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React.createElement(CSSTransition, { appear: true, timeout: 200, classNames: styles, ...transitionProps, in: open, onEntered: handleEntered, onExited: handleExited }, | ||
React.createElement("div", { className: cn(styles.component, className), ref: mergeRefs([componentRef, componentNodeRef]) }, | ||
React.createElement("div", { className: cn(styles.content, contentClassName) }, children))))))))); | ||
if (!shouldRender) | ||
return null; | ||
return (React.createElement(Stack, { value: zIndex }, (computedZIndex) => (React.createElement(Portal, { getPortalContainer: container, immediateMount: true }, | ||
React.createElement(BaseModalContext.Provider, { value: contextValue }, | ||
React.createElement(FocusLock, { autoFocus: !disableAutoFocus, disabled: disableFocusLock || !open, returnFocus: !disableRestoreFocus }, | ||
Backdrop$1 && (React.createElement(Backdrop$1, { ...backdropProps, className: cn(backdropProps.className, styles.backdrop), open: open, style: { | ||
zIndex: computedZIndex, | ||
} })), | ||
React.createElement("div", { role: 'dialog', className: cn(styles.wrapper, wrapperClassName, { | ||
[styles.hidden]: !open && isExited, | ||
}), ref: mergeRefs([ref, wrapperRef]), onKeyDown: handleKeyDown, onMouseDown: handleBackdropMouseDown, onMouseUp: handleBackdropMouseUp, | ||
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex | ||
tabIndex: 0, "data-test-id": dataTestId, style: { | ||
zIndex: computedZIndex, | ||
} }, | ||
React.createElement(CSSTransition, { appear: true, timeout: 200, classNames: styles, ...transitionProps, in: open, onEntered: handleEntered, onExited: handleExited }, | ||
React.createElement("div", { className: cn(styles.component, className), ref: mergeRefs([componentRef, componentNodeRef]) }, | ||
React.createElement("div", { className: cn(styles.content, contentClassName) }, children)))))))))); | ||
return usePortal ? (React.createElement(Portal, { getPortalContainer: container, immediateMount: true }, renderContent())) : (renderContent()); | ||
}); | ||
export { BaseModal, BaseModalContext }; |
{ | ||
"name": "@alfalab/core-components-base-modal", | ||
"version": "5.1.3", | ||
"version": "5.2.0", | ||
"description": "BaseModal component", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
109421
2492