Components

The Weavy UIKit is composed of components (interactive building blocks) that can be used individually or combined into larger and more complex solutions. Our components are just regular HTML elements, or custom elements to be precise, and you can use them like any other element.

If you’re new to custom elements, often referred to as web components, this article will familiarize you with how to use them.

Attributes and properties

Many components have properties that can be set using attributes. For example, the <wy-chat> component requires a uid attribute that maps to the uid property which identifies the corresponding app in the Weavy environment.

<wy-chat uid="test-chat"></wy-chat>

Some properties are boolean, so they only have true/false values. To activate a boolean property, add the corresponding attribute without a value.

<wy-messenger noReactions></wy-messenger>

See the reference documentation for a complete list of components and their properties.

Events

You can listen for standard events such as click and mouseover as you normally would. However, it's important to note that many events emitted within a component's shadow root will be retargeted to the host element. This may result in, for example, multiple click handlers executing even if the user clicks just once. Furthermore, event.target will point to the host element, making things even more confusing.

As a result, you should almost always listen for custom events instead. For example, instead of listening to click to determine when a notification in the notifications component is toggled, listen to wy:link.

<wy-notifications></wy-notifications>

<script>
  const notifications = document.querySelector('wy-notifications');
  notifications.addEventListener('wy:link', event => {
    // TODO: Evaluate event.detail and navigate to the correct page/view in your application
  });
</script>

All custom events are prefixed with wy: to prevent collisions with standard events and other libraries. See the reference documentation for a complete list of components and their custom events.

Methods

Some components have methods you can call to trigger various behaviors. For example, you can use the markAllAsRead() method on the notifications component to mark all notifications as read.

<wy-notifications></wy-notifications>

<script>
  const notifications = document.querySelector('wy-notifications');
  notifications.markAllAsRead();
</script>

See the reference documentation for a complete list of components and their methods and arguments.

Slots

Some components use slots to accept content inside of them. The most common slot is the default slot, which includes any content inside the component that doesn't have a slot attribute.

For example, a button's default slot is used to populate its label.

<wy-button>Click me</wy-button>

Some components also have named slots. A named slot can be populated by adding a child element with the appropriate slot attribute. Notice how the icon below has the slot="prefix" attribute? This tells the component to place the icon into its prefix slot.

<wy-button>
  <wy-icon slot="prefix" name="gear"></wy-icon>
  Settings
</wy-button>

The location of a named slot doesn't matter. You can put it anywhere inside the component and the browser will move it to the right place automatically!

See the reference documentation for a complete list of components and their available slots.

Don't use self-closing tags

Custom elements cannot have self-closing tags. Similar to <script> and <textarea>, you must always include the full closing tag.

<wy-messenger></wy-messenger>
Ask AI
Support

To access live chat with our developer success team you need a Weavy account.

Sign in or create a Weavy account