This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
combinationsModifier.story.js
78 lines (65 loc) · 1.6 KB
/
combinationsModifier.story.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import pt from 'prop-types';
import { storiesOf } from '@storybook/react';
import withPropsCombinations, { withOneOfBool } from '../src';
// A primitive implementation for the sake of brevity.
// You should probably use one from your favorite functional library instead
const compose = (...fns) => (x) => fns.reduceRight((res, f) => f(res), x)
class FancyThing extends React.Component {
static propTypes = {
red: pt.bool,
green: pt.bool,
blue: pt.bool,
big: pt.bool,
small: pt.bool,
}
getColor() {
const { red, green, blue } = this.props;
if (red) return 'red';
if (green) return 'green';
if (blue) return 'blue';
return 'black';
}
getPadding() {
const { big, small } = this.props;
if (big) return 25;
if (small) return 7;
return 15;
}
render () {
const color = this.getColor();
const style = {
display: 'inline-block',
color,
padding: this.getPadding(),
border: `2px solid ${color}`,
}
return (
<div style={style}>
{ this.props.children }
</div>
)
}
}
storiesOf('combinationsModifier example', module)
.add('one modifier', withPropsCombinations(
FancyThing,
{
children: ['Look at me!'],
},
{
combinationsModifier: withOneOfBool(['red', 'green', 'blue']),
}
))
.add('modifiers composition', withPropsCombinations(
FancyThing,
{
children: ['Look at me!'],
},
{
combinationsModifier: compose(
withOneOfBool(['red', 'green', 'blue']),
withOneOfBool(['big', 'small'])
),
}
))