Avatar
<et2-avatar> | Et2Avatar
Overview
Avatars are used to represent a person or profile.
By default a generic icon will be shown. You can customise the icon, as well as set initials and image. You
should always provide a label for assistive devices.
<et2-avatar></et2-avatar>
Our Avatar widget extends Shoelace’s Avatar widget
There are multiple components for showing an image for an account / contact / email
- Avatar: (This one) Shows an image to go with a profile.
-
LAvatar: Does everything
Avatardoes, and also shows a letter avatar if there’s no image
You probably want to use LAvatar in your template as it gives more options
Examples
Image
To use an image for the avatar, set the image attribute. Avatar images can be lazily loaded by
setting the loading attribute to lazy.
<et2-avatar
image="https://images.unsplash.com/photo-1529778873920-4da4926a72c2?ixlib=rb-1.2.1&auto=format&fit=crop&w=300&q=80"
label="Avatar of a gray tabby kitten looking down"
></et2-avatar>
<et2-avatar
image="https://images.unsplash.com/photo-1591871937573-74dbba515c4c?ixlib=rb-1.2.1&auto=format&fit=crop&w=300&q=80"
label="Avatar of a white and grey kitten on grey textile"
loading="lazy"
></et2-avatar>
Initials
If you don’t have an image to use, you can set initials to show initials instead of the icon.
<et2-avatar initials="EG"></et2-avatar>
Custom Icons
When no image or initials are set, an icon will be shown. The default avatar shows a generic “user” icon, but you can customize this with the icon slot.
<et2-avatar label="Avatar with an image icon">
<et2-image slot="icon" src="image"></et2-image>
</et2-avatar>
<et2-avatar label="Avatar with an archive icon">
<et2-image slot="icon" src="archive"></et2-image>
</et2-avatar>
<et2-avatar label="Avatar with a briefcase icon">
<et2-image slot="icon" src="briefcase"></et2-image>
</et2-avatar>
Contact ID
If you have only the ID for the profile, set contactId and Avatar will ask the server for
everything. When possible, avoid this as it requires an extra request to the server. Setting
initials will show the initials until the image is found.
contactId could be in one of these formats:
#will be considered as contact IDcontact:#similar to aboveaccount:#will be considered as account IDemail:<email>will be considered as email address
<et2-avatar contactid="contact:6"></et2-avatar>
<et2-avatar initials="TU" contactid="contact:6" loading="lazy"></et2-avatar>
The image fetched is cached by the browser, which is often fine.
If it can be changed (editable) set image to something with a
cachebuster.
Editable
Make avatar widget editable to be able to crop profile picture or upload a new photo
<et2-avatar editable></et2-avatar>
Avatar Groups
Use Avatar Group to show a group of avatars
when you have the needed information in an array. Otherwise, just use multiple
Avatars and some CSS.
<div class="avatar-group">
<et2-avatar shape="circle" image="https://images.unsplash.com/photo-1525351484163-7529414344d8?fm=jpg&q=60&w=3000&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"></et2-avatar>
<et2-avatar shape="circle" image="https://images.unsplash.com/photo-1530610476181-d83430b64dcd?q=80&w=1935&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"></et2-avatar>
<et2-avatar shape="circle" image="https://images.unsplash.com/photo-1542276867-c7f5032e1835?q=80&w=1984&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"></et2-avatar>
</div>
<style>
.avatar-group et2-avatar:not(:first-of-type) {
margin-left: -1rem;
}
.avatar-group et2-avatar::part(base) {
border: solid 2px var(--sl-color-neutral-0);
}
</style>
Slots
| Name | Description |
|---|---|
icon
|
The default icon to use when no image or initials are provided. |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
contactId
|
Function to set contactId contactId could be in one of these formats: ‘number’, will be considered
as contact_id ‘contact:number’, similar to above ‘account:number’, will be considered as account id
‘email: |
- | - | |
editable
|
Make avatar widget editable to be able to crop profile picture or upload a new photo |
boolean
|
false
|
|
image
|
Deliberately NOT reflected. For a contactId we resolve the URL asynchronously (cachedQueue() in the contactId setter, since only the server knows whether a contact has a photo), so it lands after this widget has already rendered once. Reflecting it wrote that late answer back into the host’s attributes - and Et2Datagrid renders a row by handing rowElement.outerHTML to lit’s unsafeHTML(), which replaces the whole row node whenever that string differs from last time. So every avatar that resolved an image tore its entire row down and rebuilt it, re-running every widget constructor in it, purely because one attribute appeared after the fact. Nothing reads the attribute (no :host([image]) rule, here or in Shoelace’s own avatar styles), and attribute -> property still works for templates that set image=”…” - only the property -> attribute direction is dropped. |
string
|
""
|
|
shape
|
The shape of the avatar circle | square | rounded |
|
string
|
"rounded"
|
size
|
Explicitly specify the avatar size. Better to set the –size CSS variable in app.css, since it allows inheritance and overriding | - | - | |
src
|
set the image source
please use image instead |
- | - |
Learn more about attributes and properties.
Inherited properties (23)
Et2Widget
| Name | Description |
|---|---|
accesskey |
Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character. |
actions |
Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts. |
align |
Used by Et2Box to determine alignment. Allowed values are left, right |
class |
CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component. |
data |
Set the dataset from a CSV |
deferredProperties |
Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties |
disabled |
Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file. |
dom_id |
Get the actual DOM ID, which has been prefixed to make sure it’s unique. |
full |
Take every column of a layout, the same as span="all". Boolean rather than a bare
marker so it can be driven from content the way the rest of the template can -
full="@is_wide" resolves through the array manager like any other boolean attribute.
That does mean it needs a value: write full="true", since an empty
full="" resolves to false and removes the attribute again. Reflects for the same
reason grow does.
|
grow |
How much of a layout’s leftover space this widget should take. Only means anything inside a
container that has a layout (see Et2LayoutController): a bare grow or
grow="1" takes an equal share of whatever the non-growing children left over,
grow="2" takes twice what a grow="1" sibling does. It has to reflect.
The layout stylesheet matches the [grow] attribute - CSS cannot see a property - and
transformAttributes() only calls setAttribute() for an attribute the element already carries or a
property declared as reflecting. Widgets built from a .xet are created with
document.createElement() and handed their attributes as an object, so they carry none at that
point: without this declaration grow="1" lands as an inert JS property and nothing in
the layout ever matches it.
|
hidden |
The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way. |
id |
Get the ID of the widget |
label |
The label of the image Actually not used as label, but we put it as title |
noLang |
Disable any translations for the widget |
parentId |
Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location |
span |
How many of a layout’s columns this widget should take.
span="all" is every column wherever the widget landed, span="end" /
span="*" is from its own column to the end of its line. Only means anything inside a
container that has a layout, and only for the column layouts -
stack gives every child the full width anyway. The same name is also read straight
off the XML node by the legacy <grid> widget, for the unrelated job of counting
table cells to merge; that path never looks at the widget, so declaring it here does not disturb
it. Reflecting it does mean a legacy grid’s span="all" cells now carry the attribute
too, which matches nothing outside a layout. Reflects for the same reason grow does.
|
statustext |
Tooltip which is shown for this element on hover |
styles |
WebComponent * |
options |
Get property-values as object |
supportedWidgetClasses |
et2_widget compatability |
SlAvatar (Shoelace)
| Name | Description |
|---|---|
initials |
Initials to use as a fallback when no image is available (1–2 characters max recommended). |
loading |
Indicates how the browser should load the image. |
LitElement
| Name | Description |
|---|---|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Events
| Name | Description | Event Detail |
|---|---|---|
sl-error |
The image could not be loaded. This may because of an invalid URL, a temporary network condition, or some unknown cause. | - |
Learn more about events.
Methods
| Name | Description | Arguments |
|---|---|---|
delButtonClickHandler()
|
click handler to handel click on delete button | - |
editButtonClickHandler()
|
click handler to handle click on edit button | - |
uploadAvatar_onFinish()
|
Function runs after upload in avatar dialog is finished and it tries to update image and cropper container. |
e: type
|
Learn more about methods.
Inherited methods (21)
Et2Widget
| Name | Description |
|---|---|
checkCreateNamespace() |
Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions |
clone() |
Creates a copy of this widget. |
createElementFromNode() |
Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node. |
getArrayMgr() |
Returns the array manager object for the given part |
getArrayMgrs() |
Returns an associative array containing the top-most array managers. |
getChildren() |
Get child widgets Use |
getInstanceManager() |
Returns the instance manager |
getPath() |
Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this |
getRoot() |
Returns the base widget Usually this is the same as getInstanceManager().widgetContainer |
loadFromXML() |
Loads the widget tree from an XML node |
loadingFinished() |
Needed for legacy compatability. |
parseXMLAttrs() |
The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes. |
set_label() |
NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template |
setArrayMgr() |
Sets the array manager for the given part |
setArrayMgrs() |
Sets all array manager objects - this function can be used to set the root array managers of the container object. |
setInstanceManager() |
Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference |
_handleClick() |
Click handler calling custom handler set via onclick attribute to this.onclick |
destroy() |
et2_widget compatability |
set_class() |
Set the widget class |
set_disabled() |
Wrapper on this.disabled because legacy had it. |
set_statustext() |
supports legacy set_statustext |
Parts
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
icon |
The container that wraps the avatar’s icon. |
initials |
The container that wraps the avatar’s initials. |
image |
The avatar image. Only shown when the image attribute is set, or when contactId has an associated avatar image |
Learn more about customizing CSS parts.
Related
These widgets are related by naming but not by inheritance or sub-widget composition.