@shopgate/pwa-common 7.30.0-alpha.9 → 7.30.0-beta.2
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/App.js +28 -13
- package/actions/app/handleUniversalLink.js +0 -2
- package/collections/AuthRoutes.js +15 -13
- package/collections/Configuration.js +11 -10
- package/collections/EmbeddedMedia.js +21 -19
- package/collections/PersistedReducers.js +11 -9
- package/collections/Redirects.js +15 -13
- package/collections/media-providers/MediaProvider.js +23 -21
- package/collections/media-providers/Vimeo.js +28 -22
- package/collections/media-providers/YouTube.js +17 -10
- package/components/Backdrop/index.js +15 -13
- package/components/Backdrop/spec.js +3 -2
- package/components/Button/index.js +41 -29
- package/components/Button/spec.js +16 -10
- package/components/Checkbox/index.js +36 -28
- package/components/Checkbox/spec.js +40 -27
- package/components/Consume/index.js +4 -1
- package/components/CountdownTimer/index.js +27 -20
- package/components/CountdownTimer/spec.js +2 -1
- package/components/Drawer/index.js +31 -23
- package/components/Drawer/spec.js +7 -6
- package/components/Dropdown/index.js +27 -18
- package/components/Ellipsis/index.js +5 -3
- package/components/Ellipsis/spec.js +5 -3
- package/components/EmbeddedMedia/index.js +9 -6
- package/components/EmbeddedMedia/spec.js +11 -2
- package/components/ErrorBoundary/index.js +26 -16
- package/components/Grid/components/Item/index.js +13 -6
- package/components/Grid/components/Item/spec.js +4 -3
- package/components/Grid/index.js +13 -6
- package/components/Grid/spec.js +4 -3
- package/components/HtmlSanitizer/index.js +42 -45
- package/components/HtmlSanitizer/spec.js +16 -12
- package/components/I18n/components/FormatDate/index.js +11 -4
- package/components/I18n/components/FormatDate/spec.js +22 -14
- package/components/I18n/components/FormatNumber/index.js +8 -6
- package/components/I18n/components/FormatNumber/spec.js +10 -5
- package/components/I18n/components/FormatPrice/index.js +5 -3
- package/components/I18n/components/FormatPrice/spec.js +22 -14
- package/components/I18n/components/FormatTime/index.js +11 -4
- package/components/I18n/components/FormatTime/spec.js +22 -14
- package/components/I18n/components/I18nProvider/index.js +18 -11
- package/components/I18n/components/I18nProvider/spec.js +2 -1
- package/components/I18n/components/Placeholder/index.js +10 -3
- package/components/I18n/components/Placeholder/spec.js +12 -5
- package/components/I18n/components/Translate/index.js +12 -8
- package/components/I18n/components/Translate/spec.js +9 -6
- package/components/Icon/index.js +2 -1
- package/components/Image/Image.js +23 -21
- package/components/Image/ImageInner.js +2 -1
- package/components/InfiniteContainer/index.js +59 -53
- package/components/InfiniteContainer/spec.js +10 -5
- package/components/Input/components/MultiLineInput.js +33 -26
- package/components/Input/components/SimpleInput.js +70 -54
- package/components/Input/index.js +7 -17
- package/components/Input/spec.js +12 -11
- package/components/KeyboardConsumer/index.js +19 -13
- package/components/Link/index.js +28 -20
- package/components/Link/spec.js +13 -9
- package/components/List/components/Item/index.js +5 -3
- package/components/List/index.js +5 -3
- package/components/List/spec.js +6 -9
- package/components/Loading/index.js +1 -3
- package/components/Modal/index.js +13 -10
- package/components/ModalContainer/spec.js +24 -20
- package/components/Picker/components/Button/index.js +18 -12
- package/components/Picker/components/List/index.js +19 -16
- package/components/Picker/components/Modal/index.js +34 -25
- package/components/Picker/index.js +44 -33
- package/components/Picker/spec.js +4 -1
- package/components/Portal/index.js +26 -17
- package/components/ProductCharacteristics/index.js +65 -57
- package/components/RangeSlider/components/Handle/index.js +7 -5
- package/components/RangeSlider/index.js +98 -84
- package/components/Route/RouteNotFound.js +30 -19
- package/components/Route/index.js +31 -21
- package/components/Router/index.js +51 -34
- package/components/ScannerContainer/index.js +17 -10
- package/components/Select/components/Item/index.js +5 -3
- package/components/Select/index.js +59 -47
- package/components/Select/spec.js +7 -6
- package/components/SelectBox/components/Item/index.js +23 -13
- package/components/SelectBox/index.js +83 -80
- package/components/SelectBox/spec.js +8 -5
- package/components/SurroundPortals/index.js +15 -11
- package/components/Swiper/components/SwiperItem/index.js +6 -5
- package/components/Swiper/components/SwiperItem/spec.js +8 -4
- package/components/Swiper/index.js +23 -20
- package/components/Toaster/index.js +4 -1
- package/components/Transition/index.js +19 -12
- package/components/Widgets/components/Widget/index.js +27 -16
- package/components/Widgets/components/Widget/spec.js +5 -4
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +4 -3
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +12 -13
- package/helpers/data/index.js +1 -1
- package/helpers/portals/portalCollection.js +13 -10
- package/helpers/redux/mutable.js +2 -2
- package/package.json +5 -5
- package/providers/loading/index.js +71 -57
- package/providers/toast/index.js +39 -28
- package/reducers/modal/index.js +1 -1
- package/store/index.js +1 -1
- package/subscriptions/helpers/buildRegisterUrl.js +1 -0
- package/components/Input/components/DateInput.js +0 -273
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import URLSearchParams from 'url-search-params';
|
|
2
3
|
import MediaProvider from "./MediaProvider";
|
|
3
4
|
|
|
@@ -6,13 +7,18 @@ import MediaProvider from "./MediaProvider";
|
|
|
6
7
|
/**
|
|
7
8
|
* The YouTube media provider class.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
let YouTubeMediaProvider = /*#__PURE__*/function (_MediaProvider) {
|
|
11
|
+
function YouTubeMediaProvider() {
|
|
12
|
+
return _MediaProvider.apply(this, arguments) || this;
|
|
13
|
+
}
|
|
14
|
+
_inheritsLoose(YouTubeMediaProvider, _MediaProvider);
|
|
15
|
+
var _proto = YouTubeMediaProvider.prototype;
|
|
10
16
|
/**
|
|
11
17
|
* Retrieves a list of media containers for YouTube.
|
|
12
18
|
* @param {ParentNode} container A DOM container that may contain YouTube iframes.
|
|
13
19
|
* @returns {NodeListOf<Element>}
|
|
14
20
|
*/
|
|
15
|
-
getMediaContainers(container) {
|
|
21
|
+
_proto.getMediaContainers = function getMediaContainers(container) {
|
|
16
22
|
return container.querySelectorAll('iframe[src*="youtube.com"], iframe[src*="youtube-nocookie.com"]');
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -21,8 +27,8 @@ class YouTubeMediaProvider extends MediaProvider {
|
|
|
21
27
|
* @override
|
|
22
28
|
* @param {ParentNode} container A DOM container.
|
|
23
29
|
* @returns {YouTubeMediaProvider}
|
|
24
|
-
|
|
25
|
-
add(container) {
|
|
30
|
+
*/;
|
|
31
|
+
_proto.add = function add(container) {
|
|
26
32
|
const iframes = this.getMediaContainers(container);
|
|
27
33
|
if (!iframes.length) {
|
|
28
34
|
return this;
|
|
@@ -38,8 +44,8 @@ class YouTubeMediaProvider extends MediaProvider {
|
|
|
38
44
|
*
|
|
39
45
|
* @param {Document} document - The DOM document containing iframes to optimize.
|
|
40
46
|
* @returns {YouTubeMediaProvider}
|
|
41
|
-
|
|
42
|
-
applyIframeOptimizations(document) {
|
|
47
|
+
*/;
|
|
48
|
+
_proto.applyIframeOptimizations = function applyIframeOptimizations(document) {
|
|
43
49
|
const iframes = this.getMediaContainers(document);
|
|
44
50
|
if (!iframes.length) {
|
|
45
51
|
return this;
|
|
@@ -67,8 +73,8 @@ class YouTubeMediaProvider extends MediaProvider {
|
|
|
67
73
|
* Stops all playing videos within the DOM containers.
|
|
68
74
|
* @override
|
|
69
75
|
* @returns {YouTubeMediaProvider}
|
|
70
|
-
|
|
71
|
-
stop() {
|
|
76
|
+
*/;
|
|
77
|
+
_proto.stop = function stop() {
|
|
72
78
|
// Select all iframes in the document. Actually this should be done via the iframes
|
|
73
79
|
// registered in this.containers, but that doesn't seem to work reliably anymore.
|
|
74
80
|
// Since we had to find a quick fix for CURB-5033 we now select all iframes in the document
|
|
@@ -84,8 +90,9 @@ class YouTubeMediaProvider extends MediaProvider {
|
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
92
|
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
93
|
+
};
|
|
94
|
+
return YouTubeMediaProvider;
|
|
95
|
+
}(MediaProvider);
|
|
89
96
|
export default YouTubeMediaProvider;
|
|
90
97
|
|
|
91
98
|
/* eslint-enable class-methods-use-this */
|
|
@@ -9,6 +9,7 @@ import style from "./style";
|
|
|
9
9
|
* @param {Object} props The component props.
|
|
10
10
|
* @returns {JSX.Element}
|
|
11
11
|
*/
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
function Backdrop({
|
|
13
14
|
className,
|
|
14
15
|
color,
|
|
@@ -66,24 +67,25 @@ function Backdrop({
|
|
|
66
67
|
}
|
|
67
68
|
}), [targetOpacity]);
|
|
68
69
|
const combinedClassName = `${style} ${className} common__backdrop`;
|
|
69
|
-
return /*#__PURE__*/
|
|
70
|
+
return /*#__PURE__*/_jsx(Transition, {
|
|
70
71
|
in: isVisible,
|
|
71
72
|
timeout: duration,
|
|
72
73
|
mountOnEnter: true,
|
|
73
74
|
unmountOnExit: true,
|
|
74
75
|
appear: true,
|
|
75
|
-
nodeRef: nodeRef
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
nodeRef: nodeRef,
|
|
77
|
+
children: state => /*#__PURE__*/_jsx("div", {
|
|
78
|
+
ref: nodeRef,
|
|
79
|
+
"data-test-id": "Backdrop",
|
|
80
|
+
"aria-hidden": true,
|
|
81
|
+
className: combinedClassName,
|
|
82
|
+
onClick: onClick,
|
|
83
|
+
style: {
|
|
84
|
+
...baseStyle,
|
|
85
|
+
...transitionStyles[state]
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
});
|
|
87
89
|
}
|
|
88
90
|
Backdrop.defaultProps = {
|
|
89
91
|
className: '',
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow, mount } from 'enzyme';
|
|
3
3
|
import Backdrop from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
describe('<Backdrop />', () => {
|
|
5
6
|
let mockOpen;
|
|
6
7
|
beforeEach(() => {
|
|
7
8
|
mockOpen = jest.fn();
|
|
8
9
|
});
|
|
9
10
|
it('should render', () => {
|
|
10
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
11
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Backdrop, {
|
|
11
12
|
isVisible: true
|
|
12
13
|
}));
|
|
13
14
|
expect(wrapper).toMatchSnapshot();
|
|
14
15
|
});
|
|
15
16
|
it('should execute callback when Backdrop is clicked', () => {
|
|
16
|
-
const wrapper = mount(/*#__PURE__*/
|
|
17
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Backdrop, {
|
|
17
18
|
isVisible: true,
|
|
18
19
|
onClick: mockOpen
|
|
19
20
|
}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
3
|
import React, { Component } from 'react';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
4
5
|
import style from "./style";
|
|
@@ -6,43 +7,54 @@ import style from "./style";
|
|
|
6
7
|
/**
|
|
7
8
|
* The button component.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
get buttonProps() {
|
|
15
|
-
const {
|
|
16
|
-
children,
|
|
17
|
-
testId,
|
|
18
|
-
className,
|
|
19
|
-
disabled,
|
|
20
|
-
onClick,
|
|
21
|
-
...props
|
|
22
|
-
} = this.props;
|
|
23
|
-
const buttonProps = {
|
|
24
|
-
className: `${className} ${style} common__button`,
|
|
25
|
-
disabled,
|
|
26
|
-
onClick: disabled ? null : onClick,
|
|
27
|
-
...props
|
|
28
|
-
};
|
|
29
|
-
return buttonProps;
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
let Button = /*#__PURE__*/function (_Component) {
|
|
12
|
+
function Button() {
|
|
13
|
+
return _Component.apply(this, arguments) || this;
|
|
30
14
|
}
|
|
31
|
-
|
|
15
|
+
_inheritsLoose(Button, _Component);
|
|
16
|
+
var _proto = Button.prototype;
|
|
32
17
|
/**
|
|
33
18
|
* Renders the component.
|
|
34
19
|
* @returns {JSX.Element}
|
|
35
20
|
*/
|
|
36
|
-
render() {
|
|
21
|
+
_proto.render = function render() {
|
|
37
22
|
return (
|
|
38
23
|
/*#__PURE__*/
|
|
39
24
|
// eslint-disable-next-line react/button-has-type
|
|
40
|
-
|
|
41
|
-
"data-test-id": this.props.testId
|
|
42
|
-
|
|
25
|
+
_jsx("button", {
|
|
26
|
+
"data-test-id": this.props.testId,
|
|
27
|
+
...this.buttonProps,
|
|
28
|
+
children: this.props.children
|
|
29
|
+
})
|
|
43
30
|
);
|
|
44
|
-
}
|
|
45
|
-
|
|
31
|
+
};
|
|
32
|
+
return _createClass(Button, [{
|
|
33
|
+
key: "buttonProps",
|
|
34
|
+
get:
|
|
35
|
+
/**
|
|
36
|
+
* Getter for the calculated button props.
|
|
37
|
+
* @returns {Object}
|
|
38
|
+
*/
|
|
39
|
+
function () {
|
|
40
|
+
const {
|
|
41
|
+
children,
|
|
42
|
+
testId,
|
|
43
|
+
className,
|
|
44
|
+
disabled,
|
|
45
|
+
onClick,
|
|
46
|
+
...props
|
|
47
|
+
} = this.props;
|
|
48
|
+
const buttonProps = {
|
|
49
|
+
className: `${className} ${style} common__button`,
|
|
50
|
+
disabled,
|
|
51
|
+
onClick: disabled ? null : onClick,
|
|
52
|
+
...props
|
|
53
|
+
};
|
|
54
|
+
return buttonProps;
|
|
55
|
+
}
|
|
56
|
+
}]);
|
|
57
|
+
}(Component);
|
|
46
58
|
Button.defaultProps = {
|
|
47
59
|
className: '',
|
|
48
60
|
disabled: false,
|
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
3
|
import Button from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
describe('<Button />', () => {
|
|
5
6
|
it('should render the button', () => {
|
|
6
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
7
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
8
|
+
children: "My content"
|
|
9
|
+
}));
|
|
7
10
|
expect(wrapper).toMatchSnapshot();
|
|
8
11
|
expect(wrapper.find('button').length).toBe(1);
|
|
9
12
|
});
|
|
10
13
|
it('should render the button in disabled state', () => {
|
|
11
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
12
|
-
disabled: true
|
|
13
|
-
|
|
14
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
15
|
+
disabled: true,
|
|
16
|
+
children: "My content"
|
|
17
|
+
}));
|
|
14
18
|
expect(wrapper).toMatchSnapshot();
|
|
15
19
|
expect(wrapper.find('button[disabled]').length).toBe(1);
|
|
16
20
|
});
|
|
17
21
|
it('should trigger the click event', () => {
|
|
18
22
|
const callback = jest.fn();
|
|
19
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
20
|
-
onClick: callback
|
|
21
|
-
|
|
23
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
24
|
+
onClick: callback,
|
|
25
|
+
children: "My content"
|
|
26
|
+
}));
|
|
22
27
|
wrapper.simulate('click');
|
|
23
28
|
expect(wrapper).toMatchSnapshot();
|
|
24
29
|
expect(callback).toHaveBeenCalled();
|
|
25
30
|
});
|
|
26
31
|
it('should not trigger the click event when disabled', () => {
|
|
27
32
|
const callback = jest.fn();
|
|
28
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
33
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
|
|
29
34
|
disabled: true,
|
|
30
|
-
onClick: callback
|
|
31
|
-
|
|
35
|
+
onClick: callback,
|
|
36
|
+
children: "My content"
|
|
37
|
+
}));
|
|
32
38
|
wrapper.simulate('click');
|
|
33
39
|
expect(wrapper).toMatchSnapshot();
|
|
34
40
|
expect(callback).not.toHaveBeenCalled();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import classNames from 'classnames';
|
|
@@ -21,66 +22,68 @@ import classNames from 'classnames';
|
|
|
21
22
|
* @extends {React.Component<CheckboxProps>}
|
|
22
23
|
* @returns {JSX.Element}
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
+
let Checkbox = /*#__PURE__*/function (_Component) {
|
|
25
27
|
/**
|
|
26
28
|
* The checkbox component constructor.
|
|
27
29
|
* It checks if the checkbox is a controlled or uncontrolled input and sets an internal state if
|
|
28
30
|
* uncontrolled to keep track of th checked-state.
|
|
29
31
|
* @param {Object} props The Checkbox properties.
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
function Checkbox(props) {
|
|
34
|
+
var _this;
|
|
35
|
+
_this = _Component.call(this, props) || this;
|
|
33
36
|
/**
|
|
34
37
|
* Returns if the checkbox is checked or not.
|
|
35
38
|
* @return {boolean} Is the checkbox checked?
|
|
36
39
|
*/
|
|
37
|
-
|
|
38
|
-
:
|
|
40
|
+
_this.isChecked = () => typeof _this.props.defaultChecked === 'undefined' ? _this.props.checked // Controlled.
|
|
41
|
+
: _this.state.checked // Uncontrolled.
|
|
39
42
|
;
|
|
40
43
|
/**
|
|
41
44
|
* Inverts the current "checked" value and calls the callback function with it.
|
|
42
45
|
* If the checkbox is uncontrolled, it keeps track of the value.
|
|
43
46
|
*/
|
|
44
|
-
|
|
45
|
-
if (
|
|
47
|
+
_this.handleCheck = () => {
|
|
48
|
+
if (_this.props.disabled) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
|
-
const checked = !
|
|
49
|
-
if (typeof
|
|
51
|
+
const checked = !_this.isChecked();
|
|
52
|
+
if (typeof _this.props.defaultChecked !== 'undefined') {
|
|
50
53
|
// Uncontrolled.
|
|
51
|
-
|
|
54
|
+
_this.setState({
|
|
52
55
|
checked
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
|
-
|
|
58
|
+
_this.props.onCheck(checked);
|
|
56
59
|
};
|
|
57
60
|
/**
|
|
58
61
|
* Handler for keyDown events of the checkbox
|
|
59
62
|
* @param {Object} e The keyDown event payload
|
|
60
63
|
*/
|
|
61
|
-
|
|
64
|
+
_this.handleKeyDown = e => {
|
|
62
65
|
if (e.key === ' ') {
|
|
63
66
|
// Toggle checkbox on "space" - mocks behavior of native checkboxes
|
|
64
|
-
|
|
67
|
+
_this.handleCheck();
|
|
65
68
|
}
|
|
66
69
|
};
|
|
67
70
|
/**
|
|
68
71
|
* Renders the checked/unchecked icon.
|
|
69
72
|
* @returns {JSX}
|
|
70
73
|
*/
|
|
71
|
-
|
|
74
|
+
_this.renderIcon = () => _this.isChecked() ? _this.props.checkedIcon : _this.props.uncheckedIcon;
|
|
72
75
|
/**
|
|
73
76
|
* Renders an input if a "name" prop is provided.
|
|
74
77
|
* @returns {JSX}
|
|
75
78
|
*/
|
|
76
|
-
|
|
79
|
+
_this.renderInput = () => {
|
|
77
80
|
const {
|
|
78
81
|
props: {
|
|
79
82
|
name
|
|
80
83
|
},
|
|
81
84
|
isChecked
|
|
82
|
-
} =
|
|
83
|
-
return
|
|
85
|
+
} = _this;
|
|
86
|
+
return _this.props.name ? /*#__PURE__*/_jsx("input", {
|
|
84
87
|
className: "input",
|
|
85
88
|
type: "hidden",
|
|
86
89
|
name: name,
|
|
@@ -92,25 +95,28 @@ class Checkbox extends Component {
|
|
|
92
95
|
* @param {string} side Used to check against which side to render the label on.
|
|
93
96
|
* @returns {JSX}
|
|
94
97
|
*/
|
|
95
|
-
|
|
98
|
+
_this.renderLabelIfItIsOnThe = side => _this.props.labelPosition === side ? _this.props.label : null;
|
|
96
99
|
if (typeof props.defaultChecked !== 'undefined') {
|
|
97
100
|
// Uncontrolled input.
|
|
98
|
-
|
|
101
|
+
_this.state = {
|
|
99
102
|
checked: props.defaultChecked
|
|
100
103
|
};
|
|
101
104
|
} else {
|
|
102
105
|
// Controlled input
|
|
103
|
-
|
|
106
|
+
_this.state = {
|
|
104
107
|
checked: props.checked
|
|
105
108
|
};
|
|
106
109
|
}
|
|
110
|
+
return _this;
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
114
|
* Make sure state is updated with new checked value when input is controlled
|
|
111
115
|
* @param {Object} nextProps Contains the new "checked" status
|
|
112
116
|
*/
|
|
113
|
-
|
|
117
|
+
_inheritsLoose(Checkbox, _Component);
|
|
118
|
+
var _proto = Checkbox.prototype;
|
|
119
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
114
120
|
// Update only for controlled input
|
|
115
121
|
if (typeof this.props.defaultChecked === 'undefined') {
|
|
116
122
|
if (this.state.checked !== nextProps.checked) {
|
|
@@ -119,22 +125,24 @@ class Checkbox extends Component {
|
|
|
119
125
|
});
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
|
-
}
|
|
128
|
+
};
|
|
123
129
|
/**
|
|
124
130
|
* Renders the checkbox component.
|
|
125
131
|
* @returns {JSX}
|
|
126
132
|
*/
|
|
127
|
-
render() {
|
|
128
|
-
return /*#__PURE__*/
|
|
133
|
+
_proto.render = function render() {
|
|
134
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
129
135
|
className: classNames(this.props.className, 'checkbox', 'common__checkbox'),
|
|
130
136
|
onClick: this.handleCheck,
|
|
131
137
|
onKeyDown: this.handleKeyDown,
|
|
132
138
|
role: "checkbox",
|
|
133
139
|
"aria-checked": this.props.checked,
|
|
134
|
-
tabIndex: 0
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
140
|
+
tabIndex: 0,
|
|
141
|
+
children: [this.renderInput(), this.renderLabelIfItIsOnThe('left'), this.renderIcon(), this.renderLabelIfItIsOnThe('right')]
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
return Checkbox;
|
|
145
|
+
}(Component);
|
|
138
146
|
Checkbox.defaultProps = {
|
|
139
147
|
checked: undefined,
|
|
140
148
|
className: undefined,
|
|
@@ -6,55 +6,68 @@ import Checkbox from "./index";
|
|
|
6
6
|
* Checked Icon
|
|
7
7
|
* @returns {JSX}
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const Checked = () => /*#__PURE__*/_jsx("div", {});
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Unchecked Icon
|
|
13
14
|
* @returns {JSX}
|
|
14
15
|
*/
|
|
15
|
-
const Unchecked = () => /*#__PURE__*/
|
|
16
|
+
const Unchecked = () => /*#__PURE__*/_jsx("div", {});
|
|
16
17
|
describe('<Checkbox />', () => {
|
|
17
18
|
it('should render the checkbox with the label before the icon', () => {
|
|
18
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
19
|
-
label: /*#__PURE__*/
|
|
19
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
20
|
+
label: /*#__PURE__*/_jsx("span", {
|
|
21
|
+
children: "Test Label Deluxe"
|
|
22
|
+
}),
|
|
20
23
|
labelPosition: "left",
|
|
21
|
-
checkedIcon: /*#__PURE__*/
|
|
22
|
-
uncheckedIcon: /*#__PURE__*/
|
|
24
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
25
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {}),
|
|
23
26
|
checked: false
|
|
24
27
|
}));
|
|
25
|
-
const expected = /*#__PURE__*/
|
|
28
|
+
const expected = /*#__PURE__*/_jsxs("div", {
|
|
29
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
30
|
+
children: "Test Label Deluxe"
|
|
31
|
+
}), /*#__PURE__*/_jsx(Unchecked, {})]
|
|
32
|
+
});
|
|
26
33
|
expect(wrapper).toMatchSnapshot();
|
|
27
34
|
expect(wrapper.matchesElement(expected)).toBeTruthy();
|
|
28
35
|
});
|
|
29
36
|
it('should render the checkbox with the label after the icon', () => {
|
|
30
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
31
|
-
label: /*#__PURE__*/
|
|
37
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
38
|
+
label: /*#__PURE__*/_jsx("span", {
|
|
39
|
+
children: "Test Label Deluxe"
|
|
40
|
+
}),
|
|
32
41
|
labelPosition: "right",
|
|
33
|
-
checkedIcon: /*#__PURE__*/
|
|
34
|
-
uncheckedIcon: /*#__PURE__*/
|
|
42
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
43
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {}),
|
|
35
44
|
checked: false
|
|
36
45
|
}));
|
|
37
|
-
const expected = /*#__PURE__*/
|
|
46
|
+
const expected = /*#__PURE__*/_jsxs("div", {
|
|
47
|
+
children: [/*#__PURE__*/_jsx(Unchecked, {}), /*#__PURE__*/_jsx("span", {
|
|
48
|
+
children: "Test Label Deluxe"
|
|
49
|
+
})]
|
|
50
|
+
});
|
|
38
51
|
expect(wrapper).toMatchSnapshot();
|
|
39
52
|
expect(wrapper.matchesElement(expected)).toBeTruthy();
|
|
40
53
|
});
|
|
41
54
|
it('should render the unchecked icon if "checked" is false', () => {
|
|
42
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
55
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
43
56
|
checked: false,
|
|
44
57
|
label: "Test Label Deluxe",
|
|
45
|
-
checkedIcon: /*#__PURE__*/
|
|
46
|
-
uncheckedIcon: /*#__PURE__*/
|
|
58
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
59
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {})
|
|
47
60
|
}));
|
|
48
61
|
expect(wrapper).toMatchSnapshot();
|
|
49
62
|
expect(wrapper.find(Checked).length).toBe(0);
|
|
50
63
|
expect(wrapper.find(Unchecked).length).toBe(1);
|
|
51
64
|
});
|
|
52
65
|
it('should render the unchecked icon if "checked" is false', () => {
|
|
53
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
66
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
54
67
|
checked: true,
|
|
55
68
|
label: "Test Label Deluxe",
|
|
56
|
-
checkedIcon: /*#__PURE__*/
|
|
57
|
-
uncheckedIcon: /*#__PURE__*/
|
|
69
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
70
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {})
|
|
58
71
|
}));
|
|
59
72
|
expect(wrapper).toMatchSnapshot();
|
|
60
73
|
expect(wrapper.find(Checked).length).toBe(1);
|
|
@@ -62,10 +75,10 @@ describe('<Checkbox />', () => {
|
|
|
62
75
|
});
|
|
63
76
|
it('should call the callback with the inverted value', () => {
|
|
64
77
|
const spy = jest.fn();
|
|
65
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
78
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
66
79
|
label: "Test Label Deluxe",
|
|
67
|
-
checkedIcon: /*#__PURE__*/
|
|
68
|
-
uncheckedIcon: /*#__PURE__*/
|
|
80
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
81
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {}),
|
|
69
82
|
checked: false,
|
|
70
83
|
onCheck: spy
|
|
71
84
|
}));
|
|
@@ -73,10 +86,10 @@ describe('<Checkbox />', () => {
|
|
|
73
86
|
expect(spy).toHaveBeenCalledWith(true);
|
|
74
87
|
});
|
|
75
88
|
it('should render an <input> element if a name prop is provided', () => {
|
|
76
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
89
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
77
90
|
label: "Test Label Deluxe",
|
|
78
|
-
checkedIcon: /*#__PURE__*/
|
|
79
|
-
uncheckedIcon: /*#__PURE__*/
|
|
91
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
92
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {}),
|
|
80
93
|
defaultChecked: false,
|
|
81
94
|
name: "myCheckbox"
|
|
82
95
|
}));
|
|
@@ -86,10 +99,10 @@ describe('<Checkbox />', () => {
|
|
|
86
99
|
expect(input.prop('value')).toEqual(0);
|
|
87
100
|
});
|
|
88
101
|
it('should work as an uncontrolled input', () => {
|
|
89
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
102
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Checkbox, {
|
|
90
103
|
label: "Test Label Deluxe",
|
|
91
|
-
checkedIcon: /*#__PURE__*/
|
|
92
|
-
uncheckedIcon: /*#__PURE__*/
|
|
104
|
+
checkedIcon: /*#__PURE__*/_jsx(Checked, {}),
|
|
105
|
+
uncheckedIcon: /*#__PURE__*/_jsx(Unchecked, {}),
|
|
93
106
|
defaultChecked: false
|
|
94
107
|
}));
|
|
95
108
|
wrapper.simulate('click');
|
|
@@ -8,11 +8,14 @@ import buildParams from "./helpers/buildParams";
|
|
|
8
8
|
* @param {Object} props.props The props to create.
|
|
9
9
|
* @returns {JSX}
|
|
10
10
|
*/
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
const Consume = ({
|
|
12
13
|
children,
|
|
13
14
|
context: {
|
|
14
15
|
Consumer
|
|
15
16
|
},
|
|
16
17
|
props
|
|
17
|
-
}) => /*#__PURE__*/
|
|
18
|
+
}) => /*#__PURE__*/_jsx(Consumer, {
|
|
19
|
+
children: value => children(buildParams(value, props))
|
|
20
|
+
});
|
|
18
21
|
export default Consume;
|