Skip to content

Commit

Permalink
Merge pull request #427 from styled-system/fix-space-proptypes
Browse files Browse the repository at this point in the history
Copy properties of function argument in mapProps - fixes #416
  • Loading branch information
jxnblk committed Mar 15, 2019
2 parents 50abee0 + 1c5c114 commit b76c4e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export const compose = (...funcs) => {
return func
}

export const mapProps = mapper => func => props => func(mapper(props))
export const mapProps = mapper => func => {
const next = props => func(mapper(props))
for (const key in func) {
next[key] = func[key]
}
return next
}

export const variant = ({ key, prop = 'variant' }) => {
const fn = props => get(props.theme, [key, props[prop]].join('.'), null)
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
compose,
variant,
cloneFunction,
mapProps,
} from '../src'

const width = style({
Expand Down Expand Up @@ -270,3 +271,9 @@ test('array values longer than breakpoints does not reset returned style object'
{ width: '100%' },
])
})

test('mapProps copies propTypes', t => {
const margin = style({ prop: 'margin' })
const func = mapProps(props => props)(margin)
t.is(typeof func.propTypes, 'object')
})
6 changes: 6 additions & 0 deletions test/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ test('margin overrides m prop', t => {
t.deepEqual(styles, [{ margin: '8px' }])
})

test('space includes propTypes', t => {
const { propTypes } = space
t.is(typeof propTypes, 'object')
t.is(typeof propTypes.m, 'function')
})

test('size returns width and height', t => {
const styles = size({
size: 4,
Expand Down

0 comments on commit b76c4e2

Please sign in to comment.