@khanacademy/wonder-blocks-button 7.0.5 → 7.0.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @khanacademy/wonder-blocks-button
2
2
 
3
+ ## 7.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - c089d35d: Use `semanticColor` in Button. This replaces the use of `color` primitive tokens in favor of semantic color tokens
8
+ - Updated dependencies [8cfaeab0]
9
+ - Updated dependencies [c162abb4]
10
+ - @khanacademy/wonder-blocks-tokens@4.1.0
11
+ - @khanacademy/wonder-blocks-clickable@5.0.7
12
+ - @khanacademy/wonder-blocks-progress-spinner@3.0.7
13
+
14
+ ## 7.0.6
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [0de25cd8]
19
+ - @khanacademy/wonder-blocks-tokens@4.0.0
20
+ - @khanacademy/wonder-blocks-clickable@5.0.6
21
+ - @khanacademy/wonder-blocks-progress-spinner@3.0.6
22
+
3
23
  ## 7.0.5
4
24
 
5
25
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -12,62 +12,199 @@ import { mergeTheme, createThemeContext, ThemeSwitcherContext, useScopedTheme, u
12
12
  import * as tokens from '@khanacademy/wonder-blocks-tokens';
13
13
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
14
14
 
15
+ const {
16
+ semanticColor
17
+ } = tokens;
15
18
  const textUnderlineOffset = tokens.spacing.xxxSmall_4;
16
19
  const theme$1 = {
17
20
  color: {
18
- bg: {
19
- action: {
20
- default: tokens.color.blue,
21
- active: tokens.color.activeBlue,
22
- inverse: tokens.color.fadedBlue
23
- },
24
- critical: {
25
- default: tokens.color.red,
26
- active: tokens.color.activeRed,
27
- inverse: tokens.color.fadedRed
28
- },
29
- primary: {
30
- default: tokens.color.white,
31
- disabled: tokens.color.offBlack32
32
- },
33
- secondary: {
34
- default: "none",
35
- inverse: "none",
36
- focus: tokens.color.white,
37
- active: {
38
- action: tokens.color.fadedBlue,
39
- critical: tokens.color.fadedRed
21
+ filled: {
22
+ progressive: _extends({}, semanticColor.action.filled.progressive, {
23
+ disabled: {
24
+ border: semanticColor.action.disabled.default,
25
+ background: semanticColor.action.disabled.default,
26
+ foreground: semanticColor.action.disabled.secondary
27
+ }
28
+ }),
29
+ progressiveLight: _extends({}, semanticColor.action.outlined.progressive, {
30
+ hover: _extends({}, semanticColor.action.outlined.progressive.hover, {
31
+ border: semanticColor.border.inverse
32
+ }),
33
+ press: _extends({}, semanticColor.action.outlined.progressive.press, {
34
+ border: semanticColor.action.outlined.progressive.press.background
35
+ }),
36
+ disabled: {
37
+ border: semanticColor.action.outlined.progressive.press.background,
38
+ background: semanticColor.action.outlined.progressive.press.background,
39
+ foreground: semanticColor.action.outlined.progressive.default.foreground
40
+ }
41
+ }),
42
+ destructive: _extends({}, semanticColor.action.filled.destructive, {
43
+ disabled: {
44
+ border: semanticColor.action.disabled.default,
45
+ background: semanticColor.action.disabled.default,
46
+ foreground: semanticColor.action.disabled.secondary
47
+ }
48
+ }),
49
+ destructiveLight: _extends({}, semanticColor.action.outlined.destructive, {
50
+ hover: _extends({}, semanticColor.action.outlined.progressive.hover, {
51
+ border: semanticColor.border.inverse
52
+ }),
53
+ press: _extends({}, semanticColor.action.outlined.destructive.press, {
54
+ border: semanticColor.action.outlined.destructive.press.background
55
+ }),
56
+ disabled: {
57
+ border: semanticColor.action.outlined.destructive.press.background,
58
+ background: semanticColor.action.outlined.destructive.press.background,
59
+ foreground: semanticColor.action.outlined.destructive.default.foreground
60
+ }
61
+ })
62
+ },
63
+ outlined: {
64
+ progressive: _extends({}, semanticColor.action.outlined.progressive, {
65
+ default: _extends({}, semanticColor.action.outlined.progressive.default, {
66
+ background: "transparent"
67
+ }),
68
+ hover: _extends({}, semanticColor.action.outlined.progressive.hover, {
69
+ background: "transparent",
70
+ icon: "transparent"
71
+ }),
72
+ disabled: {
73
+ border: semanticColor.action.disabled.default,
74
+ background: semanticColor.action.outlined.progressive.press.background,
75
+ foreground: semanticColor.text.disabled
76
+ }
77
+ }),
78
+ progressiveLight: {
79
+ default: {
80
+ border: tokens.color.white64,
81
+ background: "transparent",
82
+ foreground: semanticColor.text.inverse
83
+ },
84
+ hover: {
85
+ border: semanticColor.border.inverse,
86
+ background: "transparent",
87
+ foreground: semanticColor.text.inverse,
88
+ icon: "transparent"
89
+ },
90
+ press: {
91
+ border: tokens.color.fadedBlue,
92
+ background: semanticColor.action.filled.progressive.press.background,
93
+ foreground: semanticColor.text.inverse
94
+ },
95
+ disabled: {
96
+ border: semanticColor.action.outlined.progressive.press.background,
97
+ background: semanticColor.action.outlined.progressive.press.background,
98
+ foreground: tokens.color.white50
40
99
  }
41
100
  },
42
- icon: {
43
- secondaryHover: "transparent"
101
+ destructive: _extends({}, semanticColor.action.outlined.destructive, {
102
+ hover: _extends({}, semanticColor.action.outlined.destructive.hover, {
103
+ background: "transparent",
104
+ icon: "transparent"
105
+ }),
106
+ disabled: {
107
+ border: semanticColor.action.disabled.default,
108
+ background: semanticColor.action.outlined.destructive.press.background,
109
+ foreground: semanticColor.text.disabled
110
+ }
111
+ }),
112
+ destructiveLight: {
113
+ default: {
114
+ border: tokens.color.white64,
115
+ background: "transparent",
116
+ foreground: semanticColor.text.inverse
117
+ },
118
+ hover: {
119
+ border: semanticColor.border.inverse,
120
+ background: "transparent",
121
+ foreground: semanticColor.text.inverse,
122
+ icon: "transparent"
123
+ },
124
+ press: {
125
+ border: tokens.color.fadedRed,
126
+ background: semanticColor.action.filled.destructive.press.background,
127
+ foreground: semanticColor.text.inverse
128
+ },
129
+ disabled: {
130
+ border: semanticColor.action.outlined.destructive.press.background,
131
+ background: semanticColor.action.outlined.destructive.press.background,
132
+ foreground: tokens.color.white50
133
+ }
44
134
  }
45
135
  },
46
136
  text: {
47
- disabled: tokens.color.offBlack32,
48
- inverse: tokens.color.white,
49
- primary: {
50
- disabled: tokens.color.white64
51
- },
52
- secondary: {
53
- inverse: tokens.color.white50
137
+ progressive: {
138
+ default: {
139
+ background: "transparent",
140
+ foreground: semanticColor.action.outlined.progressive.default.foreground
141
+ },
142
+ hover: {
143
+ border: semanticColor.action.outlined.progressive.hover.border
144
+ },
145
+ press: {
146
+ foreground: semanticColor.action.outlined.progressive.press.foreground
147
+ },
148
+ disabled: {
149
+ border: semanticColor.action.disabled.default,
150
+ foreground: semanticColor.text.disabled
151
+ }
54
152
  },
55
- icon: {
56
- secondaryHover: "inherit"
57
- }
58
- },
59
- border: {
60
- disabled: tokens.color.offBlack32,
61
- primary: {
62
- inverse: tokens.color.white
153
+ progressiveLight: {
154
+ default: {
155
+ border: tokens.color.white64,
156
+ background: "transparent",
157
+ foreground: semanticColor.text.inverse
158
+ },
159
+ hover: {
160
+ border: semanticColor.border.inverse,
161
+ background: "transparent",
162
+ foreground: semanticColor.text.inverse
163
+ },
164
+ press: {
165
+ border: semanticColor.border.inverse,
166
+ foreground: tokens.color.fadedBlue
167
+ },
168
+ disabled: {
169
+ border: semanticColor.action.outlined.progressive.press.background,
170
+ foreground: tokens.color.white50
171
+ }
63
172
  },
64
- secondary: {
65
- action: tokens.color.offBlack50,
66
- critical: tokens.color.offBlack50,
67
- inverse: tokens.color.white50
173
+ destructive: {
174
+ default: {
175
+ background: "transparent",
176
+ foreground: semanticColor.action.outlined.destructive.default.foreground
177
+ },
178
+ hover: {
179
+ border: semanticColor.action.outlined.destructive.hover.border
180
+ },
181
+ press: {
182
+ foreground: semanticColor.action.outlined.destructive.press.foreground
183
+ },
184
+ disabled: {
185
+ border: semanticColor.action.disabled.default,
186
+ foreground: semanticColor.text.disabled
187
+ }
68
188
  },
69
- tertiary: {
70
- inverse: tokens.color.white
189
+ destructiveLight: {
190
+ default: {
191
+ border: tokens.color.white64,
192
+ background: "transparent",
193
+ foreground: semanticColor.text.inverse
194
+ },
195
+ hover: {
196
+ border: semanticColor.border.inverse,
197
+ background: "transparent",
198
+ foreground: semanticColor.text.inverse
199
+ },
200
+ press: {
201
+ border: semanticColor.border.inverse,
202
+ foreground: tokens.color.fadedRed
203
+ },
204
+ disabled: {
205
+ border: semanticColor.action.outlined.destructive.press.background,
206
+ foreground: tokens.color.white50
207
+ }
71
208
  }
72
209
  }
73
210
  },
@@ -78,7 +215,8 @@ const theme$1 = {
78
215
  disabled: tokens.border.width.thin
79
216
  },
80
217
  offset: {
81
- primary: tokens.spacing.xxxxSmall_2
218
+ primary: tokens.spacing.xxxxSmall_2,
219
+ secondary: -tokens.spacing.xxxxSmall_2
82
220
  },
83
221
  radius: {
84
222
  default: tokens.border.radius.medium_4,
@@ -128,30 +266,37 @@ const theme$1 = {
128
266
  }
129
267
  };
130
268
 
269
+ const secondaryBgColor = tokens.color.offWhite;
131
270
  const theme = mergeTheme(theme$1, {
132
271
  color: {
133
- bg: {
134
- secondary: {
135
- default: tokens.color.offWhite,
136
- active: {
137
- action: tokens.color.fadedBlue8,
138
- critical: tokens.color.fadedRed8
272
+ outlined: {
273
+ progressive: {
274
+ default: {
275
+ border: tokens.color.fadedBlue,
276
+ background: secondaryBgColor
139
277
  },
140
- focus: tokens.color.offWhite
278
+ hover: {
279
+ background: secondaryBgColor,
280
+ icon: tokens.color.fadedBlue16,
281
+ foreground: tokens.semanticColor.action.outlined.progressive.default.foreground
282
+ },
283
+ press: {
284
+ background: tokens.color.fadedBlue8
285
+ }
141
286
  },
142
- icon: {
143
- secondaryHover: tokens.color.fadedBlue16
144
- }
145
- },
146
- border: {
147
- secondary: {
148
- action: tokens.color.fadedBlue,
149
- critical: tokens.color.fadedRed
150
- }
151
- },
152
- text: {
153
- icon: {
154
- secondaryHover: tokens.color.blue
287
+ destructive: {
288
+ default: {
289
+ border: tokens.color.fadedRed,
290
+ background: secondaryBgColor
291
+ },
292
+ hover: {
293
+ background: secondaryBgColor,
294
+ icon: tokens.color.fadedRed16,
295
+ foreground: tokens.semanticColor.action.outlined.destructive.default.foreground
296
+ },
297
+ press: {
298
+ background: tokens.color.fadedRed8
299
+ }
155
300
  }
156
301
  }
157
302
  },
@@ -284,7 +429,7 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
284
429
  testId: `${testId || "button"}-spinner`
285
430
  }), endIcon && React.createElement(View, {
286
431
  testId: testId ? `${testId}-end-icon-wrapper` : undefined,
287
- style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && sharedStyles.iconWrapperSecondaryHovered]
432
+ style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
288
433
  }, React.createElement(ButtonIcon, {
289
434
  size: iconSize,
290
435
  icon: endIcon,
@@ -384,10 +529,6 @@ const themedSharedStyles = theme => ({
384
529
  padding: theme.padding.xsmall,
385
530
  minWidth: "auto"
386
531
  },
387
- iconWrapperSecondaryHovered: {
388
- backgroundColor: theme.color.bg.icon.secondaryHover,
389
- color: theme.color.text.icon.secondaryHover
390
- },
391
532
  endIconWrapper: {
392
533
  marginLeft: theme.padding.small,
393
534
  marginRight: theme.margin.icon.offset
@@ -398,32 +539,33 @@ const themedSharedStyles = theme => ({
398
539
  });
399
540
  const styles = {};
400
541
  const _generateStyles = (buttonColor = "default", kind, light, size, theme, themeName) => {
401
- const color = buttonColor === "destructive" ? theme.color.bg.critical.default : theme.color.bg.action.default;
402
- const buttonType = `${color}-${kind}-${light}-${size}-${themeName}`;
542
+ const buttonType = `${buttonColor}-${kind}-${light}-${size}-${themeName}`;
403
543
  if (styles[buttonType]) {
404
544
  return styles[buttonType];
405
545
  }
406
- const fadedColor = buttonColor === "destructive" ? theme.color.bg.critical.inverse : theme.color.bg.action.inverse;
407
- const activeColor = buttonColor === "destructive" ? theme.color.bg.critical.active : theme.color.bg.action.active;
408
546
  const padding = size === "large" ? theme.padding.xLarge : theme.padding.large;
547
+ const colorToAction = light ? buttonColor === "destructive" ? "destructiveLight" : "progressiveLight" : buttonColor === "destructive" ? "destructive" : "progressive";
409
548
  let newStyles = {};
410
549
  if (kind === "primary") {
550
+ const themeColorAction = theme.color.filled[colorToAction];
411
551
  const focusStyling = {
412
- outlineColor: light ? theme.color.bg.primary.default : color,
552
+ outlineColor: themeColorAction.hover.border,
413
553
  outlineOffset: theme.border.offset.primary,
414
554
  outlineStyle: "solid",
415
555
  outlineWidth: theme.border.width.focused
416
556
  };
417
557
  const activePressedStyling = {
418
- background: light ? fadedColor : activeColor,
419
- outlineColor: light ? fadedColor : activeColor
558
+ background: themeColorAction.press.background,
559
+ outlineColor: themeColorAction.press.border,
560
+ outlineOffset: theme.border.offset.primary,
561
+ outlineStyle: "solid",
562
+ outlineWidth: theme.border.width.focused
420
563
  };
421
564
  newStyles = {
422
565
  default: {
423
- background: light ? theme.color.bg.primary.default : color,
424
- color: light ? color : theme.color.text.inverse,
425
- paddingLeft: padding,
426
- paddingRight: padding,
566
+ background: themeColorAction.default.background,
567
+ color: themeColorAction.default.foreground,
568
+ paddingInline: padding,
427
569
  [":hover:not([aria-disabled=true])"]: focusStyling,
428
570
  [":focus-visible:not([aria-disabled=true])"]: focusStyling,
429
571
  [":active:not([aria-disabled=true])"]: activePressedStyling
@@ -431,41 +573,38 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
431
573
  focused: focusStyling,
432
574
  pressed: activePressedStyling,
433
575
  disabled: {
434
- background: light ? fadedColor : theme.color.bg.primary.disabled,
435
- color: light ? color : theme.color.text.primary.disabled,
576
+ background: themeColorAction.disabled.background,
577
+ color: themeColorAction.disabled.foreground,
436
578
  cursor: "default",
437
579
  ":focus-visible": _extends({}, focusStyling, {
438
- outlineColor: light ? fadedColor : theme.color.bg.primary.disabled
580
+ outlineColor: themeColorAction.disabled.border
439
581
  })
440
582
  }
441
583
  };
442
584
  } else if (kind === "secondary") {
443
- const secondaryBorderColor = buttonColor === "destructive" ? theme.color.border.secondary.critical : theme.color.border.secondary.action;
444
- const secondaryActiveColor = buttonColor === "destructive" ? theme.color.bg.secondary.active.critical : theme.color.bg.secondary.active.action;
585
+ const themeColorAction = theme.color.outlined[colorToAction];
445
586
  const focusStyling = {
446
- background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.focus,
447
- borderColor: "transparent",
448
- outlineColor: light ? theme.color.border.primary.inverse : color,
587
+ background: themeColorAction.hover.background,
588
+ outlineColor: themeColorAction.hover.border,
449
589
  outlineStyle: "solid",
590
+ outlineOffset: theme.border.offset.secondary,
450
591
  outlineWidth: theme.border.width.focused
451
592
  };
452
593
  const activePressedStyling = {
453
- background: light ? activeColor : secondaryActiveColor,
454
- color: light ? fadedColor : activeColor,
455
- borderColor: "transparent",
456
- outlineColor: light ? fadedColor : activeColor,
594
+ background: themeColorAction.press.background,
595
+ color: themeColorAction.press.foreground,
596
+ outlineColor: themeColorAction.press.border,
457
597
  outlineStyle: "solid",
458
598
  outlineWidth: theme.border.width.focused
459
599
  };
460
600
  newStyles = {
461
601
  default: {
462
- background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.default,
463
- color: light ? theme.color.text.inverse : color,
464
- borderColor: light ? theme.color.border.secondary.inverse : secondaryBorderColor,
602
+ background: themeColorAction.default.background,
603
+ color: themeColorAction.default.foreground,
604
+ borderColor: themeColorAction.default.border,
465
605
  borderStyle: "solid",
466
606
  borderWidth: theme.border.width.secondary,
467
- paddingLeft: padding,
468
- paddingRight: padding,
607
+ paddingInline: padding,
469
608
  [":hover:not([aria-disabled=true])"]: focusStyling,
470
609
  [":focus-visible:not([aria-disabled=true])"]: focusStyling,
471
610
  [":active:not([aria-disabled=true])"]: activePressedStyling
@@ -473,35 +612,42 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
473
612
  focused: focusStyling,
474
613
  pressed: activePressedStyling,
475
614
  disabled: {
476
- color: light ? theme.color.text.secondary.inverse : theme.color.text.disabled,
477
- outlineColor: light ? fadedColor : theme.color.border.disabled,
615
+ color: themeColorAction.disabled.foreground,
616
+ borderColor: themeColorAction.disabled.border,
478
617
  cursor: "default",
479
618
  ":focus-visible": {
480
- outlineColor: light ? theme.color.border.secondary.inverse : theme.color.border.disabled,
619
+ borderColor: themeColorAction.disabled.border,
620
+ outlineColor: themeColorAction.disabled.border,
621
+ outlineOffset: theme.border.offset.secondary,
481
622
  outlineStyle: "solid",
482
623
  outlineWidth: theme.border.width.disabled
483
624
  }
625
+ },
626
+ iconWrapperHovered: {
627
+ backgroundColor: themeColorAction.hover.icon,
628
+ color: themeColorAction.hover.foreground
484
629
  }
485
630
  };
486
631
  } else if (kind === "tertiary") {
632
+ const themeColorAction = theme.color.text[colorToAction];
487
633
  const focusStyling = {
488
634
  outlineStyle: "solid",
489
- outlineColor: light ? theme.color.border.tertiary.inverse : color,
635
+ borderColor: "transparent",
636
+ outlineColor: themeColorAction.hover.border,
490
637
  outlineWidth: theme.border.width.focused,
491
638
  borderRadius: theme.border.radius.default
492
639
  };
493
640
  const activePressedStyling = {
494
- color: light ? fadedColor : activeColor,
641
+ color: themeColorAction.press.foreground,
495
642
  textDecoration: "underline",
496
643
  textDecorationThickness: theme.size.underline.active,
497
644
  textUnderlineOffset: theme.font.offset.default
498
645
  };
499
646
  newStyles = {
500
647
  default: {
501
- background: "none",
502
- color: light ? theme.color.text.inverse : color,
503
- paddingLeft: 0,
504
- paddingRight: 0,
648
+ background: themeColorAction.default.background,
649
+ color: themeColorAction.default.foreground,
650
+ paddingInline: 0,
505
651
  [":hover:not([aria-disabled=true])"]: {
506
652
  textUnderlineOffset: theme.font.offset.default,
507
653
  textDecoration: "underline",
@@ -513,11 +659,16 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
513
659
  focused: focusStyling,
514
660
  pressed: activePressedStyling,
515
661
  disabled: {
516
- color: light ? fadedColor : theme.color.text.disabled,
517
- cursor: "default"
662
+ color: themeColorAction.disabled.foreground,
663
+ cursor: "default",
664
+ ":focus-visible": {
665
+ outlineColor: themeColorAction.disabled.border,
666
+ outlineStyle: "solid",
667
+ outlineWidth: theme.border.width.disabled
668
+ }
518
669
  },
519
670
  disabledFocus: {
520
- outlineColor: light ? theme.color.border.tertiary.inverse : theme.color.border.disabled
671
+ outlineColor: themeColorAction.disabled.border
521
672
  }
522
673
  };
523
674
  } else {