Created
March 30, 2019 05:29
-
-
Save whoisryosuke/7142b4252f1e48e577fa82b9f8855c7c to your computer and use it in GitHub Desktop.
Styled Components / JS Design System - Using functional programming and a color library to generate CSS colors for states (hover, active, focus)
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 React from "react" | |
import Color from "tinycolor2"; | |
import styled from "styled-components" | |
const colors = { | |
fullBlack: "#000000", | |
white: "#FFFFFF", | |
red: "#DB2828", | |
orange: "#F2711C", | |
} | |
const hoverColors = (color = primary) => Color(colors[color]) | |
.darken(10) | |
.saturate(10) | |
.toHexString() | |
const focusColors = (color = primary) => Color(colors[color]) | |
.darken(20) | |
.saturate(20) | |
.toHexString() | |
const downColors = (color = primary) => Color(colors[color]) | |
.darken(30) | |
.toHexString() | |
const activeColors = (color = primary) => Color(colors[color]) | |
.lighten(10) | |
.saturate(20) | |
.toHexString() | |
const coloredButton = ({theme, bg}) => css` | |
background-color: ${theme.colors[bg]}; | |
color: ${theme.colors.white}; | |
text-shadow: @redTextShadow; | |
background-image: ${buttonTheme.coloredBackgroundImage}; | |
box-shadow: ${buttonTheme.coloredBoxShadow}; | |
&:hover { | |
background-color: ${theme.hoverColors(bg)}; | |
color: ${theme.colors.white}; | |
text-shadow: @redTextShadow; | |
} | |
` | |
const StyledButton = styled(Button)` | |
// Colors | |
${props => props.bg && coloredButton(props)} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment