Last active
September 2, 2020 10:24
-
-
Save carl0zen/bcb7d275546ab344805a032e9d659bbc to your computer and use it in GitHub Desktop.
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
// Prop passing Shorthands for Styled-components | |
export const borderProps = props => css` | |
${props.borderBottom && `border-bottom: ${props.borderWidth || "1px"} solid ${color.border}`}; | |
${props.borderTop && `border-top: ${props.borderWidth || "1px"} solid ${color.border}`}; | |
${props.borderLeft && `border-left: ${props.borderWidth || "1px"} solid ${color.border}`}; | |
${props.borderRight && `border-right: ${props.borderWidth || "1px"} solid ${color.border}`}; | |
`; | |
export const marginProps = props => css` | |
${props.marginBottom && `margin-bottom: ${typeof (props.marginBottom) === "string" ? props.marginBottom : "1em"}`}; | |
${props.marginTop && `margin-top: ${typeof (props.marginTop) === "string" ? props.marginTop : "1em"}`}; | |
${props.marginLeft && `margin-left: ${typeof (props.marginLeft) === "string" ? props.marginLeft : "1em"}`}; | |
${props.marginRight && `margin-right: ${typeof (props.marginRight) === "string" ? props.marginRight : "1em"}`}; | |
${props.margin && `margin: ${typeof (props.margin) === "string" ? props.margin : "1em"}`}; | |
${props.marginVertical && ` | |
margin-top: ${typeof (props.marginVertical) === "string" ? props.marginVertical : "1em"} | |
margin-bottom: ${typeof (props.marginVertical) === "string" ? props.marginVertical : "1em"} | |
`}; | |
${props.marginHorizontal && ` | |
margin-left: ${typeof (props.marginHorizontal) === "string" ? props.marginHorizontal : "1em"} | |
margin-right: ${typeof (props.marginHorizontal) === "string" ? props.marginHorizontal : "1em"} | |
`}; | |
`; | |
// An example of how you can use it with your components | |
const SomeDiv = styled.div` | |
${borderProps} | |
${marginProps} | |
` | |
// This lets you pass all borderProps to the component like so: | |
<SomeDiv borderTop borderBottom borderLeft borderRight marginVertical> |
Hey Joezimjs, the css template function is coming from styled-components.
import { css } from 'styled-components';
styled-components/styled-components#390
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same question as Joe. How are you specifying the size of the border. I know there is a default set, but how would u specify a specific amount. Thanks.