UNPKG

@smart-react-components/ui

Version:
48 lines (47 loc) 3.63 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importDefault(require("react")); const FixedBox_1 = __importStar(require("../FixedBox")); __exportStar(require("../FixedBox"), exports); const Dropdown = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint, children, elementProps = {}, hasHideAnimation, hasShowAnimation, isDismissible, maxWidth, minWidth, position, setStatus, space, status, transitionClassName, transitionDuration, triggerInteraction = FixedBox_1.TriggerInteraction.CLICK }) => { var _a, _b, _c, _d; const triggerEl = react_1.default.useRef(null); const [localStatus, setLocalStatus] = react_1.default.useState(() => false); const getTriggerEl = () => { var _a; return ((_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl).current; }; react_1.default.useEffect(() => { getTriggerEl().dispatchEvent(new Event('src.fixedBox.setPosition')); }, [(_c = (_b = (_a = children === null || children === void 0 ? void 0 : children[1]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.length]); return (react_1.default.createElement(FixedBox_1.default, { afterHide: afterHide, afterShow: afterShow, beforeHide: beforeHide, beforeShow: beforeShow, breakpoint: breakpoint, elementProps: elementProps, hasHideAnimation: hasHideAnimation, hasShowAnimation: hasShowAnimation, isDismissible: isDismissible, maxWidth: maxWidth, minWidth: minWidth, position: position, setStatus: setStatus !== null && setStatus !== void 0 ? setStatus : setLocalStatus, space: space, status: status !== null && status !== void 0 ? status : localStatus, transitionClassName: transitionClassName, transitionDuration: transitionDuration, triggerInteraction: triggerInteraction }, react_1.default.cloneElement(children[0], Object.assign({ ref: (_d = children[0].ref) !== null && _d !== void 0 ? _d : triggerEl }, (triggerInteraction & FixedBox_1.TriggerInteraction.CLICK ? { cursor: '$cursor.dropdown' } : {}))), react_1.default.cloneElement(children[1], { setStatus: setStatus !== null && setStatus !== void 0 ? setStatus : setLocalStatus }))); }; exports.default = Dropdown;