UNPKG

@atlaskit/editor-plugin-floating-toolbar

Version:

Floating toolbar plugin for @atlaskit/editor-core

70 lines 3.49 kB
import React, { useRef } from 'react'; import Select from '@atlaskit/select'; export default function Search(props) { // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any const selectRef = useRef(null); const { width = 200 } = props; const style = React.useMemo(() => ({ // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any container: base => ({ ...base, width }), // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any menuPortal: base => { var _selectRef$current, _selectRef$current$se, _selectRef$current$se2, _selectRef$current2, _selectRef$current2$s, _selectRef$current2$s2, _selectRef$current2$s3; // ED:16095: We add two possible getter paths for safely reaching into the underlying // react-select element. We first try a getter that conforms with react-select v5 APIs, // Failing that, we try a getter consistent with react-select v4 APIs. (We // handle both as consumers may control the time of the actual dependency version // cutover). const controlWrapper = (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : (_selectRef$current$se = _selectRef$current.select) === null || _selectRef$current$se === void 0 ? void 0 : (_selectRef$current$se2 = _selectRef$current$se.controlRef) === null || _selectRef$current$se2 === void 0 ? void 0 : _selectRef$current$se2.parentNode) || (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 ? void 0 : (_selectRef$current2$s = _selectRef$current2.select) === null || _selectRef$current2$s === void 0 ? void 0 : (_selectRef$current2$s2 = _selectRef$current2$s.select) === null || _selectRef$current2$s2 === void 0 ? void 0 : (_selectRef$current2$s3 = _selectRef$current2$s2.controlRef) === null || _selectRef$current2$s3 === void 0 ? void 0 : _selectRef$current2$s3.parentNode); const menuPortalStyles = controlWrapper && props.setDisableParentScroll ? { // since the portal is now outside, we need to position it as before // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview top: controlWrapper.offsetTop, // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview left: controlWrapper.offsetLeft, height: controlWrapper.offsetHeight, width } : {}; return { ...base, ...menuPortalStyles }; } }), // eslint-disable-next-line react-hooks/exhaustive-deps [width]); const onMenuOpen = () => { if (props.setDisableParentScroll) { props.setDisableParentScroll(true); } }; const onMenuClose = () => { if (props.setDisableParentScroll) { props.setDisableParentScroll(false); } }; return /*#__PURE__*/React.createElement(Select, { ref: selectRef, options: props.options, value: props.defaultValue, onChange: props.onChange, placeholder: props.placeholder, spacing: "compact", menuPlacement: "auto", filterOption: props.filterOption, styles: style, menuPortalTarget: props.mountPoint, onMenuOpen: onMenuOpen, onMenuClose: onMenuClose, label: props.ariaLabel, classNamePrefix: props.classNamePrefix }); }