com.vaadin.flow.component.card.

Class Card

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.card.Card

All Implemented Interfaces:

AttachNotifier, DetachNotifier, HasAriaLabel, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasTheme, HasThemeVariant<CardVariant>, Serializable

@Tag("vaadin-card") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.7") @NpmPackage(value="@vaadin/card",version="24.7.7") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/card/src/vaadin-card.js") public class Card extends Component implements HasSize, HasThemeVariant<CardVariant>, HasComponents, HasAriaLabel

Card is a visual content container for creating a card-based layout.

Author:

Vaadin Ltd

See Also:

  • Constructor Details

    • Card

      public Card()
  • Method Details

    • setMedia

      public void setMedia(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 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(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 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(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 Component getSubtitle()

      Gets the current subtitle component.

      Returns:

      the subtitle component, or null if none is set

    • setHeader

      public void setHeader(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 Component getHeader()

      Gets the current header component.

      Returns:

      the header component, or null if none is set

    • setHeaderPrefix

      public void setHeaderPrefix(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 Component getHeaderPrefix()

      Gets the current header prefix component.

      Returns:

      the header prefix component, or null if none is set

    • setHeaderSuffix

      public void setHeaderSuffix(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 Component getHeaderSuffix()

      Gets the current header suffix component.

      Returns:

      the header suffix component, or null if none is set

    • addToFooter

      public void addToFooter(Component... footerComponent)

      Adds components to the card's footer slot.

      Parameters:

      footerComponent - the components to add into the footer

    • getFooterComponents

      public Component[] getFooterComponents()

      Gets all components added to the card's footer.

      Returns:

      an array of footer components

    • getChildren

      public Stream<Component> getChildren()

      Description copied from class: Component

      Gets the child components of this component.

      The default implementation finds child components by traversing each child Element tree.

      If the component is injected to a PolymerTemplate using the @Id annotation the getChildren method will only return children added from the server side and will not return any children declared in the template file.

      Overrides:

      getChildren in class Component

      Returns:

      the child components of this component

      See Also:

    • add

      public void add(Collection<Component> components)

      Description copied from interface: HasComponents

      Adds the given components as children of this component.

      In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.

      Specified by:

      add in interface HasComponents

      Parameters:

      components - the components to add

    • remove

      public void remove(Collection<Component> components)

      Description copied from interface: HasComponents

      Removes the given child components from this component.

      Specified by:

      remove in interface HasComponents

      Parameters:

      components - the components to remove

    • removeAll

      public void removeAll()

      Description copied from interface: HasComponents

      Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using the Element API. it also removes the children that were added only at the client-side.

      Specified by:

      removeAll in interface HasComponents

    • addComponentAtIndex

      public void addComponentAtIndex(int index, Component component)

      Description copied from interface: HasComponents

      Adds the given component as child of this component at the specific index.

      In case the specified component has already been added to another parent, it will be removed from there and added to this one.

      Specified by:

      addComponentAtIndex in interface HasComponents

      Parameters:

      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count

      component - the component to add, value should not be null

    • 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

    • onAttach

      protected void onAttach(AttachEvent attachEvent)

      Description copied from class: Component

      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component.

      Make sure to call super.onAttach when overriding this method.

      Overrides:

      onAttach in class Component

      Parameters:

      attachEvent - the attach event