Format
In some cases, it's adventagous 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 support by all controls.
Basic Example
For example, the following creates a slider ranging from 0-12 with a property called padding
If the slider is set to 5 and the template contains
the output will be
Arbitrary Value Example
You could also format the control's value to use tailwind's arbitrary value feature. This would allow your element precis 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 with a number input, we can do the following:
If the number field is set to 50 and the template contains
the output will be
Of cause, 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 --translateX
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