Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
fix(utils): Make themeGet curry (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylealwyn authored Mar 13, 2019
1 parent 045ae6a commit ac4a936
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Card/Card.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from 'styled-components';
import { themeGet } from 'styled-system';
import Box from '../Box';
import { createComponent } from '../utils';
import { themeGet, createComponent } from '../utils';

const StyledCard = createComponent({
name: 'Card',
Expand Down
7 changes: 3 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { get, kebabCase } from 'lodash';
import styled from 'styled-components';

export const themeGet = (theme, lookup, fallback) => get(theme, lookup, fallback);
export const themeGet = (lookup, fallback) => ({ theme } = {}) => get(theme, lookup, fallback);

export const getComponentVariant = (theme, componentName, variant) => {
const config = themeGet(
theme,
`components.${componentName}.variants.${variant}`,
theme.variants[componentName][variant]
);
)({ theme });
if (!config) throw new Error(`Molekule: "${variant}" variant not found in theme...`);
return config;
};

export const getComponentStyle = componentName => ({ theme }) => themeGet(theme, `components.${componentName}.style`);
export const getComponentStyle = componentName => themeGet(`components.${componentName}.style`);

export const getComponentClassName = ({ className, theme: { classPrefix }, variant }, name) =>
`${className || ''} ${classPrefix}-${name} ${variant ? `${classPrefix}-${name}-${variant}` : ''}`.trim();
Expand Down

0 comments on commit ac4a936

Please sign in to comment.