Variant

Add a Variant property to your component for designers to choose from a predefined list of options.

Syntax

1// Prop definition
2props.Variant({
3 name: string,
4 options: string[],
5 group?: string,
6 tooltip?: string,
7 defaultValue?: string,
8})
9
10// Prop value
11string

Prop Definition

Define the Variant prop in your Webflow code component with a name and list of options. Optionally, you can add a group, tooltip text, and a default value that matches one of the pre-defined options.

1props.Variant({
2 name: string,
3 options: string[],
4 group?: string,
5 tooltip?: string,
6 defaultValue?: string,
7})

Properties

  • name: The name for the property.
  • group: The group for this property. (optional)
  • tooltip: The tooltip for the property. (optional)
  • options: Array of available variant options.
  • defaultValue: Default selected option. (optional)

Example

MyComponent.webflow.tsx
1import { declareComponent } from '@webflow/react';
2import { props } from '@webflow/data-types';
3import { MyComponent } from "./MyComponent";
4
5export default declareComponent(MyComponent, {
6 name: "MyComponent",
7 description: "A component with a Variant property",
8 props: {
9 style: props.Variant({
10 name: "Button Style",
11 group: "Style",
12 options: ["Primary", "Secondary", "Tertiary"],
13 defaultValue: "Primary"
14 })
15 }
16});

Prop Value

The Variant prop provides a string value representing the selected option to your React component.

PropType.Variant
1string

Properties

  • n/a

Webflow properties panel