Class SvgIcon

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.icon.AbstractIcon<SvgIcon>
com.vaadin.flow.component.icon.SvgIcon
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.ClickNotifier<SvgIcon>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasTooltip, Serializable

public class SvgIcon extends AbstractIcon<SvgIcon>
Component for displaying an icon from a SVG file.
Author:
Vaadin Ltd
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    SvgIcon(com.vaadin.flow.server.AbstractStreamResource src)
    Deprecated, for removal: This API element is subject to removal in a future version.
    SvgIcon(com.vaadin.flow.server.AbstractStreamResource src, String symbol)
    Deprecated, for removal: This API element is subject to removal in a future version.
    SvgIcon(com.vaadin.flow.server.streams.DownloadHandler src)
    Creates an SVG icon with the given download handler resource.
    SvgIcon(com.vaadin.flow.server.streams.DownloadHandler src, String symbol)
    Creates an SVG icon with the given download handler resource.
    Creates an SVG icon with the given source
    SvgIcon(String src, String symbol)
    Creates an SVG icon with the given source and symbol
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the color of this icon as a String.
    Gets the source defined in the icon.
    Gets the symbol defined in the icon.
    void
    Sets the color of the icon.
    void
    setSrc(com.vaadin.flow.server.AbstractStreamResource src)
    Deprecated, for removal: This API element is subject to removal in a future version.
    void
    setSrc(com.vaadin.flow.server.AbstractStreamResource src, String symbol)
    Deprecated, for removal: This API element is subject to removal in a future version.
    void
    setSrc(com.vaadin.flow.server.streams.DownloadHandler src)
    Defines the source of the icon from the given DownloadHandler The resource must contain a valid SVG element.
    void
    setSrc(com.vaadin.flow.server.streams.DownloadHandler src, String symbol)
    Defines the src and the symbol to be used in the icon.
    void
    Sets the URL of the SVG file to be used as the icon.
    void
    setSrc(String src, String symbol)
    Defines the src and the symbol to be used in the icon.
    void
    setSymbol(String symbol)
    Defines the symbol identifier that references an ID of an element contained in the SVG element assigned to the setSrc(String) property.

    Methods inherited from class com.vaadin.flow.component.icon.AbstractIcon

    setSize

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.ClickNotifier

    addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText
  • Constructor Details

    • SvgIcon

      public SvgIcon()
      Default constructor. Creates an empty SVG icon.
    • SvgIcon

      public SvgIcon(String src)
      Creates an SVG icon with the given source
      Parameters:
      src - the SVG file path
      See Also:
    • SvgIcon

      public SvgIcon(String src, String symbol)
      Creates an SVG icon with the given source and symbol
      Parameters:
      src - the SVG file path
      symbol - the symbol reference of the icon
      See Also:
    • SvgIcon

      @Deprecated(since="24.8", forRemoval=true) public SvgIcon(com.vaadin.flow.server.AbstractStreamResource src)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an SVG icon with the given resource
      Parameters:
      src - the resource value
      See Also:
    • SvgIcon

      @Deprecated(since="24.8", forRemoval=true) public SvgIcon(com.vaadin.flow.server.AbstractStreamResource src, String symbol)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an SVG icon with the given resource
      Parameters:
      src - the resource value
      symbol - the symbol reference of the icon
      See Also:
    • SvgIcon

      public SvgIcon(com.vaadin.flow.server.streams.DownloadHandler src)
      Creates an SVG icon with the given download handler resource.

      Sets the Content-Disposition header to inline for pre-defined download handlers, created by factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      Parameters:
      src - the download handler resource
      See Also:
    • SvgIcon

      public SvgIcon(com.vaadin.flow.server.streams.DownloadHandler src, String symbol)
      Creates an SVG icon with the given download handler resource.

      Sets the Content-Disposition header to inline for pre-defined download handlers, created by factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      Parameters:
      src - the download handler resource
      symbol - the symbol reference of the icon
      See Also:
  • Method Details

    • setSrc

      public void setSrc(String src)
      Sets the URL of the SVG file to be used as the icon. The value can be:
      • A path to a standalone SVG file
      • A path in the format `"path/to/file.svg#symbol-id"` to an SVG file, where "symbol-id" refers to an id of an element (generally a `` element) to be rendered in the icon component.

        Note that the sprite file needs to follow the same-origin policy

      • Alternatively, the source can be defined as a string in the format `"data:image/svg+xml,...`
      Parameters:
      src - the source file of the icon
    • setSrc

      public void setSrc(String src, String symbol)
      Defines the src and the symbol to be used in the icon.
      Parameters:
      src - the path of the icon sprite file
      symbol - the symbol reference of the icon
      See Also:
    • setSrc

      @Deprecated(since="24.8", forRemoval=true) public void setSrc(com.vaadin.flow.server.AbstractStreamResource src)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Defines the source of the icon from the given StreamResource The resource must contain a valid SVG element.
      Parameters:
      src - the source value, not null
    • setSrc

      @Deprecated(since="24.8", forRemoval=true) public void setSrc(com.vaadin.flow.server.AbstractStreamResource src, String symbol)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Defines the src and the symbol to be used in the icon.
      Parameters:
      src - the source of the icon sprite file, not null
      symbol - the symbol reference of the icon
      See Also:
    • setSrc

      public void setSrc(com.vaadin.flow.server.streams.DownloadHandler src)
      Defines the source of the icon from the given DownloadHandler The resource must contain a valid SVG element.

      Sets the Content-Disposition header to inline for pre-defined download handlers, created by factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      Parameters:
      src - the source value, not null
    • setSrc

      public void setSrc(com.vaadin.flow.server.streams.DownloadHandler src, String symbol)
      Defines the src and the symbol to be used in the icon.

      Sets the Content-Disposition header to inline for pre-defined download handlers, created by factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      Parameters:
      src - the source of the icon sprite file, not null
      symbol - the symbol reference of the icon
      See Also:
    • getSrc

      public String getSrc()
      Gets the source defined in the icon.
      Returns:
      the source defined or null
    • setSymbol

      public void setSymbol(String symbol)

      Defines the symbol identifier that references an ID of an element contained in the SVG element assigned to the setSrc(String) property.

      If there's an identifier in the path defined in setSrc(String) in the moment this method is called, the value passed to setSymbol(String) will be used.

      Parameters:
      symbol - the symbol identifier of the icon to be shown
    • getSymbol

      public String getSymbol()
      Gets the symbol defined in the icon.
      Returns:
      the symbol defined or null
    • setColor

      public void setColor(String color)
      Description copied from class: AbstractIcon
      Sets the color of the icon.

      The color should be in a format understood by the browser, e.g. "orange", "#FF9E2C" or "rgb(255, 158, 44)".

      Specified by:
      setColor in class AbstractIcon<SvgIcon>
      Parameters:
      color - the color to set, may be null to clear the value
    • getColor

      public String getColor()
      Description copied from class: AbstractIcon
      Gets the color of this icon as a String.
      Specified by:
      getColor in class AbstractIcon<SvgIcon>
      Returns:
      the color of the icon, or null if the color has not been set