Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
add support for prop value in mapToTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartinsky committed May 9, 2019
1 parent 6274cbe commit 5b2cca7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const _dotProp = (string, object) => string
.split('.')
.reduce((acc, key) => acc[key], object);

export const mapToTheme = (key) =>
(props) => styledMap(_dotProp(key, props.theme));
export const mapToTheme = (key, prop) =>
(props) => prop ? styledMap(prop, _dotProp(key, props.theme)) : styledMap(_dotProp(key, props.theme));

export default styledMap;
6 changes: 6 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ describe('mapToTheme', () => {
});
expect(result).toEqual(_dotProp('button.foreground.primary', nestedTheme));
});
it('uses the prop value when passed a second argument', () => {
const result = mapToTheme('buttonColor', 'kind')({theme})({
kind: 'other'
});
expect(result).toEqual('#aab');
})
});

describe('_convertToObject', () => {
Expand Down

0 comments on commit 5b2cca7

Please sign in to comment.