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