@khanacademy/wonder-blocks-button 8.0.3 → 9.0.0

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,11 @@
1
1
  # @khanacademy/wonder-blocks-button
2
2
 
3
+ ## 9.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 0b47477: Removes the `light` prop as it is no longer maintained. Simplifes pseudo-states (e.g. `:hover`, `:active`).
8
+
3
9
  ## 8.0.3
4
10
 
5
11
  ### Patch Changes
@@ -6,4 +6,4 @@ import { ButtonThemeContract } from "../themes/themed-button";
6
6
  type Props = SharedProps & ChildrenProps & ClickableState;
7
7
  declare const ButtonCore: React.ForwardRefExoticComponent<Props & React.RefAttributes<typeof Link | HTMLButtonElement | HTMLAnchorElement>>;
8
8
  export default ButtonCore;
9
- export declare const _generateStyles: (buttonColor: string | undefined, kind: "primary" | "secondary" | "tertiary", light: boolean, size: "large" | "medium" | "small", theme: ButtonThemeContract, themeName: string) => any;
9
+ export declare const _generateStyles: (buttonColor: string | undefined, kind: "primary" | "secondary" | "tertiary", size: "large" | "medium" | "small", theme: ButtonThemeContract, themeName: string) => any;
@@ -27,8 +27,6 @@ Partial<Omit<AriaProps, "aria-disabled">> & {
27
27
  * If true, replaces the contents with a spinner.
28
28
  *
29
29
  * Note: setting this prop to `true` will disable the button.
30
- *
31
- * TODO(kevinb): support spinner + light once we have designs
32
30
  */
33
31
  spinner?: boolean;
34
32
  /**
@@ -45,13 +43,6 @@ Partial<Omit<AriaProps, "aria-disabled">> & {
45
43
  * - Tertiary buttons have no background or border
46
44
  */
47
45
  kind?: "primary" | "secondary" | "tertiary";
48
- /**
49
- * Whether the button is on a dark/colored background.
50
- *
51
- * Sets primary button background color to white, and secondary and
52
- * tertiary button title to color.
53
- */
54
- light?: boolean;
55
46
  /**
56
47
  * The size of the button. "medium" = height: 40; "small" = height: 32;
57
48
  * "large" = height: 56;
package/dist/es/index.js CHANGED
@@ -18,184 +18,42 @@ const textUnderlineOffset = tokens.spacing.xxxSmall_4;
18
18
  const focusOutline = {
19
19
  border: semanticColor.focus.outer
20
20
  };
21
- const focusOutlineLight = {
22
- border: semanticColor.border.inverse
23
- };
24
21
  const theme$1 = {
25
22
  color: {
26
23
  primary: {
27
24
  progressive: _extends({}, semanticColor.action.primary.progressive, {
28
- focus: focusOutline,
29
- disabled: {
30
- background: semanticColor.action.primary.disabled.background,
31
- foreground: semanticColor.action.primary.disabled.foreground
32
- }
33
- }),
34
- progressiveLight: _extends({}, semanticColor.action.secondary.progressive, {
35
- default: _extends({}, semanticColor.action.secondary.progressive.default, {
36
- background: semanticColor.surface.primary
37
- }),
38
- focus: focusOutlineLight,
39
- hover: _extends({}, semanticColor.action.secondary.progressive.hover, {
40
- border: semanticColor.border.inverse,
41
- backgrond: semanticColor.surface.primary
42
- }),
43
- press: _extends({}, semanticColor.action.secondary.progressive.press, {
44
- border: semanticColor.action.secondary.progressive.press.background
45
- }),
46
- disabled: {
47
- background: semanticColor.action.secondary.progressive.press.background,
48
- foreground: semanticColor.action.secondary.progressive.default.foreground
49
- }
25
+ focus: focusOutline
50
26
  }),
51
27
  destructive: _extends({}, semanticColor.action.primary.destructive, {
52
- focus: focusOutline,
53
- disabled: {
54
- background: semanticColor.action.primary.disabled.background,
55
- foreground: semanticColor.action.primary.disabled.foreground
56
- }
28
+ focus: focusOutline
57
29
  }),
58
- destructiveLight: _extends({}, semanticColor.action.secondary.destructive, {
59
- default: _extends({}, semanticColor.action.secondary.destructive.default, {
60
- background: semanticColor.surface.primary
61
- }),
62
- focus: focusOutlineLight,
63
- hover: _extends({}, semanticColor.action.secondary.progressive.hover, {
64
- border: semanticColor.border.inverse,
65
- background: semanticColor.surface.primary
66
- }),
67
- press: _extends({}, semanticColor.action.secondary.destructive.press, {
68
- border: semanticColor.action.secondary.destructive.press.background
69
- }),
70
- disabled: {
71
- background: semanticColor.action.secondary.destructive.press.background,
72
- foreground: semanticColor.action.secondary.destructive.default.foreground
73
- }
74
- })
30
+ disabled: semanticColor.action.primary.disabled
75
31
  },
76
32
  secondary: {
77
33
  progressive: _extends({}, semanticColor.action.secondary.progressive, {
78
34
  focus: focusOutline,
79
35
  hover: _extends({}, semanticColor.action.secondary.progressive.hover, {
80
36
  icon: "transparent"
81
- }),
82
- disabled: {
83
- border: semanticColor.action.primary.disabled.border,
84
- foreground: semanticColor.action.secondary.disabled.foreground
85
- }
37
+ })
86
38
  }),
87
- progressiveLight: {
88
- default: {
89
- border: tokens.color.white64,
90
- background: "transparent",
91
- foreground: semanticColor.text.inverse
92
- },
93
- focus: focusOutlineLight,
94
- hover: {
95
- border: semanticColor.border.inverse,
96
- background: "transparent",
97
- foreground: semanticColor.text.inverse,
98
- icon: "transparent"
99
- },
100
- press: {
101
- border: tokens.color.fadedBlue,
102
- background: semanticColor.action.primary.progressive.press.background,
103
- foreground: semanticColor.text.inverse
104
- },
105
- disabled: {
106
- border: semanticColor.action.secondary.progressive.press.background,
107
- background: semanticColor.action.secondary.progressive.press.background,
108
- foreground: tokens.color.white50
109
- }
110
- },
111
39
  destructive: _extends({}, semanticColor.action.secondary.destructive, {
112
40
  focus: focusOutline,
113
41
  hover: _extends({}, semanticColor.action.secondary.destructive.hover, {
114
42
  icon: "transparent"
115
- }),
116
- disabled: {
117
- border: semanticColor.action.primary.disabled.border,
118
- foreground: semanticColor.action.secondary.disabled.foreground
119
- }
43
+ })
120
44
  }),
121
- destructiveLight: {
122
- default: {
123
- border: tokens.color.white64,
124
- background: "transparent",
125
- foreground: semanticColor.text.inverse
126
- },
127
- focus: focusOutlineLight,
128
- hover: {
129
- border: semanticColor.border.inverse,
130
- background: "transparent",
131
- foreground: semanticColor.text.inverse,
132
- icon: "transparent"
133
- },
134
- press: {
135
- border: tokens.color.fadedRed,
136
- background: semanticColor.action.primary.destructive.press.background,
137
- foreground: semanticColor.text.inverse
138
- },
139
- disabled: {
140
- border: semanticColor.action.secondary.destructive.press.background,
141
- background: semanticColor.action.secondary.destructive.press.background,
142
- foreground: tokens.color.white50
143
- }
144
- }
45
+ disabled: _extends({}, semanticColor.action.secondary.disabled, {
46
+ border: semanticColor.action.primary.disabled.border
47
+ })
145
48
  },
146
49
  tertiary: {
147
50
  progressive: _extends({}, semanticColor.action.tertiary.progressive, {
148
- focus: focusOutline,
149
- disabled: {
150
- foreground: semanticColor.action.tertiary.disabled.foreground
151
- }
51
+ focus: focusOutline
152
52
  }),
153
- progressiveLight: {
154
- default: {
155
- border: tokens.color.white64,
156
- background: "transparent",
157
- foreground: semanticColor.text.inverse
158
- },
159
- focus: focusOutlineLight,
160
- hover: {
161
- border: semanticColor.border.inverse,
162
- background: "transparent",
163
- foreground: semanticColor.text.inverse
164
- },
165
- press: {
166
- border: semanticColor.border.inverse,
167
- foreground: tokens.color.fadedBlue
168
- },
169
- disabled: {
170
- foreground: tokens.color.white50
171
- }
172
- },
173
53
  destructive: _extends({}, semanticColor.action.tertiary.destructive, {
174
- focus: focusOutline,
175
- disabled: {
176
- foreground: semanticColor.action.tertiary.disabled.foreground
177
- }
54
+ focus: focusOutline
178
55
  }),
179
- destructiveLight: {
180
- default: {
181
- border: tokens.color.white64,
182
- background: "transparent",
183
- foreground: semanticColor.text.inverse
184
- },
185
- focus: focusOutlineLight,
186
- hover: {
187
- border: semanticColor.border.inverse,
188
- background: "transparent",
189
- foreground: semanticColor.text.inverse
190
- },
191
- press: {
192
- border: semanticColor.border.inverse,
193
- foreground: tokens.color.fadedRed
194
- },
195
- disabled: {
196
- foreground: tokens.color.white50
197
- }
198
- }
56
+ disabled: semanticColor.action.tertiary.disabled
199
57
  }
200
58
  },
201
59
  border: {
@@ -352,7 +210,7 @@ function ButtonIcon({
352
210
  }
353
211
  }
354
212
 
355
- const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
213
+ const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
356
214
  const StyledA = addStyle("a");
357
215
  const StyledButton = addStyle("button");
358
216
  const StyledLink = addStyle(Link);
@@ -373,7 +231,6 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
373
231
  href = undefined,
374
232
  kind = "primary",
375
233
  labelStyle,
376
- light = false,
377
234
  pressed,
378
235
  size = "medium",
379
236
  style,
@@ -385,9 +242,9 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
385
242
  id
386
243
  } = props,
387
244
  restProps = _objectWithoutPropertiesLoose(props, _excluded$1);
388
- const buttonStyles = _generateStyles(color, kind, light, size, theme, themeName);
245
+ const buttonStyles = _generateStyles(color, kind, size, theme, themeName);
389
246
  const disabled = spinner || disabledProp;
390
- const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, startIcon && sharedStyles.withStartIcon, endIcon && sharedStyles.withEndIcon, buttonStyles.default, disabled && buttonStyles.disabled, kind !== "tertiary" && !disabled && (pressed ? buttonStyles.pressed : focused && buttonStyles.focused), kind === "tertiary" && !pressed && focused && [buttonStyles.focused, disabled && buttonStyles.disabledFocus], size === "small" && sharedStyles.small, size === "large" && sharedStyles.large];
247
+ const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, startIcon && sharedStyles.withStartIcon, endIcon && sharedStyles.withEndIcon, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.pressed : focused && buttonStyles.focused), size === "small" && sharedStyles.small, size === "large" && sharedStyles.large];
391
248
  const commonProps = _extends({
392
249
  "data-testid": testId,
393
250
  id: id,
@@ -419,7 +276,7 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
419
276
  testId: `${testId || "button"}-spinner`
420
277
  }), endIcon && React.createElement(View, {
421
278
  testId: testId ? `${testId}-end-icon-wrapper` : undefined,
422
- style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
279
+ style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, !disabled && (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
423
280
  }, React.createElement(ButtonIcon, {
424
281
  size: iconSize,
425
282
  icon: endIcon,
@@ -526,13 +383,19 @@ const themedSharedStyles = theme => ({
526
383
  }
527
384
  });
528
385
  const styles = {};
529
- const _generateStyles = (buttonColor = "default", kind, light, size, theme, themeName) => {
530
- const buttonType = `${buttonColor}-${kind}-${light}-${size}-${themeName}`;
386
+ const _generateStyles = (buttonColor = "default", kind, size, theme, themeName) => {
387
+ const buttonType = `${buttonColor}-${kind}-${size}-${themeName}`;
531
388
  if (styles[buttonType]) {
532
389
  return styles[buttonType];
533
390
  }
534
391
  const padding = size === "large" ? theme.padding.xLarge : theme.padding.large;
535
- const colorToAction = light ? buttonColor === "destructive" ? "destructiveLight" : "progressiveLight" : buttonColor === "destructive" ? "destructive" : "progressive";
392
+ const colorToAction = buttonColor === "destructive" ? "destructive" : "progressive";
393
+ const disabledState = theme.color[kind].disabled;
394
+ const disabledStateStyles = {
395
+ borderColor: disabledState.border,
396
+ background: disabledState.background,
397
+ color: disabledState.foreground
398
+ };
536
399
  let newStyles = {};
537
400
  if (kind === "primary") {
538
401
  const themeColorAction = theme.color.primary[colorToAction];
@@ -559,18 +422,22 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
559
422
  background: themeColorAction.default.background,
560
423
  color: themeColorAction.default.foreground,
561
424
  paddingInline: padding,
562
- [":hover:not([aria-disabled=true])"]: hoverStyling,
563
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
564
- [":active:not([aria-disabled=true])"]: activePressedStyling
425
+ ":hover": hoverStyling,
426
+ ":focus-visible": focusStyling,
427
+ ":active": activePressedStyling
565
428
  },
566
429
  focused: focusStyling,
567
430
  pressed: activePressedStyling,
568
- disabled: {
569
- background: themeColorAction.disabled.background,
570
- color: themeColorAction.disabled.foreground,
571
- cursor: "default",
431
+ disabled: _extends({}, disabledStateStyles, {
432
+ cursor: "not-allowed",
433
+ ":hover": _extends({}, disabledStateStyles, {
434
+ outline: "none"
435
+ }),
436
+ ":active": _extends({}, disabledStateStyles, {
437
+ outline: "none"
438
+ }),
572
439
  ":focus-visible": focusStyling
573
- }
440
+ })
574
441
  };
575
442
  } else if (kind === "secondary") {
576
443
  const themeColorAction = theme.color.secondary[colorToAction];
@@ -584,7 +451,7 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
584
451
  outlineColor: themeColorAction.focus.border
585
452
  });
586
453
  const hoverStyling = _extends({}, sharedFocusHoverStyling, {
587
- outlineColor: themeColorAction.hover.border
454
+ borderColor: themeColorAction.hover.border
588
455
  });
589
456
  const activePressedStyling = {
590
457
  background: themeColorAction.press.background,
@@ -601,18 +468,22 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
601
468
  borderStyle: "solid",
602
469
  borderWidth: theme.border.width.secondary,
603
470
  paddingInline: padding,
604
- [":hover:not([aria-disabled=true])"]: hoverStyling,
605
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
606
- [":active:not([aria-disabled=true])"]: activePressedStyling
471
+ ":hover": hoverStyling,
472
+ ":focus-visible": focusStyling,
473
+ ":active": activePressedStyling
607
474
  },
608
475
  focused: focusStyling,
609
476
  pressed: activePressedStyling,
610
- disabled: {
611
- color: themeColorAction.disabled.foreground,
612
- borderColor: themeColorAction.disabled.border,
613
- cursor: "default",
477
+ disabled: _extends({}, disabledStateStyles, {
478
+ cursor: "not-allowed",
479
+ ":hover": _extends({}, disabledStateStyles, {
480
+ outline: "none"
481
+ }),
482
+ ":active": _extends({}, disabledStateStyles, {
483
+ outline: "none"
484
+ }),
614
485
  ":focus-visible": focusStyling
615
- },
486
+ }),
616
487
  iconWrapperHovered: {
617
488
  backgroundColor: themeColorAction.hover.icon,
618
489
  color: themeColorAction.hover.foreground
@@ -633,27 +504,33 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
633
504
  textDecorationThickness: theme.size.underline.active,
634
505
  textUnderlineOffset: theme.font.offset.default
635
506
  };
507
+ const sharedDisabledStyling = _extends({}, disabledStateStyles, {
508
+ textDecoration: "none",
509
+ textDecorationThickness: "unset",
510
+ textUnderlineOffset: "unset",
511
+ outline: "none"
512
+ });
636
513
  newStyles = {
637
514
  default: {
638
515
  background: themeColorAction.default.background,
639
516
  color: themeColorAction.default.foreground,
640
517
  paddingInline: 0,
641
- [":hover:not([aria-disabled=true])"]: {
518
+ ":hover": {
642
519
  textUnderlineOffset: theme.font.offset.default,
643
520
  textDecoration: "underline",
644
521
  textDecorationThickness: theme.size.underline.hover
645
522
  },
646
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
647
- [":active:not([aria-disabled=true])"]: activePressedStyling
523
+ ":focus-visible": focusStyling,
524
+ ":active": activePressedStyling
648
525
  },
649
526
  focused: focusStyling,
650
527
  pressed: activePressedStyling,
651
- disabled: {
652
- color: themeColorAction.disabled.foreground,
653
- cursor: "default",
528
+ disabled: _extends({}, disabledStateStyles, {
529
+ cursor: "not-allowed",
530
+ ":hover": sharedDisabledStyling,
531
+ ":active": sharedDisabledStyling,
654
532
  ":focus-visible": focusStyling
655
- },
656
- disabledFocus: focusStyling
533
+ })
657
534
  };
658
535
  } else {
659
536
  throw new Error("Button kind not recognized");
@@ -662,7 +539,7 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
662
539
  return styles[buttonType];
663
540
  };
664
541
 
665
- const _excluded = ["href", "type", "children", "skipClientNav", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel", "color", "kind", "light", "size", "disabled", "spinner"];
542
+ const _excluded = ["href", "type", "children", "skipClientNav", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel", "color", "kind", "size", "disabled", "spinner"];
666
543
  const Button = React.forwardRef(function Button(props, ref) {
667
544
  const {
668
545
  href = undefined,
@@ -677,7 +554,6 @@ const Button = React.forwardRef(function Button(props, ref) {
677
554
  rel,
678
555
  color = "default",
679
556
  kind = "primary",
680
- light = false,
681
557
  size = "medium",
682
558
  disabled = false,
683
559
  spinner = false
@@ -691,7 +567,6 @@ const Button = React.forwardRef(function Button(props, ref) {
691
567
  spinner: spinner || state.waiting,
692
568
  color: color,
693
569
  kind: kind,
694
- light: light,
695
570
  size: size,
696
571
  skipClientNav: skipClientNav,
697
572
  href: href,