-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
/
Copy pathDocgenButton.js
176 lines (167 loc) · 4.13 KB
/
DocgenButton.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import React from 'react';
import PropTypes from 'prop-types';
/**
* DocgenButton component description imported from comments inside the component file,
*
* *Important Note*: Unlike with normal `<input>` elements, setting this will
* not validate the input contents. This is because in this project we use
* Formik and Yup to validate fields at the form-level, not at the individual
* input level. It is still very important to set this value properly for
* accessibility and user experience.
*
* Here's a list to test out formatting.
*
* * `"number"` Any number not represented by a more specific type.
* * `"password"` A password.
* * `"email"` An email address.
* * `"tel"` A phone or fax number. Shows the phone number keypad on
* mobile keyboards.
*
* Here is a test for code blocks
*
* ```jsx
* const Foo = () => (
* <div>foo</div>
* );
* ```
*/
export const DocgenButton = ({ disabled, label, onClick }) => (
<button type="button" disabled={disabled} onClick={onClick}>
{label}
</button>
);
DocgenButton.defaultProps = {
disabled: false,
onClick: () => {},
optionalString: 'Default String',
one: { key: 1 },
two: {
thing: {
id: 2,
func: () => {},
arr: [],
},
},
obj: {
key: 'value',
},
shape: {
id: 3,
func: () => {},
arr: [],
shape: {
shape: {
foo: 'bar',
},
},
},
arrayOf: [1, 2, 3],
msg: new Set(),
enm: 'News',
enmEval: 'Photos',
union: 'hello',
};
/* eslint-disable react/no-unused-prop-types */
DocgenButton.propTypes = {
/** Boolean indicating whether the button should render as disabled */
disabled: PropTypes.bool,
/** button label. */
label: PropTypes.string.isRequired,
/** onClick handler */
onClick: PropTypes.func,
/**
* A simple `objectOf` propType.
*/
one: PropTypes.objectOf(PropTypes.number),
/**
* A very complex `objectOf` propType.
*/
two: PropTypes.objectOf(
PropTypes.shape({
/**
* Just an internal propType for a shape.
* It's also required, and as you can see it supports multi-line comments!
*/
id: PropTypes.number.isRequired,
/**
* A simple non-required function
*/
func: PropTypes.func,
/**
* An `arrayOf` shape
*/
arr: PropTypes.arrayOf(
PropTypes.shape({
/**
* 5-level deep propType definition and still works.
*/
index: PropTypes.number.isRequired,
})
),
})
),
/**
* Plain object propType (use shape!!)
*/
obj: PropTypes.object, // eslint-disable-line react/forbid-prop-types
/**
* propType for shape with nested arrayOf
*
* Also, multi-line description
*/
shape: PropTypes.shape({
/**
* Just an internal propType for a shape.
* It's also required, and as you can see it supports multi-line comments!
*/
id: PropTypes.number.isRequired,
/**
* A simple non-required function
*/
func: PropTypes.func,
/**
* An `arrayOf` shape
*/
arr: PropTypes.arrayOf(
PropTypes.shape({
/**
* 5-level deep propType definition and still works.
*/
index: PropTypes.number.isRequired,
})
),
shape: PropTypes.shape({
shape: PropTypes.shape({
foo: PropTypes.string,
}),
}),
}),
/**
* array of a certain type
*/
arrayOf: PropTypes.arrayOf(PropTypes.number),
/**
* `instanceOf` is also supported and the custom type will be shown instead of `instanceOf`
*/
msg: PropTypes.instanceOf(Set),
/**
* `oneOf` is basically an Enum which is also supported but can be pretty big.
*
* Testing a list:
*
* - `News` first
* - `Photos` second
*/
enm: PropTypes.oneOf(['News', 'Photos']),
enmEval: PropTypes.oneOf((() => ['News', 'Photos'])()),
/**
* A multi-type prop is also valid and is displayed as `Union<String|Message>`
*/
union: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Set)]),
/**
* test string with a comment that has
* two identical lines
* two identical lines
*/
optionalString: PropTypes.string,
};