📱
HTML Widget
  • HTML Widget
  • Getting Started
    • Regular Use
    • Module Use
  • About
    • The Function
    • Types
  • Components
    • <widget>
    • <stack>
    • <spacer>
    • <img>
    • <text>
    • <date>
    • <style>
    • <!-- Comment -->
  • Add-ons
    • Add-ons
    • <symbol>
    • <hr>
    • <progress>
    • <blockquote>
  • Template
    • Templates
    • Mapping
    • Render
  • Examples
    • Hello, World!
    • Reddit Widget
  • Closing Remarks
    • Bug Fixes and Feedback
    • Support
Powered by GitBook
On this page
  1. Template

Mapping

Mapping - the validation of attributes and styles

PreviousTemplatesNextRender

Last updated 2 months ago

Mapping

const tagName = {
  mapping: {},
  async render(template, styles, attrs, innerText) {
    await template(``);
  },
};

The mapping object defines the valid attributes, valid styles, and their types. Before the render function is run, the attributes and styles will all be validated using the mapping object. This ensures that in case of a wrong type, a useful error will appear instead of a difficult scriptable error. The object should have the camelCase attribute or property names leading to the type of the valid values (see ) or an array of the types.

Here is an example of the mapping JSON used for the <stack> element.

{
  background: ["gradient", "image", "colour"],
  spacing: "posInt",
  url: "url",
  padding: "padding",
  borderColor: "colour",
  borderWidth: "posInt",
  size: "size",
  cornerRadius: "posInt",
  alignContent: "alignContent",
  layout: "layout"
}
types