import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin, useStage } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { FormLayer, formPlugin, useForm } from '@embedpdf/react/form'; import type { FieldControl, FieldControlProps } from '@embedpdf/react/form'; import { localEngine } from '@embedpdf/engine'; import './clear-button.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), formPlugin()]; // [!doc-source forms] const forms = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/forms.pdf'); return { kind: 'bytes', id: 'forms', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] /** * A text box with a button at its end that empties it. `native` is the layer's own text box: * the field as the PDF draws it, and the editor people type in. The button is yours. */ function TextBox({ widget, native, setValue }: FieldControlProps) { const form = useForm(); if (widget.control !== 'text') return null; // Empty the box, then put the cursor back in it, ready for the new value. const clear = () => setValue({ value: '' }).then(() => form.focus(widget.fieldRef)); return ( <> {native} {!widget.disabled && widget.value !== '' && ( ); } export default function App() { return ( Loading…

}> {() => ( <> )}
); }