Merge pull request #2182 from mkonikov/snackbar-improvements

Snackbar improvements
This commit is contained in:
Kim Gardner
2019-02-13 13:57:35 -05:00
committed by GitHub
+31 -6
View File
@@ -7,17 +7,25 @@ const DEFAULT_STYLE = {
willChange: 'transform, opacity',
transition: 'transform .35s cubic-bezier(.55,0,.1,1), opacity .35s',
pointerEvents: 'none',
padding: '12px 18px',
padding: '12px 18px 0',
color: '#fff',
borderRadius: '3px 3px 0 0',
textAlign: 'center',
borderRadius: '4px',
maxWidth: '400px',
left: '50%',
opacity: 0,
transform: 'translate(-50%, 20px)',
bottom: 0,
bottom: '20px',
boxSizing: 'border-box',
fontFamily: 'Helvetica, "Helvetica Neue", Verdana, sans-serif',
display: 'flex',
};
const CLOSE_STYLE = {
fontSize: '20px',
cursor: 'pointer',
marginLeft: '10px',
position: 'relative',
top: '-4px',
};
export default class Snackbar {
@@ -26,6 +34,20 @@ export default class Snackbar {
this.el = document.createElement('div');
this.el.id = 'coral-notif';
const closeButton = document.createElement('div');
closeButton.className = 'coral-notif-close';
for (let key in CLOSE_STYLE) {
closeButton.style[key] = CLOSE_STYLE[key];
}
closeButton.textContent = '×';
closeButton.onclick = () => this.clear();
this.snackbarText = document.createElement('div');
this.snackbarText.className = 'coral-notif-text';
this.snackbarText.style.paddingBottom = '12px';
this.el.appendChild(this.snackbarText);
this.el.appendChild(closeButton);
// Apply custom styles to the snackbar.
const style = Object.assign({}, DEFAULT_STYLE, customStyle);
for (let key in style) {
@@ -35,6 +57,7 @@ export default class Snackbar {
clear() {
this.el.style.opacity = 0;
this.el.style.pointerEvents = 'none';
}
alert(message) {
@@ -42,7 +65,7 @@ export default class Snackbar {
this.el.style.transform = 'translate(-50%, 20px)';
this.el.style.opacity = 0;
this.el.className = `coral-notif-${type}`;
this.el.textContent = text;
this.snackbarText.textContent = text;
if (this.timeout) {
clearTimeout(this.timeout);
@@ -51,10 +74,12 @@ export default class Snackbar {
this.timeout = setTimeout(() => {
this.el.style.transform = 'translate(-50%, 0)';
this.el.style.opacity = 1;
this.el.style.pointerEvents = 'auto';
this.timeout = setTimeout(() => {
this.el.style.opacity = 0;
}, 7000);
this.el.style.pointerEvents = 'none';
}, 15000);
}, 0);
}