Widget Configuration
Only available in Web SDK version 2.0.0 and up.
Widget elements
Widget elements are composed of multiple "building block" elements. These elements are available to be mixed and matched, styled, and composed into unique experiences.
These elements can make use of content created and sent through our API, data from your own sources, or displayed anywhere as static elements.
For a full breakdown of all available elements and their properties, see the API reference documentation.
For example, here is the markup of a text poll, with a breakdown explaining each tag.
<template kind="image-poll">
<livelike-widget-root>
<livelike-widget-header>
<livelike-title></livelike-title>
<livelike-timer></livelike-timer>
<livelike-dismiss-button></livelike-dismiss-button>
</livelike-widget-header>
<livelike-widget-body>
<livelike-select>
<template>
<livelike-option>
<livelike-description></livelike-description>
<livelike-progress></livelike-progress>
<livelike-percentage></livelike-percentage>
<livelike-image></livelike-image>
</livelike-option>
</template>
</livelike-select>
</livelike-widget-body>
</livelike-widget-root>
</template>
-
template
Each custom widget must be wrapped in a template element with a "kind" attribute that is the widget kind. This is to let the SDK know that the markup inside template should be rendered when that kind of widget is published. -
livelike-widget-root
A container, useful for composition. Has aheader
,timer
, andbody
slot, as well as an unnamed slot for anything else. -
livelike-widget-header
A container, useful for composition. Has atitle
anddismiss-button
slot, as well as an unnamed slot for anything else. -
livelike-title
Renders the widget'stitle
orquestion
widget property. -
livelike-timer
Renders a timer with thetimeout
property that is the widget's duration in milliseconds. -
livelike-dismiss-button
Renders a button that fires thedismissclicked
event, and 'dismisses' the widget. -
livelike-widget-body
A container, useful for composition. Has an unnamed slot. -
livelike-select
Takes a template element as a child, and renders the template content as a list peroptions
/choices
array item. For example, a Text Poll widget is published with two options. As a child of the livelike-select, we have a template with an livelike-option as the content. When the Text Poll gets rendered, two livelike-option elements will get rendered as a direct child of the livelike-select, one for each item in theoptions
array.
// widgetPayload data with two `options` items.
widgetPayload : {
options: [
{description: 'Option One'},
{description: 'Option Two')
]
}
// Template
<template kind="text-poll">
<livelike-select>
<template>
<livelike-option>
<livelike-description></livelike-description>
</livelike-option>
</template>
</livelike-select>
</template>
// What gets rendered
<livelike-text-poll>
<livelike-select>
<livelike-option>
<livelike-description>Option One</livelike-description>
</livelike-option>
<livelike-option>
<livelike-description>Option Two</livelike-description>
</livelike-option>
</livelike-select>
</livelike-text-poll>
-
template
livelike-select child -
livelike-option
Container component that contains anoption
orchoice
property from theoptions
/choices
array. Click listener is attached that sends vote on click. -
livelike-description
Rendersdescription
property fromoptions
/choices
array item. -
livelike-percentage
Calculates percentage of votes in currentoption
/'choices
out of all votes inoptions
/choices
array. -
livelike-progress
Calculates same percentage as livelike-percentage> -
livelike-image
Rendersimage_url
property fromoptions
/choices
array item. Takes optionalsrc
,height
,width
attributes to override default.
Styling Widgets
Widgets can be styled with CSS directly. Each of these building block elements has one job, either as a structural container or to render a widget property, and this allows for styling and recomposing.
Different elements can be specified on a per widget basis, and custom element styles can be included alongside livelike element styles.
<style>
livelike-text-poll livelike-widget-header {
padding: 1rem;
color: white;
}
livelike-text-poll livelike-title {
font-size: 24px;
}
livelike-text-poll .custom-subtitle {
font-size: 16px;
}
livelike-text-poll livelike-widget-body {
background: grey;
}
livelike-text-poll livelike-option {
border: 1px solid blue;
}
livelike-text-poll livelike-description {
font-size: 20px;
color: white;
}
</style>
<template kind="text-poll">
<livelike-widget-header>
<livelike-title></livelike-title>
<h4 class="custom-subtitle">Subtitle</h4>
</livelike-widget-header>
<livelike-widget-body>
<livelike-widget-select>
<template>
<livelike-option>
<livelike-description></livelike-description>
</livelike-option>
</template>
</livelike-widget-select>
</livelike-widget-body>
</template>
Updated 12 months ago