@shopgate/pwa-ui-material 7.30.0-alpha.7 → 7.30.0-alpha.8
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 +51 -2
- package/Accordion/components/AccordionContent/spec.js +32 -1
- package/Accordion/components/AccordionContent/style.js +9 -1
- package/Accordion/index.js +90 -2
- package/Accordion/spec.js +39 -1
- package/Accordion/style.js +47 -1
- package/AppBar/components/Below/index.js +24 -2
- package/AppBar/components/Center/index.js +24 -2
- package/AppBar/components/Field/index.js +39 -3
- package/AppBar/components/Field/style.js +14 -1
- package/AppBar/components/Icon/index.js +43 -3
- package/AppBar/components/Icon/style.js +14 -1
- package/AppBar/components/Left/index.js +24 -2
- package/AppBar/components/Right/index.js +24 -2
- package/AppBar/components/Title/index.js +37 -3
- package/AppBar/components/Title/style.js +11 -1
- package/AppBar/index.js +87 -3
- package/AppBar/style.js +21 -1
- package/BaseDialog/components/Buttons/index.js +28 -2
- package/BaseDialog/components/Buttons/spec.js +28 -1
- package/BaseDialog/components/Content/index.js +21 -2
- package/BaseDialog/components/Content/spec.js +17 -1
- package/BaseDialog/components/Title/index.js +29 -2
- package/BaseDialog/components/Title/spec.js +17 -1
- package/BaseDialog/index.js +39 -2
- package/BaseDialog/spec.js +39 -1
- package/BaseDialog/style.js +64 -1
- package/FloatingActionButton/index.js +56 -3
- package/FloatingActionButton/style.js +33 -1
- package/NavDrawer/components/Divider/index.js +10 -2
- package/NavDrawer/components/Divider/spec.js +9 -1
- package/NavDrawer/components/Divider/style.js +12 -2
- package/NavDrawer/components/Item/index.js +72 -6
- package/NavDrawer/components/Item/style.js +49 -1
- package/NavDrawer/components/Section/index.js +29 -2
- package/NavDrawer/components/Title/index.js +23 -2
- package/NavDrawer/components/Title/style.js +8 -1
- package/NavDrawer/index.js +132 -10
- package/NavDrawer/spec.js +35 -1
- package/NavDrawer/style.js +26 -1
- package/NavDrawer/transition.js +20 -1
- package/SnackBar/index.js +158 -23
- package/SnackBar/style.js +64 -2
- package/colors.js +4 -1
- package/icons/ShareIcon.js +11 -2
- package/index.js +5 -1
- package/jest.config.js +1 -1
- package/package.json +2 -2
package/SnackBar/index.js
CHANGED
|
@@ -1,33 +1,168 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { config } from 'react-spring';
|
|
5
|
+
import { Spring } from 'react-spring/renderprops.cjs';
|
|
6
|
+
import Ellipsis from '@shopgate/pwa-common/components/Ellipsis';
|
|
7
|
+
import styles from "./style";
|
|
8
|
+
const defaultToast = {};
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* The SnackBar component.
|
|
3
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
class SnackBar extends Component {
|
|
14
|
+
/**
|
|
4
15
|
* @param {Object} props The component props.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
*/
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
this.timer = null;
|
|
20
|
+
this.handleAction = () => {
|
|
21
|
+
clearTimeout(this.timer);
|
|
22
|
+
this.props.toasts[0].action();
|
|
23
|
+
this.hide();
|
|
24
|
+
};
|
|
25
|
+
this.handleEntered = () => {
|
|
26
|
+
this.timer = setTimeout(this.hide, this.props.toasts[0].duration || 2500);
|
|
27
|
+
};
|
|
28
|
+
this.handleRest = () => {
|
|
29
|
+
if (this.state.visible) {
|
|
30
|
+
this.handleEntered();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.props.removeToast();
|
|
34
|
+
};
|
|
35
|
+
this.hide = () => {
|
|
36
|
+
this.setState({
|
|
37
|
+
visible: false
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Calculates the required amount of rows for the snack bar.
|
|
42
|
+
* @param {string} message The snack bar message.
|
|
43
|
+
* @param {string} actionLabel The snack bar action label.
|
|
13
44
|
* @return {number}
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
45
|
+
*/
|
|
46
|
+
this.calcRows = (message, actionLabel) => {
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the amount of rows for a passed text.
|
|
49
|
+
* @param {string} text The input text.
|
|
50
|
+
* @return {number}
|
|
51
|
+
*/
|
|
52
|
+
const calc = text => Math.max(2, Math.ceil(text.length / 40));
|
|
53
|
+
/**
|
|
54
|
+
* First calculate the required amount of rows for the message. Then append the action label
|
|
55
|
+
* once per line and calculate the rows again. Since the action label occupies an own column,
|
|
56
|
+
* we'll get an approximated number for the required rows.
|
|
57
|
+
*/
|
|
58
|
+
return calc(`${message}${actionLabel.repeat(calc(message))}`);
|
|
59
|
+
};
|
|
60
|
+
this.state = {
|
|
61
|
+
visible: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
19
66
|
* @param {Object} nextProps The next component props.
|
|
20
|
-
*/
|
|
67
|
+
*/
|
|
68
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
69
|
+
const hasToast = nextProps.toasts.length > 0;
|
|
70
|
+
this.setState({
|
|
71
|
+
visible: hasToast
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
21
76
|
* @param {Object} nextProps The next component props.
|
|
22
77
|
* @param {Object} nextState The next component state.
|
|
23
78
|
* @returns {boolean}
|
|
24
|
-
*/
|
|
79
|
+
*/
|
|
80
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
81
|
+
return this.state.visible !== nextState.visible;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
25
84
|
* Returns the first snack from the state.
|
|
26
85
|
* @returns {Object}
|
|
27
|
-
*/
|
|
86
|
+
*/
|
|
87
|
+
get snack() {
|
|
88
|
+
const {
|
|
89
|
+
__
|
|
90
|
+
} = this.context.i18n();
|
|
91
|
+
const snack = this.props.toasts.length ? this.props.toasts[0] : defaultToast;
|
|
92
|
+
return {
|
|
93
|
+
...snack,
|
|
94
|
+
message: __(snack.message || '', snack.messageParams || {}),
|
|
95
|
+
actionLabel: __(snack.actionLabel || '')
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
28
99
|
* @returns {JSX}
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
100
|
+
*/
|
|
101
|
+
render() {
|
|
102
|
+
const {
|
|
103
|
+
visible
|
|
104
|
+
} = this.state;
|
|
105
|
+
const {
|
|
106
|
+
action = null,
|
|
107
|
+
actionLabel = null,
|
|
108
|
+
message = null
|
|
109
|
+
} = this.snack;
|
|
110
|
+
|
|
111
|
+
// Action exits without actionLabel. Handle the whole box
|
|
112
|
+
const boxProps = {
|
|
113
|
+
...(action && !actionLabel && {
|
|
114
|
+
onClick: this.handleAction
|
|
115
|
+
})
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Calculate the required amount of rows and the height of the snack bar.
|
|
119
|
+
const rows = this.calcRows(message, actionLabel);
|
|
120
|
+
const snackBarHeight = 40 + rows * 20;
|
|
121
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
122
|
+
className: `${styles.container} ui-material__snack-bar`,
|
|
123
|
+
style: {
|
|
124
|
+
'--snack-bar-height': `${snackBarHeight}px`
|
|
125
|
+
}
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Spring, {
|
|
127
|
+
from: {
|
|
128
|
+
top: snackBarHeight
|
|
129
|
+
},
|
|
130
|
+
to: {
|
|
131
|
+
top: 0
|
|
132
|
+
},
|
|
133
|
+
config: config.stiff,
|
|
134
|
+
reverse: !visible,
|
|
135
|
+
force: true,
|
|
136
|
+
onRest: this.handleRest
|
|
137
|
+
}, props =>
|
|
138
|
+
/*#__PURE__*/
|
|
139
|
+
// eslint-disable-next-line max-len
|
|
140
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
141
|
+
React.createElement("div", {
|
|
142
|
+
className: styles.wrapper,
|
|
143
|
+
style: props,
|
|
144
|
+
"data-footer-inset-update-ignore": "true",
|
|
145
|
+
onClick: this.hide
|
|
146
|
+
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
147
|
+
className: styles.box
|
|
148
|
+
}, boxProps), /*#__PURE__*/React.createElement(Ellipsis, {
|
|
149
|
+
rows: rows
|
|
150
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
151
|
+
className: styles.label,
|
|
152
|
+
"aria-live": "assertive",
|
|
153
|
+
role: "status"
|
|
154
|
+
}, message)), action && actionLabel && /*#__PURE__*/React.createElement("button", {
|
|
155
|
+
className: styles.button,
|
|
156
|
+
onClick: this.handleAction,
|
|
157
|
+
type: "button",
|
|
158
|
+
"aria-hidden": true
|
|
159
|
+
}, actionLabel)))));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
SnackBar.defaultProps = {
|
|
163
|
+
toasts: null
|
|
164
|
+
};
|
|
165
|
+
SnackBar.contextTypes = {
|
|
166
|
+
i18n: PropTypes.func
|
|
167
|
+
};
|
|
168
|
+
export default SnackBar;
|
package/SnackBar/style.js
CHANGED
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
2
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import Color from 'color';
|
|
3
|
+
import { themeColors, themeShadows } from '@shopgate/pwa-common/helpers/config';
|
|
4
|
+
const backgroundColor = themeColors.lightDark;
|
|
5
|
+
const buttonColor = themeColors.accent;
|
|
6
|
+
const buttonColorContrast = Color(buttonColor).contrast(Color(backgroundColor));
|
|
7
|
+
// Button color can be anything. Fall back to white if accent is too dark.
|
|
8
|
+
const safeButtonColor = buttonColorContrast > 4 ? buttonColor : themeColors.light;
|
|
9
|
+
const container = css({
|
|
10
|
+
position: 'fixed',
|
|
11
|
+
height: 'var(--snack-bar-height, 80px)',
|
|
12
|
+
bottom: 'max(var(--footer-height), var(--safe-area-inset-bottom))',
|
|
13
|
+
transition: 'bottom 0.3s ease',
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
zIndex: 6,
|
|
16
|
+
width: '100%'
|
|
17
|
+
});
|
|
18
|
+
const wrapper = css({
|
|
19
|
+
top: 'var(--snack-bar-height, 80px)',
|
|
20
|
+
display: 'flex',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
left: 0,
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
width: '100%',
|
|
25
|
+
zIndex: 6
|
|
26
|
+
});
|
|
27
|
+
const box = css({
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
background: backgroundColor,
|
|
30
|
+
borderRadius: 3,
|
|
31
|
+
boxShadow: themeShadows.toast,
|
|
32
|
+
color: themeColors.light,
|
|
33
|
+
display: 'flex',
|
|
34
|
+
fontSize: '0.875rem',
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
|
+
letterSpacing: 0.5,
|
|
37
|
+
margin: 16,
|
|
38
|
+
maxWidth: 344,
|
|
39
|
+
minHeight: 48,
|
|
40
|
+
padding: '6px 16px',
|
|
41
|
+
width: '100%'
|
|
42
|
+
});
|
|
43
|
+
const label = css({
|
|
44
|
+
lineHeight: 1.4,
|
|
45
|
+
margin: '6px 0',
|
|
46
|
+
overflow: 'hidden'
|
|
47
|
+
}).toString();
|
|
48
|
+
const button = css({
|
|
49
|
+
color: safeButtonColor,
|
|
50
|
+
fontWeight: 500,
|
|
51
|
+
height: 36,
|
|
52
|
+
letterSpacing: 'inherit',
|
|
53
|
+
margin: '0 -8px 0 8px',
|
|
54
|
+
outline: 0,
|
|
55
|
+
padding: '0 8px',
|
|
56
|
+
textTransform: 'uppercase'
|
|
57
|
+
});
|
|
58
|
+
export default {
|
|
59
|
+
container,
|
|
60
|
+
wrapper,
|
|
61
|
+
box,
|
|
62
|
+
label,
|
|
63
|
+
button
|
|
64
|
+
};
|
package/colors.js
CHANGED
package/icons/ShareIcon.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Icon from '@shopgate/pwa-common/components/Icon';
|
|
4
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* The Share icon component.
|
|
3
8
|
* @param {Object} props The icon component properties.
|
|
4
9
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const ShareIcon = props => /*#__PURE__*/React.createElement(Icon, _extends({
|
|
12
|
+
content: themeConfig.icons.share
|
|
13
|
+
}, props));
|
|
14
|
+
export default ShareIcon;
|
package/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export{default as Accordion
|
|
1
|
+
export { default as Accordion } from "./Accordion";
|
|
2
|
+
export { default as AppBar } from "./AppBar";
|
|
3
|
+
export { default as FloatingActionButton } from "./FloatingActionButton";
|
|
4
|
+
export { default as NavDrawer } from "./NavDrawer";
|
|
5
|
+
export { default as SnackBar } from "./SnackBar";
|
package/jest.config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Require the default configuration.
|
|
2
|
-
module.exports=require('@shopgate/pwa-unit-test/jest.config');
|
|
2
|
+
module.exports = require('@shopgate/pwa-unit-test/jest.config');
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-ui-material",
|
|
3
|
-
"version": "7.30.0-alpha.
|
|
3
|
+
"version": "7.30.0-alpha.8",
|
|
4
4
|
"description": "Shopgate's material design UI components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@shopgate/pwa-common": "7.30.0-alpha.
|
|
8
|
+
"@shopgate/pwa-common": "7.30.0-alpha.8",
|
|
9
9
|
"react": "~16.14.0",
|
|
10
10
|
"react-dom": "~16.14.0",
|
|
11
11
|
"redux": "^4.2.1"
|