com.vaadin.flow.component.card.
Class Card
All Implemented Interfaces:
AttachNotifier
, DetachNotifier
, HasAriaLabel
, HasComponents
, HasElement
, HasEnabled
, HasSize
, HasStyle
, HasTheme
, HasThemeVariant<CardVariant>
, Serializable
Card is a visual content container for creating a card-based layout.
Author:
Vaadin Ltd
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Collection<Component> components) Adds the given components as children of this component.
void
addComponentAtIndex
(int index, Component component) Adds the given component as child of this component at the specific index.
void
addToFooter
(Component... footerComponent) Adds components to the card's footer slot.
Gets the ARIA role attribute of the card.
Gets the child components of this component.
Gets all components added to the card's footer.
Gets the current header component.
Gets the current header prefix component.
Gets the current header suffix component.
getMedia()
Gets the current media component.
Gets the current subtitle component.
getTitle()
Gets the current title component set using
setTitle(Component)
.Gets the value of the
cardTitle
property.protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.
void
remove
(Collection<Component> components) Removes the given child components from this component.
void
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.void
setAriaRole
(String role) Sets the ARIA role attribute on the card.
void
Sets the component used as the card's header.
void
setHeaderPrefix
(Component headerPrefix) Sets a component to the header prefix slot, displayed before the header content.
void
setHeaderSuffix
(Component headerSuffix) Sets a component to the header suffix slot, displayed after the header content.
void
Sets the component used as the card's media.
void
setSubtitle
(Component subtitle) Sets the component used as the card's subtitle.
void
Sets the component used as the card's title.
void
Sets the
cardTitle
property.void
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, 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
-
Constructor Details
-
Card
public Card()
-
-
Method Details
-
setMedia
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, ornull
to remove -
getMedia
Gets the current media component.
Returns:
the media component, or
null
if none is set -
setTitle
Sets the
cardTitle
property. If aheader component
is set, the title will not be displayed. Setting a title this way removes any title component set usingsetTitle(Component)
. Settingnull
or empty string removes any previously setString
titles.Parameters:
title
- the title propertySee Also:
-
setTitle
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 usingsetTitle(Component)
. Settingnull
or empty title removes any previously setString
titles.Parameters:
title
- the title propertytitleHeadingLevel
- the title heading level property,See Also:
-
setTitleHeadingLevel
Sets the title heading level property for the titles set using
setTitle(String)
. The default is 2. Settingnull
resets it to default. Does not affect the title components set usingsetTitle(Component)
.Parameters:
titleHeadingLevel
- the title heading level property,null
to remove -
setTitle
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 setString
titles.Passing
null
removes the current title from the card.Parameters:
title
- the title component, ornull
to remove -
getTitleAsText
Gets the value of the
cardTitle
property. Returns empty if no title is set.Returns:
the value of the title property
-
getTitle
Gets the current title component set using
setTitle(Component)
.Returns:
the title component, or
null
if none is set -
setSubtitle
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, ornull
to remove -
getSubtitle
Gets the current subtitle component.
Returns:
the subtitle component, or
null
if none is set -
setHeader
Sets the component used as the card's header. The header is prioritized over the
title
andsubtitle
components, and will be displayed instead.Passing
null
removes the current header component from the card.Parameters:
header
- the header component, ornull
to remove -
getHeader
Gets the current header component.
Returns:
the header component, or
null
if none is set -
setHeaderPrefix
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, ornull
to remove -
getHeaderPrefix
Gets the current header prefix component.
Returns:
the header prefix component, or
null
if none is set -
setHeaderSuffix
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, ornull
to remove -
getHeaderSuffix
Gets the current header suffix component.
Returns:
the header suffix component, or
null
if none is set -
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 classComponent
Returns:
the child components of this component
See Also:
-
add
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 interfaceHasComponents
Parameters:
components
- the components to add -
remove
Description copied from interface:
HasComponents
Removes the given child components from this component.
Specified by:
remove
in interfaceHasComponents
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 interfaceHasComponents
-
addComponentAtIndex
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 interfaceHasComponents
Parameters:
index
- the index, where the component will be added. The index must be non-negative and may not exceed the children countcomponent
- the component to add, value should not be null -
setAriaRole
Sets the ARIA role attribute on the card.
Parameters:
role
- the ARIA role, ornull
to clear -
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
Description copied from class:
Component
Called when the component is attached to a UI.
This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method.
-