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
- Link - URL input with validation
Assets and data
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 declaration file:
- Imports the
PropType
andPropValues
types from the@webflow/data-types
package. - Defines a link prop for the
Button
component. This will provide a link picker in Webflow and return thehref
andtarget
values. - Adjusts the TypeScript types of the
Button
component to include thelink
object returned from theprops.Link
prop type. - Wraps the
Button
component in a new component that gets thehref
andtarget
values from thelink
object and passes them to theButton
component 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: