UNPKG

@smart-react-components/ui

Version:
34 lines (33 loc) 3.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TriggerInteraction = exports.Position = void 0; const CSSTransition_1 = __importDefault(require("@smart-react-components/transition/CSSTransition")); const react_1 = __importDefault(require("react")); const styled_components_1 = require("styled-components"); const useFixedBoxMethods_1 = __importDefault(require("../hooks/useFixedBoxMethods")); const Overlay_1 = __importDefault(require("../Overlay")); const types_1 = require("../types"); const fixed_box_1 = require("../util/fixed-box"); const FixedBoxElement_1 = __importDefault(require("../components/FixedBox/FixedBoxElement")); const OverlayElement_1 = __importDefault(require("../components/FixedBox/OverlayElement")); var types_2 = require("../types"); Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return types_2.Position; } }); Object.defineProperty(exports, "TriggerInteraction", { enumerable: true, get: function () { return types_2.TriggerInteraction; } }); const FixedBox = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint = 'medium', children, elementProps = {}, hasHideAnimation = true, hasShowAnimation = true, isDismissible = true, isOverflowPrevented, maxWidth, minWidth, position = types_1.Position.BOTTOM, setStatus, space = 0, status, transitionClassName, transitionDuration, triggerInteraction = types_1.TriggerInteraction.CLICK, }) => { var _a; const theme = react_1.default.useContext(styled_components_1.ThemeContext); const triggerEl = react_1.default.useRef(null); const boxEl = react_1.default.useRef(null); const getTriggerEl = () => { var _a; return ((_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl).current; }; const handlePosition = e => (0, fixed_box_1.calculatePosition)(getTriggerEl(), boxEl.current, e, position, maxWidth, minWidth, space, isOverflowPrevented); const { getStatus, handleBeforeShow, } = (0, useFixedBoxMethods_1.default)({ beforeShow, boxEl, getTriggerEl, handlePosition, isDismissible, key: 'fixed-box', setStatus, status, triggerInteraction }); return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.cloneElement(children[0], { ref: (_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl }), react_1.default.createElement(CSSTransition_1.default, { afterHide: afterHide, afterShow: afterShow, beforeHide: beforeHide, beforeShow: handleBeforeShow, className: transitionClassName !== null && transitionClassName !== void 0 ? transitionClassName : 'src-fixed-box', duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration, hasHideAnimation: hasHideAnimation, hasShowAnimation: hasShowAnimation, status: getStatus() }, react_1.default.createElement(Overlay_1.default, { breakpoint: triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK ? null : breakpoint, hasBackground: !(triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK), template: react_1.default.createElement(OverlayElement_1.default, { duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration, isDisplayedWhenBreakpointNull: !!(triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) }) }, react_1.default.createElement(FixedBoxElement_1.default, Object.assign({}, elementProps, { breakpoint: breakpoint, ref: boxEl }), children[1]))))); }; exports.default = FixedBox;