@khanacademy/wonder-blocks-icon-button 6.0.7 → 6.0.8

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-icon-button
2
2
 
3
+ ## 6.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - c1f420ad: Migrate to semanticColor tokens
8
+
3
9
  ## 6.0.7
4
10
 
5
11
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -8,7 +8,7 @@ import { addStyle } from '@khanacademy/wonder-blocks-core';
8
8
  import { isClientSideUrl } from '@khanacademy/wonder-blocks-clickable';
9
9
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
10
10
  import { mergeTheme, createThemeContext, ThemeSwitcherContext, useScopedTheme } from '@khanacademy/wonder-blocks-theming';
11
- import * as tokens from '@khanacademy/wonder-blocks-tokens';
11
+ import { semanticColor, color, border } from '@khanacademy/wonder-blocks-tokens';
12
12
 
13
13
  const iconSizeForButtonSize = size => {
14
14
  switch (size) {
@@ -29,136 +29,175 @@ const targetPixelsForSize = size => ({
29
29
  large: 48
30
30
  })[size];
31
31
 
32
+ const disabledStates = {
33
+ border: semanticColor.action.disabled.default,
34
+ background: "transparent",
35
+ foreground: semanticColor.action.disabled.default
36
+ };
37
+ const disabledLightStates = {
38
+ border: color.white50,
39
+ background: "transparent",
40
+ foreground: color.white50
41
+ };
42
+ const baseColorStates = _extends({}, semanticColor.action.outlined, {
43
+ progressive: _extends({}, semanticColor.action.outlined.progressive, {
44
+ default: _extends({}, semanticColor.action.outlined.progressive.default, {
45
+ border: "transparent",
46
+ background: "transparent"
47
+ }),
48
+ press: {
49
+ border: semanticColor.action.outlined.progressive.press.border,
50
+ background: "transparent",
51
+ foreground: semanticColor.action.outlined.progressive.press.foreground
52
+ }
53
+ }),
54
+ destructive: _extends({}, semanticColor.action.outlined.destructive, {
55
+ default: _extends({}, semanticColor.action.outlined.destructive.default, {
56
+ border: "transparent",
57
+ background: "transparent"
58
+ }),
59
+ press: {
60
+ border: semanticColor.action.outlined.destructive.press.border,
61
+ background: "transparent",
62
+ foreground: semanticColor.action.outlined.destructive.press.foreground
63
+ }
64
+ }),
65
+ disabled: {
66
+ default: disabledStates,
67
+ hover: disabledStates,
68
+ press: disabledStates
69
+ },
70
+ disabledLight: {
71
+ default: disabledLightStates,
72
+ hover: disabledLightStates,
73
+ press: disabledLightStates
74
+ }
75
+ });
32
76
  const theme$1 = {
33
77
  color: {
34
- bg: {
35
- hovered: "transparent",
36
- active: "transparent",
37
- disabled: "transparent",
38
- filled: {
39
- action: {
40
- hovered: "transparent",
41
- active: "transparent"
78
+ primary: _extends({}, baseColorStates, {
79
+ progressiveLight: {
80
+ default: {
81
+ border: semanticColor.border.inverse,
82
+ background: "transparent",
83
+ foreground: semanticColor.text.inverse
42
84
  },
43
- critical: {
44
- hovered: "transparent",
45
- active: "transparent"
46
- }
47
- }
48
- },
49
- stroke: {
50
- disabled: {
51
- default: tokens.color.offBlack32,
52
- inverse: tokens.color.white50
53
- },
54
- inverse: tokens.color.white,
55
- action: {
56
- default: tokens.color.blue,
57
- active: tokens.color.activeBlue,
58
- inverse: tokens.color.fadedBlue
59
- },
60
- critical: {
61
- default: tokens.color.red,
62
- active: tokens.color.activeRed,
63
- inverse: tokens.color.fadedRed
64
- },
65
- primary: {
66
- action: {
67
- hovered: tokens.color.blue,
68
- active: tokens.color.activeBlue
69
- },
70
- critical: {
71
- hovered: tokens.color.red,
72
- active: tokens.color.activeRed
85
+ hover: {
86
+ border: semanticColor.border.inverse,
87
+ background: "transparent",
88
+ foreground: semanticColor.text.inverse
73
89
  },
74
- inverse: {
75
- default: tokens.color.white,
76
- hovered: tokens.color.white
90
+ press: {
91
+ border: color.fadedBlue,
92
+ background: "transparent",
93
+ foreground: color.fadedBlue
77
94
  }
78
95
  },
79
- secondary: {
80
- default: tokens.color.offBlack
81
- },
82
- tertiary: {
83
- default: tokens.color.offBlack64
84
- },
85
- filled: {
86
- action: {
87
- hovered: tokens.color.blue,
88
- active: tokens.color.activeBlue
96
+ destructiveLight: {
97
+ default: {
98
+ border: semanticColor.border.inverse,
99
+ background: "transparent",
100
+ foreground: semanticColor.text.inverse
89
101
  },
90
- critical: {
91
- hovered: tokens.color.red,
92
- active: tokens.color.activeRed
102
+ hover: {
103
+ border: semanticColor.border.inverse,
104
+ background: "transparent",
105
+ foreground: semanticColor.text.inverse
106
+ },
107
+ press: {
108
+ border: color.fadedRed,
109
+ background: "transparent",
110
+ foreground: color.fadedRed
93
111
  }
94
112
  }
95
- }
113
+ }),
114
+ secondary: _extends({}, baseColorStates, {
115
+ progressive: _extends({}, baseColorStates.progressive, {
116
+ default: _extends({}, baseColorStates.progressive.default, {
117
+ foreground: semanticColor.text.primary
118
+ })
119
+ }),
120
+ destructive: _extends({}, baseColorStates.destructive, {
121
+ default: _extends({}, baseColorStates.destructive.default, {
122
+ foreground: semanticColor.text.primary
123
+ })
124
+ })
125
+ }),
126
+ tertiary: _extends({}, baseColorStates, {
127
+ progressive: _extends({}, baseColorStates.progressive, {
128
+ default: _extends({}, baseColorStates.progressive.default, {
129
+ foreground: semanticColor.text.secondary
130
+ })
131
+ }),
132
+ destructive: _extends({}, baseColorStates.destructive, {
133
+ default: _extends({}, baseColorStates.destructive.default, {
134
+ foreground: semanticColor.text.secondary
135
+ })
136
+ })
137
+ })
96
138
  },
97
139
  border: {
98
140
  width: {
99
- default: tokens.border.width.thin,
100
- active: tokens.border.width.none,
101
- hovered: tokens.border.width.thin,
102
- hoveredInverse: tokens.border.width.thin
141
+ default: border.width.thin,
142
+ active: border.width.none,
143
+ hovered: border.width.thin,
144
+ hoveredInverse: border.width.thin
103
145
  },
104
146
  radius: {
105
- default: tokens.border.radius.medium_4
147
+ default: border.radius.medium_4
106
148
  }
107
149
  }
108
150
  };
109
151
 
152
+ const primaryState = {
153
+ hover: {
154
+ foreground: semanticColor.khanmigo.primary
155
+ }
156
+ };
157
+ const primaryLightState = {
158
+ hover: {
159
+ background: semanticColor.surface.primary,
160
+ foreground: semanticColor.khanmigo.primary
161
+ },
162
+ press: {
163
+ border: "transparent",
164
+ background: color.white64,
165
+ foreground: semanticColor.khanmigo.primary
166
+ }
167
+ };
110
168
  const theme = mergeTheme(theme$1, {
111
169
  color: {
112
- bg: {
113
- hovered: tokens.color.white,
114
- active: tokens.color.white64,
115
- filled: {
116
- action: {
117
- hovered: tokens.color.blue,
118
- active: tokens.color.activeBlue
119
- },
120
- critical: {
121
- hovered: tokens.color.red,
122
- active: tokens.color.activeRed
123
- }
124
- }
170
+ primary: {
171
+ progressive: primaryState,
172
+ destructive: primaryState,
173
+ progressiveLight: primaryLightState,
174
+ destructiveLight: primaryLightState
125
175
  },
126
- stroke: {
127
- action: {
128
- inverse: tokens.color.eggplant
129
- },
130
- critical: {
131
- inverse: tokens.color.eggplant
176
+ secondary: {
177
+ progressive: {
178
+ hover: semanticColor.action.filled.progressive.hover,
179
+ press: semanticColor.action.filled.progressive.press
132
180
  },
133
- primary: {
134
- action: {
135
- hovered: tokens.color.eggplant,
136
- active: tokens.color.eggplant
137
- },
138
- critical: {
139
- hovered: tokens.color.eggplant,
140
- active: tokens.color.eggplant
141
- },
142
- inverse: {
143
- hovered: tokens.color.eggplant
144
- }
181
+ destructive: {
182
+ hover: semanticColor.action.filled.destructive.hover,
183
+ press: semanticColor.action.filled.destructive.press
184
+ }
185
+ },
186
+ tertiary: {
187
+ progressive: {
188
+ hover: semanticColor.action.filled.progressive.hover,
189
+ press: semanticColor.action.filled.progressive.press
145
190
  },
146
- filled: {
147
- action: {
148
- hovered: tokens.color.white,
149
- active: tokens.color.white
150
- },
151
- critical: {
152
- hovered: tokens.color.white,
153
- active: tokens.color.white
154
- }
191
+ destructive: {
192
+ hover: semanticColor.action.filled.destructive.hover,
193
+ press: semanticColor.action.filled.destructive.press
155
194
  }
156
195
  }
157
196
  },
158
197
  border: {
159
198
  width: {
160
- hovered: tokens.border.width.none,
161
- hoveredInverse: tokens.border.width.none
199
+ hovered: border.width.none,
200
+ hoveredInverse: border.width.none
162
201
  }
163
202
  }
164
203
  });
@@ -222,7 +261,7 @@ const IconButtonCore = React.forwardRef(function IconButtonCore(props, ref) {
222
261
  themeName
223
262
  } = useScopedTheme(IconButtonThemeContext);
224
263
  const renderInner = router => {
225
- const buttonStyles = _generateStyles(color, kind, light, size, theme, themeName);
264
+ const buttonStyles = _generateStyles(color, !!disabled, kind, light, size, theme, themeName);
226
265
  const defaultStyle = [sharedStyles.shared, buttonStyles.default, disabled && buttonStyles.disabled];
227
266
  const child = React.createElement(IconChooser, {
228
267
  size: size,
@@ -270,93 +309,114 @@ const sharedStyles = StyleSheet.create({
270
309
  }
271
310
  });
272
311
  const styles = {};
273
- function getStylesByKind(kind, theme, color, light, buttonColor) {
274
- switch (kind) {
275
- case "primary":
276
- const primaryHoveredColor = buttonColor === "destructive" ? theme.color.stroke.primary.critical.hovered : theme.color.stroke.primary.action.hovered;
277
- return {
278
- ":hover": {
279
- backgroundColor: theme.color.bg.hovered,
280
- color: light ? theme.color.stroke.primary.inverse.hovered : primaryHoveredColor,
281
- outlineColor: light ? theme.color.stroke.inverse : color,
282
- outlineOffset: 1,
283
- outlineStyle: "solid",
284
- outlineWidth: light ? theme.border.width.hoveredInverse : theme.border.width.hovered
285
- },
286
- ":active": {
287
- backgroundColor: theme.color.bg.active
288
- }
289
- };
290
- case "secondary":
291
- case "tertiary":
292
- return {
293
- ":hover": {
294
- backgroundColor: buttonColor === "destructive" ? theme.color.bg.filled.critical.hovered : theme.color.bg.filled.action.hovered,
295
- color: buttonColor === "destructive" ? theme.color.stroke.filled.critical.hovered : theme.color.stroke.filled.action.hovered,
296
- outlineWidth: theme.border.width.active
297
- },
298
- ":active": {
299
- backgroundColor: buttonColor === "destructive" ? theme.color.bg.filled.critical.active : theme.color.bg.filled.action.active,
300
- color: buttonColor === "destructive" ? theme.color.stroke.filled.critical.active : theme.color.stroke.filled.action.active,
301
- outlineWidth: theme.border.width.active
302
- }
303
- };
304
- default:
305
- return {
306
- ":focus-visible": {},
307
- ":hover": {},
308
- ":active": {}
309
- };
312
+ function getActionType(buttonColor, disabled) {
313
+ const actionType = buttonColor === "destructive" ? "destructive" : "progressive";
314
+ if (disabled) {
315
+ return "disabled";
310
316
  }
317
+ return actionType;
311
318
  }
312
- const _generateStyles = (buttonColor = "default", kind, light, size, theme, themeName) => {
313
- const color = buttonColor === "destructive" ? theme.color.stroke.critical.default : theme.color.stroke.action.default;
314
- const buttonType = `${color}-${kind}-${light}-${size}-${themeName}`;
319
+ function getStylesByKind(buttonColor, disabled, kind, light, theme) {
320
+ let actionType = getActionType(buttonColor, disabled);
321
+ const themeVariant = theme.color[kind][actionType];
322
+ if (kind === "primary") {
323
+ if (light) {
324
+ actionType = `${actionType}Light`;
325
+ }
326
+ const _themeVariant = theme.color[kind][actionType];
327
+ return {
328
+ default: {
329
+ borderColor: _themeVariant.default.border,
330
+ background: _themeVariant.default.background,
331
+ color: _themeVariant.default.foreground
332
+ },
333
+ ":hover": {
334
+ background: _themeVariant.hover.background,
335
+ color: _themeVariant.hover.foreground,
336
+ outlineColor: _themeVariant.hover.border,
337
+ outlineOffset: 1,
338
+ outlineStyle: "solid",
339
+ outlineWidth: light ? theme.border.width.hoveredInverse : theme.border.width.hovered
340
+ },
341
+ ":focus-visible": {
342
+ outlineColor: _themeVariant.hover.border
343
+ },
344
+ ":active": {
345
+ borderColor: _themeVariant.press.border,
346
+ background: _themeVariant.press.background,
347
+ color: _themeVariant.press.foreground,
348
+ outlineColor: _themeVariant.press.border
349
+ },
350
+ disabled: {
351
+ background: _themeVariant.default.background,
352
+ color: _themeVariant.default.foreground,
353
+ outlineColor: _themeVariant.default.border
354
+ }
355
+ };
356
+ }
357
+ if (kind === "secondary" || kind === "tertiary") {
358
+ return {
359
+ default: {
360
+ borderColor: themeVariant.default.border,
361
+ background: themeVariant.default.background,
362
+ color: themeVariant.default.foreground
363
+ },
364
+ ":hover": {
365
+ borderColor: themeVariant.hover.border,
366
+ background: themeVariant.hover.background,
367
+ color: themeVariant.hover.foreground,
368
+ outlineWidth: theme.border.width.active
369
+ },
370
+ ":focus-visible": {
371
+ outlineColor: themeVariant.hover.border
372
+ },
373
+ ":active": {
374
+ borderColor: themeVariant.press.border,
375
+ background: themeVariant.press.background,
376
+ color: themeVariant.press.foreground,
377
+ outlineColor: themeVariant.press.border,
378
+ outlineWidth: theme.border.width.active
379
+ },
380
+ disabled: {
381
+ background: themeVariant.default.background,
382
+ color: themeVariant.default.foreground,
383
+ outlineColor: themeVariant.default.border
384
+ }
385
+ };
386
+ }
387
+ return {
388
+ default: {},
389
+ ":hover": {},
390
+ ":focus-visible": {},
391
+ ":active": {},
392
+ disabled: {}
393
+ };
394
+ }
395
+ const _generateStyles = (buttonColor = "default", disabled, kind, light, size, theme, themeName) => {
396
+ const buttonType = `${buttonColor}-d_${disabled}-${kind}-l_${light}-${size}-${themeName}`;
315
397
  if (styles[buttonType]) {
316
398
  return styles[buttonType];
317
399
  }
318
400
  if (light && kind !== "primary") {
319
401
  throw new Error("Light is only supported for primary IconButtons");
320
402
  }
321
- const defaultColor = (() => {
322
- switch (kind) {
323
- case "primary":
324
- return light ? theme.color.stroke.primary.inverse.default : color;
325
- case "secondary":
326
- return theme.color.stroke.secondary.default;
327
- case "tertiary":
328
- return theme.color.stroke.tertiary.default;
329
- default:
330
- throw new Error("IconButton kind not recognized");
331
- }
332
- })();
333
403
  const pixelsForSize = targetPixelsForSize(size);
334
- const kindOverrides = getStylesByKind(kind, theme, color, light, buttonColor);
335
- const activeInverseColor = buttonColor === "destructive" ? theme.color.stroke.critical.inverse : theme.color.stroke.action.inverse;
336
- const activeColor = buttonColor === "destructive" ? theme.color.stroke.critical.active : theme.color.stroke.action.active;
337
- const defaultStrokeColor = light ? theme.color.stroke.inverse : color;
338
- const disabledStrokeColor = light ? theme.color.stroke.disabled.inverse : theme.color.stroke.disabled.default;
339
- const disabledStatesStyles = {
340
- backgroundColor: theme.color.bg.disabled,
341
- color: disabledStrokeColor,
342
- outlineColor: disabledStrokeColor
343
- };
404
+ const kindOverrides = getStylesByKind(buttonColor, disabled, kind, light, theme);
405
+ const disabledStatesStyles = kindOverrides.disabled;
344
406
  const newStyles = {
345
- default: {
407
+ default: _extends({
346
408
  height: pixelsForSize,
347
409
  width: pixelsForSize,
348
- color: defaultColor,
349
- borderRadius: theme.border.radius.default,
410
+ borderRadius: theme.border.radius.default
411
+ }, kindOverrides.default, {
350
412
  ":hover": _extends({
351
413
  boxShadow: "none",
352
- color: defaultStrokeColor,
353
414
  borderRadius: theme.border.radius.default,
354
415
  outlineWidth: theme.border.width.default
355
416
  }, kindOverrides[":hover"]),
356
417
  ["@media not (hover: hover)"]: {
357
418
  ":hover": {
358
419
  boxShadow: "none",
359
- color: defaultColor,
360
420
  borderRadius: theme.border.radius.default,
361
421
  outline: "none",
362
422
  backgroundColor: "transparent"
@@ -364,23 +424,20 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
364
424
  },
365
425
  ":focus-visible": _extends({
366
426
  outlineWidth: theme.border.width.default,
367
- outlineColor: defaultStrokeColor,
368
427
  outlineOffset: 1,
369
428
  outlineStyle: "solid",
370
429
  borderRadius: theme.border.radius.default
371
430
  }, kindOverrides[":focus-visible"]),
372
431
  ":active": _extends({
373
- color: light ? activeInverseColor : activeColor,
374
432
  outlineWidth: theme.border.width.default,
375
- outlineColor: light ? activeInverseColor : activeColor,
376
433
  outlineOffset: 1,
377
434
  outlineStyle: "solid",
378
435
  borderRadius: theme.border.radius.default
379
436
  }, kindOverrides[":active"])
380
- },
381
- disabled: {
382
- color: disabledStrokeColor,
383
- cursor: "not-allowed",
437
+ }),
438
+ disabled: _extends({
439
+ cursor: "not-allowed"
440
+ }, disabledStatesStyles, {
384
441
  ":hover": _extends({}, disabledStatesStyles, {
385
442
  outline: "none"
386
443
  }),
@@ -388,7 +445,7 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
388
445
  outline: "none"
389
446
  }),
390
447
  ":focus-visible": disabledStatesStyles
391
- }
448
+ })
392
449
  };
393
450
  styles[buttonType] = StyleSheet.create(newStyles);
394
451
  return styles[buttonType];