Skip to content

Instantly share code, notes, and snippets.

@neiljohnston
Created January 21, 2022 23:14
Show Gist options
  • Save neiljohnston/dd1842369e0b93b6d99c31d0ad7e9d47 to your computer and use it in GitHub Desktop.
Save neiljohnston/dd1842369e0b93b6d99c31d0ad7e9d47 to your computer and use it in GitHub Desktop.
Simple Inclusion of CSS in Framer via a Code Component
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