@atlaskit/editor-plugin-floating-toolbar
Version:
Floating toolbar plugin for @atlaskit/editor-core
72 lines • 4.29 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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
var selectRef = useRef(null);
var _props$width = props.width,
width = _props$width === void 0 ? 200 : _props$width;
var style = React.useMemo(function () {
return {
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
container: function container(base) {
return _objectSpread(_objectSpread({}, base), {}, {
width: width
});
},
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
menuPortal: function menuPortal(base) {
var _selectRef$current, _selectRef$current2;
// 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).
var controlWrapper = (selectRef === null || selectRef === void 0 || (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 || (_selectRef$current = _selectRef$current.select) === null || _selectRef$current === void 0 || (_selectRef$current = _selectRef$current.controlRef) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.parentNode) || (selectRef === null || selectRef === void 0 || (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 || (_selectRef$current2 = _selectRef$current2.select) === null || _selectRef$current2 === void 0 || (_selectRef$current2 = _selectRef$current2.select) === null || _selectRef$current2 === void 0 || (_selectRef$current2 = _selectRef$current2.controlRef) === null || _selectRef$current2 === void 0 ? void 0 : _selectRef$current2.parentNode);
var 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: width
} : {};
return _objectSpread(_objectSpread({}, base), menuPortalStyles);
}
};
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[width]);
var onMenuOpen = function onMenuOpen() {
if (props.setDisableParentScroll) {
props.setDisableParentScroll(true);
}
};
var onMenuClose = function 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
});
}