Prop Types
Prop types define the configurable properties that designers can edit in the Webflow designer. When you create a code component, you specify which React component properties to expose to designers, and how they should appear in Webflow.
Defining props in your code component
In your declareComponent function, include a props property that maps your React component’s properties to Webflow prop types. This tells Webflow:
- Which properties designers can configure.
- How each property should appear in the designer
- Which values are valid for each property
- Default values for each property (for certain prop types)
Basic usage
Available prop types
Choose the appropriate prop type based on what you want designers to configure:
Text and content
- Text - Single line text input
- Rich Text - Multi-line text with formatting
- Text Node - Single and Multi-line text that designers can edit on the canvas
- Link - URL input with validation
Assets and data
- Image - Image upload and selection
- Number - Numeric input with validation
- Boolean - True/false toggle
Structure and styles
- Variant - Dropdown with predefined options
- Visibility - Show/hide controls
- Slot - Content areas for other components
- ID - HTML Element ID
Prop values
Each prop type returns a value to your React component. For example, props.Text returns a string, while props.Link() returns an object with href and target properties.
Most times, you can map the prop values directly. For example, if your React component expects text as a string, you can map it to a props.Text prop.
However, if your React component expects specific properties from the returned object, you need to create a wrapper component that transforms the data. For example, the props.Link() prop type returns the following object:
If your React component expects href and target separately, you need to create a wrapper component that transforms the data:
This example definition file:
- Imports the
PropTypeandPropValuestypes from the@webflow/data-typespackage. - Defines a link prop for the
Buttoncomponent. This will provide a link picker in Webflow and return thehrefandtargetvalues. - Adjusts the TypeScript types of the
Buttoncomponent to include thelinkobject returned from theprops.Linkprop type. - Wraps the
Buttoncomponent in a new component that gets thehrefandtargetvalues from thelinkobject and passes them to theButtoncomponent as expected.
Best practices
Provide helpful defaults
Always set meaningful default values so components work immediately when added to a page. Some prop types have default values built in, like props.Text which defaults to an empty string. However, you may want to set a default value in your React component as well.
Use succinct names
The name property appears in the Webflow designer, keep them short and title case. Use descriptions to provide more context.
Group related props
Consider how props will appear together in the designer. Use the group property to group related props together.
Example: Complete component
Here’s how you might define props for a button component: