-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathhocPattern.js
93 lines (84 loc) · 2.37 KB
/
hocPattern.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import { storiesOf } from '@storybook/react';
const SeeHOCComponent = `
\`\`\`javascript
export const withHOC = options => WrappedComponent => {
const Enhanced = props => {
return <WrappedComponent {...props} />;
};
Enhanced.defaultProps = {
name: 'Enhanced Component',
whatever: 'Whatever string here',
};
Enhanced.propTypes = {
/**
* Name of this Component
*/
name: PropTypes.string.isRequired,
/**
* Whatever string here
*/
whatever: PropTypes.string.isRequired,
};
return Enhanced;
};
\`\`\`
`;
const HocPattern = `
# HOC Pattern
Currently using HOC pattern in actual usage is very limited. It will show the
tables of \`Enhancing Component\`with its prop names, but \`Type\` is always
\`other\` and \`Description\` is always blank. It is due to the limitation of
\`react-docgen\`. Please see the related.
issues.
[#288](https://github.com/reactjs/react-docgen/issues/288),
[#336](https://github.com/reactjs/react-docgen/issues/336),
### From specific story
\`\`\`javascript
import { SmallComponentThree } from '../../components/PropTables/SmallComponentThree';
import { withHOC } from '../../components/PropTables/withHOC';
const EnhancedSmallComponent = withHOC({ maybe: 'some option' })(
SmallComponentThree
);
storiesOf('PropsTable|More usages', module).add(
'HOC pattern',
() => (
<EnhancedSmallComponent
backgroundColor="lightgrey"
type="I'm an Enhanced Small Component"
/>
),
{
readme: {
content: \`<!-- STORY --><!-- PROPS -->\`,
},
}
);
\`\`\`
You can notice from below that propTable of \`Enhancing Component\` inside of
HOC component is only showing.
**Note**: Only \`Enhancing Component\` propTable is showing.
<details>
<summary>See HOC Component and Enhancing Component inside of it</summary>
${SeeHOCComponent}
</details>
`;
import { SmallComponentThree } from '../../components/PropTables/SmallComponentThree';
import { withHOC } from '../../components/PropTables/withHOC';
const EnhancedSmallComponent = withHOC({ maybe: 'some option' })(
SmallComponentThree
);
storiesOf('PropsTable|More usages', module).add(
'HOC pattern',
() => (
<EnhancedSmallComponent
backgroundColor="lightgrey"
type="I'm an Enhanced Small Component"
/>
),
{
readme: {
content: `${HocPattern}<!-- STORY --><!-- PROPS -->`,
},
}
);