@khanacademy/wonder-blocks-button 8.0.3 → 9.0.1

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/dist/es/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import _extends from '@babel/runtime/helpers/extends';
2
- import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
2
  import * as React from 'react';
4
3
  import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
5
4
  import { Link, useInRouterContext } from 'react-router-dom-v5-compat';
@@ -11,719 +10,16 @@ import { mergeTheme, createThemeContext, ThemeSwitcherContext, useScopedTheme, u
11
10
  import * as tokens from '@khanacademy/wonder-blocks-tokens';
12
11
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
13
12
 
14
- const {
15
- semanticColor
16
- } = tokens;
17
- const textUnderlineOffset = tokens.spacing.xxxSmall_4;
18
- const focusOutline = {
19
- border: semanticColor.focus.outer
20
- };
21
- const focusOutlineLight = {
22
- border: semanticColor.border.inverse
23
- };
24
- const theme$1 = {
25
- color: {
26
- primary: {
27
- 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
- }
50
- }),
51
- 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
- }
57
- }),
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
- })
75
- },
76
- secondary: {
77
- progressive: _extends({}, semanticColor.action.secondary.progressive, {
78
- focus: focusOutline,
79
- hover: _extends({}, semanticColor.action.secondary.progressive.hover, {
80
- icon: "transparent"
81
- }),
82
- disabled: {
83
- border: semanticColor.action.primary.disabled.border,
84
- foreground: semanticColor.action.secondary.disabled.foreground
85
- }
86
- }),
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
- destructive: _extends({}, semanticColor.action.secondary.destructive, {
112
- focus: focusOutline,
113
- hover: _extends({}, semanticColor.action.secondary.destructive.hover, {
114
- icon: "transparent"
115
- }),
116
- disabled: {
117
- border: semanticColor.action.primary.disabled.border,
118
- foreground: semanticColor.action.secondary.disabled.foreground
119
- }
120
- }),
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
- }
145
- },
146
- tertiary: {
147
- progressive: _extends({}, semanticColor.action.tertiary.progressive, {
148
- focus: focusOutline,
149
- disabled: {
150
- foreground: semanticColor.action.tertiary.disabled.foreground
151
- }
152
- }),
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
- destructive: _extends({}, semanticColor.action.tertiary.destructive, {
174
- focus: focusOutline,
175
- disabled: {
176
- foreground: semanticColor.action.tertiary.disabled.foreground
177
- }
178
- }),
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
- }
199
- }
200
- },
201
- border: {
202
- width: {
203
- secondary: tokens.border.width.thin,
204
- focused: tokens.border.width.medium,
205
- disabled: tokens.border.width.medium
206
- },
207
- offset: {
208
- primary: tokens.spacing.xxxxSmall_2,
209
- secondary: -tokens.spacing.xxxxSmall_2
210
- },
211
- radius: {
212
- default: tokens.border.radius.radius_040,
213
- small: tokens.border.radius.radius_040,
214
- large: tokens.border.radius.radius_040,
215
- icon: tokens.border.radius.radius_full
216
- }
217
- },
218
- size: {
219
- height: {
220
- small: tokens.spacing.xLarge_32,
221
- medium: 40,
222
- large: 56
223
- },
224
- underline: {
225
- hover: tokens.spacing.xxxxSmall_2,
226
- active: 1
227
- }
228
- },
229
- margin: {
230
- icon: {
231
- offset: -tokens.spacing.xxxxSmall_2
232
- }
233
- },
234
- padding: {
235
- xsmall: tokens.spacing.xxxxSmall_2,
236
- small: tokens.spacing.xxSmall_6,
237
- medium: tokens.spacing.small_12,
238
- large: tokens.spacing.medium_16,
239
- xLarge: tokens.spacing.xLarge_32
240
- },
241
- font: {
242
- size: {
243
- large: 18
244
- },
245
- lineHeight: {
246
- small: tokens.font.lineHeight.small + textUnderlineOffset,
247
- default: tokens.font.lineHeight.medium + textUnderlineOffset,
248
- large: tokens.font.lineHeight.medium + 2 + textUnderlineOffset
249
- },
250
- weight: {
251
- default: tokens.font.weight.bold
252
- },
253
- offset: {
254
- default: textUnderlineOffset
255
- }
256
- }
257
- };
13
+ const{semanticColor}=tokens;const textUnderlineOffset=tokens.sizing.size_040;const focusOutline={border:semanticColor.focus.outer};const theme$1={color:{primary:{progressive:{...semanticColor.action.primary.progressive,focus:focusOutline},destructive:{...semanticColor.action.primary.destructive,focus:focusOutline},disabled:semanticColor.action.primary.disabled},secondary:{progressive:{...semanticColor.action.secondary.progressive,focus:focusOutline,hover:{...semanticColor.action.secondary.progressive.hover,icon:"transparent"}},destructive:{...semanticColor.action.secondary.destructive,focus:focusOutline,hover:{...semanticColor.action.secondary.destructive.hover,icon:"transparent"}},disabled:{...semanticColor.action.secondary.disabled,border:semanticColor.action.primary.disabled.border}},tertiary:{progressive:{...semanticColor.action.tertiary.progressive,focus:focusOutline},destructive:{...semanticColor.action.tertiary.destructive,focus:focusOutline},disabled:semanticColor.action.tertiary.disabled}},border:{width:{secondary:tokens.border.width.thin,focused:tokens.border.width.medium,disabled:tokens.border.width.medium},offset:{primary:tokens.spacing.xxxxSmall_2,secondary:-tokens.spacing.xxxxSmall_2},radius:{default:tokens.border.radius.radius_040,small:tokens.border.radius.radius_040,large:tokens.border.radius.radius_040,icon:tokens.border.radius.radius_full}},size:{height:{small:tokens.spacing.xLarge_32,medium:40,large:56},underline:{hover:tokens.spacing.xxxxSmall_2,active:1}},margin:{icon:{offset:-tokens.spacing.xxxxSmall_2}},padding:{xsmall:tokens.spacing.xxxxSmall_2,small:tokens.spacing.xxSmall_6,medium:tokens.spacing.small_12,large:tokens.spacing.medium_16,xLarge:tokens.spacing.xLarge_32},font:{size:{large:"1.8rem"},lineHeight:{small:tokens.font.lineHeight.xMedium,default:tokens.font.lineHeight.large,large:"2.6rem"},weight:{default:tokens.font.weight.bold},offset:{default:textUnderlineOffset}}};
258
14
 
259
- const secondaryBgColor = tokens.color.offWhite;
260
- const theme = mergeTheme(theme$1, {
261
- color: {
262
- secondary: {
263
- progressive: {
264
- default: {
265
- border: tokens.color.fadedBlue,
266
- background: secondaryBgColor
267
- },
268
- hover: {
269
- background: secondaryBgColor,
270
- icon: tokens.color.fadedBlue16,
271
- foreground: tokens.semanticColor.action.secondary.progressive.default.foreground
272
- },
273
- press: {
274
- background: tokens.color.fadedBlue8
275
- }
276
- },
277
- destructive: {
278
- default: {
279
- border: tokens.color.fadedRed,
280
- background: secondaryBgColor
281
- },
282
- hover: {
283
- background: secondaryBgColor,
284
- icon: tokens.color.fadedRed16,
285
- foreground: tokens.semanticColor.action.secondary.destructive.default.foreground
286
- },
287
- press: {
288
- background: tokens.color.fadedRed8
289
- }
290
- }
291
- }
292
- },
293
- border: {
294
- radius: {
295
- default: tokens.border.radius.radius_120,
296
- small: tokens.border.radius.radius_080,
297
- large: tokens.border.radius.radius_120
298
- },
299
- width: {
300
- focused: tokens.border.width.thin
301
- }
302
- },
303
- margin: {
304
- icon: {
305
- offset: -tokens.spacing.xSmall_8
306
- }
307
- },
308
- font: {
309
- weight: {
310
- default: tokens.font.weight.regular
311
- }
312
- }
313
- });
15
+ const secondaryBgColor=tokens.color.offWhite;const theme=mergeTheme(theme$1,{color:{secondary:{progressive:{default:{border:tokens.color.fadedBlue,background:secondaryBgColor},hover:{background:secondaryBgColor,icon:tokens.color.fadedBlue16,foreground:tokens.semanticColor.action.secondary.progressive.default.foreground},press:{background:tokens.color.fadedBlue8}},destructive:{default:{border:tokens.color.fadedRed,background:secondaryBgColor},hover:{background:secondaryBgColor,icon:tokens.color.fadedRed16,foreground:tokens.semanticColor.action.secondary.destructive.default.foreground},press:{background:tokens.color.fadedRed8}}}},border:{radius:{default:tokens.border.radius.radius_120,small:tokens.border.radius.radius_080,large:tokens.border.radius.radius_120},width:{focused:tokens.border.width.thin}},margin:{icon:{offset:-tokens.spacing.xSmall_8}},font:{weight:{default:tokens.font.weight.regular}}});
314
16
 
315
- const themes = {
316
- default: theme$1,
317
- khanmigo: theme
318
- };
319
- const ButtonThemeContext = createThemeContext(theme$1);
320
- function ThemedButton(props) {
321
- const currentTheme = React.useContext(ThemeSwitcherContext);
322
- const theme = themes[currentTheme] || theme$1;
323
- return React.createElement(ButtonThemeContext.Provider, {
324
- value: theme
325
- }, props.children);
326
- }
17
+ const themes={default:theme$1,khanmigo:theme};const ButtonThemeContext=createThemeContext(theme$1);function ThemedButton(props){const currentTheme=React.useContext(ThemeSwitcherContext);const theme=themes[currentTheme]||theme$1;return jsx(ButtonThemeContext.Provider,{value:theme,children:props.children})}
327
18
 
328
- function ButtonIcon({
329
- icon,
330
- size,
331
- style,
332
- testId
333
- }) {
334
- const commonProps = {
335
- "aria-hidden": true,
336
- color: "currentColor",
337
- style: style,
338
- testId
339
- };
340
- switch (size) {
341
- case "small":
342
- return React.createElement(PhosphorIcon, _extends({}, commonProps, {
343
- size: "small",
344
- icon: icon
345
- }));
346
- case "medium":
347
- default:
348
- return React.createElement(PhosphorIcon, _extends({}, commonProps, {
349
- size: "medium",
350
- icon: icon
351
- }));
352
- }
353
- }
19
+ function ButtonIcon({icon,size,style,testId}){const commonProps={"aria-hidden":true,color:"currentColor",style:style,testId};switch(size){case"small":return jsx(PhosphorIcon,{...commonProps,size:"small",icon:icon});case"medium":default:return jsx(PhosphorIcon,{...commonProps,size:"medium",icon:icon})}}
354
20
 
355
- const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
356
- const StyledA = addStyle("a");
357
- const StyledButton = addStyle("button");
358
- const StyledLink = addStyle(Link);
359
- const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
360
- const {
361
- theme,
362
- themeName
363
- } = useScopedTheme(ButtonThemeContext);
364
- const sharedStyles = useStyles(themedSharedStyles, theme);
365
- const inRouterContext = useInRouterContext();
366
- const {
367
- children,
368
- skipClientNav,
369
- color,
370
- disabled: disabledProp,
371
- focused,
372
- hovered,
373
- href = undefined,
374
- kind = "primary",
375
- labelStyle,
376
- light = false,
377
- pressed,
378
- size = "medium",
379
- style,
380
- testId,
381
- type = undefined,
382
- spinner,
383
- startIcon,
384
- endIcon,
385
- id
386
- } = props,
387
- restProps = _objectWithoutPropertiesLoose(props, _excluded$1);
388
- const buttonStyles = _generateStyles(color, kind, light, size, theme, themeName);
389
- 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];
391
- const commonProps = _extends({
392
- "data-testid": testId,
393
- id: id,
394
- role: "button",
395
- style: [defaultStyle, style]
396
- }, restProps);
397
- const Label = size === "small" ? LabelSmall : LabelLarge;
398
- const label = React.createElement(Label, {
399
- style: [sharedStyles.text, size === "small" && sharedStyles.smallText, size === "large" && sharedStyles.largeText, labelStyle, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
400
- testId: testId ? `${testId}-inner-label` : undefined
401
- }, children);
402
- const sizeMapping = {
403
- medium: "small",
404
- small: "xsmall",
405
- large: "medium"
406
- };
407
- const iconSize = size === "small" ? "small" : "medium";
408
- const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(View, {
409
- style: sharedStyles.iconWrapper
410
- }, React.createElement(ButtonIcon, {
411
- size: iconSize,
412
- icon: startIcon,
413
- style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
414
- testId: testId ? `${testId}-start-icon` : undefined
415
- })), label, spinner && React.createElement(CircularSpinner, {
416
- style: sharedStyles.spinner,
417
- size: sizeMapping[size],
418
- light: kind === "primary",
419
- testId: `${testId || "button"}-spinner`
420
- }), endIcon && React.createElement(View, {
421
- 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]
423
- }, React.createElement(ButtonIcon, {
424
- size: iconSize,
425
- icon: endIcon,
426
- testId: testId ? `${testId}-end-icon` : undefined
427
- })));
428
- if (href && !disabled) {
429
- return inRouterContext && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
430
- to: href,
431
- ref: ref
432
- }), contents) : React.createElement(StyledA, _extends({}, commonProps, {
433
- href: href,
434
- ref: ref
435
- }), contents);
436
- } else {
437
- return React.createElement(StyledButton, _extends({
438
- type: type || "button"
439
- }, commonProps, {
440
- "aria-disabled": disabled,
441
- ref: ref
442
- }), contents);
443
- }
444
- });
445
- const themedSharedStyles = theme => ({
446
- shared: {
447
- position: "relative",
448
- display: "inline-flex",
449
- alignItems: "center",
450
- justifyContent: "center",
451
- height: theme.size.height.medium,
452
- paddingTop: 0,
453
- paddingBottom: 0,
454
- paddingLeft: theme.padding.large,
455
- paddingRight: theme.padding.large,
456
- border: "none",
457
- borderRadius: theme.border.radius.default,
458
- cursor: "pointer",
459
- outline: "none",
460
- textDecoration: "none",
461
- boxSizing: "border-box",
462
- touchAction: "manipulation",
463
- userSelect: "none",
464
- ":focus": {
465
- WebkitTapHighlightColor: "rgba(0,0,0,0)"
466
- }
467
- },
468
- disabled: {
469
- cursor: "auto"
470
- },
471
- small: {
472
- borderRadius: theme.border.radius.small,
473
- height: theme.size.height.small
474
- },
475
- large: {
476
- borderRadius: theme.border.radius.large,
477
- height: theme.size.height.large
478
- },
479
- text: {
480
- alignItems: "center",
481
- fontWeight: theme.font.weight.default,
482
- whiteSpace: "nowrap",
483
- overflow: "hidden",
484
- lineHeight: `${theme.font.lineHeight.default}px`,
485
- textOverflow: "ellipsis",
486
- display: "inline-block",
487
- pointerEvents: "none"
488
- },
489
- smallText: {
490
- lineHeight: `${theme.font.lineHeight.small}px`
491
- },
492
- largeText: {
493
- fontSize: theme.font.size.large,
494
- lineHeight: `${theme.font.lineHeight.large}px`
495
- },
496
- textWithFocus: {
497
- position: "relative"
498
- },
499
- hiddenText: {
500
- visibility: "hidden"
501
- },
502
- spinner: {
503
- position: "absolute"
504
- },
505
- startIcon: {
506
- marginRight: theme.padding.small,
507
- marginLeft: theme.margin.icon.offset
508
- },
509
- tertiaryStartIcon: {
510
- marginLeft: 0
511
- },
512
- endIcon: {
513
- marginLeft: theme.padding.small
514
- },
515
- iconWrapper: {
516
- borderRadius: theme.border.radius.icon,
517
- padding: theme.padding.xsmall,
518
- minWidth: "auto"
519
- },
520
- endIconWrapper: {
521
- marginLeft: theme.padding.small,
522
- marginRight: theme.margin.icon.offset
523
- },
524
- endIconWrapperTertiary: {
525
- marginRight: 0
526
- }
527
- });
528
- const styles = {};
529
- const _generateStyles = (buttonColor = "default", kind, light, size, theme, themeName) => {
530
- const buttonType = `${buttonColor}-${kind}-${light}-${size}-${themeName}`;
531
- if (styles[buttonType]) {
532
- return styles[buttonType];
533
- }
534
- const padding = size === "large" ? theme.padding.xLarge : theme.padding.large;
535
- const colorToAction = light ? buttonColor === "destructive" ? "destructiveLight" : "progressiveLight" : buttonColor === "destructive" ? "destructive" : "progressive";
536
- let newStyles = {};
537
- if (kind === "primary") {
538
- const themeColorAction = theme.color.primary[colorToAction];
539
- const sharedFocusHoverStyling = {
540
- outlineOffset: theme.border.offset.primary,
541
- outlineStyle: "solid",
542
- outlineWidth: theme.border.width.focused
543
- };
544
- const focusStyling = _extends({}, sharedFocusHoverStyling, {
545
- outlineColor: themeColorAction.focus.border
546
- });
547
- const hoverStyling = _extends({}, sharedFocusHoverStyling, {
548
- outlineColor: themeColorAction.hover.border
549
- });
550
- const activePressedStyling = {
551
- background: themeColorAction.press.background,
552
- outlineColor: themeColorAction.press.border,
553
- outlineOffset: theme.border.offset.primary,
554
- outlineStyle: "solid",
555
- outlineWidth: theme.border.width.focused
556
- };
557
- newStyles = {
558
- default: {
559
- background: themeColorAction.default.background,
560
- color: themeColorAction.default.foreground,
561
- paddingInline: padding,
562
- [":hover:not([aria-disabled=true])"]: hoverStyling,
563
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
564
- [":active:not([aria-disabled=true])"]: activePressedStyling
565
- },
566
- focused: focusStyling,
567
- pressed: activePressedStyling,
568
- disabled: {
569
- background: themeColorAction.disabled.background,
570
- color: themeColorAction.disabled.foreground,
571
- cursor: "default",
572
- ":focus-visible": focusStyling
573
- }
574
- };
575
- } else if (kind === "secondary") {
576
- const themeColorAction = theme.color.secondary[colorToAction];
577
- const sharedFocusHoverStyling = {
578
- background: themeColorAction.hover.background,
579
- outlineStyle: "solid",
580
- outlineOffset: theme.border.offset.secondary,
581
- outlineWidth: theme.border.width.focused
582
- };
583
- const focusStyling = _extends({}, sharedFocusHoverStyling, {
584
- outlineColor: themeColorAction.focus.border
585
- });
586
- const hoverStyling = _extends({}, sharedFocusHoverStyling, {
587
- outlineColor: themeColorAction.hover.border
588
- });
589
- const activePressedStyling = {
590
- background: themeColorAction.press.background,
591
- color: themeColorAction.press.foreground,
592
- outlineColor: themeColorAction.press.border,
593
- outlineStyle: "solid",
594
- outlineWidth: theme.border.width.focused
595
- };
596
- newStyles = {
597
- default: {
598
- background: themeColorAction.default.background,
599
- color: themeColorAction.default.foreground,
600
- borderColor: themeColorAction.default.border,
601
- borderStyle: "solid",
602
- borderWidth: theme.border.width.secondary,
603
- paddingInline: padding,
604
- [":hover:not([aria-disabled=true])"]: hoverStyling,
605
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
606
- [":active:not([aria-disabled=true])"]: activePressedStyling
607
- },
608
- focused: focusStyling,
609
- pressed: activePressedStyling,
610
- disabled: {
611
- color: themeColorAction.disabled.foreground,
612
- borderColor: themeColorAction.disabled.border,
613
- cursor: "default",
614
- ":focus-visible": focusStyling
615
- },
616
- iconWrapperHovered: {
617
- backgroundColor: themeColorAction.hover.icon,
618
- color: themeColorAction.hover.foreground
619
- }
620
- };
621
- } else if (kind === "tertiary") {
622
- const themeColorAction = theme.color.tertiary[colorToAction];
623
- const focusStyling = {
624
- outlineStyle: "solid",
625
- borderColor: "transparent",
626
- outlineColor: themeColorAction.focus.border,
627
- outlineWidth: theme.border.width.focused,
628
- borderRadius: theme.border.radius.default
629
- };
630
- const activePressedStyling = {
631
- color: themeColorAction.press.foreground,
632
- textDecoration: "underline",
633
- textDecorationThickness: theme.size.underline.active,
634
- textUnderlineOffset: theme.font.offset.default
635
- };
636
- newStyles = {
637
- default: {
638
- background: themeColorAction.default.background,
639
- color: themeColorAction.default.foreground,
640
- paddingInline: 0,
641
- [":hover:not([aria-disabled=true])"]: {
642
- textUnderlineOffset: theme.font.offset.default,
643
- textDecoration: "underline",
644
- textDecorationThickness: theme.size.underline.hover
645
- },
646
- [":focus-visible:not([aria-disabled=true])"]: focusStyling,
647
- [":active:not([aria-disabled=true])"]: activePressedStyling
648
- },
649
- focused: focusStyling,
650
- pressed: activePressedStyling,
651
- disabled: {
652
- color: themeColorAction.disabled.foreground,
653
- cursor: "default",
654
- ":focus-visible": focusStyling
655
- },
656
- disabledFocus: focusStyling
657
- };
658
- } else {
659
- throw new Error("Button kind not recognized");
660
- }
661
- styles[buttonType] = StyleSheet.create(newStyles);
662
- return styles[buttonType];
663
- };
21
+ const StyledA=addStyle("a");const StyledButton=addStyle("button");const StyledLink=addStyle(Link);const ButtonCore=React.forwardRef(function ButtonCore(props,ref){const{theme,themeName}=useScopedTheme(ButtonThemeContext);const sharedStyles=useStyles(themedSharedStyles,theme);const inRouterContext=useInRouterContext();const{children,skipClientNav,color,disabled:disabledProp,focused,hovered,href=undefined,kind="primary",labelStyle,pressed,size="medium",style,testId,type=undefined,spinner,startIcon,endIcon,id,waiting:_,...restProps}=props;const buttonStyles=_generateStyles(color,kind,size,theme,themeName);const disabled=spinner||disabledProp;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];const commonProps={"data-testid":testId,id:id,role:"button",style:[defaultStyle,style],...restProps};const Label=size==="small"?LabelSmall:LabelLarge;const label=jsx(Label,{style:[sharedStyles.text,size==="small"&&sharedStyles.smallText,size==="large"&&sharedStyles.largeText,labelStyle,spinner&&sharedStyles.hiddenText,kind==="tertiary"&&sharedStyles.textWithFocus,kind==="tertiary"&&!disabled&&(pressed?[buttonStyles.hover,buttonStyles.active]:hovered&&buttonStyles.hover)],testId:testId?`${testId}-inner-label`:undefined,children:children});const sizeMapping={medium:"small",small:"xsmall",large:"medium"};const iconSize=size==="small"?"small":"medium";const contents=jsxs(React.Fragment,{children:[startIcon&&jsx(View,{style:sharedStyles.iconWrapper,children:jsx(ButtonIcon,{size:iconSize,icon:startIcon,style:[sharedStyles.startIcon,kind==="tertiary"&&sharedStyles.tertiaryStartIcon],testId:testId?`${testId}-start-icon`:undefined})}),label,spinner&&jsx(CircularSpinner,{style:sharedStyles.spinner,size:sizeMapping[size],light:kind==="primary",testId:`${testId||"button"}-spinner`}),endIcon&&jsx(View,{testId:testId?`${testId}-end-icon-wrapper`:undefined,style:[styles.endIcon,sharedStyles.iconWrapper,sharedStyles.endIconWrapper,kind==="tertiary"&&sharedStyles.endIconWrapperTertiary,!disabled&&(focused||hovered)&&kind!=="primary"&&buttonStyles.iconWrapperHovered],children:jsx(ButtonIcon,{size:iconSize,icon:endIcon,testId:testId?`${testId}-end-icon`:undefined})})]});if(href&&!disabled){return inRouterContext&&!skipClientNav&&isClientSideUrl(href)?jsx(StyledLink,{...commonProps,to:href,ref:ref,children:contents}):jsx(StyledA,{...commonProps,href:href,ref:ref,children:contents})}else {return jsx(StyledButton,{type:type||"button",...commonProps,"aria-disabled":disabled,ref:ref,children:contents})}});const themedSharedStyles=theme=>({shared:{position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",height:theme.size.height.medium,paddingTop:0,paddingBottom:0,paddingLeft:theme.padding.large,paddingRight:theme.padding.large,border:"none",borderRadius:theme.border.radius.default,cursor:"pointer",outline:"none",textDecoration:"none",boxSizing:"border-box",touchAction:"manipulation",userSelect:"none",":focus":{WebkitTapHighlightColor:"rgba(0,0,0,0)"}},disabled:{cursor:"auto"},small:{borderRadius:theme.border.radius.small,height:theme.size.height.small},large:{borderRadius:theme.border.radius.large,height:theme.size.height.large},text:{alignItems:"center",fontWeight:theme.font.weight.default,whiteSpace:"nowrap",overflow:"hidden",lineHeight:theme.font.lineHeight.default,textOverflow:"ellipsis",display:"inline-block",pointerEvents:"none"},smallText:{lineHeight:theme.font.lineHeight.small},largeText:{fontSize:theme.font.size.large,lineHeight:theme.font.lineHeight.large},textWithFocus:{position:"relative"},hiddenText:{visibility:"hidden"},spinner:{position:"absolute"},startIcon:{marginRight:theme.padding.small,marginLeft:theme.margin.icon.offset},tertiaryStartIcon:{marginLeft:0},endIcon:{marginLeft:theme.padding.small},iconWrapper:{borderRadius:theme.border.radius.icon,padding:theme.padding.xsmall,minWidth:"auto"},endIconWrapper:{marginLeft:theme.padding.small,marginRight:theme.margin.icon.offset},endIconWrapperTertiary:{marginRight:0}});const styles={};const _generateStyles=(buttonColor="default",kind,size,theme,themeName)=>{const buttonType=`${buttonColor}-${kind}-${size}-${themeName}`;if(styles[buttonType]){return styles[buttonType]}const padding=size==="large"?theme.padding.xLarge:theme.padding.large;const colorToAction=buttonColor==="destructive"?"destructive":"progressive";const disabledState=theme.color[kind].disabled;const disabledStateStyles={borderColor:disabledState.border,background:disabledState.background,color:disabledState.foreground};let newStyles={};if(kind==="primary"){const themeColorAction=theme.color.primary[colorToAction];const sharedFocusHoverStyling={outlineOffset:theme.border.offset.primary,outlineStyle:"solid",outlineWidth:theme.border.width.focused};const focusStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.focus.border};const hoverStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.hover.border};const activePressedStyling={background:themeColorAction.press.background,outlineColor:themeColorAction.press.border,outlineOffset:theme.border.offset.primary,outlineStyle:"solid",outlineWidth:theme.border.width.focused};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,paddingInline:padding,":hover":hoverStyling,":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":{...disabledStateStyles,outline:"none"},":active":{...disabledStateStyles,outline:"none"},":focus-visible":focusStyling}};}else if(kind==="secondary"){const themeColorAction=theme.color.secondary[colorToAction];const sharedFocusHoverStyling={background:themeColorAction.hover.background,outlineStyle:"solid",outlineOffset:theme.border.offset.secondary,outlineWidth:theme.border.width.focused};const focusStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.focus.border};const hoverStyling={...sharedFocusHoverStyling,borderColor:themeColorAction.hover.border};const activePressedStyling={background:themeColorAction.press.background,color:themeColorAction.press.foreground,outlineColor:themeColorAction.press.border,outlineStyle:"solid",outlineWidth:theme.border.width.focused};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,borderColor:themeColorAction.default.border,borderStyle:"solid",borderWidth:theme.border.width.secondary,paddingInline:padding,":hover":hoverStyling,":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":{...disabledStateStyles,outline:"none"},":active":{...disabledStateStyles,outline:"none"},":focus-visible":focusStyling},iconWrapperHovered:{backgroundColor:themeColorAction.hover.icon,color:themeColorAction.hover.foreground}};}else if(kind==="tertiary"){const themeColorAction=theme.color.tertiary[colorToAction];const focusStyling={outlineStyle:"solid",borderColor:"transparent",outlineColor:themeColorAction.focus.border,outlineWidth:theme.border.width.focused,borderRadius:theme.border.radius.default};const activePressedStyling={color:themeColorAction.press.foreground,textDecoration:"underline",textDecorationThickness:theme.size.underline.active,textUnderlineOffset:theme.font.offset.default};const sharedDisabledStyling={...disabledStateStyles,textDecoration:"none",textDecorationThickness:"unset",textUnderlineOffset:"unset",outline:"none"};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,paddingInline:0,":hover":{textUnderlineOffset:theme.font.offset.default,textDecoration:"underline",textDecorationThickness:theme.size.underline.hover},":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":sharedDisabledStyling,":active":sharedDisabledStyling,":focus-visible":focusStyling}};}else {throw new Error("Button kind not recognized")}styles[buttonType]=StyleSheet.create(newStyles);return styles[buttonType]};
664
22
 
665
- const _excluded = ["href", "type", "children", "skipClientNav", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel", "color", "kind", "light", "size", "disabled", "spinner"];
666
- const Button = React.forwardRef(function Button(props, ref) {
667
- const {
668
- href = undefined,
669
- type = undefined,
670
- children,
671
- skipClientNav,
672
- onClick,
673
- beforeNav = undefined,
674
- safeWithNav = undefined,
675
- tabIndex,
676
- target,
677
- rel,
678
- color = "default",
679
- kind = "primary",
680
- light = false,
681
- size = "medium",
682
- disabled = false,
683
- spinner = false
684
- } = props,
685
- sharedButtonCoreProps = _objectWithoutPropertiesLoose(props, _excluded);
686
- const inRouterContext = useInRouterContext();
687
- const ClickableBehavior = getClickableBehavior(href, skipClientNav, inRouterContext);
688
- const renderProp = (state, restChildProps) => {
689
- return React.createElement(ThemedButton, null, React.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
690
- disabled: disabled,
691
- spinner: spinner || state.waiting,
692
- color: color,
693
- kind: kind,
694
- light: light,
695
- size: size,
696
- skipClientNav: skipClientNav,
697
- href: href,
698
- target: target,
699
- type: type,
700
- tabIndex: tabIndex,
701
- ref: ref
702
- }), children));
703
- };
704
- if (beforeNav) {
705
- return React.createElement(ClickableBehavior, {
706
- disabled: spinner || disabled,
707
- href: href,
708
- role: "button",
709
- type: type,
710
- onClick: onClick,
711
- beforeNav: beforeNav,
712
- safeWithNav: safeWithNav,
713
- rel: rel
714
- }, renderProp);
715
- } else {
716
- return React.createElement(ClickableBehavior, {
717
- disabled: spinner || disabled,
718
- href: href,
719
- role: "button",
720
- type: type,
721
- onClick: onClick,
722
- safeWithNav: safeWithNav,
723
- target: target,
724
- rel: rel
725
- }, renderProp);
726
- }
727
- });
23
+ const Button=React.forwardRef(function Button(props,ref){const{href=undefined,type=undefined,children,skipClientNav,onClick,beforeNav=undefined,safeWithNav=undefined,tabIndex,target,rel,color="default",kind="primary",size="medium",disabled=false,spinner=false,...sharedButtonCoreProps}=props;const inRouterContext=useInRouterContext();const ClickableBehavior=getClickableBehavior(href,skipClientNav,inRouterContext);const renderProp=(state,restChildProps)=>{return jsx(ThemedButton,{children:jsx(ButtonCore,{...sharedButtonCoreProps,...state,...restChildProps,disabled:disabled,spinner:spinner||state.waiting,color:color,kind:kind,size:size,skipClientNav:skipClientNav,href:href,target:target,type:type,tabIndex:tabIndex,ref:ref,children:children})})};if(beforeNav){return jsx(ClickableBehavior,{disabled:spinner||disabled,href:href,role:"button",type:type,onClick:onClick,beforeNav:beforeNav,safeWithNav:safeWithNav,rel:rel,children:renderProp})}else {return jsx(ClickableBehavior,{disabled:spinner||disabled,href:href,role:"button",type:type,onClick:onClick,safeWithNav:safeWithNav,target:target,rel:rel,children:renderProp})}});
728
24
 
729
25
  export { Button as default };