@atlaskit/editor-plugin-selection-toolbar
Version:
@atlaskit/editor-plugin-selection-toolbar for @atlaskit/editor-core
32 lines • 1.25 kB
JavaScript
import React from 'react';
import { useIntl } from 'react-intl';
import { selectionToolbarMessages } from '@atlaskit/editor-common/messages';
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
import { PinnedIcon, ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
export const PinButton = ({
api
}) => {
const intl = useIntl();
const message = intl.formatMessage(selectionToolbarMessages.toolbarPositionPinedAtTop);
const {
isOffline: isDisabled
} = useEditorToolbar();
const onClick = () => {
var _api$userPreferences;
if (!api || isDisabled) {
return;
}
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.actions.updateUserPreference('toolbarDockingPosition', 'none'));
};
return /*#__PURE__*/React.createElement(ToolbarTooltip, {
content: message
}, /*#__PURE__*/React.createElement(ToolbarButton, {
iconBefore: /*#__PURE__*/React.createElement(PinnedIcon, {
size: "small",
label: ""
}),
label: message,
onClick: onClick,
isDisabled: isDisabled
}));
};