Class Card

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.card.Card
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, HasThemeVariant<CardVariant>, Serializable

@Tag("vaadin-card") @NpmPackage(value="@vaadin/card", version="25.0.0-alpha19") @JsModule("@vaadin/card/src/vaadin-card.js") public class Card extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasSize, HasThemeVariant<CardVariant>, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasAriaLabel
Card is a visual content container for creating a card-based layout.
Author:
Vaadin Ltd
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Collection<com.vaadin.flow.component.Component> components)
     
    void
    addComponentAtIndex(int index, com.vaadin.flow.component.Component component)
     
    void
    addToFooter(com.vaadin.flow.component.Component... footerComponent)
    Adds components to the card's footer slot.
    Gets the ARIA role attribute of the card.
    Stream<com.vaadin.flow.component.Component>
     
    com.vaadin.flow.component.Component[]
    Gets all components added to the card's footer.
    com.vaadin.flow.component.Component
    Gets the current header component.
    com.vaadin.flow.component.Component
    Gets the current header prefix component.
    com.vaadin.flow.component.Component
    Gets the current header suffix component.
    com.vaadin.flow.component.Component
    Gets the current media component.
    com.vaadin.flow.component.Component
    Gets the current subtitle component.
    com.vaadin.flow.component.Component
    Gets the current title component set using setTitle(Component).
    Gets the value of the cardTitle property.
    void
    remove(Collection<com.vaadin.flow.component.Component> components)
     
    void
     
    void
    Sets the ARIA role attribute on the card.
    void
    setHeader(com.vaadin.flow.component.Component header)
    Sets the component used as the card's header.
    void
    setHeaderPrefix(com.vaadin.flow.component.Component headerPrefix)
    Sets a component to the header prefix slot, displayed before the header content.
    void
    setHeaderSuffix(com.vaadin.flow.component.Component headerSuffix)
    Sets a component to the header suffix slot, displayed after the header content.
    void
    setMedia(com.vaadin.flow.component.Component media)
    Sets the component used as the card's media.
    void
    setSubtitle(com.vaadin.flow.component.Component subtitle)
    Sets the component used as the card's subtitle.
    void
    setTitle(com.vaadin.flow.component.Component title)
    Sets the component used as the card's title.
    void
    Sets the cardTitle property.
    void
    setTitle(String title, Integer titleHeadingLevel)
    Sets the title and the heading level for the title.
    void
    setTitleHeadingLevel(Integer titleHeadingLevel)
    Sets the title heading level property for the titles set using setTitle(String).

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

    addListener, findAncestor, fireEvent, from, get, 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.DetachNotifier

    addDetachListener

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

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy

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

    add, add, addComponentAsFirst, remove

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

    getElement

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

    isEnabled, setEnabled

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

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    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.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

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

    addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
  • Constructor Details

    • Card

      public Card()
  • Method Details

    • setMedia

      public void setMedia(com.vaadin.flow.component.Component media)
      Sets the component used as the card's media. The media slot is typically used to display an image, icon, or other visual element.

      Passing null removes the current media component from the card.

      Parameters:
      media - the media component, or null to remove
    • getMedia

      public com.vaadin.flow.component.Component getMedia()
      Gets the current media component.
      Returns:
      the media component, or null if none is set
    • setTitle

      public void setTitle(String title)
      Sets the cardTitle property. If a header component is set, the title will not be displayed. Setting a title this way removes any title component set using setTitle(Component). Setting null or empty string removes any previously set String titles.
      Parameters:
      title - the title property
      See Also:
    • setTitle

      public void setTitle(String title, Integer titleHeadingLevel)
      Sets the title and the heading level for the title. If a header component is set, the title will not be displayed. Setting a title this way removes any title component set using setTitle(Component). Setting null or empty title removes any previously set String titles.
      Parameters:
      title - the title property
      titleHeadingLevel - the title heading level property,
      See Also:
    • setTitleHeadingLevel

      public void setTitleHeadingLevel(Integer titleHeadingLevel)
      Sets the title heading level property for the titles set using setTitle(String). The default is 2. Setting null resets it to default. Does not affect the title components set using setTitle(Component).
      Parameters:
      titleHeadingLevel - the title heading level property, null to remove
    • setTitle

      public void setTitle(com.vaadin.flow.component.Component title)
      Sets the component used as the card's title. If a header component is set, the title will not be displayed. This also removes any previously set String titles.

      Passing null removes the current title from the card.

      Parameters:
      title - the title component, or null to remove
    • getTitleAsText

      public String getTitleAsText()
      Gets the value of the cardTitle property. Returns empty if no title is set.
      Returns:
      the value of the title property
    • getTitle

      public com.vaadin.flow.component.Component getTitle()
      Gets the current title component set using setTitle(Component).
      Returns:
      the title component, or null if none is set
    • setSubtitle

      public void setSubtitle(com.vaadin.flow.component.Component subtitle)
      Sets the component used as the card's subtitle. If a header component is set, the subtitle will not be displayed.

      Passing null removes the current subtitle from the card.

      Parameters:
      subtitle - the subtitle component, or null to remove
    • getSubtitle

      public com.vaadin.flow.component.Component getSubtitle()
      Gets the current subtitle component.
      Returns:
      the subtitle component, or null if none is set
    • setHeader

      public void setHeader(com.vaadin.flow.component.Component header)
      Sets the component used as the card's header. The header is prioritized over the title and subtitle components, and will be displayed instead.

      Passing null removes the current header component from the card.

      Parameters:
      header - the header component, or null to remove
    • getHeader

      public com.vaadin.flow.component.Component getHeader()
      Gets the current header component.
      Returns:
      the header component, or null if none is set
    • setHeaderPrefix

      public void setHeaderPrefix(com.vaadin.flow.component.Component headerPrefix)
      Sets a component to the header prefix slot, displayed before the header content.

      Passing null removes any existing prefix from the header.

      Parameters:
      headerPrefix - the header prefix component, or null to remove
    • getHeaderPrefix

      public com.vaadin.flow.component.Component getHeaderPrefix()
      Gets the current header prefix component.
      Returns:
      the header prefix component, or null if none is set
    • setHeaderSuffix

      public void setHeaderSuffix(com.vaadin.flow.component.Component headerSuffix)
      Sets a component to the header suffix slot, displayed after the header content. Commonly used for decorative icons or custom suffixes.

      Passing null removes any existing suffix from the header.

      Parameters:
      headerSuffix - the header suffix component, or null to remove
    • getHeaderSuffix

      public com.vaadin.flow.component.Component getHeaderSuffix()
      Gets the current header suffix component.
      Returns:
      the header suffix component, or null if none is set
    • addToFooter

      public void addToFooter(com.vaadin.flow.component.Component... footerComponent)
      Adds components to the card's footer slot.
      Parameters:
      footerComponent - the components to add into the footer
    • getFooterComponents

      public com.vaadin.flow.component.Component[] getFooterComponents()
      Gets all components added to the card's footer.
      Returns:
      an array of footer components
    • getChildren

      public Stream<com.vaadin.flow.component.Component> getChildren()
      Overrides:
      getChildren in class com.vaadin.flow.component.Component
    • add

      public void add(Collection<com.vaadin.flow.component.Component> components)
      Specified by:
      add in interface com.vaadin.flow.component.HasComponents
    • remove

      public void remove(Collection<com.vaadin.flow.component.Component> components)
      Specified by:
      remove in interface com.vaadin.flow.component.HasComponents
    • removeAll

      public void removeAll()
      Specified by:
      removeAll in interface com.vaadin.flow.component.HasComponents
    • addComponentAtIndex

      public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component)
      Specified by:
      addComponentAtIndex in interface com.vaadin.flow.component.HasComponents
    • setAriaRole

      public void setAriaRole(String role)
      Sets the ARIA role attribute on the card.
      Parameters:
      role - the ARIA role, or null to clear
    • getAriaRole

      public Optional<String> getAriaRole()
      Gets the ARIA role attribute of the card.
      Returns:
      an optional ARIA role of the card if no ARIA role has been set