Property Controls
Property Controls allow users to pass properties (or props) to a code component through the Framer interface. When a user selects a code component on the canvas, its Property Controls are visible on the properties panel. As a component author, it’s up to you to decide which Property Controls to add and what options they should present to the user.
Adding Controls
To give your component Property Controls, import both the addPropertyControls
function and the ControlType
type from the framer
library.
Below your component, call the addPropertyControls
function with two arguments: first, the name of your component; and second, an object that defines controls for different properties. You have several types of controls to choose from, each of which are documented on this page.
Property Controls only affect components on the canvas. For this reason, you'll still want to use defaultProps
for your component’s props, both to prevent errors as you code the component and when a designer creates an instance of your component from code.
In this example, we’re adding a Property Control for our component’s text
prop. On the canvas, selecting the component will now display a control that allows us to set this property.
Hiding Controls
Controls can be hidden by adding the hidden
function to the property description. The function receives an object containing the set properties and returns a boolean
. In this example, we hide the text
property entirely when the connected property (the toggle
) is false
. Now you can toggle the visibility of the text property control by changing the toggle
boolean from within the property panel in Framer.
Adding Descriptions
Controls can have a description
property to add documentation about the control in the Framer UI—it appears in the Properties panel just above the control. It also supports adding emphasis and links using Markdown syntax. To add line breaks, use the newline character “\n
”.
Controls
Array ControlType.Array
A control that allows multiple values per ControlType
, provided as an array via properties. For most control types this will be displayed as an additional section in the properties panel allowing as many fields to be provided as required.
For a ControlType.ComponentInstance the component will also gain an additional outlet control on the Canvas that allows links to be created between frames.
Group properties together by using an object control.
Boolean ControlType.Boolean
A control that displays an on / off checkbox. The associated property will be true
or false
, depending on the state of the checkbox. Includes an optional defaultValue
, which is set to true
by default.
Color ControlType.Color
A control that represents a color value. It will be included in the component props as a string.
This control is displayed as a color field and will provide the selected color in either RGB (rgb(255, 255, 255)
) or RGBA (rgba(255, 255, 255, 0.5)
notation, depending on whether there is an alpha channel.
You can also make the color optional by adding the optional property.
ComponentInstance ControlType.ComponentInstance
A control that references to another component on the canvas, included in the component props as a React node. The component will have an outlet to allow linking to other Frames. Available Frames will also be displayed in a dropdown menu in the properties panel. The component reference will be provided as a property. As a convention, the name for the property is usually just children
.
Multiple components can be linked by combining the ComponentInstance
type with the ControlType.Array
.
Date ControlType.Date
A property control that represents a date. The date will be passed in as an ISO 8601 formatted string.
Enum ControlType.Enum
A property control that represents a list of options. The list contains primitive values and each value has to be unique. The selected option will be provided as a property. This control is displayed as a dropdown menu in which a user can select one of the items. displaySegmentedControl
can be enabled to display a segmented control instead.
Note: ControlType.SegmentedEnum
is deprecated, please use ControlType.Enum
and enable displaySegmentedControl
.
EventHandler ControlType.EventHandler
A control that exposes events in the Interactions section of the Properties Panel when used within Smart Components.When selection Interactions such as “New Transition”, you can select which event to listen to.
File ControlType.File
A control that allows the user to pick a file resource. It will be included in the component props as a URL string. Displayed as a file picker that will open a native file browser. The selected file will be provided as a fully qualified URL. The allowedFileTypes
property must be provided to specify acceptable file types.
ResponsiveImage ControlType.ResponsiveImage
A control that allows the user to pick an image resource. Displayed as an image picker with associated file picker.
The chosen image will be provided in the component props as an object with src
and srcSet
properties:
src
: a string containing the URL of a full resolution imagesrcSet
: an optional string with scaled down image variants. This is typically passed into<img srcSet />
and helps the browser to load a smaller image when a full-size one isn’t necessary.alt
: an optional description of the image.
Note: ControlType.Image
is deprecated, please use ControlType.ResponsiveImage
Number ControlType.Number
A control that accepts any numeric value. This will be provided directly as a property. Will display an input field with a range slider by default. The displayStepper
option can be enabled to include a stepper control instead.
Object ControlType.Object
A control that allows for grouping multiple properties as an object.
You can make the object removable by adding the optional property. To replace the default button title, use the buttonTitle
property. To change the default icon, use the icon
property.
String ControlType.String
A control that accepts plain text values. This will be provided directly as a property. Will display an input field with an optional placeholder value.
If obscured
attribute is set to true a password input field will be used instead of a regular text input so that the value in the input will be visually obscured, yet still be available as plain text inside the component. displayTextArea
can be enabled to display a multi-line input area instead. maxLength
can be set to limit the maximum number of characters that can be entered in the input field.
Transition ControlType.Transition
A control that allows for editing Framer Motion transition options within the Framer UI.
Link ControlType.Link
A control that allows for exposing web links.
Padding ControlType.Padding
A control that represents CSS padding. Will display an input field to accept a single value, alongside a segmented control allowing four distinct values to be provided.
Includes an optional defaultValue
that can be set with single value (e.g. "10px"
or "10px 20px 30px 40px"
).
Note: FusedNumber
is deprecated, please use ControlType.Padding
and ControlType.BorderRadius
BorderRadius ControlType.BorderRadius
A control that represents CSS border radius. Will display an input field to accept a single value, alongside a segmented control allowing four distinct values to be provided.
Includes an optional defaultValue
that can be set with single value (e.g. "10px"
or "10px 20px 30px 40px"
).
Note: FusedNumber
is deprecated, please use ControlType.Padding
and ControlType.BorderRadius
Border ControlType.Border
A control that represents a border style. Either borderWidth
or the equivalent per-side values (e.g borderTopWidth
, borderLeftWidth
, borderRightWidth
, borderBottomWidth
) will be provided.
You can also set the default value for each side.
BoxShadow ControlType.BoxShadow
A control that allows for exposing shadows. The value will be provided as a string with valid CSS box-shadow values.