Last updated
Was this helpful?
Last updated
Was this helpful?
Since a small framework is chosen to build the Web Components, it is recommended to consider doing the same. There are no strict requirements for how to build your components. However, most of the code and documentation examples are based on Lit. That said, many users successfully use other frameworks as well.
To help you get started, here’s an overview of some relevant Lit features.
To decide the content of your Element, you define a `render` method. It could look like this:
Declare a static styles property with the CSS Declarations you want for your Component.
Once your Element has some Data to represent, you most likely want to re-render the contents of your element when the data changes.
To enable this, you can decorate the Properties that should be reactive with either `@property` or `@state`; the difference between these two is whether it's a Public property (@property) or a protected property (@state).
The Web Component above can then be used like this:
You might want to parse data directly to an element within the render method. The following example shows how to parse a complex object into another Web Component without it being parsed via the DOM. This can be done by setting it directly as a JavaScript property:
Notice the .
in front of the property name (myValue
)
You may like to listen to an event on one of the elements created via the render method. Luckily Lit enables you to do this. The following example shows how to assign an event listener to the 'click' event.
It is recommended to use Lit for writing Web Components. It is not recommended to use Lit Controllers or the Lit Context API, as the Backoffice has its own APIs for those use cases.
To explore more features, visit the .
Backoffice supports any native Web Components. But we choose to use a little framework to make it simpler.