diff --git a/package.json b/package.json index c33a4003..0b1dc87b 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "webpack-dev-server": "^1.16.2" }, "dependencies": { + "arc-theme": "^0.2.1", "history": "3.0.0", "lodash": "^4.16.4", "react": "^15.3.2", @@ -63,6 +64,6 @@ "react-modal": "^1.6.4", "react-router": "^3.0.0", "react-router-scroll": "^0.4.1", - "styled-components": "1.1.1" + "styled-components": "^1.2.1" } } diff --git a/src-clean/components/globals.js b/src-clean/components/globals.js deleted file mode 100644 index 6214251b..00000000 --- a/src-clean/components/globals.js +++ /dev/null @@ -1,20 +0,0 @@ -export const colors = { - primary: ['#1976d2', '#2196f3', '#71bcf7', '#c2e2fb'], - secondary: ['#c2185b', '#e91e63', '#f06292', '#f8bbd0'], - danger: ['#d32f2f', '#f44336', '#f8877f', '#ffcdd2'], - alert: ['#ffa000', '#ffc107', '#ffd761', '#ffecb3'], - success: ['#388e3c', '#4caf50', '#7cc47f', '#c8e6c9'], - grayscale: ['#212121', '#616161', '#9e9e9e', '#bdbdbd', '#e0e0e0', '#eeeeee', '#ffffff'] -} - -export const reverseColors = {} - -Object.keys(colors).forEach((key) => { - reverseColors[key] = [ ...colors[key] ].reverse() -}) - -export const fonts = { - primary: 'Helvetica Neue, Helvetica, Roboto, sans-serif', - pre: 'Consolas, Liberation Mono, Menlo, Courier, monospace', - quote: 'Georgia, serif' -} diff --git a/src/components/App.js b/src/components/App.js index 47b1d977..0e338016 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,7 +1,7 @@ import React, { PropTypes, Component } from 'react' import { injectGlobal, ThemeProvider } from 'styled-components' -import theme from './theme' +import theme from './themes/default' injectGlobal` body { diff --git a/src/components/atoms/Atom/index.js b/src/components/atoms/Atom/index.js index 0c020662..37900f6c 100644 --- a/src/components/atoms/Atom/index.js +++ b/src/components/atoms/Atom/index.js @@ -1,14 +1,10 @@ import { PropTypes } from 'react' import styled from 'styled-components' - -export const fontFamily = ({ theme }) => theme.fonts.primary - -export const color = ({ theme, reverse, color }) => - theme[reverse ? 'reverseColors' : 'colors'][color][color === 'grayscale' ? 0 : 1] +import { font, color } from 'arc-theme' const Atom = styled.span` - font-family: ${fontFamily}; - color: ${color}; + font-family: ${font('primary')}; + color: ${color({ grayscale: 0 }, 1)}; ` Atom.propTypes = { @@ -17,18 +13,7 @@ Atom.propTypes = { } Atom.defaultProps = { - color: 'grayscale', - theme: { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222' } - }, - reverseColors: { - grayscale: { 0: '#fff' } - } - } + color: 'grayscale' } export default Atom diff --git a/src/components/atoms/Atom/index.test.js b/src/components/atoms/Atom/index.test.js index 6352ec98..ca02bd9c 100644 --- a/src/components/atoms/Atom/index.test.js +++ b/src/components/atoms/Atom/index.test.js @@ -1,6 +1,6 @@ import React from 'react' import { shallow } from 'enzyme' -import Atom, * as styles from '.' +import Atom from '.' const wrap = (props = {}) => shallow() @@ -13,34 +13,3 @@ it('renders props when passed in', () => { const wrapper = wrap({ id: 'foo' }) expect(wrapper.find({ id: 'foo' })).toHaveLength(1) }) - -describe('styles', () => { - const theme = { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222' }, - primary: { 1: 'red' } - }, - reverseColors: { - grayscale: { 0: '#fff' }, - primary: { 1: 'blue' } - } - } - - test('fontFamily', () => { - expect(styles.fontFamily({ theme })).toBe(theme.fonts.primary) - }) - - test('color', () => { - const props = { - color: 'grayscale', - reverse: false, - theme - } - expect(styles.color(props)).toBe(theme.colors.grayscale[0]) - expect(styles.color({ ...props, reverse: true })).toBe(theme.reverseColors.grayscale[0]) - expect(styles.color({ ...props, color: 'primary' })).toBe(theme.colors.primary[1]) - }) -}) diff --git a/src/components/atoms/Badge/index.js b/src/components/atoms/Badge/index.js index 6a18ee68..8bf10e90 100644 --- a/src/components/atoms/Badge/index.js +++ b/src/components/atoms/Badge/index.js @@ -1,21 +1,14 @@ import { PropTypes } from 'react' import styled from 'styled-components' - -export const fontFamily = ({ theme }) => theme.fonts.primary - -export const color = ({ reverse, theme }) => - reverse ? theme.colors.grayscale[0] : theme.reverseColors.grayscale[0] - -export const backgroundColor = ({ reverse, theme, color }) => - theme[reverse ? 'reverseColors' : 'colors'][color][1] +import { font, color, reverseColor } from 'arc-theme' const Badge = styled.span` - font-family: ${fontFamily}; + font-family: ${font('primary')}; font-size: 0.75rem; line-height: 1.5em; padding: 0 0.3em; - color: ${color}; - background-color: ${backgroundColor}; + color: ${reverseColor('grayscale', 0)}; + background-color: ${color(1)}; border-radius: 0.16667em; ` @@ -25,20 +18,7 @@ Badge.propTypes = { } Badge.defaultProps = { - color: 'primary', - theme: { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222', 1: '#555' }, - primary: { 1: '#2196f3' } - }, - reverseColors: { - grayscale: { 0: '#fff', 1: '#bbb' }, - primary: { 1: '#71bcf7' } - } - } + color: 'primary' } export default Badge diff --git a/src/components/atoms/Badge/index.test.js b/src/components/atoms/Badge/index.test.js index f9383d84..0fb7062e 100644 --- a/src/components/atoms/Badge/index.test.js +++ b/src/components/atoms/Badge/index.test.js @@ -1,6 +1,6 @@ import React from 'react' import { shallow } from 'enzyme' -import Badge, * as styles from '.' +import Badge from '.' const wrap = (props = {}) => shallow() @@ -13,38 +13,3 @@ it('renders props when passed in', () => { const wrapper = wrap({ id: 'foo' }) expect(wrapper.find({ id: 'foo' })).toHaveLength(1) }) - -describe('styles', () => { - const theme = { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222', 1: '#555' }, - primary: { 1: '#2196f3' } - }, - reverseColors: { - grayscale: { 0: '#fff', 1: '#bbb' }, - primary: { 1: '#71bcf7' } - } - } - - test('fontFamily', () => { - expect(styles.fontFamily({ theme })).toBe(theme.fonts.primary) - }) - - test('color', () => { - expect(styles.color({ theme, reverse: false })).toBe(theme.reverseColors.grayscale[0]) - expect(styles.color({ theme, reverse: true })).toBe(theme.colors.grayscale[0]) - }) - - test('backgroundColor', () => { - const props = { - color: 'primary', - reverse: false, - theme - } - expect(styles.backgroundColor(props)).toBe(theme.colors.primary[1]) - expect(styles.backgroundColor({ ...props, reverse: true })).toBe(theme.reverseColors.primary[1]) - }) -}) diff --git a/src/components/atoms/Block/index.js b/src/components/atoms/Block/index.js index 216fb697..b7475c22 100644 --- a/src/components/atoms/Block/index.js +++ b/src/components/atoms/Block/index.js @@ -1,18 +1,11 @@ import { PropTypes } from 'react' import styled from 'styled-components' - -export const fontFamily = ({ theme }) => theme.fonts.primary - -export const backgroundColor = ({ theme, reverse, color, transparent }) => - transparent ? 'transparent' : theme[reverse ? 'colors' : 'reverseColors'][color][0] - -export const color = ({ theme, reverse, color }) => - theme[reverse ? 'reverseColors' : 'colors'][color][color === 'grayscale' ? 0 : 1] +import { font, color, reverseColor, ifProps } from 'arc-theme' const Block = styled.div` - font-family: ${fontFamily}; - background-color: ${backgroundColor}; - color: ${color}; + font-family: ${font('primary')}; + background-color: ${ifProps('transparent', 'transparent', reverseColor(0))}; + color: ${color({ grayscale: 0 }, 1)}; ` Block.propTypes = { @@ -21,18 +14,7 @@ Block.propTypes = { } Block.defaultProps = { - color: 'grayscale', - theme: { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222' } - }, - reverseColors: { - grayscale: { 0: '#fff' } - } - } + color: 'grayscale' } export default Block diff --git a/src/components/atoms/Block/index.test.js b/src/components/atoms/Block/index.test.js index ff85b90c..f4d6bf36 100644 --- a/src/components/atoms/Block/index.test.js +++ b/src/components/atoms/Block/index.test.js @@ -1,6 +1,6 @@ import React from 'react' import { shallow } from 'enzyme' -import Block, * as styles from '.' +import Block from '.' const wrap = (props = {}) => shallow() @@ -13,47 +13,3 @@ it('renders props when passed in', () => { const wrapper = wrap({ id: 'foo' }) expect(wrapper.find({ id: 'foo' })).toHaveLength(1) }) - -describe('styles', () => { - const theme = { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222' }, - primary: { 0: 'darkred', 1: 'red' } - }, - reverseColors: { - grayscale: { 0: '#fff' }, - primary: { 0: 'lightblue', 1: 'blue' } - } - } - - test('fontFamily', () => { - expect(styles.fontFamily({ theme })).toBe(theme.fonts.primary) - }) - - test('backgroundColor', () => { - const props = { - color: 'grayscale', - reverse: false, - theme - } - expect(styles.backgroundColor(props)).toBe(theme.reverseColors.grayscale[0]) - expect(styles.backgroundColor({ ...props, transparent: true })).toBe('transparent') - expect(styles.backgroundColor({ ...props, reverse: true })).toBe(theme.colors.grayscale[0]) - expect(styles.backgroundColor({ ...props, color: 'primary' })) - .toBe(theme.reverseColors.primary[0]) - }) - - test('color', () => { - const props = { - color: 'grayscale', - reverse: false, - theme - } - expect(styles.color(props)).toBe(theme.colors.grayscale[0]) - expect(styles.color({ ...props, reverse: true })).toBe(theme.reverseColors.grayscale[0]) - expect(styles.color({ ...props, color: 'primary' })).toBe(theme.colors.primary[1]) - }) -}) diff --git a/src/components/atoms/Button/index.js b/src/components/atoms/Button/index.js index 4bd90bac..d764aa80 100644 --- a/src/components/atoms/Button/index.js +++ b/src/components/atoms/Button/index.js @@ -1,52 +1,42 @@ import React, { PropTypes } from 'react' import styled, { css } from 'styled-components' import { Link } from 'react-router' +import { font, color, reverseColor, ifProps } from 'arc-theme' -export const colorKind = ({ theme, reverse }) => theme[reverse ? 'reverseColors' : 'colors'] +const fontSize = ({ height }) => `${height / 40}rem` -export const fontFamily = ({ theme }) => theme.fonts.primary -export const fontSize = ({ height }) => `${height / 40}rem` -export const borderColor = ({ transparent }) => transparent ? 'currentcolor' : 'transparent' -export const cursor = ({ disabled }) => disabled ? 'default' : 'pointer' -export const pointerEvents = ({ disabled }) => disabled ? 'none' : 'auto' +const backgroundColor = ({ transparent, disabled }) => + transparent ? 'transparent' : color(disabled ? 2 : 1) -export const backgroundColor = ({ transparent, disabled, color, ...props }) => - transparent ? 'transparent' : colorKind(props)[color][disabled ? 2 : 1] +const foregroundColor = ({ transparent, disabled }) => + transparent ? color(disabled ? 2 : 1) : reverseColor('grayscale', 0) -export const color = ({ transparent, disabled, color, ...props, reverse }) => - transparent - ? colorKind(props)[color][disabled ? 2 : 1] - : colorKind({ ...props, reverse: !reverse }).grayscale[0] - -export const hoverBackgroundColor = ({ disabled, transparent, color, ...props }) => - !disabled && !transparent && colorKind(props)[color][0] - -export const hoverColor = ({ disabled, transparent, color, ...props }) => - !disabled && transparent && colorKind(props)[color][0] +const hoverBackgroundColor = ({ disabled, transparent }) => !disabled && !transparent && color(0) +const hoverForegroundColor = ({ disabled, transparent }) => !disabled && transparent && color(0) const styles = css` display: inline-flex; - font-family: ${fontFamily}; + font-family: ${font('primary')}; align-items: center; white-space: nowrap; font-size: ${fontSize}; - border: 0.0625em solid ${borderColor}; + border: 0.0625em solid ${ifProps('transparent', 'currentcolor', 'transparent')}; height: 2.5em; justify-content: center; text-decoration: none; - cursor: ${cursor}; + cursor: ${ifProps('disabled', 'default', 'pointer')}; appearance: none; padding: 0 1em; border-radius: 0.125em; box-sizing: border-box; - pointer-events: ${pointerEvents}; + pointer-events: ${ifProps('disabled', 'none', 'auto')}; transition: background-color 250ms ease-out, color 250ms ease-out, border-color 250ms ease-out; background-color: ${backgroundColor}; - color: ${color}; + color: ${foregroundColor}; &:hover, &:focus, &:active { background-color: ${hoverBackgroundColor}; - color: ${hoverColor}; + color: ${hoverForegroundColor}; } &:focus { @@ -83,20 +73,7 @@ Button.propTypes = { Button.defaultProps = { color: 'primary', type: 'button', - height: 40, - theme: { - fonts: { - primary: 'sans-serif' - }, - colors: { - grayscale: { 0: '#222', 1: '#555', 2: '#888' }, - primary: { 0: '#1976d2', 1: '#2196f3', 2: '#71bcf7' } - }, - reverseColors: { - grayscale: { 0: '#fff', 1: '#bbb', 2: '#888' }, - primary: { 0: '#c2e2fb', 1: '#71bcf7', 2: '#2196f3' } - } - } + height: 40 } export default Button diff --git a/src/components/atoms/Button/index.test.js b/src/components/atoms/Button/index.test.js index 17dd48b4..67ea7308 100644 --- a/src/components/atoms/Button/index.test.js +++ b/src/components/atoms/Button/index.test.js @@ -1,9 +1,15 @@ import React from 'react' import { shallow } from 'enzyme' -import Button, * as styles from '.' +import Button from '.' const wrap = (props = {}) => shallow(