Skip to content

Instantly share code, notes, and snippets.

@simonfranzen
Last active May 6, 2021 10:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simonfranzen/f46ff1a8b24356f6729d11a6ca8b968b to your computer and use it in GitHub Desktop.
Save simonfranzen/f46ff1a8b24356f6729d11a6ca8b968b to your computer and use it in GitHub Desktop.
FramerX Styled Component Example Button
import * as React from "react"
import { PropertyControls, ControlType } from "framer"
import styled, { css } from "styled-components"
const StyledButton = styled.button`
padding: 20px;
border-radius: 10px;
border: 0;
font-size: 2em;
${props => props.type == 'primary' && css`
color: white;
background-color: green;
`}
${props => props.type == 'secondary' && css`
color: white;
background-color: blue;
`}
`
// Define type of property
interface Props {
text: string;
type: string;
}
export class Button extends React.Component<Props> {
// Set default properties
static defaultProps = {
text: "Hello World!",
type: "primary",
}
// Items shown in property panel
static propertyControls: PropertyControls = {
text: {
type: ControlType.String,
title: "Text"
},
type: {
type: ControlType.Enum,
title: "Type",
options: ['primary', 'secondary'],
optionTitles: ['Primary Button', 'Secondary Button']
},
}
render() {
return (
<StyledButton type={this.props.type}>
{this.props.text}
</StyledButton>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment