The style field is a unique field that enables you to attach component style controls to components in the visual editor. This is the only field type that doesn't appear in the page editor sidebar.
Control Type
Inferred from and automatically set by the style being used. See style control types for a list of controls used by component styles.
Stored Value
An object of style values, as selected by the editor.
Usage Example#
Consider a HeroSection model that wants to allow editors to control the content width.
When highlighting the component, a palette icon will appear, which will enable the editor to set these values.
Component Style Control for HeroSection Component
Stored Values#
A style field's is an JSON object representing the shape of the configured options and values chose by the user.
Using the example above, assuming the user chose narrow for self and large for fontSize, the resulting values on the object would look like this:
1
2
3
4
{"self":"narrow","fontSize":"large"}
Some properties like margin and padding allow for multiple values to be selected, in which case the resulting value becomes a nested object.
Required Properties#
All style fields require a style property.
style
Object, where the keys are one of:
self: Refers to the wrapping element on the model.
{fieldName}: (e.g. title) Must match the name property on a field definition within the same model.
These properties (self or {fieldName}) should be an object with properties where the key/name is one of the styles shown throughout this reference, and the value is the set of options available for that style.
Style Control Types#
Control types differ depending on the property and the value options available for that property type.
Button#
A button control is used when a finite number of text (non-numeric) options can be represented by icons and when multiple values can exist for a style field.
Button Style Control
fontStyle is a good example of a button control, as multiple values may be selected.
Button Group#
A button group control is used when a finite number of text (non-numeric) options can be represented by icons and when a single value can be chosen for a style field.
Button Group Style Control
The textAlign field uses a button group, as there are a finite number of options, from which only one can be chosen.
Color#
A dropdown of color tiles.
Color Style Control
A color picker field must specify an array of options with the following properties:
color
The value of the color. This can be a hex value (e.g. #444444) or a variable representing the name of a global style field (e.g. primary).
label
String shown in the dropdown option.
value
The value to store in the content source..
Dropdown#
Dropdown controls is a generic control type that produces a single value.
Dropdown Style Control
They are used in a number of scenarios:
A list of options can not be represented by a pre-determined set of icons
A set of numbers is not conducive to using a slider control (see below)
There are too many options to reasonably render a button group
Slider#
When numbers can be used for the values options of a field, you can specify a range, which will be rendered in the UI as a slider.
Slider Control
Sliders are configured like so:
*
Any number within the bounds allowed by the property.
a:b
Any number between a and b, in step increments based on the property. (Step is 1 unless otherwise specified.)
Example: 0:4
a:b:n
Any number between a and b, with step increments of n. For example, 0:8:2 is the equivalent of ['0', '2', '4', '6', '8'].
Example: 0:8:2
[...]
An explicit list (array) of of specific values and ranges. Note that each array item can use ranges mentioned above.
Example: ['0', '2', '4:8']
Spacing#
Spacing controls allow for setting values on one, more, or all sides of an element.
Spacing Control
Sliders are configured like so:
*
Any number within the bounds allowed by the property on any or all sides.
a:b
Any number between a and b on any side or all sides, in step increments based on the property. (Step is 1 unless otherwise specified.)
Example: 0:4 is the equivalent of ['0', '1', '2', '3', '4']
a:b:n
Any number between a and b, on any or all sides, with step increments of n.
Example: 0:8:2 is the equivalent of ['0', '2', '4', '6', '8']
{side}a:b(:n)
Any number between a and b, with an optional step increments of n, on a specific side, where {side} can be:
b: bottom
l: left
r: right
t: top
x: left and right
y: top and bottom
Example: x0:8:2 is the equivalent of ['0', '2', '4', '6', '8'], but only for left and right sides. Top and bottom sides won't be set.
[...]
An explicit list (array) of of specific values and ranges. Note that each array item can use ranges mentioned above.
Example: ['0', '2', '4:8'] is the equivalent of ['0', '2', '4', '5', '6', '7', '8']
Mixing Options: Specifying a side will add to the options available, not override them.
Example: ['0:4:2', 't0:20:4'] would result in ['0', '2', '4'] for all sides, except the top, which would have options `['0', '2', '4', '8', '12', '16', '20'] (notice '2' is still present).
Because these values can be configured and set on one or more sides, just as with CSS. The resulting selected values produce an object that can be mapped to CSS classes as necessary.
Note that using this style will also make a Bold button appear alongside the fontStyle and textDecoration buttons. Enabling bold will set the font weight slider to 700.