@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
41 lines (39 loc) • 1.47 kB
JavaScript
/* ToolbarPortal.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./ToolbarPortal.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
var ToolbarPortalContext = /*#__PURE__*/React.createContext(undefined);
export var ToolbarPortalContextProvider = function ToolbarPortalContextProvider(_ref) {
var children = _ref.children,
portal = _ref.portal,
isActive = _ref.isActive;
var value = React.useMemo(function () {
return {
Portal: portal,
isActive: isActive
};
}, [portal, isActive]);
return /*#__PURE__*/React.createElement(ToolbarPortalContext.Provider, {
value: value
}, children);
};
// NOTE: This doesn't throw on undefined context on purpose, as it is likely that
// the outer toolbar _won't_ have a context provider as it is unlikely to portal
// anywhere
export var useToolbarPortal = function useToolbarPortal() {
return React.useContext(ToolbarPortalContext);
};
var toolbarPortalStyles = {
portal: "_1r04ze3t _kqswstnw _fiawglyw"
};
export var ToolbarPortalMountPoint = function ToolbarPortalMountPoint() {
var portal = useToolbarPortal();
// Don't render a mountpoint when we're already inside a portal
if (portal) {
return null;
}
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
return /*#__PURE__*/React.createElement("div", {
className: ax([toolbarPortalStyles.portal, "ak-editor-toolbar-portal"])
});
};