UNPKG

@wordpress/block-library

Version:
1 lines • 1.47 kB
{"version":3,"file":"view-link-button.mjs","names":[],"sources":["../../src/utils/view-link-button.tsx"],"sourcesContent":["import { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { external } from '@wordpress/icons';\nimport { useResolvedUrl } from './use-resolved-url';\n\ninterface ViewLinkButtonProps {\n\t/** The link, as stored in the block's attributes. */\n\turl?: string;\n}\n\n/**\n * The block inspector's \"View\" button for a block that links somewhere. It\n * opens the link in a new tab, resolved against the site's home URL, and\n * renders nothing while there is no link to open.\n *\n * @param props Component props.\n * @param props.url The link, as stored in the block's attributes.\n */\nexport default function ViewLinkButton( { url }: ViewLinkButtonProps ) {\n\tconst resolvedUrl = useResolvedUrl( url );\n\n\tif ( ! resolvedUrl ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\thref={ resolvedUrl }\n\t\t\ttarget=\"_blank\"\n\t\t\ticon={ external }\n\t\t\ticonPosition=\"right\"\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName=\"navigation-link-to__action-button\"\n\t\t>\n\t\t\t{ __( 'View' ) }\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,SAAwB,eAAgB,EAAE,OAA6B;CACtE,MAAM,cAAc,eAAgB,GAAI;CAExC,IAAK,CAAE,aACN,OAAO;CAGR,OACC,oBAAC,QAAD;EACC,SAAQ;EACR,MAAO;EACP,QAAO;EACP,MAAO;EACP,cAAa;EACb,uBAAA;EACA,WAAU;EAER,UAAA,GAAI,MAAO;CACN,CAAA;AAEV"}