@khanacademy/wonder-blocks-button 2.9.13 → 2.10.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-button",
3
- "version": "2.9.13",
3
+ "version": "2.10.2",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,23 +15,23 @@
15
15
  "author": "",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@babel/runtime": "^7.13.10",
19
- "@khanacademy/wonder-blocks-clickable": "^2.1.2",
20
- "@khanacademy/wonder-blocks-color": "^1.1.18",
21
- "@khanacademy/wonder-blocks-core": "^3.1.4",
22
- "@khanacademy/wonder-blocks-icon": "^1.2.21",
23
- "@khanacademy/wonder-blocks-progress-spinner": "^1.1.25",
24
- "@khanacademy/wonder-blocks-spacing": "^3.0.3",
25
- "@khanacademy/wonder-blocks-typography": "^1.1.25"
18
+ "@babel/runtime": "^7.16.3",
19
+ "@khanacademy/wonder-blocks-clickable": "^2.2.1",
20
+ "@khanacademy/wonder-blocks-color": "^1.1.20",
21
+ "@khanacademy/wonder-blocks-core": "^4.0.0",
22
+ "@khanacademy/wonder-blocks-icon": "^1.2.24",
23
+ "@khanacademy/wonder-blocks-progress-spinner": "^1.1.28",
24
+ "@khanacademy/wonder-blocks-spacing": "^3.0.5",
25
+ "@khanacademy/wonder-blocks-typography": "^1.1.28"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "aphrodite": "^1.2.5",
29
- "prop-types": "^15.6.2",
30
- "react": "^16.4.1",
31
- "react-router-dom": "^4.2.2"
29
+ "react": "16.14.0",
30
+ "react-router": "5.2.1",
31
+ "react-router-dom": "5.3.0"
32
32
  },
33
33
  "devDependencies": {
34
- "wb-dev-build-settings": "^0.1.0"
34
+ "wb-dev-build-settings": "^0.2.0"
35
35
  },
36
- "gitHead": "8022bb419eed74be37f71f71c7621854794a731c"
36
+ "gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
37
37
  }
@@ -2850,7 +2850,7 @@ exports[`wonder-blocks-button example 9 1`] = `
2850
2850
  }
2851
2851
  }
2852
2852
  >
2853
- Async action, client-side nav
2853
+ beforeNav, client-side nav
2854
2854
  </span>
2855
2855
  </a>
2856
2856
  <a
@@ -2918,7 +2918,7 @@ exports[`wonder-blocks-button example 9 1`] = `
2918
2918
  }
2919
2919
  }
2920
2920
  >
2921
- Async action, server-side nav
2921
+ beforeNav, server-side nav
2922
2922
  </span>
2923
2923
  </a>
2924
2924
  <a
@@ -2987,7 +2987,7 @@ exports[`wonder-blocks-button example 9 1`] = `
2987
2987
  }
2988
2988
  }
2989
2989
  >
2990
- Async action, open URL in new tab
2990
+ beforeNav, open URL in new tab
2991
2991
  </span>
2992
2992
  </a>
2993
2993
  </div>
@@ -3078,13 +3078,242 @@ exports[`wonder-blocks-button example 10 1`] = `
3078
3078
  }
3079
3079
  }
3080
3080
  >
3081
- This button prevent navigation.
3081
+ safeWithNav, client-side nav
3082
+ </span>
3083
+ </a>
3084
+ <a
3085
+ className=""
3086
+ href="/foo"
3087
+ onBlur={[Function]}
3088
+ onClick={[Function]}
3089
+ onDragStart={[Function]}
3090
+ onFocus={[Function]}
3091
+ onKeyDown={[Function]}
3092
+ onKeyUp={[Function]}
3093
+ onMouseDown={[Function]}
3094
+ onMouseEnter={[Function]}
3095
+ onMouseLeave={[Function]}
3096
+ onMouseUp={[Function]}
3097
+ onTouchCancel={[Function]}
3098
+ onTouchEnd={[Function]}
3099
+ onTouchStart={[Function]}
3100
+ role="button"
3101
+ style={
3102
+ Object {
3103
+ ":focus": Object {
3104
+ "WebkitTapHighlightColor": "rgba(0,0,0,0)",
3105
+ },
3106
+ "alignItems": "center",
3107
+ "background": "#1865f2",
3108
+ "border": "none",
3109
+ "borderRadius": 4,
3110
+ "boxSizing": "border-box",
3111
+ "color": "#ffffff",
3112
+ "cursor": "pointer",
3113
+ "display": "inline-flex",
3114
+ "height": 40,
3115
+ "justifyContent": "center",
3116
+ "marginRight": 10,
3117
+ "outline": "none",
3118
+ "paddingBottom": 0,
3119
+ "paddingLeft": 16,
3120
+ "paddingRight": 16,
3121
+ "paddingTop": 0,
3122
+ "position": "relative",
3123
+ "textDecoration": "none",
3124
+ "touchAction": "manipulation",
3125
+ "userSelect": "none",
3126
+ }
3127
+ }
3128
+ tabIndex={0}
3129
+ >
3130
+ <span
3131
+ className=""
3132
+ style={
3133
+ Object {
3134
+ "MozOsxFontSmoothing": "grayscale",
3135
+ "WebkitFontSmoothing": "antialiased",
3136
+ "alignItems": "center",
3137
+ "display": "inline-block",
3138
+ "fontFamily": "Lato, \\"Noto Sans\\", sans-serif",
3139
+ "fontSize": 16,
3140
+ "fontWeight": "bold",
3141
+ "lineHeight": "20px",
3142
+ "overflow": "hidden",
3143
+ "pointerEvents": "none",
3144
+ "textOverflow": "ellipsis",
3145
+ "whiteSpace": "nowrap",
3146
+ }
3147
+ }
3148
+ >
3149
+ safeWithNav, server-side nav
3150
+ </span>
3151
+ </a>
3152
+ <a
3153
+ className=""
3154
+ href="https://google.com"
3155
+ onBlur={[Function]}
3156
+ onClick={[Function]}
3157
+ onDragStart={[Function]}
3158
+ onFocus={[Function]}
3159
+ onKeyDown={[Function]}
3160
+ onKeyUp={[Function]}
3161
+ onMouseDown={[Function]}
3162
+ onMouseEnter={[Function]}
3163
+ onMouseLeave={[Function]}
3164
+ onMouseUp={[Function]}
3165
+ onTouchCancel={[Function]}
3166
+ onTouchEnd={[Function]}
3167
+ onTouchStart={[Function]}
3168
+ rel="noopener noreferrer"
3169
+ role="button"
3170
+ style={
3171
+ Object {
3172
+ ":focus": Object {
3173
+ "WebkitTapHighlightColor": "rgba(0,0,0,0)",
3174
+ },
3175
+ "alignItems": "center",
3176
+ "background": "#1865f2",
3177
+ "border": "none",
3178
+ "borderRadius": 4,
3179
+ "boxSizing": "border-box",
3180
+ "color": "#ffffff",
3181
+ "cursor": "pointer",
3182
+ "display": "inline-flex",
3183
+ "height": 40,
3184
+ "justifyContent": "center",
3185
+ "marginRight": 10,
3186
+ "outline": "none",
3187
+ "paddingBottom": 0,
3188
+ "paddingLeft": 16,
3189
+ "paddingRight": 16,
3190
+ "paddingTop": 0,
3191
+ "position": "relative",
3192
+ "textDecoration": "none",
3193
+ "touchAction": "manipulation",
3194
+ "userSelect": "none",
3195
+ }
3196
+ }
3197
+ tabIndex={0}
3198
+ target="_blank"
3199
+ >
3200
+ <span
3201
+ className=""
3202
+ style={
3203
+ Object {
3204
+ "MozOsxFontSmoothing": "grayscale",
3205
+ "WebkitFontSmoothing": "antialiased",
3206
+ "alignItems": "center",
3207
+ "display": "inline-block",
3208
+ "fontFamily": "Lato, \\"Noto Sans\\", sans-serif",
3209
+ "fontSize": 16,
3210
+ "fontWeight": "bold",
3211
+ "lineHeight": "20px",
3212
+ "overflow": "hidden",
3213
+ "pointerEvents": "none",
3214
+ "textOverflow": "ellipsis",
3215
+ "whiteSpace": "nowrap",
3216
+ }
3217
+ }
3218
+ >
3219
+ safeWithNav, open URL in new tab
3082
3220
  </span>
3083
3221
  </a>
3084
3222
  </div>
3085
3223
  `;
3086
3224
 
3087
3225
  exports[`wonder-blocks-button example 11 1`] = `
3226
+ <div
3227
+ className=""
3228
+ style={
3229
+ Object {
3230
+ "alignItems": "center",
3231
+ "borderStyle": "solid",
3232
+ "borderWidth": 0,
3233
+ "boxSizing": "border-box",
3234
+ "display": "flex",
3235
+ "flexDirection": "row",
3236
+ "margin": 0,
3237
+ "minHeight": 0,
3238
+ "minWidth": 0,
3239
+ "padding": 0,
3240
+ "position": "relative",
3241
+ "zIndex": 0,
3242
+ }
3243
+ }
3244
+ >
3245
+ <a
3246
+ className=""
3247
+ href="/foo"
3248
+ onBlur={[Function]}
3249
+ onClick={[Function]}
3250
+ onDragStart={[Function]}
3251
+ onFocus={[Function]}
3252
+ onKeyDown={[Function]}
3253
+ onKeyUp={[Function]}
3254
+ onMouseDown={[Function]}
3255
+ onMouseEnter={[Function]}
3256
+ onMouseLeave={[Function]}
3257
+ onMouseUp={[Function]}
3258
+ onTouchCancel={[Function]}
3259
+ onTouchEnd={[Function]}
3260
+ onTouchStart={[Function]}
3261
+ role="button"
3262
+ style={
3263
+ Object {
3264
+ ":focus": Object {
3265
+ "WebkitTapHighlightColor": "rgba(0,0,0,0)",
3266
+ },
3267
+ "alignItems": "center",
3268
+ "background": "#1865f2",
3269
+ "border": "none",
3270
+ "borderRadius": 4,
3271
+ "boxSizing": "border-box",
3272
+ "color": "#ffffff",
3273
+ "cursor": "pointer",
3274
+ "display": "inline-flex",
3275
+ "height": 40,
3276
+ "justifyContent": "center",
3277
+ "marginRight": 10,
3278
+ "outline": "none",
3279
+ "paddingBottom": 0,
3280
+ "paddingLeft": 16,
3281
+ "paddingRight": 16,
3282
+ "paddingTop": 0,
3283
+ "position": "relative",
3284
+ "textDecoration": "none",
3285
+ "touchAction": "manipulation",
3286
+ "userSelect": "none",
3287
+ }
3288
+ }
3289
+ tabIndex={0}
3290
+ >
3291
+ <span
3292
+ className=""
3293
+ style={
3294
+ Object {
3295
+ "MozOsxFontSmoothing": "grayscale",
3296
+ "WebkitFontSmoothing": "antialiased",
3297
+ "alignItems": "center",
3298
+ "display": "inline-block",
3299
+ "fontFamily": "Lato, \\"Noto Sans\\", sans-serif",
3300
+ "fontSize": 16,
3301
+ "fontWeight": "bold",
3302
+ "lineHeight": "20px",
3303
+ "overflow": "hidden",
3304
+ "pointerEvents": "none",
3305
+ "textOverflow": "ellipsis",
3306
+ "whiteSpace": "nowrap",
3307
+ }
3308
+ }
3309
+ >
3310
+ This button prevents navigation.
3311
+ </span>
3312
+ </a>
3313
+ </div>
3314
+ `;
3315
+
3316
+ exports[`wonder-blocks-button example 12 1`] = `
3088
3317
  <div
3089
3318
  className=""
3090
3319
  style={
@@ -3718,7 +3947,7 @@ exports[`wonder-blocks-button example 11 1`] = `
3718
3947
  </div>
3719
3948
  `;
3720
3949
 
3721
- exports[`wonder-blocks-button example 12 1`] = `
3950
+ exports[`wonder-blocks-button example 13 1`] = `
3722
3951
  <div
3723
3952
  className=""
3724
3953
  style={
@@ -3817,7 +4046,7 @@ exports[`wonder-blocks-button example 12 1`] = `
3817
4046
  </div>
3818
4047
  `;
3819
4048
 
3820
- exports[`wonder-blocks-button example 13 1`] = `
4049
+ exports[`wonder-blocks-button example 14 1`] = `
3821
4050
  <div
3822
4051
  className=""
3823
4052
  style={
@@ -3912,7 +4141,7 @@ exports[`wonder-blocks-button example 13 1`] = `
3912
4141
  </div>
3913
4142
  `;
3914
4143
 
3915
- exports[`wonder-blocks-button example 14 1`] = `
4144
+ exports[`wonder-blocks-button example 15 1`] = `
3916
4145
  <div
3917
4146
  className=""
3918
4147
  style={
@@ -4139,7 +4368,7 @@ exports[`wonder-blocks-button example 14 1`] = `
4139
4368
  </div>
4140
4369
  `;
4141
4370
 
4142
- exports[`wonder-blocks-button example 15 1`] = `
4371
+ exports[`wonder-blocks-button example 16 1`] = `
4143
4372
  <div
4144
4373
  className=""
4145
4374
  style={
@@ -4313,7 +4542,7 @@ exports[`wonder-blocks-button example 15 1`] = `
4313
4542
  </div>
4314
4543
  `;
4315
4544
 
4316
- exports[`wonder-blocks-button example 16 1`] = `
4545
+ exports[`wonder-blocks-button example 17 1`] = `
4317
4546
  <div
4318
4547
  className=""
4319
4548
  style={
@@ -4488,7 +4717,7 @@ exports[`wonder-blocks-button example 16 1`] = `
4488
4717
  </div>
4489
4718
  `;
4490
4719
 
4491
- exports[`wonder-blocks-button example 17 1`] = `
4720
+ exports[`wonder-blocks-button example 18 1`] = `
4492
4721
  <div
4493
4722
  className=""
4494
4723
  style={
@@ -4677,7 +4906,7 @@ exports[`wonder-blocks-button example 17 1`] = `
4677
4906
  </div>
4678
4907
  `;
4679
4908
 
4680
- exports[`wonder-blocks-button example 18 1`] = `
4909
+ exports[`wonder-blocks-button example 19 1`] = `
4681
4910
  <div
4682
4911
  className=""
4683
4912
  style={
@@ -426,7 +426,7 @@ describe("wonder-blocks-button", () => {
426
426
  })
427
427
  }
428
428
  >
429
- Async action, client-side nav
429
+ beforeNav, client-side nav
430
430
  </Button>
431
431
  <Button
432
432
  href="/foo"
@@ -438,7 +438,7 @@ describe("wonder-blocks-button", () => {
438
438
  })
439
439
  }
440
440
  >
441
- Async action, server-side nav
441
+ beforeNav, server-side nav
442
442
  </Button>
443
443
  <Button
444
444
  href="https://google.com"
@@ -451,7 +451,7 @@ describe("wonder-blocks-button", () => {
451
451
  })
452
452
  }
453
453
  >
454
- Async action, open URL in new tab
454
+ beforeNav, open URL in new tab
455
455
  </Button>
456
456
  <Switch>
457
457
  <Route path="/foo">
@@ -482,9 +482,38 @@ describe("wonder-blocks-button", () => {
482
482
  <Button
483
483
  href="/foo"
484
484
  style={styles.button}
485
- onClick={(e) => e.preventDefault()}
485
+ safeWithNav={() =>
486
+ new Promise((resolve, reject) => {
487
+ setTimeout(resolve, 1000);
488
+ })
489
+ }
490
+ >
491
+ safeWithNav, client-side nav
492
+ </Button>
493
+ <Button
494
+ href="/foo"
495
+ style={styles.button}
496
+ skipClientNav={true}
497
+ safeWithNav={() =>
498
+ new Promise((resolve, reject) => {
499
+ setTimeout(resolve, 1000);
500
+ })
501
+ }
502
+ >
503
+ safeWithNav, server-side nav
504
+ </Button>
505
+ <Button
506
+ href="https://google.com"
507
+ target="_blank"
508
+ style={styles.button}
509
+ skipClientNav={true}
510
+ safeWithNav={() =>
511
+ new Promise((resolve, reject) => {
512
+ setTimeout(resolve, 1000);
513
+ })
514
+ }
486
515
  >
487
- This button prevent navigation.
516
+ safeWithNav, open URL in new tab
488
517
  </Button>
489
518
  <Switch>
490
519
  <Route path="/foo">
@@ -499,6 +528,39 @@ describe("wonder-blocks-button", () => {
499
528
  });
500
529
 
501
530
  it("example 11", () => {
531
+ const styles = StyleSheet.create({
532
+ row: {
533
+ flexDirection: "row",
534
+ alignItems: "center",
535
+ },
536
+ button: {
537
+ marginRight: 10,
538
+ },
539
+ }); // NOTE: In actual code you would use BrowserRouter instead
540
+
541
+ const example = (
542
+ <MemoryRouter>
543
+ <View style={styles.row}>
544
+ <Button
545
+ href="/foo"
546
+ style={styles.button}
547
+ onClick={(e) => e.preventDefault()}
548
+ >
549
+ This button prevents navigation.
550
+ </Button>
551
+ <Switch>
552
+ <Route path="/foo">
553
+ <View id="foo">Hello, world!</View>
554
+ </Route>
555
+ </Switch>
556
+ </View>
557
+ </MemoryRouter>
558
+ );
559
+ const tree = renderer.create(example).toJSON();
560
+ expect(tree).toMatchSnapshot();
561
+ });
562
+
563
+ it("example 12", () => {
502
564
  const styles = StyleSheet.create({
503
565
  row: {
504
566
  flexDirection: "row",
@@ -542,7 +604,7 @@ describe("wonder-blocks-button", () => {
542
604
  expect(tree).toMatchSnapshot();
543
605
  });
544
606
 
545
- it("example 12", () => {
607
+ it("example 13", () => {
546
608
  const example = (
547
609
  <View>
548
610
  <form onSubmit={() => alert("the form was submitted")}>
@@ -554,7 +616,7 @@ describe("wonder-blocks-button", () => {
554
616
  expect(tree).toMatchSnapshot();
555
617
  });
556
618
 
557
- it("example 13", () => {
619
+ it("example 14", () => {
558
620
  const example = (
559
621
  <View>
560
622
  <Button>Label</Button>
@@ -564,7 +626,7 @@ describe("wonder-blocks-button", () => {
564
626
  expect(tree).toMatchSnapshot();
565
627
  });
566
628
 
567
- it("example 14", () => {
629
+ it("example 15", () => {
568
630
  const styles = StyleSheet.create({
569
631
  column: {
570
632
  alignItems: "flex-start",
@@ -594,7 +656,7 @@ describe("wonder-blocks-button", () => {
594
656
  expect(tree).toMatchSnapshot();
595
657
  });
596
658
 
597
- it("example 15", () => {
659
+ it("example 16", () => {
598
660
  const styles = StyleSheet.create({
599
661
  row: {
600
662
  flexDirection: "row",
@@ -621,7 +683,7 @@ describe("wonder-blocks-button", () => {
621
683
  expect(tree).toMatchSnapshot();
622
684
  });
623
685
 
624
- it("example 16", () => {
686
+ it("example 17", () => {
625
687
  const styles = StyleSheet.create({
626
688
  row: {
627
689
  flexDirection: "row",
@@ -649,7 +711,7 @@ describe("wonder-blocks-button", () => {
649
711
  expect(tree).toMatchSnapshot();
650
712
  });
651
713
 
652
- it("example 17", () => {
714
+ it("example 18", () => {
653
715
  const styles = StyleSheet.create({
654
716
  row: {
655
717
  flexDirection: "row",
@@ -672,7 +734,7 @@ describe("wonder-blocks-button", () => {
672
734
  expect(tree).toMatchSnapshot();
673
735
  });
674
736
 
675
- it("example 18", () => {
737
+ it("example 19", () => {
676
738
  const styles = StyleSheet.create({
677
739
  row: {
678
740
  flexDirection: "row",
@@ -0,0 +1,92 @@
1
+ import {Meta, Story, Canvas} from "@storybook/addon-docs";
2
+ import {StyleSheet} from "aphrodite";
3
+
4
+ import Button from "@khanacademy/wonder-blocks-button";
5
+ import {View} from "@khanacademy/wonder-blocks-core";
6
+
7
+ <Meta
8
+ title="Navigation/Button/Accessibility"
9
+ component={Button}
10
+ parameters={{
11
+ previewTabs: {
12
+ canvas: {hidden: true},
13
+ },
14
+ viewMode: "docs",
15
+ chromatic: {
16
+ // Disables chromatic testing for these stories.
17
+ disableSnapshot: true,
18
+ },
19
+ }}
20
+ />
21
+
22
+ export const Template = (args) => <Button {...args} />;
23
+
24
+ ## Accessibility
25
+
26
+ ### Labeling
27
+
28
+ `Button` has an accessible label by default. The accessible name is computed from
29
+ the `children` prop. However, `aria-label` should be used when `spinner={true}`
30
+ to let people using screen readers that the action taken by clicking the button
31
+ will take some time to complete.
32
+
33
+ This is an example of a component with an accessible label:
34
+
35
+ <Canvas>
36
+ <Story name="Labeling">
37
+ <View>
38
+ <Button spinner={true} aria-label="The action is being saved...">
39
+ Label
40
+ </Button>
41
+ </View>
42
+ </Story>
43
+ </Canvas>
44
+
45
+ ### Disabled state
46
+
47
+ Buttons do not need an `aria-disabled` attribute, if it also has a `disabled`
48
+ attribute. Users operating the web page through a screen reader may not be able
49
+ to fully evaluate the implied behaviors of the button element itself.
50
+
51
+ <Canvas>
52
+ <Story name="Disabled state">
53
+ <View style={{flexDirection: "row"}}>
54
+ <Button
55
+ style={styles.button}
56
+ onClick={(e) => console.log("Hello, world!")}
57
+ disabled={true}
58
+ >
59
+ Primary
60
+ </Button>
61
+ <Button
62
+ style={styles.button}
63
+ href={"/foo"}
64
+ kind="secondary"
65
+ disabled={true}
66
+ >
67
+ Secondary
68
+ </Button>
69
+ <Button
70
+ style={styles.button}
71
+ onClick={(e) => console.log("Hello, world!")}
72
+ kind="tertiary"
73
+ disabled={true}
74
+ >
75
+ Tertiary
76
+ </Button>
77
+ </View>
78
+ </Story>
79
+ </Canvas>
80
+
81
+ ### References
82
+
83
+ - [Implicit ARIA semantics](https://www.w3.org/TR/wai-aria-1.1/#implicit_semantics)
84
+ - [Document conformance requirements](https://www.w3.org/TR/html-aria/#document-conformance-requirements-for-use-of-aria-attributes-in-html)
85
+
86
+ For more details, see the [Accessibility section](https://www.w3.org/TR/wai-aria-practices-1.1/#button) in w3.org.
87
+
88
+ export const styles = StyleSheet.create({
89
+ button: {
90
+ marginRight: 10,
91
+ },
92
+ });