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