UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

37 lines 1.48 kB
import React, { useCallback } from 'react'; import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui'; import LinkExternalIcon from '@atlaskit/icon/core/link-external'; import { useSmartLinkDestinationUrl } from '@atlaskit/smart-card/hook/use-smart-link-destination-url'; /** * Toolbar button that opens a Smart Link URL in a new tab, with the XPC-wrapped destination URL. * * This component is only rendered when `fg('platform_smartlink_xpc_url_wrapping')` is ON. * It wraps `FloatingToolbarButton` and replaces `href` with the resolved destination URL * (cross-product analytics parameters appended), falling back to the raw `url` when the * link is unresolved or not a first-party Atlassian link. */ export const OpenLinkToolbarButton = ({ url, areAnyNewToolbarFlagsEnabled, editorView, onClick, title }) => { const destinationUrl = useSmartLinkDestinationUrl(url); const handleClick = useCallback(() => { onClick(editorView.state, editorView.dispatch); }, [editorView, onClick]); return /*#__PURE__*/React.createElement(Button // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , { className: "hyperlink-open-link", title: title, icon: /*#__PURE__*/React.createElement(LinkExternalIcon, { label: "" }), href: destinationUrl, target: "_blank", onClick: handleClick, areAnyNewToolbarFlagsEnabled: areAnyNewToolbarFlagsEnabled }); };