Class ClipboardContent

java.lang.Object
com.vaadin.flow.component.clipboard.ClipboardContent
All Implemented Interfaces:
Serializable

public final class ClipboardContent extends Object implements Serializable
Multi-format payload for ClipboardBinding.write(com.vaadin.flow.component.clipboard.ClipboardContent). Any combination of text/plain, text/html and an image source can be set; each accessor returns null when the corresponding slot is empty.

Use the static factory:


 Clipboard.onClick(button).write(ClipboardContent.create().text("Hello")
         .html("<b>Hello</b>").image(previewImage));
 
See Also:
  • Method Details

    • create

      public static ClipboardContent create()
      Creates a new empty content builder.
      Returns:
      a new builder
    • text

      public ClipboardContent text(String literal)
      Sets the plain text to be written to the clipboard.
      Parameters:
      literal - the value, not null
      Returns:
      this builder
    • text

      public <C extends Component & HasValue<?, String>> ClipboardContent text(C source)
      Sets the plain text to be written to the clipboard, taken from the value property of the given component (typically an input field). The value is read on the client when the trigger fires.
      Type Parameters:
      C - component type implementing HasValue<?, String>
      Parameters:
      source - the component whose value property should be read, not null
      Returns:
      this builder
    • html

      public ClipboardContent html(String literal)
      Sets the HTML to be written to the clipboard.
      Parameters:
      literal - the value, not null
      Returns:
      this builder
    • image

      public ClipboardContent image(Component source)
      Sets the image/png payload to a PNG re-encoding of the given component's root <img> element, produced on the client when the trigger fires. The source can be any rasterisable image (image/png, image/jpeg, image/svg+xml, ...) with intrinsic dimensions; cross-origin sources need crossorigin="anonymous" on the <img> plus matching CORS headers, otherwise the canvas is tainted and the write fails.
      Parameters:
      source - the component whose root <img> should be copied, not null
      Returns:
      this builder
    • getTextInput

      public @Nullable Action.Input<String> getTextInput()
      Returns:
      the text input, or null if no text was set
    • getHtmlInput

      public @Nullable Action.Input<String> getHtmlInput()
      Returns:
      the html input, or null if no html was set
    • getImageInput

      public @Nullable Action.Input<?> getImageInput()
      Returns:
      the image input, or null if no image was set