Skip to content

Instantly share code, notes, and snippets.

@d4rekanguok
Last active January 9, 2019 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4rekanguok/f51c07ae6c165b6f3f061542345d3c1f to your computer and use it in GitHub Desktop.
Save d4rekanguok/f51c07ae6c165b6f3f061542345d3c1f to your computer and use it in GitHub Desktop.
Take advantage of CSS's cascading to write manageable css-in-js
const Button = styled<IStyle, 'button'>('button')`
display: inline-block;
vertical-align: middle;
padding: 0.5em 1em;
font-size: ${getFontSize};
font-weight: bold;
font-weight: ${getFontWeightFromSize};
text-align: center;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
line-height: 1;
color: #fff;
background: ${getColor('main')};
border-radius: 490px;
border-width: 0;
border-style: solid;
border-color: ${getColor('main')};
box-sizing: border-box;
& + & {
margin-left: 1em;
}
&:hover,
&:focus {
transform: translateY(-1px);
background: ${getColor('lighter')};
box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.4);
}
&:focus {
outline: 2px dotted rgba(255, 255, 255, 0.4);
}
&:active {
transform: translateY(0);
}
${({ icon }) =>
icon && `
padding: 0.5em;
line-height: 0;
`}
${({ square, theme }) =>
square && `
border-radius: ${theme.borderRadius};
`}
${({ theme, outline, size }) =>
outline && `
border-width: ${theme.borderWidth[size]};
background: transparent;
&:hover, &:focus {
background: rgba(255,255,255,0.12);
}
`}
${({ color }) =>
color === 'link' && `
&:hover, &:focus {
box-shadow: transparent;
}
`}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment