Component props reference
Reference for the prop types a custom component can declare, how each type shows in the Content tab, and how to read values.
Props are the fields a custom component exposes in the Content tab. You declare each prop once, in the component constructor, and read its value when the component renders.
#Declare props
Call this.addProp in the constructor, after super(props, styles). Each call adds one field to the Content tab.
| Field | Required | What it sets |
|---|---|---|
type | Yes | The kind of value and the control the Content tab shows. |
key | Yes | The name you use to read the value. Keep it unique in the component. |
displayer | Yes | The label shown above the field in the Content tab. |
value | Yes | The default value. Its shape depends on type. |
max | No | The highest number a number prop accepts. |
additionalParams | No | Extra settings for some types, such as selectItems for select. |
constructor(props?: any) { super(props, styles); this.addProp({ type: "string", key: "title", displayer: "Title", value: "Welcome to your site", }); this.addProp({ type: "boolean", key: "showButton", displayer: "Show button", value: true, }); this.addProp({ type: "select", key: "accent", displayer: "Accent", value: "primary", additionalParams: { selectItems: ["primary", "secondary", "tertiary"] }, });}To let people add, remove, and reorder items, wrap an object in an array. Each item is an object that holds its own props:
this.addProp({ type: "array", key: "features", displayer: "Features", value: [ { type: "object", key: "feature", displayer: "Feature", value: [ { type: "string", key: "title", displayer: "Title", value: "Fast" }, { type: "string", key: "description", displayer: "Description", value: "Loads quickly." }, ], }, ],});#Prop types
Use one of these values for type. There is no separate type for long text. Use string, which also accepts formatted text.
| Type | Content tab control | Value you receive | Example value |
|---|---|---|---|
string | Text field with formatting | A React element. Plain text with { as_string: true } | "Welcome" |
number | Number field, capped by max | A number | 3 |
boolean | Toggle | true or false | true |
page | Link picker for pages and sections | The link target as text | "" |
media | Media picker for images, videos, icons, or Lottie animations | An object with type and url | { type: "image", url: "https://example.com/hero.jpg" } |
image | Image picker | The image address as text | "https://example.com/hero.jpg" |
video | Video picker | The video address as text | "https://example.com/intro.mp4" |
file | File picker with an Add File button | The file address as text | "" |
color | Color picker | The color as text | "#4f46e5" |
icon | Icon picker with a Select button | The icon as text | "" |
select | Dropdown filled from selectItems | The chosen item as text | "primary" |
multiSelect | Multiple-choice dropdown filled from selectItems | A list of the chosen items | ["primary"] |
email | Email field | The address as text | "you@example.com" |
phone | Phone number field | The number as text | "" |
dateTime | Date and time picker | The date as text | "" |
location | Location picker | An object with lat and lng | { lat: 0, lng: 0 } |
range | Slider with minRange, maxRange, and step | The chosen number as text | "50" |
currency | Amount field with a currency list | An object with value and currency | { value: "10", currency: "USD" } |
tag | Tag field. Type a tag and press Enter | A list of text | ["new"] |
embededLink | Embedded link field | The link as text | "" |
array | List where you add, remove, and reorder items | A list of items | A list of object props |
object | Group of nested props | The group's props | A list of props |
The type name embededLink is spelled this way in code. Type it exactly as shown.
#Read prop values
Call this.getPropValue("key") in render. Text from a string prop comes back as a React element, so render it directly in your JSX. Pass { as_string: true } when you need plain text, for example for an alt or aria-label attribute.
Use this.castToObject to read an array or an object as plain objects keyed by prop name. Use this.castToString to turn a text element into plain text, for example to check whether a field is empty.
render() { const title = this.getPropValue("title"); const altText = this.getPropValue("title", { as_string: true }); const showButton = this.getPropValue("showButton"); const features = this.castToObject<Feature[]>("features"); return ( <section className={this.decorateCSS("container")}> {this.castToString(title) && <h2 aria-label={altText}>{title}</h2>} {features.map((feature, index) => ( <div key={index}> <h3>{feature.title}</h3> <p>{feature.description}</p> </div> ))} {showButton && <a href="https://example.com">Learn more</a>} </section> );}#Use theme variables
The editor and your published site set these CSS variables from the project theme. Use them in your component styles so the component follows the theme when it changes.
| Variable | What it holds |
|---|---|
--composer-primary-color | The primary theme color |
--composer-secondary-color | The secondary theme color |
--composer-tertiary-color | The tertiary theme color |
--composer-html-background | The page background color |
--composer-font-color-primary | The main text color |
--composer-font-color-secondary | The secondary text color |
--composer-font-family | The theme font |
--composer-content-width | The maximum content width |
.button { background: var(--composer-primary-color); color: var(--composer-font-color-secondary); font-family: var(--composer-font-family);}Component Studio sets the same variables in its preview, so the Theme panel shows how your component reacts. See Theme system for how to change the project theme.