Last active
September 2, 2020 10:24
-
-
Save carl0zen/2e898cc74dcd51f9e4da2602566cf41f to your computer and use it in GitHub Desktop.
Styled Components layout example
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 styled from "styled-components"; | |
import { | |
theme, | |
borderProps, | |
sizeProps, | |
backgroundColorProps, | |
marginProps | |
} from "ui"; | |
const { color, font, topbar, gutter } = theme; | |
export const Panel = styled.article` | |
${marginProps} | |
padding: 1em; | |
background: white; | |
color: ${color.black}; | |
font-size: ${font.base}; | |
font-weight: 300; | |
${props => !props.noborder && `border: 1px solid ${color.border}`}; | |
width: ${props => props.width ? props.width : "100%"}; | |
${props => borderProps(props)} | |
transition: | |
transform 300ms ease-in-out, | |
box-shadow 300ms ease-in-out, | |
margin 300ms ease-in-out; | |
box-shadow: 0 3px 3px rgba(0,0,0,0.1); | |
${props => props.dark && ` | |
color: ${color.white}; | |
background-color: ${color.black}; | |
`} | |
&:hover { | |
transform: translateY(-5px); | |
box-shadow: 0 6px 3px rgba(0,0,0,0.1); | |
} | |
`; | |
export const ScrollView = styled.section` | |
overflow: hidden; | |
font-family: ${font.family}; | |
-webkit-overflow-scrolling: touch; | |
overflow-y: auto; | |
${props => props.horizontal && ` | |
white-space: nowrap; | |
overflow-x: auto; | |
overflow-y: hidden; | |
` | |
} | |
${props => sizeProps(props)} | |
`; | |
export const MainContent = styled(ScrollView)` | |
position: absolute; | |
top: ${props => props.topbar ? topbar.height : 0}; | |
right: 0; | |
left: 0; | |
bottom: 0; | |
font-size: ${font.base}; | |
padding: ${gutter} 3em; | |
${props => props.bg && ` | |
background-color: ${props.bg}; | |
`} | |
`; | |
export const Slide = styled.section` | |
${backgroundColorProps} | |
font-weight: 400; | |
flex: 1; | |
height: ${props => props.height ? props.height : "100%"}; | |
width: ${props => props.width ? props.width : "100%"}; | |
justify-content: center; | |
flex-direction: column; | |
align-items: center; | |
text-align: center; | |
display: flex; | |
font-size: 3em; | |
color: ${color.white}; | |
`; | |
export const App = styled.div` | |
*, & { | |
box-sizing: border-box; | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment