@khanacademy/wonder-blocks-button 6.0.1 → 6.2.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 +17 -0
- package/dist/components/button-core.d.ts +2 -0
- package/dist/components/button.d.ts +4 -0
- package/dist/es/index.js +81 -47
- package/dist/index.js +80 -46
- package/dist/themes/default.d.ts +23 -1
- package/dist/themes/khanmigo.d.ts +14 -1
- package/dist/themes/themed-button.d.ts +14 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +384 -446
- package/src/components/__tests__/button-with-icon.test.tsx +274 -0
- package/src/components/__tests__/button.test.tsx +6 -88
- package/src/components/button-core.tsx +94 -66
- package/src/components/button.tsx +4 -0
- package/src/themes/default.ts +27 -1
- package/src/themes/khanmigo.ts +14 -0
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-button
|
|
2
2
|
|
|
3
|
+
## 6.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a70a929b: Add `labelStyle` to override the styles of the internal label
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7b24db93]
|
|
12
|
+
- @khanacademy/wonder-blocks-clickable@4.0.10
|
|
13
|
+
|
|
14
|
+
## 6.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- d73f6988: Add Khanmigo theming support to buttons with icons
|
|
19
|
+
|
|
3
20
|
## 6.0.1
|
|
4
21
|
|
|
5
22
|
### 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
|
-
|
|
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
|
|
@@ -209,7 +235,7 @@ function ButtonIcon({
|
|
|
209
235
|
}
|
|
210
236
|
}
|
|
211
237
|
|
|
212
|
-
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
|
|
238
|
+
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
|
|
213
239
|
const StyledAnchor = addStyle("a");
|
|
214
240
|
const StyledButton = addStyle("button");
|
|
215
241
|
const StyledLink = addStyle(Link);
|
|
@@ -229,6 +255,7 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
|
|
|
229
255
|
hovered,
|
|
230
256
|
href = undefined,
|
|
231
257
|
kind = "primary",
|
|
258
|
+
labelStyle,
|
|
232
259
|
light = false,
|
|
233
260
|
pressed,
|
|
234
261
|
size = "medium",
|
|
@@ -252,7 +279,7 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
|
|
|
252
279
|
}, restProps);
|
|
253
280
|
const Label = size === "small" ? LabelSmall : LabelLarge;
|
|
254
281
|
const label = React.createElement(Label, {
|
|
255
|
-
style: [sharedStyles.text, size === "large" && sharedStyles.largeText, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
|
|
282
|
+
style: [sharedStyles.text, size === "large" && sharedStyles.largeText, labelStyle, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
|
|
256
283
|
testId: testId ? `${testId}-inner-label` : undefined
|
|
257
284
|
}, children);
|
|
258
285
|
const sizeMapping = {
|
|
@@ -261,22 +288,26 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
|
|
|
261
288
|
large: "medium"
|
|
262
289
|
};
|
|
263
290
|
const iconSize = size === "small" ? "small" : "medium";
|
|
264
|
-
const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(
|
|
291
|
+
const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(View, {
|
|
292
|
+
style: sharedStyles.iconWrapper
|
|
293
|
+
}, React.createElement(ButtonIcon, {
|
|
265
294
|
size: iconSize,
|
|
266
295
|
icon: startIcon,
|
|
267
|
-
style: sharedStyles.startIcon,
|
|
296
|
+
style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
|
|
268
297
|
testId: testId ? `${testId}-start-icon` : undefined
|
|
269
|
-
}), label, spinner && React.createElement(CircularSpinner, {
|
|
298
|
+
})), label, spinner && React.createElement(CircularSpinner, {
|
|
270
299
|
style: sharedStyles.spinner,
|
|
271
300
|
size: sizeMapping[size],
|
|
272
301
|
light: kind === "primary",
|
|
273
302
|
testId: `${testId || "button"}-spinner`
|
|
274
|
-
}), endIcon && React.createElement(
|
|
303
|
+
}), endIcon && React.createElement(View, {
|
|
304
|
+
testId: testId ? `${testId}-end-icon-wrapper` : undefined,
|
|
305
|
+
style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && sharedStyles.iconWrapperSecondaryHovered]
|
|
306
|
+
}, React.createElement(ButtonIcon, {
|
|
275
307
|
size: iconSize,
|
|
276
308
|
icon: endIcon,
|
|
277
|
-
style: sharedStyles.endIcon,
|
|
278
309
|
testId: testId ? `${testId}-end-icon` : undefined
|
|
279
|
-
}));
|
|
310
|
+
})));
|
|
280
311
|
if (href && !disabled) {
|
|
281
312
|
return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
|
|
282
313
|
to: href,
|
|
@@ -319,9 +350,6 @@ const themedSharedStyles = theme => ({
|
|
|
319
350
|
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
320
351
|
}
|
|
321
352
|
},
|
|
322
|
-
withIcon: {
|
|
323
|
-
paddingLeft: theme.padding.medium
|
|
324
|
-
},
|
|
325
353
|
disabled: {
|
|
326
354
|
cursor: "auto"
|
|
327
355
|
},
|
|
@@ -344,7 +372,7 @@ const themedSharedStyles = theme => ({
|
|
|
344
372
|
},
|
|
345
373
|
largeText: {
|
|
346
374
|
fontSize: theme.font.size.large,
|
|
347
|
-
lineHeight: theme.font.lineHeight.large
|
|
375
|
+
lineHeight: `${theme.font.lineHeight.large}px`
|
|
348
376
|
},
|
|
349
377
|
textWithFocus: {
|
|
350
378
|
position: "relative"
|
|
@@ -356,10 +384,30 @@ const themedSharedStyles = theme => ({
|
|
|
356
384
|
position: "absolute"
|
|
357
385
|
},
|
|
358
386
|
startIcon: {
|
|
359
|
-
|
|
387
|
+
marginRight: theme.padding.small,
|
|
388
|
+
marginLeft: theme.margin.icon.offset
|
|
389
|
+
},
|
|
390
|
+
tertiaryStartIcon: {
|
|
391
|
+
marginLeft: 0
|
|
360
392
|
},
|
|
361
393
|
endIcon: {
|
|
362
|
-
|
|
394
|
+
marginLeft: theme.padding.small
|
|
395
|
+
},
|
|
396
|
+
iconWrapper: {
|
|
397
|
+
borderRadius: theme.border.radius.icon,
|
|
398
|
+
padding: theme.padding.xsmall,
|
|
399
|
+
minWidth: "auto"
|
|
400
|
+
},
|
|
401
|
+
iconWrapperSecondaryHovered: {
|
|
402
|
+
backgroundColor: theme.color.bg.icon.secondaryHover,
|
|
403
|
+
color: theme.color.text.icon.secondaryHover
|
|
404
|
+
},
|
|
405
|
+
endIconWrapper: {
|
|
406
|
+
marginLeft: theme.padding.small,
|
|
407
|
+
marginRight: theme.margin.icon.offset
|
|
408
|
+
},
|
|
409
|
+
endIconWrapperTertiary: {
|
|
410
|
+
marginRight: 0
|
|
363
411
|
}
|
|
364
412
|
});
|
|
365
413
|
const styles = {};
|
|
@@ -400,43 +448,37 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
400
448
|
}
|
|
401
449
|
};
|
|
402
450
|
} else if (kind === "secondary") {
|
|
403
|
-
const horizontalPadding = padding - (theme.border.width.focused - 1);
|
|
404
451
|
const secondaryBorderColor = buttonColor === "destructive" ? theme.color.border.secondary.critical : theme.color.border.secondary.action;
|
|
405
452
|
const secondaryActiveColor = buttonColor === "destructive" ? theme.color.bg.secondary.active.critical : theme.color.bg.secondary.active.action;
|
|
406
453
|
newStyles = {
|
|
407
454
|
default: {
|
|
408
455
|
background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.default,
|
|
409
456
|
color: light ? theme.color.text.inverse : color,
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
457
|
+
outlineColor: light ? theme.color.border.secondary.inverse : secondaryBorderColor,
|
|
458
|
+
outlineStyle: "solid",
|
|
459
|
+
outlineWidth: theme.border.width.secondary,
|
|
460
|
+
outlineOffset: 1,
|
|
413
461
|
paddingLeft: padding,
|
|
414
462
|
paddingRight: padding
|
|
415
463
|
},
|
|
416
464
|
focus: {
|
|
417
465
|
background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.focus,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
paddingLeft: horizontalPadding,
|
|
421
|
-
paddingRight: horizontalPadding
|
|
466
|
+
outlineColor: light ? theme.color.border.primary.inverse : color,
|
|
467
|
+
outlineWidth: theme.border.width.focused
|
|
422
468
|
},
|
|
423
469
|
active: {
|
|
424
470
|
background: light ? activeColor : secondaryActiveColor,
|
|
425
471
|
color: light ? fadedColor : activeColor,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
paddingLeft: horizontalPadding,
|
|
429
|
-
paddingRight: horizontalPadding
|
|
472
|
+
outlineColor: light ? fadedColor : activeColor,
|
|
473
|
+
outlineWidth: theme.border.width.focused
|
|
430
474
|
},
|
|
431
475
|
disabled: {
|
|
432
476
|
color: light ? theme.color.text.secondary.inverse : theme.color.text.disabled,
|
|
433
|
-
|
|
477
|
+
outlineColor: light ? fadedColor : theme.color.border.disabled,
|
|
434
478
|
cursor: "default",
|
|
435
479
|
":focus": {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
paddingLeft: padding - 1,
|
|
439
|
-
paddingRight: padding - 1
|
|
480
|
+
outlineColor: light ? theme.color.border.secondary.inverse : theme.color.border.disabled,
|
|
481
|
+
outlineWidth: theme.border.width.disabled
|
|
440
482
|
}
|
|
441
483
|
}
|
|
442
484
|
};
|
|
@@ -461,16 +503,10 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
461
503
|
}
|
|
462
504
|
},
|
|
463
505
|
focus: {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
height: `calc(100% - ${theme.border.width.focused * 2}px)`,
|
|
469
|
-
borderStyle: "solid",
|
|
470
|
-
borderColor: light ? theme.color.border.tertiary.inverse : color,
|
|
471
|
-
borderWidth: theme.border.width.focused,
|
|
472
|
-
borderRadius: theme.border.radius.default
|
|
473
|
-
}
|
|
506
|
+
outlineStyle: "solid",
|
|
507
|
+
outlineColor: light ? theme.color.border.tertiary.inverse : color,
|
|
508
|
+
outlineWidth: theme.border.width.focused,
|
|
509
|
+
borderRadius: theme.border.radius.default
|
|
474
510
|
},
|
|
475
511
|
active: {
|
|
476
512
|
color: light ? fadedColor : activeColor,
|
|
@@ -484,9 +520,7 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
484
520
|
cursor: "default"
|
|
485
521
|
},
|
|
486
522
|
disabledFocus: {
|
|
487
|
-
|
|
488
|
-
borderColor: light ? theme.color.border.tertiary.inverse : theme.color.border.disabled
|
|
489
|
-
}
|
|
523
|
+
outlineColor: light ? theme.color.border.tertiary.inverse : theme.color.border.disabled
|
|
490
524
|
}
|
|
491
525
|
};
|
|
492
526
|
} else {
|
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
|
-
|
|
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
|
|
@@ -231,7 +257,7 @@ function ButtonIcon({
|
|
|
231
257
|
}
|
|
232
258
|
}
|
|
233
259
|
|
|
234
|
-
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
|
|
260
|
+
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
|
|
235
261
|
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
236
262
|
const StyledButton = wonderBlocksCore.addStyle("button");
|
|
237
263
|
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
@@ -251,6 +277,7 @@ const ButtonCore = React__namespace.forwardRef(function ButtonCore(props, ref) {
|
|
|
251
277
|
hovered,
|
|
252
278
|
href = undefined,
|
|
253
279
|
kind = "primary",
|
|
280
|
+
labelStyle,
|
|
254
281
|
light = false,
|
|
255
282
|
pressed,
|
|
256
283
|
size = "medium",
|
|
@@ -274,7 +301,7 @@ const ButtonCore = React__namespace.forwardRef(function ButtonCore(props, ref) {
|
|
|
274
301
|
}, restProps);
|
|
275
302
|
const Label = size === "small" ? wonderBlocksTypography.LabelSmall : wonderBlocksTypography.LabelLarge;
|
|
276
303
|
const label = React__namespace.createElement(Label, {
|
|
277
|
-
style: [sharedStyles.text, size === "large" && sharedStyles.largeText, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
|
|
304
|
+
style: [sharedStyles.text, size === "large" && sharedStyles.largeText, labelStyle, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
|
|
278
305
|
testId: testId ? `${testId}-inner-label` : undefined
|
|
279
306
|
}, children);
|
|
280
307
|
const sizeMapping = {
|
|
@@ -283,22 +310,26 @@ const ButtonCore = React__namespace.forwardRef(function ButtonCore(props, ref) {
|
|
|
283
310
|
large: "medium"
|
|
284
311
|
};
|
|
285
312
|
const iconSize = size === "small" ? "small" : "medium";
|
|
286
|
-
const contents = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(
|
|
313
|
+
const contents = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(wonderBlocksCore.View, {
|
|
314
|
+
style: sharedStyles.iconWrapper
|
|
315
|
+
}, React__namespace.createElement(ButtonIcon, {
|
|
287
316
|
size: iconSize,
|
|
288
317
|
icon: startIcon,
|
|
289
|
-
style: sharedStyles.startIcon,
|
|
318
|
+
style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
|
|
290
319
|
testId: testId ? `${testId}-start-icon` : undefined
|
|
291
|
-
}), label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
|
|
320
|
+
})), label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
|
|
292
321
|
style: sharedStyles.spinner,
|
|
293
322
|
size: sizeMapping[size],
|
|
294
323
|
light: kind === "primary",
|
|
295
324
|
testId: `${testId || "button"}-spinner`
|
|
296
|
-
}), endIcon && React__namespace.createElement(
|
|
325
|
+
}), endIcon && React__namespace.createElement(wonderBlocksCore.View, {
|
|
326
|
+
testId: testId ? `${testId}-end-icon-wrapper` : undefined,
|
|
327
|
+
style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && sharedStyles.iconWrapperSecondaryHovered]
|
|
328
|
+
}, React__namespace.createElement(ButtonIcon, {
|
|
297
329
|
size: iconSize,
|
|
298
330
|
icon: endIcon,
|
|
299
|
-
style: sharedStyles.endIcon,
|
|
300
331
|
testId: testId ? `${testId}-end-icon` : undefined
|
|
301
|
-
}));
|
|
332
|
+
})));
|
|
302
333
|
if (href && !disabled) {
|
|
303
334
|
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
|
|
304
335
|
to: href,
|
|
@@ -341,9 +372,6 @@ const themedSharedStyles = theme => ({
|
|
|
341
372
|
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
342
373
|
}
|
|
343
374
|
},
|
|
344
|
-
withIcon: {
|
|
345
|
-
paddingLeft: theme.padding.medium
|
|
346
|
-
},
|
|
347
375
|
disabled: {
|
|
348
376
|
cursor: "auto"
|
|
349
377
|
},
|
|
@@ -366,7 +394,7 @@ const themedSharedStyles = theme => ({
|
|
|
366
394
|
},
|
|
367
395
|
largeText: {
|
|
368
396
|
fontSize: theme.font.size.large,
|
|
369
|
-
lineHeight: theme.font.lineHeight.large
|
|
397
|
+
lineHeight: `${theme.font.lineHeight.large}px`
|
|
370
398
|
},
|
|
371
399
|
textWithFocus: {
|
|
372
400
|
position: "relative"
|
|
@@ -378,10 +406,30 @@ const themedSharedStyles = theme => ({
|
|
|
378
406
|
position: "absolute"
|
|
379
407
|
},
|
|
380
408
|
startIcon: {
|
|
381
|
-
|
|
409
|
+
marginRight: theme.padding.small,
|
|
410
|
+
marginLeft: theme.margin.icon.offset
|
|
411
|
+
},
|
|
412
|
+
tertiaryStartIcon: {
|
|
413
|
+
marginLeft: 0
|
|
382
414
|
},
|
|
383
415
|
endIcon: {
|
|
384
|
-
|
|
416
|
+
marginLeft: theme.padding.small
|
|
417
|
+
},
|
|
418
|
+
iconWrapper: {
|
|
419
|
+
borderRadius: theme.border.radius.icon,
|
|
420
|
+
padding: theme.padding.xsmall,
|
|
421
|
+
minWidth: "auto"
|
|
422
|
+
},
|
|
423
|
+
iconWrapperSecondaryHovered: {
|
|
424
|
+
backgroundColor: theme.color.bg.icon.secondaryHover,
|
|
425
|
+
color: theme.color.text.icon.secondaryHover
|
|
426
|
+
},
|
|
427
|
+
endIconWrapper: {
|
|
428
|
+
marginLeft: theme.padding.small,
|
|
429
|
+
marginRight: theme.margin.icon.offset
|
|
430
|
+
},
|
|
431
|
+
endIconWrapperTertiary: {
|
|
432
|
+
marginRight: 0
|
|
385
433
|
}
|
|
386
434
|
});
|
|
387
435
|
const styles = {};
|
|
@@ -422,43 +470,37 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
422
470
|
}
|
|
423
471
|
};
|
|
424
472
|
} else if (kind === "secondary") {
|
|
425
|
-
const horizontalPadding = padding - (theme.border.width.focused - 1);
|
|
426
473
|
const secondaryBorderColor = buttonColor === "destructive" ? theme.color.border.secondary.critical : theme.color.border.secondary.action;
|
|
427
474
|
const secondaryActiveColor = buttonColor === "destructive" ? theme.color.bg.secondary.active.critical : theme.color.bg.secondary.active.action;
|
|
428
475
|
newStyles = {
|
|
429
476
|
default: {
|
|
430
477
|
background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.default,
|
|
431
478
|
color: light ? theme.color.text.inverse : color,
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
479
|
+
outlineColor: light ? theme.color.border.secondary.inverse : secondaryBorderColor,
|
|
480
|
+
outlineStyle: "solid",
|
|
481
|
+
outlineWidth: theme.border.width.secondary,
|
|
482
|
+
outlineOffset: 1,
|
|
435
483
|
paddingLeft: padding,
|
|
436
484
|
paddingRight: padding
|
|
437
485
|
},
|
|
438
486
|
focus: {
|
|
439
487
|
background: light ? theme.color.bg.secondary.inverse : theme.color.bg.secondary.focus,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
paddingLeft: horizontalPadding,
|
|
443
|
-
paddingRight: horizontalPadding
|
|
488
|
+
outlineColor: light ? theme.color.border.primary.inverse : color,
|
|
489
|
+
outlineWidth: theme.border.width.focused
|
|
444
490
|
},
|
|
445
491
|
active: {
|
|
446
492
|
background: light ? activeColor : secondaryActiveColor,
|
|
447
493
|
color: light ? fadedColor : activeColor,
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
paddingLeft: horizontalPadding,
|
|
451
|
-
paddingRight: horizontalPadding
|
|
494
|
+
outlineColor: light ? fadedColor : activeColor,
|
|
495
|
+
outlineWidth: theme.border.width.focused
|
|
452
496
|
},
|
|
453
497
|
disabled: {
|
|
454
498
|
color: light ? theme.color.text.secondary.inverse : theme.color.text.disabled,
|
|
455
|
-
|
|
499
|
+
outlineColor: light ? fadedColor : theme.color.border.disabled,
|
|
456
500
|
cursor: "default",
|
|
457
501
|
":focus": {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
paddingLeft: padding - 1,
|
|
461
|
-
paddingRight: padding - 1
|
|
502
|
+
outlineColor: light ? theme.color.border.secondary.inverse : theme.color.border.disabled,
|
|
503
|
+
outlineWidth: theme.border.width.disabled
|
|
462
504
|
}
|
|
463
505
|
}
|
|
464
506
|
};
|
|
@@ -483,16 +525,10 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
483
525
|
}
|
|
484
526
|
},
|
|
485
527
|
focus: {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
height: `calc(100% - ${theme.border.width.focused * 2}px)`,
|
|
491
|
-
borderStyle: "solid",
|
|
492
|
-
borderColor: light ? theme.color.border.tertiary.inverse : color,
|
|
493
|
-
borderWidth: theme.border.width.focused,
|
|
494
|
-
borderRadius: theme.border.radius.default
|
|
495
|
-
}
|
|
528
|
+
outlineStyle: "solid",
|
|
529
|
+
outlineColor: light ? theme.color.border.tertiary.inverse : color,
|
|
530
|
+
outlineWidth: theme.border.width.focused,
|
|
531
|
+
borderRadius: theme.border.radius.default
|
|
496
532
|
},
|
|
497
533
|
active: {
|
|
498
534
|
color: light ? fadedColor : activeColor,
|
|
@@ -506,9 +542,7 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
|
|
|
506
542
|
cursor: "default"
|
|
507
543
|
},
|
|
508
544
|
disabledFocus: {
|
|
509
|
-
|
|
510
|
-
borderColor: light ? theme.color.border.tertiary.inverse : theme.color.border.disabled
|
|
511
|
-
}
|
|
545
|
+
outlineColor: light ? theme.color.border.tertiary.inverse : theme.color.border.disabled
|
|
512
546
|
}
|
|
513
547
|
};
|
|
514
548
|
} else {
|
package/dist/themes/default.d.ts
CHANGED
|
@@ -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
|
-
|
|
118
|
+
xsmall: 2;
|
|
119
|
+
small: 6;
|
|
98
120
|
medium: 12;
|
|
99
121
|
large: 16;
|
|
100
122
|
xLarge: 32;
|