Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions doc/src/components/common/componentData/Snackbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const componentData = {
name: 'snackbarWrapper',
description: 'Class used for snackbar wrapper element',
},
{
name: 'snackbarContent',
description: 'Class used for snackbar content',
},
{
name: 'close',
description: 'Class used for indefinite snackbar close icon',
},
],
basicComponent: `
class SnackDisplay extends React.Component {
Expand Down Expand Up @@ -106,6 +114,7 @@ export const componentData = {
this.openTopSnackbar = this.openTopSnackbar.bind(this);
this.openIndefiniteSnackbar = this.openIndefiniteSnackbar.bind(this);
this.handleSnackClose = this.handleSnackClose.bind(this);
this.handleIndefiniteSnackClose = this.handleIndefiniteSnackClose.bind(this);
}

openBottomSnackbar() {
Expand Down Expand Up @@ -134,6 +143,12 @@ export const componentData = {
});
}

handleIndefiniteSnackClose() {
this.setState({
showIndefiniteSnackbar: false,
})
}

render() {
return (
<div>
Expand Down Expand Up @@ -176,9 +191,9 @@ export const componentData = {

<Snackbar
active={this.state.showIndefiniteSnackbar}
onClose={this.handleSnackClose}
onClose={this.handleIndefiniteSnackClose}
autoClose={false}>
<span>This is a indefinite snackbar.</span>
<span>This is a indefinite snackbar. Click x to close.</span>
</Snackbar>

</PreviewBlock>
Expand Down
15 changes: 13 additions & 2 deletions lib/snackbar/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { MdClose } from 'react-icons/md';
import { themr } from 'react-css-themr';
import defaultTheme from './theme.module.scss';

Expand Down Expand Up @@ -81,7 +82,7 @@ class Snackbar extends React.Component {

render() {
const {
theme, additionaClasses, position, children,
theme, additionaClasses, position, children, autoClose,
} = this.props;
const { active } = this.state;
const classes = classnames(theme.snackbar, additionaClasses);
Expand All @@ -95,7 +96,17 @@ class Snackbar extends React.Component {
active ? `${theme.active} active` : '',
)}
>
<div className={classes}>{children}</div>
<div className={classes}>
<div className={theme.snackbarContent}>{children}</div>
{
!autoClose && (
<MdClose
onClick={() => this.dismissSnackbar()}
className={classnames(theme.close)}
/>
)
}
</div>
</div>
);
}
Expand Down
34 changes: 29 additions & 5 deletions lib/snackbar/theme.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
will-change: transform;
transition: transform 0.4s;
&.top {
top: 10%;
top: 4%;
&:not(.active) {
-webkit-transform: translateY(-1000%);
transform: translateY(-1000%);
Expand All @@ -20,7 +20,7 @@
}
}
&.bottom {
bottom: 10%;
bottom: 4%;
&:not(.active) {
-webkit-transform: translateY(1000%);
transform: translateY(1000%);
Expand All @@ -34,10 +34,34 @@
}

:local(.snackbar) {
background: $primary-color;
display: flex;
align-items: center;
justify-content: center;
width: 42em;
background: $cool-blue;
border-radius: 3px;
padding: 10px 20px;
padding: 0.9em 1.2em;
margin: 0 auto;
width: 40%;
text-align: center;
box-shadow: 2px 2px 4px #33333352;
color: $original-white;
position: relative;
}

:local(.snackbarContent) {
margin-right: 0.7em;
}

:local(.close) {
color: inherit;
cursor: pointer;
justify-self: flex-end;
position: absolute;
right: 1em;
}

@media only screen and (max-width: 768px) {
:local(.snackbar) {
width: 80%;
}
}