@khanacademy/wonder-blocks-button 6.0.1 → 6.1.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
+ ## 6.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d73f6988: Add Khanmigo theming support to buttons with icons
8
+
3
9
  ## 6.0.1
4
10
 
5
11
  ### Patch Changes
@@ -2,6 +2,8 @@ import * as React from "react";
2
2
  import { Link } from "react-router-dom";
3
3
  import type { ChildrenProps, ClickableState } from "@khanacademy/wonder-blocks-clickable";
4
4
  import type { SharedProps } from "./button";
5
+ import { ButtonThemeContract } from "../themes/themed-button";
5
6
  type Props = SharedProps & ChildrenProps & ClickableState;
6
7
  declare const ButtonCore: React.ForwardRefExoticComponent<Props & React.RefAttributes<typeof Link | HTMLButtonElement | HTMLAnchorElement>>;
7
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;
package/dist/es/index.js CHANGED
@@ -4,7 +4,7 @@ import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-block
4
4
  import { StyleSheet } from 'aphrodite';
5
5
  import { Link } from 'react-router-dom';
6
6
  import { LabelSmall, LabelLarge } from '@khanacademy/wonder-blocks-typography';
7
- import { addStyle } from '@khanacademy/wonder-blocks-core';
7
+ import { addStyle, View } from '@khanacademy/wonder-blocks-core';
8
8
  import { CircularSpinner } from '@khanacademy/wonder-blocks-progress-spinner';
9
9
  import { tokens, mergeTheme, createThemeContext, ThemeSwitcherContext, useScopedTheme, useStyles } from '@khanacademy/wonder-blocks-theming';
10
10
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
@@ -66,6 +66,9 @@ const theme$1 = {
66
66
  },
67
67
  tertiary: {
68
68
  hover: tokens.color.white
69
+ },
70
+ icon: {
71
+ secondaryHover: "transparent"
69
72
  }
70
73
  },
71
74
  text: {
@@ -76,6 +79,9 @@ const theme$1 = {
76
79
  },
77
80
  secondary: {
78
81
  inverse: tokens.color.white50
82
+ },
83
+ icon: {
84
+ secondaryHover: tokens.color.blue
79
85
  }
80
86
  },
81
87
  border: {
@@ -103,7 +109,8 @@ const theme$1 = {
103
109
  default: tokens.border.radius.medium_4,
104
110
  tertiary: tokens.border.radius.xSmall_2,
105
111
  small: tokens.border.radius.medium_4,
106
- large: tokens.border.radius.large_6
112
+ large: tokens.border.radius.large_6,
113
+ icon: tokens.border.radius.full
107
114
  }
108
115
  },
109
116
  size: {
@@ -114,8 +121,14 @@ const theme$1 = {
114
121
  large: 56
115
122
  }
116
123
  },
124
+ margin: {
125
+ icon: {
126
+ offset: -tokens.spacing.xxxxSmall_2
127
+ }
128
+ },
117
129
  padding: {
118
- small: tokens.spacing.xSmall_8,
130
+ xsmall: tokens.spacing.xxxxSmall_2,
131
+ small: tokens.spacing.xxSmall_6,
119
132
  medium: tokens.spacing.small_12,
120
133
  large: tokens.spacing.medium_16,
121
134
  xLarge: tokens.spacing.xLarge_32
@@ -143,6 +156,9 @@ const theme = mergeTheme(theme$1, {
143
156
  critical: tokens.color.fadedRed8
144
157
  },
145
158
  focus: tokens.color.offWhite
159
+ },
160
+ icon: {
161
+ secondaryHover: tokens.color.fadedBlue16
146
162
  }
147
163
  },
148
164
  border: {
@@ -150,6 +166,11 @@ const theme = mergeTheme(theme$1, {
150
166
  action: tokens.color.fadedBlue,
151
167
  critical: tokens.color.fadedRed
152
168
  }
169
+ },
170
+ text: {
171
+ icon: {
172
+ secondaryHover: tokens.color.blue
173
+ }
153
174
  }
154
175
  },
155
176
  border: {
@@ -162,6 +183,11 @@ const theme = mergeTheme(theme$1, {
162
183
  focused: tokens.border.width.hairline
163
184
  }
164
185
  },
186
+ margin: {
187
+ icon: {
188
+ offset: -tokens.spacing.xSmall_8
189
+ }
190
+ },
165
191
  font: {
166
192
  weight: {
167
193
  default: tokens.font.weight.regular
@@ -261,22 +287,26 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
261
287
  large: "medium"
262
288
  };
263
289
  const iconSize = size === "small" ? "small" : "medium";
264
- const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(ButtonIcon, {
290
+ const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(View, {
291
+ style: sharedStyles.iconWrapper
292
+ }, React.createElement(ButtonIcon, {
265
293
  size: iconSize,
266
294
  icon: startIcon,
267
- style: sharedStyles.startIcon,
295
+ style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
268
296
  testId: testId ? `${testId}-start-icon` : undefined
269
- }), label, spinner && React.createElement(CircularSpinner, {
297
+ })), label, spinner && React.createElement(CircularSpinner, {
270
298
  style: sharedStyles.spinner,
271
299
  size: sizeMapping[size],
272
300
  light: kind === "primary",
273
301
  testId: `${testId || "button"}-spinner`
274
- }), endIcon && React.createElement(ButtonIcon, {
302
+ }), endIcon && React.createElement(View, {
303
+ testId: testId ? `${testId}-end-icon-wrapper` : undefined,
304
+ style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && sharedStyles.iconWrapperSecondaryHovered]
305
+ }, React.createElement(ButtonIcon, {
275
306
  size: iconSize,
276
307
  icon: endIcon,
277
- style: sharedStyles.endIcon,
278
308
  testId: testId ? `${testId}-end-icon` : undefined
279
- }));
309
+ })));
280
310
  if (href && !disabled) {
281
311
  return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
282
312
  to: href,
@@ -319,9 +349,6 @@ const themedSharedStyles = theme => ({
319
349
  WebkitTapHighlightColor: "rgba(0,0,0,0)"
320
350
  }
321
351
  },
322
- withIcon: {
323
- paddingLeft: theme.padding.medium
324
- },
325
352
  disabled: {
326
353
  cursor: "auto"
327
354
  },
@@ -344,7 +371,7 @@ const themedSharedStyles = theme => ({
344
371
  },
345
372
  largeText: {
346
373
  fontSize: theme.font.size.large,
347
- lineHeight: theme.font.lineHeight.large
374
+ lineHeight: `${theme.font.lineHeight.large}px`
348
375
  },
349
376
  textWithFocus: {
350
377
  position: "relative"
@@ -356,10 +383,30 @@ const themedSharedStyles = theme => ({
356
383
  position: "absolute"
357
384
  },
358
385
  startIcon: {
359
- marginInlineEnd: theme.padding.small
386
+ marginRight: theme.padding.small,
387
+ marginLeft: theme.margin.icon.offset
388
+ },
389
+ tertiaryStartIcon: {
390
+ marginLeft: 0
360
391
  },
361
392
  endIcon: {
362
- marginInlineStart: theme.padding.small
393
+ marginLeft: theme.padding.small
394
+ },
395
+ iconWrapper: {
396
+ borderRadius: theme.border.radius.icon,
397
+ padding: theme.padding.xsmall,
398
+ minWidth: "auto"
399
+ },
400
+ iconWrapperSecondaryHovered: {
401
+ backgroundColor: theme.color.bg.icon.secondaryHover,
402
+ color: theme.color.text.icon.secondaryHover
403
+ },
404
+ endIconWrapper: {
405
+ marginLeft: theme.padding.small,
406
+ marginRight: theme.margin.icon.offset
407
+ },
408
+ endIconWrapperTertiary: {
409
+ marginRight: 0
363
410
  }
364
411
  });
365
412
  const styles = {};
package/dist/index.js CHANGED
@@ -88,6 +88,9 @@ const theme$1 = {
88
88
  },
89
89
  tertiary: {
90
90
  hover: wonderBlocksTheming.tokens.color.white
91
+ },
92
+ icon: {
93
+ secondaryHover: "transparent"
91
94
  }
92
95
  },
93
96
  text: {
@@ -98,6 +101,9 @@ const theme$1 = {
98
101
  },
99
102
  secondary: {
100
103
  inverse: wonderBlocksTheming.tokens.color.white50
104
+ },
105
+ icon: {
106
+ secondaryHover: wonderBlocksTheming.tokens.color.blue
101
107
  }
102
108
  },
103
109
  border: {
@@ -125,7 +131,8 @@ const theme$1 = {
125
131
  default: wonderBlocksTheming.tokens.border.radius.medium_4,
126
132
  tertiary: wonderBlocksTheming.tokens.border.radius.xSmall_2,
127
133
  small: wonderBlocksTheming.tokens.border.radius.medium_4,
128
- large: wonderBlocksTheming.tokens.border.radius.large_6
134
+ large: wonderBlocksTheming.tokens.border.radius.large_6,
135
+ icon: wonderBlocksTheming.tokens.border.radius.full
129
136
  }
130
137
  },
131
138
  size: {
@@ -136,8 +143,14 @@ const theme$1 = {
136
143
  large: 56
137
144
  }
138
145
  },
146
+ margin: {
147
+ icon: {
148
+ offset: -wonderBlocksTheming.tokens.spacing.xxxxSmall_2
149
+ }
150
+ },
139
151
  padding: {
140
- small: wonderBlocksTheming.tokens.spacing.xSmall_8,
152
+ xsmall: wonderBlocksTheming.tokens.spacing.xxxxSmall_2,
153
+ small: wonderBlocksTheming.tokens.spacing.xxSmall_6,
141
154
  medium: wonderBlocksTheming.tokens.spacing.small_12,
142
155
  large: wonderBlocksTheming.tokens.spacing.medium_16,
143
156
  xLarge: wonderBlocksTheming.tokens.spacing.xLarge_32
@@ -165,6 +178,9 @@ const theme = wonderBlocksTheming.mergeTheme(theme$1, {
165
178
  critical: wonderBlocksTheming.tokens.color.fadedRed8
166
179
  },
167
180
  focus: wonderBlocksTheming.tokens.color.offWhite
181
+ },
182
+ icon: {
183
+ secondaryHover: wonderBlocksTheming.tokens.color.fadedBlue16
168
184
  }
169
185
  },
170
186
  border: {
@@ -172,6 +188,11 @@ const theme = wonderBlocksTheming.mergeTheme(theme$1, {
172
188
  action: wonderBlocksTheming.tokens.color.fadedBlue,
173
189
  critical: wonderBlocksTheming.tokens.color.fadedRed
174
190
  }
191
+ },
192
+ text: {
193
+ icon: {
194
+ secondaryHover: wonderBlocksTheming.tokens.color.blue
195
+ }
175
196
  }
176
197
  },
177
198
  border: {
@@ -184,6 +205,11 @@ const theme = wonderBlocksTheming.mergeTheme(theme$1, {
184
205
  focused: wonderBlocksTheming.tokens.border.width.hairline
185
206
  }
186
207
  },
208
+ margin: {
209
+ icon: {
210
+ offset: -wonderBlocksTheming.tokens.spacing.xSmall_8
211
+ }
212
+ },
187
213
  font: {
188
214
  weight: {
189
215
  default: wonderBlocksTheming.tokens.font.weight.regular
@@ -283,22 +309,26 @@ const ButtonCore = React__namespace.forwardRef(function ButtonCore(props, ref) {
283
309
  large: "medium"
284
310
  };
285
311
  const iconSize = size === "small" ? "small" : "medium";
286
- const contents = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(ButtonIcon, {
312
+ const contents = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(wonderBlocksCore.View, {
313
+ style: sharedStyles.iconWrapper
314
+ }, React__namespace.createElement(ButtonIcon, {
287
315
  size: iconSize,
288
316
  icon: startIcon,
289
- style: sharedStyles.startIcon,
317
+ style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
290
318
  testId: testId ? `${testId}-start-icon` : undefined
291
- }), label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
319
+ })), label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
292
320
  style: sharedStyles.spinner,
293
321
  size: sizeMapping[size],
294
322
  light: kind === "primary",
295
323
  testId: `${testId || "button"}-spinner`
296
- }), endIcon && React__namespace.createElement(ButtonIcon, {
324
+ }), endIcon && React__namespace.createElement(wonderBlocksCore.View, {
325
+ testId: testId ? `${testId}-end-icon-wrapper` : undefined,
326
+ style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && sharedStyles.iconWrapperSecondaryHovered]
327
+ }, React__namespace.createElement(ButtonIcon, {
297
328
  size: iconSize,
298
329
  icon: endIcon,
299
- style: sharedStyles.endIcon,
300
330
  testId: testId ? `${testId}-end-icon` : undefined
301
- }));
331
+ })));
302
332
  if (href && !disabled) {
303
333
  return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
304
334
  to: href,
@@ -341,9 +371,6 @@ const themedSharedStyles = theme => ({
341
371
  WebkitTapHighlightColor: "rgba(0,0,0,0)"
342
372
  }
343
373
  },
344
- withIcon: {
345
- paddingLeft: theme.padding.medium
346
- },
347
374
  disabled: {
348
375
  cursor: "auto"
349
376
  },
@@ -366,7 +393,7 @@ const themedSharedStyles = theme => ({
366
393
  },
367
394
  largeText: {
368
395
  fontSize: theme.font.size.large,
369
- lineHeight: theme.font.lineHeight.large
396
+ lineHeight: `${theme.font.lineHeight.large}px`
370
397
  },
371
398
  textWithFocus: {
372
399
  position: "relative"
@@ -378,10 +405,30 @@ const themedSharedStyles = theme => ({
378
405
  position: "absolute"
379
406
  },
380
407
  startIcon: {
381
- marginInlineEnd: theme.padding.small
408
+ marginRight: theme.padding.small,
409
+ marginLeft: theme.margin.icon.offset
410
+ },
411
+ tertiaryStartIcon: {
412
+ marginLeft: 0
382
413
  },
383
414
  endIcon: {
384
- marginInlineStart: theme.padding.small
415
+ marginLeft: theme.padding.small
416
+ },
417
+ iconWrapper: {
418
+ borderRadius: theme.border.radius.icon,
419
+ padding: theme.padding.xsmall,
420
+ minWidth: "auto"
421
+ },
422
+ iconWrapperSecondaryHovered: {
423
+ backgroundColor: theme.color.bg.icon.secondaryHover,
424
+ color: theme.color.text.icon.secondaryHover
425
+ },
426
+ endIconWrapper: {
427
+ marginLeft: theme.padding.small,
428
+ marginRight: theme.margin.icon.offset
429
+ },
430
+ endIconWrapperTertiary: {
431
+ marginRight: 0
385
432
  }
386
433
  });
387
434
  const styles = {};
@@ -34,6 +34,12 @@ declare const theme: {
34
34
  tertiary: {
35
35
  hover: string;
36
36
  };
37
+ /**
38
+ * Icons
39
+ */
40
+ icon: {
41
+ secondaryHover: string;
42
+ };
37
43
  };
38
44
  text: {
39
45
  /**
@@ -50,6 +56,12 @@ declare const theme: {
50
56
  secondary: {
51
57
  inverse: string;
52
58
  };
59
+ /**
60
+ * Icons
61
+ */
62
+ icon: {
63
+ secondaryHover: string;
64
+ };
53
65
  };
54
66
  border: {
55
67
  /**
@@ -83,6 +95,10 @@ declare const theme: {
83
95
  tertiary: number;
84
96
  small: number;
85
97
  large: number;
98
+ /**
99
+ * Icons
100
+ */
101
+ icon: string;
86
102
  };
87
103
  };
88
104
  size: {
@@ -93,8 +109,14 @@ declare const theme: {
93
109
  large: number;
94
110
  };
95
111
  };
112
+ margin: {
113
+ icon: {
114
+ offset: number;
115
+ };
116
+ };
96
117
  padding: {
97
- small: 8;
118
+ xsmall: 2;
119
+ small: 6;
98
120
  medium: 12;
99
121
  large: 16;
100
122
  xLarge: 32;
@@ -31,6 +31,9 @@ declare const theme: {
31
31
  tertiary: {
32
32
  hover: string;
33
33
  };
34
+ icon: {
35
+ secondaryHover: string;
36
+ };
34
37
  };
35
38
  text: {
36
39
  disabled: string;
@@ -41,6 +44,9 @@ declare const theme: {
41
44
  secondary: {
42
45
  inverse: string;
43
46
  };
47
+ icon: {
48
+ secondaryHover: string;
49
+ };
44
50
  };
45
51
  border: {
46
52
  disabled: string;
@@ -68,6 +74,7 @@ declare const theme: {
68
74
  tertiary: number;
69
75
  small: number;
70
76
  large: number;
77
+ icon: string;
71
78
  };
72
79
  };
73
80
  size: {
@@ -78,8 +85,14 @@ declare const theme: {
78
85
  large: number;
79
86
  };
80
87
  };
88
+ margin: {
89
+ icon: {
90
+ offset: number;
91
+ };
92
+ };
81
93
  padding: {
82
- small: 8;
94
+ xsmall: 2;
95
+ small: 6;
83
96
  medium: 12;
84
97
  large: 16;
85
98
  xLarge: 32;
@@ -38,6 +38,9 @@ export declare const ButtonThemeContext: React.Context<{
38
38
  tertiary: {
39
39
  hover: string;
40
40
  };
41
+ icon: {
42
+ secondaryHover: string;
43
+ };
41
44
  };
42
45
  text: {
43
46
  disabled: string;
@@ -48,6 +51,9 @@ export declare const ButtonThemeContext: React.Context<{
48
51
  secondary: {
49
52
  inverse: string;
50
53
  };
54
+ icon: {
55
+ secondaryHover: string;
56
+ };
51
57
  };
52
58
  border: {
53
59
  disabled: string;
@@ -75,6 +81,7 @@ export declare const ButtonThemeContext: React.Context<{
75
81
  tertiary: number;
76
82
  small: number;
77
83
  large: number;
84
+ icon: string;
78
85
  };
79
86
  };
80
87
  size: {
@@ -85,8 +92,14 @@ export declare const ButtonThemeContext: React.Context<{
85
92
  large: number;
86
93
  };
87
94
  };
95
+ margin: {
96
+ icon: {
97
+ offset: number;
98
+ };
99
+ };
88
100
  padding: {
89
- small: 8;
101
+ xsmall: 2;
102
+ small: 6;
90
103
  medium: 12;
91
104
  large: 16;
92
105
  xLarge: 32;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-button",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"