@shopgate/pwa-ui-material 7.30.0-alpha.10 → 7.30.0-alpha.12
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/Accordion/components/AccordionContent/index.js +12 -8
- package/Accordion/components/AccordionContent/spec.js +15 -10
- package/Accordion/index.js +53 -43
- package/Accordion/spec.js +8 -6
- package/AppBar/components/Below/index.js +11 -9
- package/AppBar/components/Center/index.js +11 -9
- package/AppBar/components/Field/index.js +22 -13
- package/AppBar/components/Icon/index.js +16 -7
- package/AppBar/components/Left/index.js +11 -9
- package/AppBar/components/Right/index.js +11 -9
- package/AppBar/components/Title/index.js +23 -14
- package/AppBar/index.js +19 -15
- package/BaseDialog/components/Buttons/index.js +7 -6
- package/BaseDialog/components/Buttons/spec.js +3 -2
- package/BaseDialog/components/Content/index.js +5 -3
- package/BaseDialog/components/Content/spec.js +3 -2
- package/BaseDialog/components/Title/index.js +10 -7
- package/BaseDialog/components/Title/spec.js +3 -2
- package/BaseDialog/index.js +26 -19
- package/BaseDialog/spec.js +8 -3
- package/FloatingActionButton/index.js +14 -14
- package/NavDrawer/components/Divider/index.js +2 -1
- package/NavDrawer/components/Divider/spec.js +2 -1
- package/NavDrawer/components/Item/index.js +30 -21
- package/NavDrawer/components/Section/index.js +6 -3
- package/NavDrawer/components/Title/index.js +7 -5
- package/NavDrawer/index.js +82 -69
- package/NavDrawer/spec.js +11 -5
- package/SnackBar/index.js +94 -76
- package/icons/ShareIcon.js +5 -4
- package/package.json +6 -6
|
@@ -6,16 +6,18 @@ import styles from "../../style";
|
|
|
6
6
|
* @param {Object} props The component props.
|
|
7
7
|
* @returns {JSX}
|
|
8
8
|
*/
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
const Content = ({
|
|
10
11
|
content
|
|
11
12
|
}) => {
|
|
12
13
|
if (!content) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
15
|
-
return /*#__PURE__*/
|
|
16
|
+
return /*#__PURE__*/_jsx("div", {
|
|
16
17
|
className: styles.body,
|
|
17
|
-
id: "basicDialogDesc"
|
|
18
|
-
|
|
18
|
+
id: "basicDialogDesc",
|
|
19
|
+
children: content
|
|
20
|
+
});
|
|
19
21
|
};
|
|
20
22
|
Content.defaultProps = {
|
|
21
23
|
content: null
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
3
|
import Content from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
describe('<Content />', () => {
|
|
5
6
|
it('should not render if no content is passed', () => {
|
|
6
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
7
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Content, {}));
|
|
7
8
|
expect(wrapper).toMatchSnapshot();
|
|
8
9
|
expect(wrapper.instance()).toEqual(null);
|
|
9
10
|
});
|
|
10
11
|
it('should render content components', () => {
|
|
11
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
12
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Content, {
|
|
12
13
|
content: "Hello World"
|
|
13
14
|
}));
|
|
14
15
|
expect(wrapper).toMatchSnapshot();
|
|
@@ -8,22 +8,25 @@ import styles from "../../style";
|
|
|
8
8
|
* @param {Object} props The component props.
|
|
9
9
|
* @returns {JSX}
|
|
10
10
|
*/
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
const Title = ({
|
|
12
13
|
title
|
|
13
14
|
}) => {
|
|
14
15
|
if (!title) {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
|
-
return /*#__PURE__*/
|
|
18
|
+
return /*#__PURE__*/_jsx("div", {
|
|
18
19
|
className: styles.title,
|
|
19
20
|
id: "basicDialogTitle",
|
|
20
21
|
role: "heading",
|
|
21
|
-
"aria-level": "2"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
"aria-level": "2",
|
|
23
|
+
children: /*#__PURE__*/_jsx(Ellipsis, {
|
|
24
|
+
rows: 3,
|
|
25
|
+
children: typeof title === 'string' ? /*#__PURE__*/_jsx(I18n.Text, {
|
|
26
|
+
string: title
|
|
27
|
+
}) : title
|
|
28
|
+
})
|
|
29
|
+
});
|
|
27
30
|
};
|
|
28
31
|
Title.defaultProps = {
|
|
29
32
|
title: null
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
3
|
import Title from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
describe('<Title />', () => {
|
|
5
6
|
it('should not render without a title', () => {
|
|
6
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
7
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Title, {}));
|
|
7
8
|
expect(wrapper).toMatchSnapshot();
|
|
8
9
|
expect(wrapper.instance()).toEqual(null);
|
|
9
10
|
});
|
|
10
11
|
it('should render with a title', () => {
|
|
11
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
12
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Title, {
|
|
12
13
|
title: "Some test title"
|
|
13
14
|
}));
|
|
14
15
|
expect(wrapper).toMatchSnapshot();
|
package/BaseDialog/index.js
CHANGED
|
@@ -15,29 +15,36 @@ import styles from "./style";
|
|
|
15
15
|
* @param {string | ReactNode} props.title The title of the dialog.
|
|
16
16
|
* @return {JSX.Element} The rendered dialog.
|
|
17
17
|
*/
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
const BasicDialog = ({
|
|
19
20
|
children,
|
|
20
21
|
actions,
|
|
21
22
|
title
|
|
22
|
-
}) => /*#__PURE__*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, /*#__PURE__*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
}) => /*#__PURE__*/_jsx(FocusTrap, {
|
|
24
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
25
|
+
className: `${styles.container} ui-material__base-dialog`,
|
|
26
|
+
"data-test-id": "basicDialog",
|
|
27
|
+
role: "alertdialog",
|
|
28
|
+
"aria-modal": true,
|
|
29
|
+
"aria-labelledby": "basicDialogTitle basicDialogDesc",
|
|
30
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
31
|
+
className: styles.content,
|
|
32
|
+
children: [/*#__PURE__*/_jsx(Title, {
|
|
33
|
+
title: title
|
|
34
|
+
}), /*#__PURE__*/_jsx(Content, {
|
|
35
|
+
content: children
|
|
36
|
+
})]
|
|
37
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
38
|
+
className: styles.actions,
|
|
39
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
40
|
+
className: styles.innerActions,
|
|
41
|
+
children: /*#__PURE__*/_jsx(Buttons, {
|
|
42
|
+
actions: actions
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
})]
|
|
46
|
+
})
|
|
47
|
+
});
|
|
41
48
|
BasicDialog.defaultProps = {
|
|
42
49
|
children: null,
|
|
43
50
|
actions: [],
|
package/BaseDialog/spec.js
CHANGED
|
@@ -4,9 +4,12 @@ import Title from "./components/Title";
|
|
|
4
4
|
import Content from "./components/Content";
|
|
5
5
|
import Buttons from "./components/Buttons";
|
|
6
6
|
import BasicDialog from "./index";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
8
|
const props = {
|
|
8
9
|
title: 'Hello World',
|
|
9
|
-
children: /*#__PURE__*/
|
|
10
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
11
|
+
children: "Hello World"
|
|
12
|
+
}),
|
|
10
13
|
actions: [{
|
|
11
14
|
label: 'action0',
|
|
12
15
|
action: jest.fn()
|
|
@@ -21,13 +24,15 @@ const props = {
|
|
|
21
24
|
jest.mock('@shopgate/engage/a11y/components');
|
|
22
25
|
describe('<BasicDialog />', () => {
|
|
23
26
|
it('should render with minimal props', () => {
|
|
24
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
27
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(BasicDialog, {
|
|
25
28
|
actions: []
|
|
26
29
|
}));
|
|
27
30
|
expect(wrapper).toMatchSnapshot();
|
|
28
31
|
});
|
|
29
32
|
it('should render as expected', () => {
|
|
30
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
33
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(BasicDialog, {
|
|
34
|
+
...props
|
|
35
|
+
}));
|
|
31
36
|
expect(wrapper).toMatchSnapshot();
|
|
32
37
|
expect(wrapper.find(Title).length).toBe(1);
|
|
33
38
|
expect(wrapper.find(Title).props().title).toEqual(props.title);
|
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import colors from "../colors";
|
|
5
5
|
import styles from "./style";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
7
|
const SIZE_BIG = 'big';
|
|
7
8
|
const SIZE_SMALL = 'small';
|
|
8
9
|
/**
|
|
@@ -29,21 +30,20 @@ const FloatingActionButton = props => {
|
|
|
29
30
|
[styles.buttonLarge]: size === SIZE_BIG,
|
|
30
31
|
[styles.buttonShadow]: raised
|
|
31
32
|
});
|
|
32
|
-
return (
|
|
33
|
-
|
|
33
|
+
return /*#__PURE__*/_jsx("button", {
|
|
34
|
+
className: classes,
|
|
35
|
+
disabled: disabled,
|
|
36
|
+
onClick: onClick,
|
|
37
|
+
ref: ref,
|
|
38
|
+
style: {
|
|
39
|
+
background
|
|
40
|
+
}
|
|
34
41
|
// eslint-disable-next-line react/button-has-type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
style: {
|
|
41
|
-
background
|
|
42
|
-
},
|
|
43
|
-
type: type,
|
|
44
|
-
"data-test-id": props.testId
|
|
45
|
-
}, children)
|
|
46
|
-
);
|
|
42
|
+
,
|
|
43
|
+
type: type,
|
|
44
|
+
"data-test-id": props.testId,
|
|
45
|
+
children: children
|
|
46
|
+
});
|
|
47
47
|
};
|
|
48
48
|
FloatingActionButton.defaultProps = {
|
|
49
49
|
background: `var(--color-primary, ${colors.primary})`,
|
|
@@ -4,7 +4,8 @@ import styles from "./style";
|
|
|
4
4
|
/**
|
|
5
5
|
* @returns {JSX}
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const NavDrawerDivider = () => /*#__PURE__*/_jsx("hr", {
|
|
8
9
|
"aria-hidden": true,
|
|
9
10
|
className: styles
|
|
10
11
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { mount } from 'enzyme';
|
|
3
3
|
import Divider from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
describe('<NavDrawerDivider />', () => {
|
|
5
6
|
it('should match the snapshot', () => {
|
|
6
|
-
const wrapper = mount(/*#__PURE__*/
|
|
7
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Divider, {}));
|
|
7
8
|
expect(wrapper).toMatchSnapshot();
|
|
8
9
|
});
|
|
9
10
|
});
|
|
@@ -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 { UIEvents } from '@shopgate/pwa-core';
|
|
@@ -8,30 +9,35 @@ import styles from "./style";
|
|
|
8
9
|
/**
|
|
9
10
|
* The NavDrawerItem component.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
let NavDrawerItem = /*#__PURE__*/function (_Component) {
|
|
14
|
+
function NavDrawerItem(...args) {
|
|
15
|
+
var _this;
|
|
16
|
+
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
14
17
|
/**
|
|
15
18
|
* Handles an Item click by executing it's href.
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
_this.handleClick = () => {
|
|
18
21
|
UIEvents.emit('navdrawer_close');
|
|
19
|
-
setTimeout(
|
|
22
|
+
setTimeout(_this.props.onClick, 300);
|
|
20
23
|
};
|
|
24
|
+
return _this;
|
|
21
25
|
}
|
|
26
|
+
_inheritsLoose(NavDrawerItem, _Component);
|
|
27
|
+
var _proto = NavDrawerItem.prototype;
|
|
22
28
|
/**
|
|
23
29
|
* Only re-render when the label prop changes.
|
|
24
30
|
* @param {Object} nextProps The next component props.
|
|
25
31
|
* @returns {boolean}
|
|
26
32
|
*/
|
|
27
|
-
shouldComponentUpdate(nextProps) {
|
|
33
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
|
28
34
|
return this.props.label !== nextProps.label || this.props['aria-label'] !== nextProps['aria-label'];
|
|
29
|
-
}
|
|
35
|
+
};
|
|
30
36
|
/**
|
|
31
37
|
* Renders the component.
|
|
32
38
|
* @returns {JSX}
|
|
33
39
|
*/
|
|
34
|
-
render() {
|
|
40
|
+
_proto.render = function render() {
|
|
35
41
|
const {
|
|
36
42
|
'aria-hidden': ariaHidden,
|
|
37
43
|
'aria-label': ariaLabel,
|
|
@@ -43,7 +49,7 @@ class NavDrawerItem extends Component {
|
|
|
43
49
|
style,
|
|
44
50
|
testId
|
|
45
51
|
} = this.props;
|
|
46
|
-
return /*#__PURE__*/
|
|
52
|
+
return /*#__PURE__*/_jsxs("button", {
|
|
47
53
|
ref: forwardedRef,
|
|
48
54
|
className: srOnly ? styles.srOnly : styles.button,
|
|
49
55
|
"data-test-id": testId,
|
|
@@ -52,18 +58,21 @@ class NavDrawerItem extends Component {
|
|
|
52
58
|
type: "button",
|
|
53
59
|
"aria-hidden": ariaHidden,
|
|
54
60
|
"aria-label": ariaLabel,
|
|
55
|
-
tabIndex: "0"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
61
|
+
tabIndex: "0",
|
|
62
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
63
|
+
className: styles.iconWrapper,
|
|
64
|
+
children: Icon && /*#__PURE__*/_jsx(Icon, {
|
|
65
|
+
className: styles.icon,
|
|
66
|
+
size: 24
|
|
67
|
+
})
|
|
68
|
+
}), /*#__PURE__*/_jsx(I18n.Text, {
|
|
69
|
+
className: styles.label,
|
|
70
|
+
string: label
|
|
71
|
+
}), Badge && /*#__PURE__*/_jsx(Badge, {})]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
return NavDrawerItem;
|
|
75
|
+
}(Component);
|
|
67
76
|
NavDrawerItem.defaultProps = {
|
|
68
77
|
'aria-hidden': null,
|
|
69
78
|
'aria-label': null,
|
|
@@ -9,6 +9,7 @@ import Divider from "../Divider";
|
|
|
9
9
|
* @param {Object} props The component props.
|
|
10
10
|
* @returns {JSX}
|
|
11
11
|
*/
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
const NavDrawerSection = ({
|
|
13
14
|
children,
|
|
14
15
|
title,
|
|
@@ -18,9 +19,11 @@ const NavDrawerSection = ({
|
|
|
18
19
|
if (!children) {
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
21
|
-
return /*#__PURE__*/
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
23
|
+
children: [dividerTop && /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(Title, {
|
|
24
|
+
text: title
|
|
25
|
+
}), children, dividerBottom && /*#__PURE__*/_jsx(Divider, {})]
|
|
26
|
+
});
|
|
24
27
|
};
|
|
25
28
|
NavDrawerSection.Item = Item;
|
|
26
29
|
NavDrawerSection.defaultProps = {
|
|
@@ -7,17 +7,19 @@ import styles from "./style";
|
|
|
7
7
|
* @param {Object} props The component props.
|
|
8
8
|
* @returns {JSX}
|
|
9
9
|
*/
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
11
|
const NavDrawerTitle = ({
|
|
11
12
|
text
|
|
12
13
|
}) => {
|
|
13
14
|
if (!text.length) {
|
|
14
15
|
return null;
|
|
15
16
|
}
|
|
16
|
-
return /*#__PURE__*/
|
|
17
|
-
className: styles
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
return /*#__PURE__*/_jsx("div", {
|
|
18
|
+
className: styles,
|
|
19
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
20
|
+
string: text
|
|
21
|
+
})
|
|
22
|
+
});
|
|
21
23
|
};
|
|
22
24
|
NavDrawerTitle.defaultProps = {
|
|
23
25
|
text: ''
|
package/NavDrawer/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component, Fragment } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import noop from 'lodash/noop';
|
|
@@ -11,58 +12,61 @@ import Section from "./components/Section";
|
|
|
11
12
|
import Title from "./components/Title";
|
|
12
13
|
import { contentStyle, drawerStyle } from "./style";
|
|
13
14
|
import transition from "./transition";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
16
|
const OPEN = 'navdrawer_open';
|
|
15
17
|
const CLOSE = 'navdrawer_close';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* The NavDrawer component
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
let NavDrawer = /*#__PURE__*/function (_Component) {
|
|
21
23
|
/**
|
|
22
24
|
* @param {Object} props The component props.
|
|
23
25
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
function NavDrawer(props) {
|
|
27
|
+
var _this;
|
|
28
|
+
_this = _Component.call(this, props) || this;
|
|
29
|
+
_this.onEntering = () => {
|
|
30
|
+
_this.props.onOpen();
|
|
28
31
|
};
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
+
_this.onEntered = () => {
|
|
33
|
+
if (_this.a11yCloseRef.current) {
|
|
34
|
+
_this.a11yCloseRef.current.focus();
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
+
_this.onExited = () => {
|
|
38
|
+
_this.contentRef.current.scrollTop = 0;
|
|
39
|
+
if (_this.triggerElement && typeof _this.triggerElement.focus === 'function') {
|
|
37
40
|
// Focus the element that triggered the NavDrawer after it closes
|
|
38
|
-
|
|
41
|
+
_this.triggerElement.focus();
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
_this.onExiting = () => {
|
|
45
|
+
_this.props.onClose();
|
|
43
46
|
};
|
|
44
|
-
|
|
47
|
+
_this.open = () => {
|
|
45
48
|
// Save a reference to the element that triggered the NavDrawer
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
_this.triggerElement = document.activeElement;
|
|
50
|
+
_this.setState({
|
|
48
51
|
open: true
|
|
49
52
|
});
|
|
50
53
|
};
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
_this.close = () => {
|
|
55
|
+
_this.setState({
|
|
53
56
|
open: false
|
|
54
57
|
});
|
|
55
58
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
_this.contentRef = /*#__PURE__*/React.createRef();
|
|
60
|
+
_this.a11yCloseRef = /*#__PURE__*/React.createRef();
|
|
61
|
+
_this.state = {
|
|
59
62
|
open: false
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
// Save a reference to the element that triggered the NavDrawer
|
|
63
|
-
|
|
64
|
-
UIEvents.addListener(OPEN,
|
|
65
|
-
UIEvents.addListener(CLOSE,
|
|
66
|
+
_this.triggerElement = null;
|
|
67
|
+
UIEvents.addListener(OPEN, _this.open);
|
|
68
|
+
UIEvents.addListener(CLOSE, _this.close);
|
|
69
|
+
return _this;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
/**
|
|
@@ -70,66 +74,75 @@ class NavDrawer extends Component {
|
|
|
70
74
|
* @param {Object} nextState The next component state.
|
|
71
75
|
* @returns {JSX}
|
|
72
76
|
*/
|
|
73
|
-
|
|
77
|
+
_inheritsLoose(NavDrawer, _Component);
|
|
78
|
+
var _proto = NavDrawer.prototype;
|
|
79
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
74
80
|
return this.state.open !== nextState.open;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
/**
|
|
78
84
|
* The unmount lifecycle hook
|
|
79
|
-
|
|
80
|
-
componentWillUnmount() {
|
|
85
|
+
*/;
|
|
86
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
81
87
|
UIEvents.removeListener(OPEN, this.open);
|
|
82
88
|
UIEvents.removeListener(CLOSE, this.close);
|
|
83
|
-
}
|
|
89
|
+
};
|
|
84
90
|
/**
|
|
85
91
|
* @returns {JSX}
|
|
86
92
|
*/
|
|
87
|
-
render() {
|
|
88
|
-
return /*#__PURE__*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
93
|
+
_proto.render = function render() {
|
|
94
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
95
|
+
children: [/*#__PURE__*/_jsx(Transition, {
|
|
96
|
+
onEntering: this.onEntering,
|
|
97
|
+
onEntered: this.onEntered,
|
|
98
|
+
onExited: this.onExited,
|
|
99
|
+
onExiting: this.onExiting,
|
|
100
|
+
in: this.state.open,
|
|
101
|
+
timeout: 300,
|
|
102
|
+
children: state => {
|
|
103
|
+
const ariaHidden = this.props['aria-hidden'] || state === 'exited';
|
|
104
|
+
return /*#__PURE__*/_jsx(ModalStateTracker, {
|
|
105
|
+
isVisible: this.state.open,
|
|
106
|
+
children: /*#__PURE__*/_jsxs("section", {
|
|
107
|
+
className: `${drawerStyle} ui-material__nav-drawer`,
|
|
108
|
+
"data-test-id": "NavDrawer",
|
|
109
|
+
style: transition[state],
|
|
110
|
+
"aria-hidden": ariaHidden,
|
|
111
|
+
tabIndex: "-1",
|
|
112
|
+
children: [/*#__PURE__*/_jsx(Item, {
|
|
113
|
+
label: "common.close",
|
|
114
|
+
ref: this.a11yCloseRef,
|
|
115
|
+
srOnly: true
|
|
116
|
+
}), /*#__PURE__*/_jsx("nav", {
|
|
117
|
+
className: contentStyle,
|
|
118
|
+
ref: this.contentRef,
|
|
119
|
+
children: this.props.children
|
|
120
|
+
})]
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}), /*#__PURE__*/_jsx(Backdrop, {
|
|
125
|
+
isVisible: this.state.open,
|
|
126
|
+
level: 4,
|
|
127
|
+
onClick: this.close,
|
|
128
|
+
opacity: 20
|
|
129
|
+
})]
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
return NavDrawer;
|
|
133
|
+
}(Component);
|
|
127
134
|
NavDrawer.EVENT_OPEN = OPEN;
|
|
128
135
|
NavDrawer.EVENT_CLOSE = CLOSE;
|
|
129
136
|
NavDrawer.Divider = Divider;
|
|
130
137
|
NavDrawer.Item = Item;
|
|
131
138
|
NavDrawer.Section = Section;
|
|
132
139
|
NavDrawer.Title = Title;
|
|
140
|
+
NavDrawer.close = () => {
|
|
141
|
+
UIEvents.emit(CLOSE);
|
|
142
|
+
};
|
|
143
|
+
NavDrawer.open = () => {
|
|
144
|
+
UIEvents.emit(OPEN);
|
|
145
|
+
};
|
|
133
146
|
NavDrawer.defaultProps = {
|
|
134
147
|
'aria-hidden': false,
|
|
135
148
|
onClose: noop,
|
package/NavDrawer/spec.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow, mount } from 'enzyme';
|
|
3
3
|
import NavDrawer from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
jest.unmock('@shopgate/pwa-core');
|
|
5
6
|
jest.mock('@shopgate/engage/components');
|
|
6
7
|
jest.mock('@shopgate/engage/a11y/components');
|
|
7
8
|
describe('NavDrawer', () => {
|
|
8
9
|
it('should match the snapshot', () => {
|
|
9
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
10
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(NavDrawer, {
|
|
11
|
+
children: "Content"
|
|
12
|
+
}));
|
|
10
13
|
expect(wrapper).toMatchSnapshot();
|
|
11
14
|
});
|
|
12
15
|
it('should open and close with an event', () => {
|
|
13
16
|
const onOpen = jest.fn();
|
|
14
17
|
const onClose = jest.fn();
|
|
15
|
-
const wrapper = mount(/*#__PURE__*/
|
|
18
|
+
const wrapper = mount(/*#__PURE__*/_jsx(NavDrawer, {
|
|
16
19
|
onOpen: onOpen,
|
|
17
|
-
onClose: onClose
|
|
18
|
-
|
|
20
|
+
onClose: onClose,
|
|
21
|
+
children: "Content"
|
|
22
|
+
}));
|
|
19
23
|
NavDrawer.open();
|
|
20
24
|
expect(wrapper.state().open).toEqual(true);
|
|
21
25
|
expect(onOpen).toHaveBeenCalled();
|
|
@@ -25,7 +29,9 @@ describe('NavDrawer', () => {
|
|
|
25
29
|
expect(onClose).toHaveBeenCalled();
|
|
26
30
|
});
|
|
27
31
|
it('should close when Backdrop is clicked', () => {
|
|
28
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
32
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(NavDrawer, {
|
|
33
|
+
children: "Content"
|
|
34
|
+
}));
|
|
29
35
|
const backdrop = wrapper.find('Backdrop');
|
|
30
36
|
NavDrawer.open();
|
|
31
37
|
expect(wrapper.state().open).toEqual(true);
|