Created
January 9, 2020 04:05
-
-
Save szy0syz/2604af964f8743270057a8496aca677b to your computer and use it in GitHub Desktop.
Reusing CSS With Styled Components
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 styled, { css } from ‘styled-components’; | |
export const DefaultInput = styled.input` | |
border: 1px solid ${({error})=>( error ? `red` : `grey` )}; | |
border-radius: 4px; | |
outline: none; | |
padding: 0.5em; | |
`; | |
export const SecondComponent = styled(DefaultInput)` | |
/* make changes as needed*/ | |
`; | |
const baseInputStyles = css` | |
border: 1px solid ${({error})=>( error ? `red` : `grey` )}; | |
border-radius: 4px; | |
outline: none; | |
padding: 0.5em; | |
`; | |
export const DefaultInput = styled.input` | |
${baseInputStyles} | |
`; | |
export const SecondComponent = styled.button` | |
${baseInputStyles} | |
/* make changes as needed*/ | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment