UNPKG

design-system-simplefi

Version:

Design System for SimpleFi Applications

46 lines 1.84 kB
import React from 'react'; import PropTypes from 'prop-types'; import { useDropdown } from '../../hooks/useDropdown'; import { SpaceSizes } from '../../theme'; import { Padbox, Stack } from '../layout'; import { ControlDropdownPlacements } from './ControlDropdown.enums'; var ControlDropdown = function (_a) { var children = _a.children, parentRef = _a.parentRef, _b = _a.isOpen, isOpen = _b === void 0 ? false : _b, onOpen = _a.onOpen, onClose = _a.onClose, _c = _a.placement, placement = _c === void 0 ? ControlDropdownPlacements.bottom : _c, _d = _a.width, width = _d === void 0 ? 300 : _d; var _e = useDropdown(parentRef, { defaultIsPaneDisplayed: isOpen, paneWidth: width, onClickOut: onClose, onShow: function () { if (isPaneDisplayed) { onClose(); } else { onOpen(); } }, onHide: onClose, placement: placement, isElevated: true, hasInternalShowHide: false, }), isPaneDisplayed = _e.isPaneDisplayed, Pane = _e.Pane; if (!isOpen) { return null; } return (React.createElement(Pane, null, React.createElement(Padbox, { paddingSize: SpaceSizes.sm, paddingType: "square" }, React.createElement(Stack, { gap: SpaceSizes.md }, children)))); }; ControlDropdown.propTypes = { parentRef: PropTypes.exact({ current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(HTMLDivElement), }).isRequired, onOpen: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, isOpen: PropTypes.bool, placement: PropTypes.oneOf(Object.values(ControlDropdownPlacements)), width: PropTypes.number, }; export default ControlDropdown; //# sourceMappingURL=ControlDropdown.js.map