@khanacademy/wonder-blocks-button 2.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/es/index.js +402 -0
- package/dist/index.js +668 -0
- package/dist/index.js.flow +2 -0
- package/docs.md +0 -0
- package/package.json +37 -0
- package/src/__tests__/__snapshots__/custom-snapshot.test.js.snap +8710 -0
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +4774 -0
- package/src/__tests__/custom-snapshot.test.js +117 -0
- package/src/__tests__/generated-snapshot.test.js +727 -0
- package/src/components/__tests__/button.flowtest.js +53 -0
- package/src/components/__tests__/button.test.js +826 -0
- package/src/components/button-core.js +375 -0
- package/src/components/button.js +347 -0
- package/src/components/button.md +810 -0
- package/src/components/button.stories.js +276 -0
- package/src/index.js +6 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
// This file is auto-generated by gen-snapshot-tests.js
|
|
2
|
+
// Do not edit this file. To make changes to these snapshot tests:
|
|
3
|
+
// 1. edit the markdown documentation files in the package,
|
|
4
|
+
// packages/wonder-blocks-button
|
|
5
|
+
// 2. Run `yarn run gen-snapshot-tests`.
|
|
6
|
+
import React from "react";
|
|
7
|
+
import renderer from "react-test-renderer";
|
|
8
|
+
|
|
9
|
+
// Mock react-dom as jest doesn't like findDOMNode.
|
|
10
|
+
jest.mock("react-dom");
|
|
11
|
+
import Button from "@khanacademy/wonder-blocks-button";
|
|
12
|
+
import {View} from "@khanacademy/wonder-blocks-core";
|
|
13
|
+
import {StyleSheet} from "aphrodite";
|
|
14
|
+
import Color from "@khanacademy/wonder-blocks-color";
|
|
15
|
+
import {MemoryRouter, Route, Switch} from "react-router-dom";
|
|
16
|
+
import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
17
|
+
|
|
18
|
+
describe("wonder-blocks-button", () => {
|
|
19
|
+
it("example 1", () => {
|
|
20
|
+
const styles = StyleSheet.create({
|
|
21
|
+
row: {
|
|
22
|
+
flexDirection: "row",
|
|
23
|
+
},
|
|
24
|
+
button: {
|
|
25
|
+
marginRight: 10,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const example = (
|
|
29
|
+
<View style={styles.row}>
|
|
30
|
+
<Button
|
|
31
|
+
style={styles.button}
|
|
32
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
33
|
+
>
|
|
34
|
+
Primary
|
|
35
|
+
</Button>
|
|
36
|
+
<Button
|
|
37
|
+
style={styles.button}
|
|
38
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
39
|
+
kind="secondary"
|
|
40
|
+
>
|
|
41
|
+
Secondary
|
|
42
|
+
</Button>
|
|
43
|
+
<Button
|
|
44
|
+
style={styles.button}
|
|
45
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
46
|
+
kind="tertiary"
|
|
47
|
+
>
|
|
48
|
+
Tertiary
|
|
49
|
+
</Button>
|
|
50
|
+
</View>
|
|
51
|
+
);
|
|
52
|
+
const tree = renderer.create(example).toJSON();
|
|
53
|
+
expect(tree).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("example 2", () => {
|
|
57
|
+
const styles = StyleSheet.create({
|
|
58
|
+
row: {
|
|
59
|
+
flexDirection: "row",
|
|
60
|
+
},
|
|
61
|
+
button: {
|
|
62
|
+
marginRight: 10,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const example = (
|
|
66
|
+
<View style={styles.row}>
|
|
67
|
+
<Button
|
|
68
|
+
style={styles.button}
|
|
69
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
70
|
+
color="destructive"
|
|
71
|
+
>
|
|
72
|
+
Primary
|
|
73
|
+
</Button>
|
|
74
|
+
<Button
|
|
75
|
+
style={styles.button}
|
|
76
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
77
|
+
kind="secondary"
|
|
78
|
+
color="destructive"
|
|
79
|
+
>
|
|
80
|
+
Secondary
|
|
81
|
+
</Button>
|
|
82
|
+
<Button
|
|
83
|
+
style={styles.button}
|
|
84
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
85
|
+
kind="tertiary"
|
|
86
|
+
color="destructive"
|
|
87
|
+
>
|
|
88
|
+
Tertiary
|
|
89
|
+
</Button>
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
92
|
+
const tree = renderer.create(example).toJSON();
|
|
93
|
+
expect(tree).toMatchSnapshot();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("example 3", () => {
|
|
97
|
+
const styles = StyleSheet.create({
|
|
98
|
+
row: {
|
|
99
|
+
flexDirection: "row",
|
|
100
|
+
},
|
|
101
|
+
button: {
|
|
102
|
+
marginRight: 10,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const example = (
|
|
106
|
+
<View style={styles.row}>
|
|
107
|
+
<Button
|
|
108
|
+
style={styles.button}
|
|
109
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
110
|
+
disabled={true}
|
|
111
|
+
>
|
|
112
|
+
Primary
|
|
113
|
+
</Button>
|
|
114
|
+
<Button
|
|
115
|
+
style={styles.button}
|
|
116
|
+
href={"/foo"}
|
|
117
|
+
kind="secondary"
|
|
118
|
+
disabled={true}
|
|
119
|
+
>
|
|
120
|
+
Secondary
|
|
121
|
+
</Button>
|
|
122
|
+
<Button
|
|
123
|
+
style={styles.button}
|
|
124
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
125
|
+
kind="tertiary"
|
|
126
|
+
disabled={true}
|
|
127
|
+
>
|
|
128
|
+
Tertiary
|
|
129
|
+
</Button>
|
|
130
|
+
</View>
|
|
131
|
+
);
|
|
132
|
+
const tree = renderer.create(example).toJSON();
|
|
133
|
+
expect(tree).toMatchSnapshot();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("example 4", () => {
|
|
137
|
+
const styles = StyleSheet.create({
|
|
138
|
+
row: {
|
|
139
|
+
flexDirection: "row",
|
|
140
|
+
backgroundColor: Color.darkBlue,
|
|
141
|
+
padding: 10,
|
|
142
|
+
},
|
|
143
|
+
button: {
|
|
144
|
+
marginRight: 10,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
const example = (
|
|
148
|
+
<View style={styles.row}>
|
|
149
|
+
<Button
|
|
150
|
+
light={true}
|
|
151
|
+
style={styles.button}
|
|
152
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
153
|
+
>
|
|
154
|
+
Primary
|
|
155
|
+
</Button>
|
|
156
|
+
<Button
|
|
157
|
+
light={true}
|
|
158
|
+
style={styles.button}
|
|
159
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
160
|
+
kind="secondary"
|
|
161
|
+
>
|
|
162
|
+
Secondary
|
|
163
|
+
</Button>
|
|
164
|
+
<Button
|
|
165
|
+
light={true}
|
|
166
|
+
style={styles.button}
|
|
167
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
168
|
+
kind="tertiary"
|
|
169
|
+
>
|
|
170
|
+
Tertiary
|
|
171
|
+
</Button>
|
|
172
|
+
<Button
|
|
173
|
+
light={true}
|
|
174
|
+
style={styles.button}
|
|
175
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
176
|
+
disabled={true}
|
|
177
|
+
>
|
|
178
|
+
Primary
|
|
179
|
+
</Button>
|
|
180
|
+
<Button
|
|
181
|
+
light={true}
|
|
182
|
+
style={styles.button}
|
|
183
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
184
|
+
kind="secondary"
|
|
185
|
+
disabled={true}
|
|
186
|
+
>
|
|
187
|
+
Secondary
|
|
188
|
+
</Button>
|
|
189
|
+
<Button
|
|
190
|
+
light={true}
|
|
191
|
+
style={styles.button}
|
|
192
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
193
|
+
kind="tertiary"
|
|
194
|
+
disabled={true}
|
|
195
|
+
>
|
|
196
|
+
Tertiary
|
|
197
|
+
</Button>
|
|
198
|
+
</View>
|
|
199
|
+
);
|
|
200
|
+
const tree = renderer.create(example).toJSON();
|
|
201
|
+
expect(tree).toMatchSnapshot();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("example 5", () => {
|
|
205
|
+
const styles = StyleSheet.create({
|
|
206
|
+
row: {
|
|
207
|
+
flexDirection: "row",
|
|
208
|
+
marginBottom: 8,
|
|
209
|
+
},
|
|
210
|
+
button: {
|
|
211
|
+
marginRight: 10,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
const example = (
|
|
215
|
+
<View>
|
|
216
|
+
<View style={styles.row}>
|
|
217
|
+
<Button
|
|
218
|
+
style={styles.button}
|
|
219
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
220
|
+
size="small"
|
|
221
|
+
>
|
|
222
|
+
Label
|
|
223
|
+
</Button>
|
|
224
|
+
<Button
|
|
225
|
+
style={styles.button}
|
|
226
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
227
|
+
kind="secondary"
|
|
228
|
+
size="small"
|
|
229
|
+
>
|
|
230
|
+
Label
|
|
231
|
+
</Button>
|
|
232
|
+
<Button
|
|
233
|
+
style={styles.button}
|
|
234
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
235
|
+
kind="tertiary"
|
|
236
|
+
size="small"
|
|
237
|
+
>
|
|
238
|
+
Label
|
|
239
|
+
</Button>
|
|
240
|
+
</View>
|
|
241
|
+
<View style={styles.row}>
|
|
242
|
+
<Button
|
|
243
|
+
style={styles.button}
|
|
244
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
245
|
+
size="medium"
|
|
246
|
+
>
|
|
247
|
+
Label
|
|
248
|
+
</Button>
|
|
249
|
+
<Button
|
|
250
|
+
style={styles.button}
|
|
251
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
252
|
+
kind="secondary"
|
|
253
|
+
size="medium"
|
|
254
|
+
>
|
|
255
|
+
Label
|
|
256
|
+
</Button>
|
|
257
|
+
<Button
|
|
258
|
+
style={styles.button}
|
|
259
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
260
|
+
kind="tertiary"
|
|
261
|
+
size="medium"
|
|
262
|
+
>
|
|
263
|
+
Label
|
|
264
|
+
</Button>
|
|
265
|
+
</View>
|
|
266
|
+
<View style={styles.row}>
|
|
267
|
+
<Button
|
|
268
|
+
style={styles.button}
|
|
269
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
270
|
+
size="xlarge"
|
|
271
|
+
>
|
|
272
|
+
Label
|
|
273
|
+
</Button>
|
|
274
|
+
<Button
|
|
275
|
+
style={styles.button}
|
|
276
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
277
|
+
kind="secondary"
|
|
278
|
+
size="xlarge"
|
|
279
|
+
>
|
|
280
|
+
Label
|
|
281
|
+
</Button>
|
|
282
|
+
<Button
|
|
283
|
+
style={styles.button}
|
|
284
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
285
|
+
kind="tertiary"
|
|
286
|
+
size="xlarge"
|
|
287
|
+
>
|
|
288
|
+
Label
|
|
289
|
+
</Button>
|
|
290
|
+
</View>
|
|
291
|
+
</View>
|
|
292
|
+
);
|
|
293
|
+
const tree = renderer.create(example).toJSON();
|
|
294
|
+
expect(tree).toMatchSnapshot();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("example 6", () => {
|
|
298
|
+
const styles = StyleSheet.create({
|
|
299
|
+
row: {
|
|
300
|
+
flexDirection: "row",
|
|
301
|
+
alignItems: "center",
|
|
302
|
+
},
|
|
303
|
+
button: {
|
|
304
|
+
marginRight: 10,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
const example = (
|
|
308
|
+
<View style={styles.row}>
|
|
309
|
+
<Button
|
|
310
|
+
spinner={true}
|
|
311
|
+
aria-label="loading"
|
|
312
|
+
size="xlarge"
|
|
313
|
+
style={styles.button}
|
|
314
|
+
>
|
|
315
|
+
Click me!
|
|
316
|
+
</Button>
|
|
317
|
+
<Button
|
|
318
|
+
spinner={true}
|
|
319
|
+
aria-label="loading"
|
|
320
|
+
style={styles.button}
|
|
321
|
+
href="/foo"
|
|
322
|
+
>
|
|
323
|
+
Click me!
|
|
324
|
+
</Button>
|
|
325
|
+
<Button
|
|
326
|
+
spinner={true}
|
|
327
|
+
aria-label="loading"
|
|
328
|
+
size="small"
|
|
329
|
+
style={styles.button}
|
|
330
|
+
>
|
|
331
|
+
Click me!
|
|
332
|
+
</Button>
|
|
333
|
+
</View>
|
|
334
|
+
);
|
|
335
|
+
const tree = renderer.create(example).toJSON();
|
|
336
|
+
expect(tree).toMatchSnapshot();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("example 7", () => {
|
|
340
|
+
const styles = StyleSheet.create({
|
|
341
|
+
row: {
|
|
342
|
+
flexDirection: "row",
|
|
343
|
+
},
|
|
344
|
+
button: {
|
|
345
|
+
marginRight: 10,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
const example = (
|
|
349
|
+
<View style={styles.row}>
|
|
350
|
+
<Button href="#button-1" style={styles.button}>
|
|
351
|
+
href
|
|
352
|
+
</Button>
|
|
353
|
+
<Button
|
|
354
|
+
kind="secondary"
|
|
355
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
356
|
+
style={styles.button}
|
|
357
|
+
>
|
|
358
|
+
onClick
|
|
359
|
+
</Button>
|
|
360
|
+
<Button
|
|
361
|
+
kind="tertiary"
|
|
362
|
+
href="#button-1"
|
|
363
|
+
onClick={(e) => window.alert("Hello, world!")}
|
|
364
|
+
style={styles.button}
|
|
365
|
+
>
|
|
366
|
+
both
|
|
367
|
+
</Button>
|
|
368
|
+
</View>
|
|
369
|
+
);
|
|
370
|
+
const tree = renderer.create(example).toJSON();
|
|
371
|
+
expect(tree).toMatchSnapshot();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("example 8", () => {
|
|
375
|
+
const styles = StyleSheet.create({
|
|
376
|
+
row: {
|
|
377
|
+
flexDirection: "row",
|
|
378
|
+
alignItems: "center",
|
|
379
|
+
},
|
|
380
|
+
button: {
|
|
381
|
+
marginRight: 10,
|
|
382
|
+
},
|
|
383
|
+
}); // NOTE: In actual code you would use BrowserRouter instead
|
|
384
|
+
|
|
385
|
+
const example = (
|
|
386
|
+
<MemoryRouter>
|
|
387
|
+
<View style={styles.row}>
|
|
388
|
+
<Button href="/foo" style={styles.button}>
|
|
389
|
+
Uses Client-side Nav
|
|
390
|
+
</Button>
|
|
391
|
+
<Button href="/foo" style={styles.button} skipClientNav>
|
|
392
|
+
Avoids Client-side Nav
|
|
393
|
+
</Button>
|
|
394
|
+
<Switch>
|
|
395
|
+
<Route path="/foo">
|
|
396
|
+
<View id="foo">Hello, world!</View>
|
|
397
|
+
</Route>
|
|
398
|
+
</Switch>
|
|
399
|
+
</View>
|
|
400
|
+
</MemoryRouter>
|
|
401
|
+
);
|
|
402
|
+
const tree = renderer.create(example).toJSON();
|
|
403
|
+
expect(tree).toMatchSnapshot();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("example 9", () => {
|
|
407
|
+
const styles = StyleSheet.create({
|
|
408
|
+
row: {
|
|
409
|
+
flexDirection: "row",
|
|
410
|
+
alignItems: "center",
|
|
411
|
+
},
|
|
412
|
+
button: {
|
|
413
|
+
marginRight: 10,
|
|
414
|
+
},
|
|
415
|
+
}); // NOTE: In actual code you would use BrowserRouter instead
|
|
416
|
+
|
|
417
|
+
const example = (
|
|
418
|
+
<MemoryRouter>
|
|
419
|
+
<View style={styles.row}>
|
|
420
|
+
<Button
|
|
421
|
+
href="/foo"
|
|
422
|
+
style={styles.button}
|
|
423
|
+
beforeNav={() =>
|
|
424
|
+
new Promise((resolve, reject) => {
|
|
425
|
+
setTimeout(resolve, 1000);
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
>
|
|
429
|
+
Async action, client-side nav
|
|
430
|
+
</Button>
|
|
431
|
+
<Button
|
|
432
|
+
href="/foo"
|
|
433
|
+
style={styles.button}
|
|
434
|
+
skipClientNav={true}
|
|
435
|
+
beforeNav={() =>
|
|
436
|
+
new Promise((resolve, reject) => {
|
|
437
|
+
setTimeout(resolve, 1000);
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
>
|
|
441
|
+
Async action, server-side nav
|
|
442
|
+
</Button>
|
|
443
|
+
<Button
|
|
444
|
+
href="https://google.com"
|
|
445
|
+
target="_blank"
|
|
446
|
+
style={styles.button}
|
|
447
|
+
skipClientNav={true}
|
|
448
|
+
beforeNav={() =>
|
|
449
|
+
new Promise((resolve, reject) => {
|
|
450
|
+
setTimeout(resolve, 1000);
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
>
|
|
454
|
+
Async action, open URL in new tab
|
|
455
|
+
</Button>
|
|
456
|
+
<Switch>
|
|
457
|
+
<Route path="/foo">
|
|
458
|
+
<View id="foo">Hello, world!</View>
|
|
459
|
+
</Route>
|
|
460
|
+
</Switch>
|
|
461
|
+
</View>
|
|
462
|
+
</MemoryRouter>
|
|
463
|
+
);
|
|
464
|
+
const tree = renderer.create(example).toJSON();
|
|
465
|
+
expect(tree).toMatchSnapshot();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("example 10", () => {
|
|
469
|
+
const styles = StyleSheet.create({
|
|
470
|
+
row: {
|
|
471
|
+
flexDirection: "row",
|
|
472
|
+
alignItems: "center",
|
|
473
|
+
},
|
|
474
|
+
button: {
|
|
475
|
+
marginRight: 10,
|
|
476
|
+
},
|
|
477
|
+
}); // NOTE: In actual code you would use BrowserRouter instead
|
|
478
|
+
|
|
479
|
+
const example = (
|
|
480
|
+
<MemoryRouter>
|
|
481
|
+
<View style={styles.row}>
|
|
482
|
+
<Button
|
|
483
|
+
href="/foo"
|
|
484
|
+
style={styles.button}
|
|
485
|
+
onClick={(e) => e.preventDefault()}
|
|
486
|
+
>
|
|
487
|
+
This button prevent navigation.
|
|
488
|
+
</Button>
|
|
489
|
+
<Switch>
|
|
490
|
+
<Route path="/foo">
|
|
491
|
+
<View id="foo">Hello, world!</View>
|
|
492
|
+
</Route>
|
|
493
|
+
</Switch>
|
|
494
|
+
</View>
|
|
495
|
+
</MemoryRouter>
|
|
496
|
+
);
|
|
497
|
+
const tree = renderer.create(example).toJSON();
|
|
498
|
+
expect(tree).toMatchSnapshot();
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it("example 11", () => {
|
|
502
|
+
const styles = StyleSheet.create({
|
|
503
|
+
row: {
|
|
504
|
+
flexDirection: "row",
|
|
505
|
+
marginBottom: 10,
|
|
506
|
+
},
|
|
507
|
+
button: {
|
|
508
|
+
marginRight: 10,
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
const kinds = ["primary", "secondary", "tertiary"];
|
|
512
|
+
const example = (
|
|
513
|
+
<View>
|
|
514
|
+
<View style={styles.row}>
|
|
515
|
+
{kinds.map((kind, idx) => (
|
|
516
|
+
<Button
|
|
517
|
+
kind={kind}
|
|
518
|
+
icon={icons.contentExercise}
|
|
519
|
+
style={styles.button}
|
|
520
|
+
key={idx}
|
|
521
|
+
>
|
|
522
|
+
{kind}
|
|
523
|
+
</Button>
|
|
524
|
+
))}
|
|
525
|
+
</View>
|
|
526
|
+
<View style={styles.row}>
|
|
527
|
+
{kinds.map((kind, idx) => (
|
|
528
|
+
<Button
|
|
529
|
+
kind={kind}
|
|
530
|
+
icon={icons.contentExercise}
|
|
531
|
+
style={styles.button}
|
|
532
|
+
key={idx}
|
|
533
|
+
size="small"
|
|
534
|
+
>
|
|
535
|
+
{kind} small
|
|
536
|
+
</Button>
|
|
537
|
+
))}
|
|
538
|
+
</View>
|
|
539
|
+
</View>
|
|
540
|
+
);
|
|
541
|
+
const tree = renderer.create(example).toJSON();
|
|
542
|
+
expect(tree).toMatchSnapshot();
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it("example 12", () => {
|
|
546
|
+
const example = (
|
|
547
|
+
<View>
|
|
548
|
+
<form onSubmit={() => alert("the form was submitted")}>
|
|
549
|
+
<Button type="submit">Submit</Button>
|
|
550
|
+
</form>
|
|
551
|
+
</View>
|
|
552
|
+
);
|
|
553
|
+
const tree = renderer.create(example).toJSON();
|
|
554
|
+
expect(tree).toMatchSnapshot();
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it("example 13", () => {
|
|
558
|
+
const example = (
|
|
559
|
+
<View>
|
|
560
|
+
<Button>Label</Button>
|
|
561
|
+
</View>
|
|
562
|
+
);
|
|
563
|
+
const tree = renderer.create(example).toJSON();
|
|
564
|
+
expect(tree).toMatchSnapshot();
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
it("example 14", () => {
|
|
568
|
+
const styles = StyleSheet.create({
|
|
569
|
+
column: {
|
|
570
|
+
alignItems: "flex-start",
|
|
571
|
+
},
|
|
572
|
+
row: {
|
|
573
|
+
flexDirection: "row",
|
|
574
|
+
},
|
|
575
|
+
gap: {
|
|
576
|
+
height: 16,
|
|
577
|
+
},
|
|
578
|
+
button: {
|
|
579
|
+
marginRight: 10,
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
const example = (
|
|
583
|
+
<View>
|
|
584
|
+
<View style={styles.row}>
|
|
585
|
+
<Button>Button in a row</Button>
|
|
586
|
+
</View>
|
|
587
|
+
<View style={styles.gap} />
|
|
588
|
+
<View style={styles.column}>
|
|
589
|
+
<Button>Button in a column</Button>
|
|
590
|
+
</View>
|
|
591
|
+
</View>
|
|
592
|
+
);
|
|
593
|
+
const tree = renderer.create(example).toJSON();
|
|
594
|
+
expect(tree).toMatchSnapshot();
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it("example 15", () => {
|
|
598
|
+
const styles = StyleSheet.create({
|
|
599
|
+
row: {
|
|
600
|
+
flexDirection: "row",
|
|
601
|
+
},
|
|
602
|
+
gap: {
|
|
603
|
+
height: 16,
|
|
604
|
+
},
|
|
605
|
+
button: {
|
|
606
|
+
marginRight: 10,
|
|
607
|
+
minWidth: 144,
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
const example = (
|
|
611
|
+
<View style={styles.row}>
|
|
612
|
+
<Button style={styles.button} kind="secondary">
|
|
613
|
+
label
|
|
614
|
+
</Button>
|
|
615
|
+
<Button style={styles.button}>
|
|
616
|
+
label in a different language
|
|
617
|
+
</Button>
|
|
618
|
+
</View>
|
|
619
|
+
);
|
|
620
|
+
const tree = renderer.create(example).toJSON();
|
|
621
|
+
expect(tree).toMatchSnapshot();
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it("example 16", () => {
|
|
625
|
+
const styles = StyleSheet.create({
|
|
626
|
+
row: {
|
|
627
|
+
flexDirection: "row",
|
|
628
|
+
width: 300,
|
|
629
|
+
},
|
|
630
|
+
gap: {
|
|
631
|
+
height: 16,
|
|
632
|
+
},
|
|
633
|
+
button: {
|
|
634
|
+
marginRight: 10,
|
|
635
|
+
minWidth: 144,
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
const example = (
|
|
639
|
+
<View style={styles.row}>
|
|
640
|
+
<Button style={styles.button} kind="secondary">
|
|
641
|
+
label
|
|
642
|
+
</Button>
|
|
643
|
+
<Button style={styles.button}>
|
|
644
|
+
label too long for the parent container
|
|
645
|
+
</Button>
|
|
646
|
+
</View>
|
|
647
|
+
);
|
|
648
|
+
const tree = renderer.create(example).toJSON();
|
|
649
|
+
expect(tree).toMatchSnapshot();
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it("example 17", () => {
|
|
653
|
+
const styles = StyleSheet.create({
|
|
654
|
+
row: {
|
|
655
|
+
flexDirection: "row",
|
|
656
|
+
},
|
|
657
|
+
button: {
|
|
658
|
+
marginRight: 10,
|
|
659
|
+
},
|
|
660
|
+
});
|
|
661
|
+
const example = (
|
|
662
|
+
<View>
|
|
663
|
+
<View style={styles.row}>
|
|
664
|
+
<Button style={styles.button} kind="tertiary">
|
|
665
|
+
Tertiary
|
|
666
|
+
</Button>
|
|
667
|
+
<Button style={styles.badButton}>Primary</Button>
|
|
668
|
+
</View>
|
|
669
|
+
</View>
|
|
670
|
+
);
|
|
671
|
+
const tree = renderer.create(example).toJSON();
|
|
672
|
+
expect(tree).toMatchSnapshot();
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it("example 18", () => {
|
|
676
|
+
const styles = StyleSheet.create({
|
|
677
|
+
row: {
|
|
678
|
+
flexDirection: "row",
|
|
679
|
+
},
|
|
680
|
+
button: {
|
|
681
|
+
marginRight: 10,
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
class Example extends React.Component {
|
|
686
|
+
constructor(props) {
|
|
687
|
+
super(props);
|
|
688
|
+
this.state = {
|
|
689
|
+
waiting: false,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
componentWillUnmount() {
|
|
694
|
+
this.timeout && this.timeout.clear();
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
handleClick() {
|
|
698
|
+
this.setState({
|
|
699
|
+
waiting: true,
|
|
700
|
+
});
|
|
701
|
+
this.timeout = setTimeout(() => {
|
|
702
|
+
this.setState({
|
|
703
|
+
waiting: false,
|
|
704
|
+
});
|
|
705
|
+
}, 2000);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
render() {
|
|
709
|
+
return (
|
|
710
|
+
<View style={styles.row}>
|
|
711
|
+
<Button
|
|
712
|
+
spinner={this.state.waiting}
|
|
713
|
+
aria-label={this.state.waiting ? "waiting" : ""}
|
|
714
|
+
onClick={() => this.handleClick()}
|
|
715
|
+
>
|
|
716
|
+
Click me!
|
|
717
|
+
</Button>
|
|
718
|
+
</View>
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const example = <Example />;
|
|
724
|
+
const tree = renderer.create(example).toJSON();
|
|
725
|
+
expect(tree).toMatchSnapshot();
|
|
726
|
+
});
|
|
727
|
+
});
|