Skip to content

Commit 99500c8

Browse files
KRRISH96rishichawda
authored andcommitted
fix(snackbar): update snackbardesign (#294)
* fix(Snackbar): fix snackbar positioning and responsiveness * feat(Snackbar): Add close icon for indefinite snackbar #287 * docs(Snackbar): Update docs page * style(Snackbar): fix padding
1 parent ed515c4 commit 99500c8

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

doc/src/components/common/componentData/Snackbar/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ export const componentData = {
5353
name: 'snackbarWrapper',
5454
description: 'Class used for snackbar wrapper element',
5555
},
56+
{
57+
name: 'snackbarContent',
58+
description: 'Class used for snackbar content',
59+
},
60+
{
61+
name: 'close',
62+
description: 'Class used for indefinite snackbar close icon',
63+
},
5664
],
5765
basicComponent: `
5866
class SnackDisplay extends React.Component {
@@ -106,6 +114,7 @@ export const componentData = {
106114
this.openTopSnackbar = this.openTopSnackbar.bind(this);
107115
this.openIndefiniteSnackbar = this.openIndefiniteSnackbar.bind(this);
108116
this.handleSnackClose = this.handleSnackClose.bind(this);
117+
this.handleIndefiniteSnackClose = this.handleIndefiniteSnackClose.bind(this);
109118
}
110119
111120
openBottomSnackbar() {
@@ -134,6 +143,12 @@ export const componentData = {
134143
});
135144
}
136145
146+
handleIndefiniteSnackClose() {
147+
this.setState({
148+
showIndefiniteSnackbar: false,
149+
})
150+
}
151+
137152
render() {
138153
return (
139154
<div>
@@ -176,9 +191,9 @@ export const componentData = {
176191
177192
<Snackbar
178193
active={this.state.showIndefiniteSnackbar}
179-
onClose={this.handleSnackClose}
194+
onClose={this.handleIndefiniteSnackClose}
180195
autoClose={false}>
181-
<span>This is a indefinite snackbar.</span>
196+
<span>This is a indefinite snackbar. Click x to close.</span>
182197
</Snackbar>
183198
184199
</PreviewBlock>

lib/snackbar/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
4+
import { MdClose } from 'react-icons/md';
45
import { themr } from 'react-css-themr';
56
import defaultTheme from './theme.module.scss';
67

@@ -81,7 +82,7 @@ class Snackbar extends React.Component {
8182

8283
render() {
8384
const {
84-
theme, additionaClasses, position, children,
85+
theme, additionaClasses, position, children, autoClose,
8586
} = this.props;
8687
const { active } = this.state;
8788
const classes = classnames(theme.snackbar, additionaClasses);
@@ -95,7 +96,17 @@ class Snackbar extends React.Component {
9596
active ? `${theme.active} active` : '',
9697
)}
9798
>
98-
<div className={classes}>{children}</div>
99+
<div className={classes}>
100+
<div className={theme.snackbarContent}>{children}</div>
101+
{
102+
!autoClose && (
103+
<MdClose
104+
onClick={() => this.dismissSnackbar()}
105+
className={classnames(theme.close)}
106+
/>
107+
)
108+
}
109+
</div>
99110
</div>
100111
);
101112
}

lib/snackbar/theme.module.scss

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
will-change: transform;
99
transition: transform 0.4s;
1010
&.top {
11-
top: 10%;
11+
top: 4%;
1212
&:not(.active) {
1313
-webkit-transform: translateY(-1000%);
1414
transform: translateY(-1000%);
@@ -20,7 +20,7 @@
2020
}
2121
}
2222
&.bottom {
23-
bottom: 10%;
23+
bottom: 4%;
2424
&:not(.active) {
2525
-webkit-transform: translateY(1000%);
2626
transform: translateY(1000%);
@@ -34,10 +34,34 @@
3434
}
3535

3636
:local(.snackbar) {
37-
background: $primary-color;
37+
display: flex;
38+
align-items: center;
39+
justify-content: center;
40+
width: 42em;
41+
background: $cool-blue;
3842
border-radius: 3px;
39-
padding: 10px 20px;
43+
padding: 0.9em 1.2em;
4044
margin: 0 auto;
41-
width: 40%;
45+
text-align: center;
4246
box-shadow: 2px 2px 4px #33333352;
47+
color: $original-white;
48+
position: relative;
4349
}
50+
51+
:local(.snackbarContent) {
52+
margin-right: 0.7em;
53+
}
54+
55+
:local(.close) {
56+
color: inherit;
57+
cursor: pointer;
58+
justify-self: flex-end;
59+
position: absolute;
60+
right: 1em;
61+
}
62+
63+
@media only screen and (max-width: 768px) {
64+
:local(.snackbar) {
65+
width: 80%;
66+
}
67+
}

0 commit comments

Comments
 (0)