@khanacademy/wonder-blocks-button 7.1.6 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/components/button-core.d.ts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/es/index.js +119 -124
- package/dist/index.js +120 -125
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-button
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 38c926c: Upgrade WB to using react-router-dom-v5-compat.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [38c926c]
|
|
12
|
+
- @khanacademy/wonder-blocks-clickable@7.0.0
|
|
13
|
+
- @khanacademy/wonder-blocks-core@12.2.1
|
|
14
|
+
|
|
3
15
|
## 7.1.6
|
|
4
16
|
|
|
5
17
|
### 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';
|
|
@@ -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
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
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
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
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');
|
|
@@ -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(
|
|
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
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
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
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
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
|
-
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-button",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@babel/runtime": "^7.24.5",
|
|
16
|
-
"@khanacademy/wonder-blocks-clickable": "
|
|
16
|
+
"@khanacademy/wonder-blocks-clickable": "7.0.0",
|
|
17
17
|
"@khanacademy/wonder-blocks-core": "12.2.1",
|
|
18
18
|
"@khanacademy/wonder-blocks-icon": "5.1.3",
|
|
19
19
|
"@khanacademy/wonder-blocks-progress-spinner": "3.1.6",
|
|
@@ -25,7 +25,8 @@
|
|
|
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"
|