@khanacademy/wonder-blocks-button 2.10.0 → 2.11.1

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.
@@ -1,24 +1,40 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
+ import {StyleSheet} from "aphrodite";
4
+ import {withDesign} from "storybook-addon-designs";
3
5
  import {action} from "@storybook/addon-actions";
4
6
 
7
+ import {MemoryRouter, Route, Switch} from "react-router-dom";
8
+
9
+ import Color from "@khanacademy/wonder-blocks-color";
5
10
  import {View} from "@khanacademy/wonder-blocks-core";
11
+ import {icons} from "@khanacademy/wonder-blocks-icon";
6
12
  import {Strut} from "@khanacademy/wonder-blocks-layout";
7
- import Color from "@khanacademy/wonder-blocks-color";
8
-
13
+ import Spacing from "@khanacademy/wonder-blocks-spacing";
9
14
  import type {StoryComponentType} from "@storybook/react";
10
15
  import Button from "./button.js";
11
16
 
17
+ import ComponentInfo from "../../../../.storybook/components/component-info.js";
18
+ import ButtonArgTypes from "./__docs__/button.argtypes.js";
19
+ import {name, version} from "../../package.json";
20
+
12
21
  export default {
13
22
  title: "Navigation/Button",
14
23
  component: Button,
24
+ parameters: {
25
+ componentSubtitle: ((
26
+ <ComponentInfo name={name} version={version} />
27
+ ): any),
28
+ },
29
+ decorators: [withDesign],
30
+ argTypes: ButtonArgTypes,
15
31
  };
16
32
 
17
- export const buttonsWithKnobs: StoryComponentType = (args) => {
18
- return <Button {...args} onClick={action("onClick")} />;
19
- };
33
+ const Template = (args) => <Button {...args} />;
34
+
35
+ export const DefaultButton: StoryComponentType = Template.bind({});
20
36
 
21
- buttonsWithKnobs.args = {
37
+ DefaultButton.args = {
22
38
  children: "Hello, world!",
23
39
  kind: "primary",
24
40
  color: "default",
@@ -26,11 +42,13 @@ buttonsWithKnobs.args = {
26
42
  light: false,
27
43
  disabled: false,
28
44
  style: {maxWidth: 200},
45
+ onClick: () => {},
29
46
  };
30
47
 
31
- buttonsWithKnobs.parameters = {
32
- options: {
33
- showAddonPanel: true,
48
+ DefaultButton.parameters = {
49
+ design: {
50
+ type: "figma",
51
+ url: "https://www.figma.com/file/VbVu3h2BpBhH80niq101MHHE/Wonder-Blocks-(Web)?node-id=401%3A307",
34
52
  },
35
53
  chromatic: {
36
54
  // We already have screenshots of other stories that cover more of the button states
@@ -38,7 +56,7 @@ buttonsWithKnobs.parameters = {
38
56
  },
39
57
  };
40
58
 
41
- export const basicButtons: StoryComponentType = () => (
59
+ export const BasicButtons: StoryComponentType = () => (
42
60
  <View>
43
61
  <View style={{flexDirection: "row"}}>
44
62
  <Button onClick={() => {}}>Hello, world!</Button>
@@ -82,7 +100,45 @@ export const basicButtons: StoryComponentType = () => (
82
100
  </View>
83
101
  );
84
102
 
85
- export const darkBackgroundButtons: StoryComponentType = () => (
103
+ BasicButtons.parameters = {
104
+ docs: {
105
+ storyDescription:
106
+ "There are three kinds of buttons: `primary` (default), `secondary`, and `tertiary`.",
107
+ },
108
+ };
109
+
110
+ export const ButtonsWithColors: StoryComponentType = () => (
111
+ <View style={styles.row}>
112
+ <Button style={styles.button} onClick={() => {}} color="destructive">
113
+ Primary
114
+ </Button>
115
+ <Button
116
+ style={styles.button}
117
+ onClick={() => {}}
118
+ kind="secondary"
119
+ color="destructive"
120
+ >
121
+ Secondary
122
+ </Button>
123
+ <Button
124
+ style={styles.button}
125
+ onClick={() => {}}
126
+ kind="tertiary"
127
+ color="destructive"
128
+ >
129
+ Tertiary
130
+ </Button>
131
+ </View>
132
+ );
133
+
134
+ ButtonsWithColors.parameters = {
135
+ docs: {
136
+ storyDescription:
137
+ "Buttons have a `color` that is either `default` (the default, as shown above) or `destructive` (as can seen below):",
138
+ },
139
+ };
140
+
141
+ export const DarkBackgroundButtons: StoryComponentType = () => (
86
142
  <View style={{backgroundColor: Color.darkBlue}}>
87
143
  <View style={{flexDirection: "row"}}>
88
144
  <Button onClick={() => {}} light={true}>
@@ -148,51 +204,92 @@ export const darkBackgroundButtons: StoryComponentType = () => (
148
204
  </View>
149
205
  );
150
206
 
151
- darkBackgroundButtons.parameters = {
207
+ DarkBackgroundButtons.parameters = {
152
208
  backgrounds: {
153
209
  default: "darkBlue",
154
210
  },
211
+ docs: {
212
+ storyDescription:
213
+ "Buttons on a `darkBlue` background should set `light` to `true`.",
214
+ },
155
215
  };
156
216
 
157
- export const smallButtons: StoryComponentType = () => (
158
- <View style={{flexDirection: "row"}}>
159
- <Button onClick={() => {}} size="small">
160
- Hello, world!
161
- </Button>
162
- <Strut size={16} />
163
- <Button onClick={() => {}} size="small" kind="secondary">
164
- Hello, world!
165
- </Button>
166
- <Strut size={16} />
167
- <Button onClick={() => {}} size="small" kind="tertiary">
168
- Hello, world!
169
- </Button>
170
- </View>
171
- );
172
-
173
- export const xlargeButtons: StoryComponentType = () => (
174
- <View style={{flexDirection: "row"}}>
175
- <Button onClick={() => {}} size="xlarge">
176
- Hello, world!
177
- </Button>
178
- <Strut size={16} />
179
- <Button onClick={() => {}} size="xlarge" kind="secondary">
180
- Hello, world!
181
- </Button>
182
- <Strut size={16} />
183
- <Button onClick={() => {}} size="xlarge" kind="tertiary">
184
- Hello, world!
185
- </Button>
217
+ export const ButtonsWithSize: StoryComponentType = () => (
218
+ <View>
219
+ <View style={styles.row}>
220
+ <Button style={styles.button} onClick={() => {}} size="small">
221
+ Label
222
+ </Button>
223
+ <Button
224
+ style={styles.button}
225
+ onClick={() => {}}
226
+ kind="secondary"
227
+ size="small"
228
+ >
229
+ Label
230
+ </Button>
231
+ <Button
232
+ style={styles.button}
233
+ onClick={() => {}}
234
+ kind="tertiary"
235
+ size="small"
236
+ >
237
+ Label
238
+ </Button>
239
+ </View>
240
+ <View style={styles.row}>
241
+ <Button style={styles.button} onClick={() => {}} size="medium">
242
+ Label
243
+ </Button>
244
+ <Button
245
+ style={styles.button}
246
+ onClick={() => {}}
247
+ kind="secondary"
248
+ size="medium"
249
+ >
250
+ Label
251
+ </Button>
252
+ <Button
253
+ style={styles.button}
254
+ onClick={() => {}}
255
+ kind="tertiary"
256
+ size="medium"
257
+ >
258
+ Label
259
+ </Button>
260
+ </View>
261
+ <View style={styles.row}>
262
+ <Button style={styles.button} onClick={() => {}} size="xlarge">
263
+ Label
264
+ </Button>
265
+ <Button
266
+ style={styles.button}
267
+ onClick={() => {}}
268
+ kind="secondary"
269
+ size="xlarge"
270
+ >
271
+ Label
272
+ </Button>
273
+ <Button
274
+ style={styles.button}
275
+ onClick={() => {}}
276
+ kind="tertiary"
277
+ size="xlarge"
278
+ >
279
+ Label
280
+ </Button>
281
+ </View>
186
282
  </View>
187
283
  );
188
284
 
189
- export const longLabelsAreEllipsized: StoryComponentType = () => (
190
- <Button onClick={() => {}} style={{maxWidth: 200}}>
191
- label too long for the parent container
192
- </Button>
193
- );
285
+ ButtonsWithSize.parameters = {
286
+ docs: {
287
+ storyDescription:
288
+ "Buttons have a size that's either `medium` (default), `small`, or `xlarge`.",
289
+ },
290
+ };
194
291
 
195
- export const buttonWithSpinner: StoryComponentType = () => (
292
+ export const ButtonWithSpinner: StoryComponentType = () => (
196
293
  <View style={{flexDirection: "row"}}>
197
294
  <Button
198
295
  onClick={() => {}}
@@ -218,7 +315,241 @@ export const buttonWithSpinner: StoryComponentType = () => (
218
315
  </View>
219
316
  );
220
317
 
221
- export const submitButtonInForm: StoryComponentType = () => (
318
+ ButtonWithSpinner.parameters = {
319
+ docs: {
320
+ storyDescription:
321
+ "Buttons can show a spinner. This is useful when indicating to a user that their input has been recognized but that the operation will take some time. While the spinner property is set to true the button is disabled.",
322
+ },
323
+ };
324
+
325
+ export const ButtonsWithRouter: StoryComponentType = () => (
326
+ <MemoryRouter>
327
+ <View style={styles.row}>
328
+ <Button href="/foo" style={styles.button}>
329
+ Uses Client-side Nav
330
+ </Button>
331
+ <Button href="/foo" style={styles.button} skipClientNav>
332
+ Avoids Client-side Nav
333
+ </Button>
334
+ <Switch>
335
+ <Route path="/foo">
336
+ <View id="foo">Hello, world!</View>
337
+ </Route>
338
+ </Switch>
339
+ </View>
340
+ </MemoryRouter>
341
+ );
342
+
343
+ ButtonsWithRouter.storyName = "Navigation with React Router";
344
+
345
+ ButtonsWithRouter.parameters = {
346
+ docs: {
347
+ storyDescription:
348
+ "Buttons do client-side navigation by default, if React Router exists:",
349
+ },
350
+ chromatic: {
351
+ disableSnapshot: true,
352
+ },
353
+ };
354
+
355
+ export const BeforeNavCallbacks: StoryComponentType = () => (
356
+ <MemoryRouter>
357
+ <View style={styles.row}>
358
+ <Button
359
+ href="/foo"
360
+ style={styles.button}
361
+ beforeNav={() =>
362
+ new Promise((resolve, reject) => {
363
+ setTimeout(resolve, 1000);
364
+ })
365
+ }
366
+ >
367
+ beforeNav, client-side nav
368
+ </Button>
369
+ <Button
370
+ href="/foo"
371
+ style={styles.button}
372
+ skipClientNav={true}
373
+ beforeNav={() =>
374
+ new Promise((resolve, reject) => {
375
+ setTimeout(resolve, 1000);
376
+ })
377
+ }
378
+ >
379
+ beforeNav, server-side nav
380
+ </Button>
381
+ <Button
382
+ href="https://google.com"
383
+ style={styles.button}
384
+ skipClientNav={true}
385
+ beforeNav={() =>
386
+ new Promise((resolve, reject) => {
387
+ setTimeout(resolve, 1000);
388
+ })
389
+ }
390
+ >
391
+ beforeNav, open URL in new tab
392
+ </Button>
393
+ <Switch>
394
+ <Route path="/foo">
395
+ <View id="foo">Hello, world!</View>
396
+ </Route>
397
+ </Switch>
398
+ </View>
399
+ </MemoryRouter>
400
+ );
401
+
402
+ BeforeNavCallbacks.storyName = "beforeNav Callbacks";
403
+
404
+ BeforeNavCallbacks.parameters = {
405
+ docs: {
406
+ storyDescription:
407
+ "These buttons always wait until the async callback code completes before starting navigation.",
408
+ },
409
+ chromatic: {
410
+ disableSnapshot: true,
411
+ },
412
+ };
413
+
414
+ export const SafeWithNavCallbacks: StoryComponentType = () => (
415
+ <MemoryRouter>
416
+ <View style={styles.row}>
417
+ <Button
418
+ href="/foo"
419
+ style={styles.button}
420
+ safeWithNav={() =>
421
+ new Promise((resolve, reject) => {
422
+ setTimeout(resolve, 1000);
423
+ })
424
+ }
425
+ >
426
+ safeWithNav, client-side nav
427
+ </Button>
428
+ <Button
429
+ href="/foo"
430
+ style={styles.button}
431
+ skipClientNav={true}
432
+ safeWithNav={() =>
433
+ new Promise((resolve, reject) => {
434
+ setTimeout(resolve, 1000);
435
+ })
436
+ }
437
+ >
438
+ safeWithNav, server-side nav
439
+ </Button>
440
+ <Button
441
+ href="https://google.com"
442
+ style={styles.button}
443
+ skipClientNav={true}
444
+ safeWithNav={() =>
445
+ new Promise((resolve, reject) => {
446
+ setTimeout(resolve, 1000);
447
+ })
448
+ }
449
+ >
450
+ safeWithNav, open URL in new tab
451
+ </Button>
452
+ <Switch>
453
+ <Route path="/foo">
454
+ <View id="foo">Hello, world!</View>
455
+ </Route>
456
+ </Switch>
457
+ </View>
458
+ </MemoryRouter>
459
+ );
460
+
461
+ SafeWithNavCallbacks.storyName = "safeWithNav Callbacks";
462
+
463
+ SafeWithNavCallbacks.parameters = {
464
+ docs: {
465
+ storyDescription:
466
+ "If the `onClick` callback calls `preventDefault()`, then navigation will not occur.",
467
+ },
468
+ chromatic: {
469
+ disableSnapshot: true,
470
+ },
471
+ };
472
+
473
+ export const PreventNavigation: StoryComponentType = () => (
474
+ <MemoryRouter>
475
+ <View style={styles.row}>
476
+ <Button
477
+ href="/foo"
478
+ style={styles.button}
479
+ onClick={(e) => {
480
+ action("clicked")(e);
481
+ e.preventDefault();
482
+ }}
483
+ >
484
+ This button prevents navigation.
485
+ </Button>
486
+ <Switch>
487
+ <Route path="/foo">
488
+ <View id="foo">Hello, world!</View>
489
+ </Route>
490
+ </Switch>
491
+ </View>
492
+ </MemoryRouter>
493
+ );
494
+
495
+ PreventNavigation.storyName =
496
+ "Prevent navigation by calling e.preventDefault()";
497
+
498
+ PreventNavigation.parameters = {
499
+ docs: {
500
+ storyDescription:
501
+ "Sometimes you may need to perform an async action either before or during navigation. This can be accomplished with `beforeNav` and `safeWithNav` respectively.",
502
+ },
503
+ chromatic: {
504
+ disableSnapshot: true,
505
+ },
506
+ };
507
+
508
+ const kinds = ["primary", "secondary", "tertiary"];
509
+
510
+ export const ButtonsWithIcons: StoryComponentType = () => (
511
+ <View>
512
+ <View style={styles.row}>
513
+ {kinds.map((kind, idx) => (
514
+ <Button
515
+ kind={kind}
516
+ icon={icons.contentExercise}
517
+ style={styles.button}
518
+ key={idx}
519
+ >
520
+ {kind}
521
+ </Button>
522
+ ))}
523
+ </View>
524
+ <View style={styles.row}>
525
+ {kinds.map((kind, idx) => (
526
+ <Button
527
+ kind={kind}
528
+ icon={icons.contentExercise}
529
+ style={styles.button}
530
+ key={idx}
531
+ size="small"
532
+ >
533
+ {`${kind} small`}
534
+ </Button>
535
+ ))}
536
+ </View>
537
+ </View>
538
+ );
539
+
540
+ ButtonsWithIcons.parameters = {
541
+ docs: {
542
+ storyDescription: "Buttons can have an icon on it's left side.",
543
+ },
544
+ };
545
+
546
+ export const LongLabelsAreEllipsized: StoryComponentType = () => (
547
+ <Button onClick={() => {}} style={{maxWidth: 200}}>
548
+ label too long for the parent container
549
+ </Button>
550
+ );
551
+
552
+ export const SubmitButtonInForm: StoryComponentType = () => (
222
553
  <form
223
554
  onSubmit={(e) => {
224
555
  e.preventDefault();
@@ -232,12 +563,23 @@ export const submitButtonInForm: StoryComponentType = () => (
232
563
  </form>
233
564
  );
234
565
 
235
- submitButtonInForm.parameters = {
566
+ SubmitButtonInForm.parameters = {
236
567
  options: {
237
568
  showAddonPanel: true,
238
569
  },
239
570
  chromatic: {
240
- // We already have screenshots of other stories that cover more of the button states
571
+ // We already have screenshots of other stories that cover more of the
572
+ // button states.
241
573
  disableSnapshot: true,
242
574
  },
243
575
  };
576
+
577
+ const styles = StyleSheet.create({
578
+ row: {
579
+ flexDirection: "row",
580
+ marginBottom: Spacing.xSmall_8,
581
+ },
582
+ button: {
583
+ marginRight: Spacing.xSmall_8,
584
+ },
585
+ });
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Khan Academy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.