Created
January 21, 2022 23:14
-
-
Save neiljohnston/dd1842369e0b93b6d99c31d0ad7e9d47 to your computer and use it in GitHub Desktop.
Simple Inclusion of CSS in Framer via a Code Component
This file contains 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 } from "framer" | |
import { motion } from "framer-motion" | |
// Learn more: https://www.framer.com/docs/guides/code-components/ | |
async function importStylesheets(id, css) { | |
let styleElement = document.createElement("style") | |
styleElement.id = "customStyleSheet" | |
styleElement.innerHTML = String.raw`${css}` | |
document.head.appendChild(styleElement) | |
console.log(styleElement) | |
} | |
export default function SimpleFramerCSS(props) { | |
const { css, style } = props | |
const id = `${props.id}_styleSheet` | |
console.log(props) | |
if (!document.getElementById(id)) { | |
importStylesheets(id, css) | |
console.log("Stylesheets loaded") | |
} else { | |
console.log("Stylesheets already loaded") | |
} | |
// "...style" enables switching between auto & fixed sizing | |
// Learn more: https://www.framer.com/docs/guides/auto-sizing | |
return ( | |
<motion.div style={{ ...style, ...containerStyle }}>{css}</motion.div> | |
) | |
} | |
SimpleFramerCSS.defaultProps = { | |
css: `* { | |
border: 1px solid green !important; | |
}`, | |
} | |
// Learn More: https://www.framer.com/docs/property-controls/ | |
addPropertyControls(SimpleFramerCSS, { | |
css: { | |
title: "Text", | |
type: ControlType.String, | |
displayTextArea: true, | |
}, | |
}) | |
const containerStyle = { | |
display: "flex", | |
justifyContent: "center", | |
alignItems: "center", | |
overflow: "hidden", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment