Skip to content

Pass inputs as Object props instead of setting properties on the web component's reference #34

@MantisClone

Description

@MantisClone

Problem

Today, the end-user must pass inputs into the web component by storing a reference to it and setting properties on it before passing the ref as a prop.

This is a lot of boilerplate code for the end-user to write.

Solution

Configure the web component to accept Object props. This would reduce the amount of boilerplate code that the end user must write.

<svelte:options
  customElement={{
    tag: 'invoice-dashboard',
    props: {
      config: { type: 'Object' },
      wallet: {type: 'Object' },
      requestnetwork: { type: 'Object', attribute: 'request-network' },
    },

Definition of Done

  • Update the READMEs and documentation

Reference

https://svelte.dev/docs/custom-elements-api#component-options

  • props: an optional property to modify certain details and behaviors of your component's properties. It offers the following settings:
    • attribute: string: To update a custom element's prop, you have two alternatives: either set the property on the custom element's reference as illustrated above or use an HTML attribute. For the latter, the default attribute name is the lowercase property name. Modify this by assigning attribute: "".
    • reflect: boolean: By default, updated prop values do not reflect back to the DOM. To enable this behavior, set reflect: true.
    • type: 'String' | 'Boolean' | 'Number' | 'Array' | 'Object': While converting an attribute value to a prop value and reflecting it back, the prop value is assumed to be a String by default. This may not always be accurate. For instance, for a number type, define it using type: "Number" You don't need to list all properties, those not listed will use the default settings.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

✅ Done

Relationships

None yet

Development

No branches or pull requests

Issue actions