Format

In some cases, it's advantageous to format a value before it's passed to your element's templates. To achieve this, add a format property to the configuration specifying the format string.

Value formatting is supported by all controls.

Basic Example

For example, the following creates a slider ranging from 0-12 with a property called cardPadding.

{
  "title": "Card Padding",
  "id": "cardPadding",
  "format": "p-{{value}}",
  "slider": {
    "default": 4,
    "min": 0,
    "max": 12
  }
}

If the slider is set to 5 and the template contains

{{cardPadding}}

the output will be

p-4

Arbitrary Value Example

You could also format the control's value to use Tailwind's arbitrary value feature. This would allow your element precise control over all CSS properties. For example, you can control the opacity utility class from Tailwind with a slider:

If the slider is set to 50 and the template contains

the output will be

Advanced CSS Example

You could also format the control's value to output a valid CSS property. For example, if we want to control the translateX CSS property for an accent badge, we can do the following:

If the number field is set to 50 and the template contains

the output will be

Of course, in this case you would want to add this to a CSS template file.

CSS Custom Property Example

You can even use the format to control a CSS Custom Property (CSS variable). If we take our previous example and expand on it, we might want to instead set a --badgeOffsetX CSS custom property with a number input:

If the number field is set to 50 and the template contains

the output will be

In this case you would either want to add this to a CSS file, or use an inline style attribute to set the --translateX:

Last updated

Was this helpful?