import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { speak } from '@wordpress/a11y'; import FieldControl from '../components/FieldControl'; import Button from '../components/Button'; /** * Read-only Slot ID + embed-snippet display for the Headless placement type. * * @param field * @param entityData */ const SlotInfoField = ( { field, entityData } ) => { const [ copied, setCopied ] = useState( false ); const { slug = '', saved = false } = entityData?.slot_info || {}; const snippet = ``; const handleCopy = () => { navigator.clipboard.writeText( snippet ); setCopied( true ); speak( __( 'Snippet copied to clipboard.', 'adpresso' ) ); setTimeout( () => setCopied( false ), 2000 ); }; return ( { ! saved || ! slug ? ( { __( 'Save this placement to get its Slot ID.', 'adpresso' ) } ) : ( <> { __( 'Slot ID', 'adpresso' ) }:{ ' ' } { slug } { __( 'Embed snippet', 'adpresso' ) }: { snippet } { copied ? __( 'Copied!', 'adpresso' ) : __( 'Copy', 'adpresso' ) } > ) } ); }; export default SlotInfoField;
{ __( 'Save this placement to get its Slot ID.', 'adpresso' ) }
{ __( 'Slot ID', 'adpresso' ) }:{ ' ' } { slug }
{ slug }
{ __( 'Embed snippet', 'adpresso' ) }:
{ snippet }