Class Avatar
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.avatar.Avatar
-
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasSize,HasStyle,HasTheme,HasThemeVariant<AvatarVariant>,Serializable
@Tag("vaadin-avatar") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="23.5.4") @NpmPackage(value="@vaadin/avatar",version="23.5.4") @NpmPackage(value="@vaadin/vaadin-avatar",version="23.5.4") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/avatar/src/vaadin-avatar.js") public class Avatar extends Component implements HasStyle, HasSize, HasThemeVariant<AvatarVariant>
Avatar is a graphical representation of an object or entity, for example a person or an organisation.Avatar has three properties: name, abbreviation and image.
The name is shown on hover in a tooltip. When a name is set, Avatar will auto-generate and display an abbreviation of the specified name. For example, “Allison Torres” becomes “AT”, “John Smith” becomes “JS”, etc.
The abbreviation can also be set manually. Abbreviations should be kept to a maximum of 2–3 characters.
Avatar can be used to display images, such as user profile pictures or company logos. Abbreviations are not shown when images are used.
Note that this component is optimized for use with Collaboration Engine — a simple way to build real-time collaboration into your app — but can also be used standalone as a regular component.
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAvatar.AvatarI18nThe internationalization properties forAvatarGroup.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddThemeVariants(AvatarVariant... variants)Adds theme variants to the component.StringgetAbbreviation()Gets the abbreviation that was set for the avatar.IntegergetColorIndex()Gets the color index for the avatar.Avatar.AvatarI18ngetI18n()Gets the internationalization object previously set for this component.StringgetImage()Gets the image url that was set for the avatar.AbstractStreamResourcegetImageResource()Gets the image that was set for the avatar.StringgetName()Gets the name that was set for the avatar.booleanisTooltipEnabled()Gets the enabled state of the avatar tooltip, which isfalseby default.voidremoveThemeVariants(AvatarVariant... variants)Removes theme variants from the component.voidsetAbbreviation(String abbr)Sets the abbreviation for the avatar.voidsetColorIndex(Integer colorIndex)Sets the color index for the avatar.voidsetI18n(Avatar.AvatarI18n i18n)Sets the internationalization properties for this component.voidsetImage(String url)Sets the image url for the avatar.voidsetImageResource(AbstractStreamResource resource)Sets the image for the avatar.voidsetName(String name)Sets the name for the avatar.voidsetTooltipEnabled(boolean tooltipEnabled)Sets the enabled of the avatar tooltip.-
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, 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.HasElement
getElement
-
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
-
-
-
-
Constructor Detail
-
Avatar
public Avatar()
Creates a new empty avatar.The avatar displays the user icon in the avatar and "Anonymous" in the tooltip unless overridden by setting other properties.
-
Avatar
public Avatar(String name)
Creates a new avatar with the provided name.- Parameters:
name- the name for the avatar- See Also:
setName(String)
-
Avatar
public Avatar(String name, String url)
Creates a new avatar with the provided name and url.- Parameters:
name- the name for the avatarurl- the image url- See Also:
setName(String),setImage(String)
-
-
Method Detail
-
getI18n
public Avatar.AvatarI18n getI18n()
Gets the internationalization object previously set for this component.Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using
setI18n(AvatarI18n)- Returns:
- the i18n object. It will be
null, If the i18n properties weren't set.
-
setI18n
public void setI18n(Avatar.AvatarI18n i18n)
Sets the internationalization properties for this component.- Parameters:
i18n- the internationalized properties, notnull
-
getName
public String getName()
Gets the name that was set for the avatar.- Returns:
- the name
-
setName
public void setName(String name)
Sets the name for the avatar.The name is displayed in a tooltip on hover.
Automatically deduced abbreviation is displayed in the avatar if no abbreviation or image is set.
- Parameters:
name- the name for the avatar
-
getAbbreviation
public String getAbbreviation()
Gets the abbreviation that was set for the avatar.- Returns:
- the abbreviation
-
setAbbreviation
public void setAbbreviation(String abbr)
Sets the abbreviation for the avatar.The abbreviation will be displayed in the avatar if no image has been set.
- Parameters:
abbr- the abbreviation
-
getImage
public String getImage()
Gets the image url that was set for the avatar.- Returns:
- the image url
-
getImageResource
public AbstractStreamResource getImageResource()
Gets the image that was set for the avatar.- Returns:
- the image resource value or
nullif the resource has not been set
-
setImage
public void setImage(String url)
Sets the image url for the avatar.The image will be displayed in the avatar even if abbreviation or name is set.
Setting the image with this method resets the image resource provided with
setImageResource(AbstractStreamResource)- Parameters:
url- the image url- See Also:
setImageResource(AbstractStreamResource)
-
setImageResource
public void setImageResource(AbstractStreamResource resource)
Sets the image for the avatar.Setting the image as a resource with this method resets the image URL that was set with
setImage(String)- Parameters:
resource- the resource value ornullto remove the resource- See Also:
setImage(String)
-
getColorIndex
public Integer getColorIndex()
Gets the color index for the avatar.- Returns:
- the color index or
nullif the index has not been set
-
setColorIndex
public void setColorIndex(Integer colorIndex)
Sets the color index for the avatar.The color index defines which color will be used for the border of the avatar. Color index N applies CSS variable
--vaadin-user-color-Nto the border.- Parameters:
colorIndex- the color index ornullto remove the index
-
isTooltipEnabled
public boolean isTooltipEnabled()
Gets the enabled state of the avatar tooltip, which isfalseby default.- Returns:
trueif the tooltip is shown on hover or focus,falseotherwise
-
setTooltipEnabled
public void setTooltipEnabled(boolean tooltipEnabled)
Sets the enabled of the avatar tooltip.- Parameters:
tooltipEnabled-trueto show the tooltip on hover or focus,falseto not show it
-
addThemeVariants
public void addThemeVariants(AvatarVariant... variants)
Description copied from interface:HasThemeVariantAdds theme variants to the component.- Specified by:
addThemeVariantsin interfaceHasThemeVariant<AvatarVariant>- Parameters:
variants- theme variants to add
-
removeThemeVariants
public void removeThemeVariants(AvatarVariant... variants)
Description copied from interface:HasThemeVariantRemoves theme variants from the component.- Specified by:
removeThemeVariantsin interfaceHasThemeVariant<AvatarVariant>- Parameters:
variants- theme variants to remove
-
-