Created
October 3, 2025 00:25
-
-
Save jonathanstanley/6050580bed595d6022e44d3d8c478a5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { addPropertyControls, ControlType, FrameProps } from "framer" | |
| import { cloneElement, isValidElement } from "react" | |
| export default function CustomElement(props: FrameProps) { | |
| const { style, id, children } = props | |
| const childToRender = isValidElement(children) | |
| ? children | |
| : isValidElement(children?.[0]) | |
| ? children[0] | |
| : null | |
| return ( | |
| <div style={style} id={id}> | |
| {childToRender ? ( | |
| cloneElement(childToRender, { | |
| ...childToRender.props, | |
| style: { | |
| ...(childToRender.props.style ?? {}), | |
| width: style?.width ?? "100%", | |
| height: style?.height ?? "100%", | |
| }, | |
| }) | |
| ) : ( | |
| <span style={{ color: "red", fontSize: "12px" }}> | |
| Please connect to a frame from off the canvas | |
| </span> | |
| )} | |
| </div> | |
| ) | |
| } | |
| addPropertyControls(CustomElement, { | |
| children: { | |
| title: "Frame", | |
| type: ControlType.ComponentInstance, | |
| }, | |
| id: { | |
| type: ControlType.String, | |
| title: "ID", | |
| description: "HTML id", | |
| placeholder: "example-element-id", | |
| }, | |
| }) | |
| {childToRender ? ( | |
| cloneElement(childToRender, { | |
| ...childToRender.props, | |
| style: { | |
| ...(childToRender.props.style ?? {}), | |
| width: style?.width ?? "100%", | |
| height: style?.height ?? "100%", | |
| }, | |
| }) | |
| ) : ( | |
| <span style={{ color: "red", fontSize: "12px" }}> | |
| Please connect to a frame from off the canvas | |
| </span> | |
| )} | |
| </div> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this experiment to familiarize myself with Framer's Custom Code Component. Although this "works", it probably isn't useful on its own. It does highlight some of the limitations with Framer.
fill). But, since we're treating it as a child, this is an example a way to override the sizing so that the child receives the same size as this custom component. However, the recommended approach isRenderTargetdata-framer-nameproperty. here is what you can expect to find in the framer rendered HTML:If anyone does find this helpful, or has thoughts to add, please let me know!