-
Notifications
You must be signed in to change notification settings - Fork 0
/
prop-type.js
50 lines (44 loc) · 998 Bytes
/
prop-type.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const PropTypes = require('prop-types')
var valuePropType = PropTypes.oneOfType([
PropTypes.bool,
PropTypes.string,
PropTypes.number
])
var propType = PropTypes.oneOfType([
valuePropType,
PropTypes.arrayOf(valuePropType),
PropTypes.objectOf(valuePropType)
])
/**
* Return prop types for styles created with `pss`.
*
* Must have [prop-types](https://www.npmjs.com/package/prop-types) installed in project.
*
* @example
* import { sizes } from 'pss'
* import { getPropTypes } from 'pss/prop-types'
*
* cont Box = styled('div')`
* ${sizes}
* `
*
* Box.propTypes = {
* ...getPropTypes(sizes)
* }
*/
function getPropTypes (input) {
if (!Array.isArray(input.props)) {
console.warn('First argument must be function with `.props` static property')
return
}
return input.props.reduce(
function propsListToPropTypes (acc, name) {
return Object.assign(acc, { [name]: propType })
},
{}
)
}
module.exports = {
propType,
getPropTypes
}