Last active
December 8, 2021 05:51
-
-
Save carl0zen/7704cce24edba0520eb6b36d894f04ae to your computer and use it in GitHub Desktop.
Styled Components Mixin example
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
// Mixin like functionality | |
const textInput = props => ` | |
color: ${props.error ? color.white : color.base}; | |
background-color: ${props.error ? color.alert : color.white}; | |
`; | |
export const Input = styled.input` | |
${textInput} | |
`; | |
export const Textarea = styled.textarea` | |
${textInput}; | |
height: ${props => props.height ? props.height : '130px'} | |
resize: none; | |
overflow: auto; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just to add my 2 cents, you can re-use mixins for different pseudo classes or elements.
Here is an example mixin:
And you can use it like such:
Note that I was able to reuse the mixin for the hover state.
That button component could then be used like this: