# All files / extensions themeGet.js

80% Statements 4/5
50% Branches 1/2
100% Functions 2/2
80% Lines 4/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    2070x
    17x
    17x
    17x

     import { get } from 'lodash';
    import { NAMESPACE } from '../theme';

    /**
     * Creates a getter which will retrieve the specified value from
     * a provided object which contains a `theme`. Use this to create
     * a function to pass to a styled component to select a theme value.
     *
     * Example usage:
     *
     * styled.div`
     *   color: ${themeGet('colors.primary.default')};
     * `;
     */
    export default key => props => {
      const result = get(props, `theme.${NAMESPACE}.${key}`);
      Eif (!result) {
        throw new Error(`Could not find value for theme style getter ${key}!`);
      }
      return result;
    };