Reads a component’s propTypes to return an array of permutations that can be used to show component variations.
Given a Button component with propTypes defined, the module returns {permutations.length} permutations for showing variations.
By configuring options for the colors prop, there are now {permutationsColors.length} permutations.
Reads a component’s propTypes to return an array of permutations that can be used to show component variations.
Given a Button component with propTypes defined, the module returns 8 permutations for showing variations.
import React from 'react'
2 | import colors from 'colors.css'
3 |
4 | const colorKeys = Object.keys(colors)
5 |
6 | const Button = ({ big, color, pill, outline, ...props }) => (
7 | <button
8 | style={{
9 | fontFamily: 'inherit',
10 | fontSize: 'inherit',
11 | display: 'inline-block',
12 | padding: big ? 16 : 12,
13 | border: 0,
14 | borderRadius: pill ? 9999 : 2,
15 | color: outline ? colors[color] : 'white',
16 | backgroundColor: outline ? 'transparent' : colors[color],
17 | boxShadow: outline ? 'inset 0 0 0 2px' : null
18 | }}
19 | {...props} />
20 | )
21 |
22 | Button.propTypes = {
23 | big: React.PropTypes.bool,
24 | color: React.PropTypes.oneOf(colorKeys),
25 | pill: React.PropTypes.bool,
26 | outline: React.PropTypes.bool
27 | }
28 |
29 | Button.defaultProps = {
30 | color: 'blue'
31 | }
32 |
33 | export default Button
34 | permutations(buttonSourceString)
By configuring options for the colors prop, there are now 128 permutations.
permutations(buttonSourceString, { colors: colorKeys })