Skip to content
BlinkpageBlinkpageDocs

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.

On this page

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.

FieldRequiredWhat it sets
typeYesThe kind of value and the control the Content tab shows.
keyYesThe name you use to read the value. Keep it unique in the component.
displayerYesThe label shown above the field in the Content tab.
valueYesThe default value. Its shape depends on type.
maxNoThe highest number a number prop accepts.
additionalParamsNoExtra settings for some types, such as selectItems for select.
my-hero/index.tsx
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:

my-features/index.tsx
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.

TypeContent tab controlValue you receiveExample value
stringText field with formattingA React element. Plain text with { as_string: true }"Welcome"
numberNumber field, capped by maxA number3
booleanToggletrue or falsetrue
pageLink picker for pages and sectionsThe link target as text""
mediaMedia picker for images, videos, icons, or Lottie animationsAn object with type and url{ type: "image", url: "https://example.com/hero.jpg" }
imageImage pickerThe image address as text"https://example.com/hero.jpg"
videoVideo pickerThe video address as text"https://example.com/intro.mp4"
fileFile picker with an Add File buttonThe file address as text""
colorColor pickerThe color as text"#4f46e5"
iconIcon picker with a Select buttonThe icon as text""
selectDropdown filled from selectItemsThe chosen item as text"primary"
multiSelectMultiple-choice dropdown filled from selectItemsA list of the chosen items["primary"]
emailEmail fieldThe address as text"you@example.com"
phonePhone number fieldThe number as text""
dateTimeDate and time pickerThe date as text""
locationLocation pickerAn object with lat and lng{ lat: 0, lng: 0 }
rangeSlider with minRange, maxRange, and stepThe chosen number as text"50"
currencyAmount field with a currency listAn object with value and currency{ value: "10", currency: "USD" }
tagTag field. Type a tag and press EnterA list of text["new"]
embededLinkEmbedded link fieldThe link as text""
arrayList where you add, remove, and reorder itemsA list of itemsA list of object props
objectGroup of nested propsThe group's propsA 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.

my-features/index.tsx
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>  );}
Each declared prop becomes a field in the Content tab.

#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.

VariableWhat it holds
--composer-primary-colorThe primary theme color
--composer-secondary-colorThe secondary theme color
--composer-tertiary-colorThe tertiary theme color
--composer-html-backgroundThe page background color
--composer-font-color-primaryThe main text color
--composer-font-color-secondaryThe secondary text color
--composer-font-familyThe theme font
--composer-content-widthThe maximum content width
my-hero/styles.module.css
.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.

#Next steps

Edit this page(opens in a new tab)