Skip to content

Simple API to create vanilla custom elements with riot

License

Notifications You must be signed in to change notification settings

riot/custom-elements

Folders and files

NameName
Last commit message
Last commit date

Latest commit

12ce68e · Nov 2, 2024

History

56 Commits
Nov 2, 2024
Nov 2, 2024
Dec 1, 2023
Dec 1, 2023
Nov 2, 2024
Dec 18, 2018
Oct 4, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024

Repository files navigation

@riotjs/custom-elements

Riot.js custom elements logo

Simple API to create vanilla custom elements with riot

Build Status NPM version NPM downloads MIT License

Demos

Usage

import MyComponent from './my-component.riot'
import define from '@riotjs/custom-elements'

define('x-tag', MyComponent)

Notice that in order to update the component properties via attribute you will need to rely on the observedAttributes array

<my-component>
  <p>{props.message}</p>
  <script>
    export default {
      // the message property will be automatically updated anytime the DOM `message` attribute will change
      observedAttributes: ['message']
    }
  </script>
</my-component>

API

This module exports only a single factory function that is a wrapper around the native customElements.define. The define function accepts only 3 parameters:

  • tag name
  • tag api normally generated via riot compiler
  • custom options to pass to customElements.define like {extends: 'button'} for example