@wordpress/block-library
Version:
Block library for the WordPress editor.
31 lines (30 loc) • 1.04 kB
JavaScript
import { Button } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { external } from "@wordpress/icons";
import { useResolvedUrl } from "./use-resolved-url.mjs";
import { jsx } from "react/jsx-runtime";
// packages/block-library/src/utils/view-link-button.tsx
/**
* The block inspector's "View" button for a block that links somewhere. It
* opens the link in a new tab, resolved against the site's home URL, and
* renders nothing while there is no link to open.
*
* @param props Component props.
* @param props.url The link, as stored in the block's attributes.
*/
function ViewLinkButton({ url }) {
const resolvedUrl = useResolvedUrl(url);
if (!resolvedUrl) return null;
return /* @__PURE__ */ jsx(Button, {
variant: "secondary",
href: resolvedUrl,
target: "_blank",
icon: external,
iconPosition: "right",
__next40pxDefaultSize: true,
className: "navigation-link-to__action-button",
children: __("View")
});
}
export { ViewLinkButton as default };
//# sourceMappingURL=view-link-button.mjs.map