Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created March 30, 2019 05:29
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 whoisryosuke/7142b4252f1e48e577fa82b9f8855c7c to your computer and use it in GitHub Desktop.
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)
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