@khanacademy/wonder-blocks-button 7.1.6 → 8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @khanacademy/wonder-blocks-button
2
2
 
3
+ ## 8.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e8ccf60: - Update `Button.large` to use `radius_40` (4px, 0.4rem) instead of `6px`.
8
+ - Update `Button.small (khanmigo)` to use `radius_80` (8px, 0.8rem) instead of `6px`.
9
+ - Updated dependencies [e8ccf60]
10
+ - @khanacademy/wonder-blocks-tokens@7.0.0
11
+ - @khanacademy/wonder-blocks-clickable@7.0.1
12
+ - @khanacademy/wonder-blocks-progress-spinner@3.1.7
13
+
14
+ ## 8.0.0
15
+
16
+ ### Major Changes
17
+
18
+ - 38c926c: Upgrade WB to using react-router-dom-v5-compat.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [38c926c]
23
+ - @khanacademy/wonder-blocks-clickable@7.0.0
24
+ - @khanacademy/wonder-blocks-core@12.2.1
25
+
3
26
  ## 7.1.6
4
27
 
5
28
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { Link } from "react-router-dom";
2
+ import { Link } from "react-router-dom-v5-compat";
3
3
  import type { ChildrenProps, ClickableState } from "@khanacademy/wonder-blocks-clickable";
4
4
  import type { SharedProps } from "./button";
5
5
  import { ButtonThemeContract } from "../themes/themed-button";
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
3
3
  import type { PhosphorIconAsset } from "@khanacademy/wonder-blocks-icon";
4
- import { Link } from "react-router-dom";
4
+ import { Link } from "react-router-dom-v5-compat";
5
5
  export type SharedProps =
6
6
  /**
7
7
  * aria-label should be used when `spinner={true}` to let people using screen
package/dist/es/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import _extends from '@babel/runtime/helpers/extends';
2
2
  import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
3
3
  import * as React from 'react';
4
- import { __RouterContext } from 'react-router';
5
4
  import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
5
+ import { Link, useInRouterContext } from 'react-router-dom-v5-compat';
6
6
  import { StyleSheet } from 'aphrodite';
7
- import { Link } from 'react-router-dom';
8
7
  import { LabelSmall, LabelLarge } from '@khanacademy/wonder-blocks-typography';
9
8
  import { addStyle, View } from '@khanacademy/wonder-blocks-core';
10
9
  import { CircularSpinner } from '@khanacademy/wonder-blocks-progress-spinner';
@@ -210,10 +209,10 @@ const theme$1 = {
210
209
  secondary: -tokens.spacing.xxxxSmall_2
211
210
  },
212
211
  radius: {
213
- default: tokens.border.radius.medium_4,
214
- small: tokens.border.radius.medium_4,
215
- large: tokens.border.radius.large_6,
216
- icon: tokens.border.radius.full
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
217
216
  }
218
217
  },
219
218
  size: {
@@ -293,9 +292,9 @@ const theme = mergeTheme(theme$1, {
293
292
  },
294
293
  border: {
295
294
  radius: {
296
- default: tokens.border.radius.xLarge_12,
297
- small: tokens.border.radius.large_6,
298
- large: tokens.border.radius.xLarge_12
295
+ default: tokens.border.radius.radius_120,
296
+ small: tokens.border.radius.radius_080,
297
+ large: tokens.border.radius.radius_120
299
298
  },
300
299
  width: {
301
300
  focused: tokens.border.width.hairline
@@ -363,87 +362,85 @@ const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
363
362
  themeName
364
363
  } = useScopedTheme(ButtonThemeContext);
365
364
  const sharedStyles = useStyles(themedSharedStyles, theme);
366
- const renderInner = router => {
367
- const {
368
- children,
369
- skipClientNav,
370
- color,
371
- disabled: disabledProp,
372
- focused,
373
- hovered,
374
- href = undefined,
375
- kind = "primary",
376
- labelStyle,
377
- light = false,
378
- pressed,
379
- size = "medium",
380
- style,
381
- testId,
382
- type = undefined,
383
- spinner,
384
- startIcon,
385
- endIcon,
386
- id
387
- } = props,
388
- restProps = _objectWithoutPropertiesLoose(props, _excluded$1);
389
- const buttonStyles = _generateStyles(color, kind, light, size, theme, themeName);
390
- const disabled = spinner || disabledProp;
391
- 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];
392
- const commonProps = _extends({
393
- "data-testid": testId,
394
- id: id,
395
- role: "button",
396
- style: [defaultStyle, style]
397
- }, restProps);
398
- const Label = size === "small" ? LabelSmall : LabelLarge;
399
- const label = React.createElement(Label, {
400
- 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)],
401
- testId: testId ? `${testId}-inner-label` : undefined
402
- }, children);
403
- const sizeMapping = {
404
- medium: "small",
405
- small: "xsmall",
406
- large: "medium"
407
- };
408
- const iconSize = size === "small" ? "small" : "medium";
409
- const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(View, {
410
- style: sharedStyles.iconWrapper
411
- }, React.createElement(ButtonIcon, {
412
- size: iconSize,
413
- icon: startIcon,
414
- style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
415
- testId: testId ? `${testId}-start-icon` : undefined
416
- })), label, spinner && React.createElement(CircularSpinner, {
417
- style: sharedStyles.spinner,
418
- size: sizeMapping[size],
419
- light: kind === "primary",
420
- testId: `${testId || "button"}-spinner`
421
- }), endIcon && React.createElement(View, {
422
- testId: testId ? `${testId}-end-icon-wrapper` : undefined,
423
- style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
424
- }, React.createElement(ButtonIcon, {
425
- size: iconSize,
426
- icon: endIcon,
427
- testId: testId ? `${testId}-end-icon` : undefined
428
- })));
429
- if (href && !disabled) {
430
- return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
431
- to: href,
432
- ref: ref
433
- }), contents) : React.createElement(StyledA, _extends({}, commonProps, {
434
- href: href,
435
- ref: ref
436
- }), contents);
437
- } else {
438
- return React.createElement(StyledButton, _extends({
439
- type: type || "button"
440
- }, commonProps, {
441
- "aria-disabled": disabled,
442
- ref: ref
443
- }), contents);
444
- }
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"
445
406
  };
446
- return React.createElement(__RouterContext.Consumer, null, router => renderInner(router));
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
+ }
447
444
  });
448
445
  const themedSharedStyles = theme => ({
449
446
  shared: {
@@ -686,49 +683,47 @@ const Button = React.forwardRef(function Button(props, ref) {
686
683
  spinner = false
687
684
  } = props,
688
685
  sharedButtonCoreProps = _objectWithoutPropertiesLoose(props, _excluded);
689
- const renderClickableBehavior = router => {
690
- const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
691
- const renderProp = (state, restChildProps) => {
692
- return React.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
693
- disabled: disabled,
694
- spinner: spinner || state.waiting,
695
- color: color,
696
- kind: kind,
697
- light: light,
698
- size: size,
699
- skipClientNav: skipClientNav,
700
- href: href,
701
- target: target,
702
- type: type,
703
- tabIndex: tabIndex,
704
- ref: ref
705
- }), children);
706
- };
707
- if (beforeNav) {
708
- return React.createElement(ClickableBehavior, {
709
- disabled: spinner || disabled,
710
- href: href,
711
- role: "button",
712
- type: type,
713
- onClick: onClick,
714
- beforeNav: beforeNav,
715
- safeWithNav: safeWithNav,
716
- rel: rel
717
- }, renderProp);
718
- } else {
719
- return React.createElement(ClickableBehavior, {
720
- disabled: spinner || disabled,
721
- href: href,
722
- role: "button",
723
- type: type,
724
- onClick: onClick,
725
- safeWithNav: safeWithNav,
726
- target: target,
727
- rel: rel
728
- }, renderProp);
729
- }
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));
730
703
  };
731
- return React.createElement(ThemedButton, null, React.createElement(__RouterContext.Consumer, null, router => renderClickableBehavior(router)));
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
+ }
732
727
  });
733
728
 
734
729
  export { Button as default };
package/dist/index.js CHANGED
@@ -3,10 +3,9 @@
3
3
  var _extends = require('@babel/runtime/helpers/extends');
4
4
  var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
5
5
  var React = require('react');
6
- var reactRouter = require('react-router');
7
6
  var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
7
+ var reactRouterDomV5Compat = require('react-router-dom-v5-compat');
8
8
  var aphrodite = require('aphrodite');
9
- var reactRouterDom = require('react-router-dom');
10
9
  var wonderBlocksTypography = require('@khanacademy/wonder-blocks-typography');
11
10
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
12
11
  var wonderBlocksProgressSpinner = require('@khanacademy/wonder-blocks-progress-spinner');
@@ -237,10 +236,10 @@ const theme$1 = {
237
236
  secondary: -tokens__namespace.spacing.xxxxSmall_2
238
237
  },
239
238
  radius: {
240
- default: tokens__namespace.border.radius.medium_4,
241
- small: tokens__namespace.border.radius.medium_4,
242
- large: tokens__namespace.border.radius.large_6,
243
- icon: tokens__namespace.border.radius.full
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
244
243
  }
245
244
  },
246
245
  size: {
@@ -320,9 +319,9 @@ const theme = wonderBlocksTheming.mergeTheme(theme$1, {
320
319
  },
321
320
  border: {
322
321
  radius: {
323
- default: tokens__namespace.border.radius.xLarge_12,
324
- small: tokens__namespace.border.radius.large_6,
325
- large: tokens__namespace.border.radius.xLarge_12
322
+ default: tokens__namespace.border.radius.radius_120,
323
+ small: tokens__namespace.border.radius.radius_080,
324
+ large: tokens__namespace.border.radius.radius_120
326
325
  },
327
326
  width: {
328
327
  focused: tokens__namespace.border.width.hairline
@@ -383,94 +382,92 @@ function ButtonIcon({
383
382
  const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "labelStyle", "light", "pressed", "size", "style", "testId", "type", "spinner", "startIcon", "endIcon", "id", "waiting"];
384
383
  const StyledA = wonderBlocksCore.addStyle("a");
385
384
  const StyledButton = wonderBlocksCore.addStyle("button");
386
- const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
385
+ const StyledLink = wonderBlocksCore.addStyle(reactRouterDomV5Compat.Link);
387
386
  const ButtonCore = React__namespace.forwardRef(function ButtonCore(props, ref) {
388
387
  const {
389
388
  theme,
390
389
  themeName
391
390
  } = wonderBlocksTheming.useScopedTheme(ButtonThemeContext);
392
391
  const sharedStyles = wonderBlocksTheming.useStyles(themedSharedStyles, theme);
393
- const renderInner = router => {
394
- const {
395
- children,
396
- skipClientNav,
397
- color,
398
- disabled: disabledProp,
399
- focused,
400
- hovered,
401
- href = undefined,
402
- kind = "primary",
403
- labelStyle,
404
- light = false,
405
- pressed,
406
- size = "medium",
407
- style,
408
- testId,
409
- type = undefined,
410
- spinner,
411
- startIcon,
412
- endIcon,
413
- id
414
- } = props,
415
- restProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$1);
416
- const buttonStyles = _generateStyles(color, kind, light, size, theme, themeName);
417
- const disabled = spinner || disabledProp;
418
- 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];
419
- const commonProps = _extends__default["default"]({
420
- "data-testid": testId,
421
- id: id,
422
- role: "button",
423
- style: [defaultStyle, style]
424
- }, restProps);
425
- const Label = size === "small" ? wonderBlocksTypography.LabelSmall : wonderBlocksTypography.LabelLarge;
426
- const label = React__namespace.createElement(Label, {
427
- 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)],
428
- testId: testId ? `${testId}-inner-label` : undefined
429
- }, children);
430
- const sizeMapping = {
431
- medium: "small",
432
- small: "xsmall",
433
- large: "medium"
434
- };
435
- const iconSize = size === "small" ? "small" : "medium";
436
- const contents = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(wonderBlocksCore.View, {
437
- style: sharedStyles.iconWrapper
438
- }, React__namespace.createElement(ButtonIcon, {
439
- size: iconSize,
440
- icon: startIcon,
441
- style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
442
- testId: testId ? `${testId}-start-icon` : undefined
443
- })), label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
444
- style: sharedStyles.spinner,
445
- size: sizeMapping[size],
446
- light: kind === "primary",
447
- testId: `${testId || "button"}-spinner`
448
- }), endIcon && React__namespace.createElement(wonderBlocksCore.View, {
449
- testId: testId ? `${testId}-end-icon-wrapper` : undefined,
450
- style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
451
- }, React__namespace.createElement(ButtonIcon, {
452
- size: iconSize,
453
- icon: endIcon,
454
- testId: testId ? `${testId}-end-icon` : undefined
455
- })));
456
- if (href && !disabled) {
457
- return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
458
- to: href,
459
- ref: ref
460
- }), contents) : React__namespace.createElement(StyledA, _extends__default["default"]({}, commonProps, {
461
- href: href,
462
- ref: ref
463
- }), contents);
464
- } else {
465
- return React__namespace.createElement(StyledButton, _extends__default["default"]({
466
- type: type || "button"
467
- }, commonProps, {
468
- "aria-disabled": disabled,
469
- ref: ref
470
- }), contents);
471
- }
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"
472
433
  };
473
- return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => renderInner(router));
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
+ }
474
471
  });
475
472
  const themedSharedStyles = theme => ({
476
473
  shared: {
@@ -713,49 +710,47 @@ const Button = React__namespace.forwardRef(function Button(props, ref) {
713
710
  spinner = false
714
711
  } = props,
715
712
  sharedButtonCoreProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded);
716
- const renderClickableBehavior = router => {
717
- const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
718
- const renderProp = (state, restChildProps) => {
719
- return React__namespace.createElement(ButtonCore, _extends__default["default"]({}, sharedButtonCoreProps, state, restChildProps, {
720
- disabled: disabled,
721
- spinner: spinner || state.waiting,
722
- color: color,
723
- kind: kind,
724
- light: light,
725
- size: size,
726
- skipClientNav: skipClientNav,
727
- href: href,
728
- target: target,
729
- type: type,
730
- tabIndex: tabIndex,
731
- ref: ref
732
- }), children);
733
- };
734
- if (beforeNav) {
735
- return React__namespace.createElement(ClickableBehavior, {
736
- disabled: spinner || disabled,
737
- href: href,
738
- role: "button",
739
- type: type,
740
- onClick: onClick,
741
- beforeNav: beforeNav,
742
- safeWithNav: safeWithNav,
743
- rel: rel
744
- }, renderProp);
745
- } else {
746
- return React__namespace.createElement(ClickableBehavior, {
747
- disabled: spinner || disabled,
748
- href: href,
749
- role: "button",
750
- type: type,
751
- onClick: onClick,
752
- safeWithNav: safeWithNav,
753
- target: target,
754
- rel: rel
755
- }, renderProp);
756
- }
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));
757
730
  };
758
- return React__namespace.createElement(ThemedButton, null, React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => renderClickableBehavior(router)));
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
+ }
759
754
  });
760
755
 
761
756
  module.exports = Button;
@@ -320,9 +320,9 @@ declare const theme: {
320
320
  secondary: number;
321
321
  };
322
322
  radius: {
323
- default: number;
324
- small: number;
325
- large: number;
323
+ default: string;
324
+ small: string;
325
+ large: string;
326
326
  /**
327
327
  * Icons
328
328
  */
@@ -310,9 +310,9 @@ declare const theme: {
310
310
  secondary: number;
311
311
  };
312
312
  radius: {
313
- default: number;
314
- small: number;
315
- large: number;
313
+ default: string;
314
+ small: string;
315
+ large: string;
316
316
  icon: string;
317
317
  };
318
318
  };
@@ -317,9 +317,9 @@ export declare const ButtonThemeContext: React.Context<{
317
317
  secondary: number;
318
318
  };
319
319
  radius: {
320
- default: number;
321
- small: number;
322
- large: number;
320
+ default: string;
321
+ small: string;
322
+ large: string;
323
323
  icon: string;
324
324
  };
325
325
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-button",
3
- "version": "7.1.6",
3
+ "version": "8.0.1",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,19 +13,20 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@babel/runtime": "^7.24.5",
16
- "@khanacademy/wonder-blocks-clickable": "6.1.6",
16
+ "@khanacademy/wonder-blocks-clickable": "7.0.1",
17
17
  "@khanacademy/wonder-blocks-core": "12.2.1",
18
18
  "@khanacademy/wonder-blocks-icon": "5.1.3",
19
- "@khanacademy/wonder-blocks-progress-spinner": "3.1.6",
19
+ "@khanacademy/wonder-blocks-progress-spinner": "3.1.7",
20
20
  "@khanacademy/wonder-blocks-theming": "3.2.1",
21
- "@khanacademy/wonder-blocks-tokens": "6.0.0",
21
+ "@khanacademy/wonder-blocks-tokens": "7.0.0",
22
22
  "@khanacademy/wonder-blocks-typography": "3.1.3"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "aphrodite": "^1.2.5",
26
26
  "react": "18.2.0",
27
27
  "react-router": "5.3.4",
28
- "react-router-dom": "5.3.4"
28
+ "react-router-dom": "5.3.4",
29
+ "react-router-dom-v5-compat": "^6.30.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@khanacademy/wb-dev-build-settings": "2.1.1"