@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 1.59 kB
Source Map (JSON)
{"version":3,"file":"view-link-button.cjs","names":["useResolvedUrl","Button","external","__"],"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,eAAA,GAAcA,sBAAAA,eAAAA,CAAgB,GAAI;CAExC,IAAK,CAAE,aACN,OAAO;CAGR,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,QAAD;EACC,SAAQ;EACR,MAAO;EACP,QAAO;EACP,MAAOC,iBAAAA;EACP,cAAa;EACb,uBAAA;EACA,WAAU;EAERC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,MAAO;CACN,CAAA;AAEV"}