Skip to content

Commit f3f7ecc

Browse files
committed
fix style issues
1 parent 765d505 commit f3f7ecc

File tree

6 files changed

+149
-26
lines changed

6 files changed

+149
-26
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
export const defaultCode = `
2+
class SnackDisplay extends React.Component {
3+
constructor(props) {
4+
super(props);
5+
this.state = {
6+
showSnackbar: false,
7+
showTopSnackbar: false,
8+
showIndefiniteSnackbar: false,
9+
}
10+
this.openBottomSnackbar = this.openBottomSnackbar.bind(this);
11+
this.openTopSnackbar = this.openTopSnackbar.bind(this);
12+
this.openIndefiniteSnackbar = this.openIndefiniteSnackbar.bind(this);
13+
this.handleSnackClose = this.handleSnackClose.bind(this);
14+
}
15+
16+
openBottomSnackbar() {
17+
this.setState({
18+
showSnackbar: !this.state.showSnackbar
19+
});
20+
}
21+
22+
openTopSnackbar() {
23+
this.setState({
24+
showTopSnackbar: !this.state.showTopSnackbar
25+
});
26+
}
27+
28+
openIndefiniteSnackbar() {
29+
this.setState({
30+
showIndefiniteSnackbar: !this.state.showIndefiniteSnackbar
31+
});
32+
}
33+
34+
35+
handleSnackClose() {
36+
this.setState({
37+
showSnackbar: false,
38+
showTopSnackbar: false,
39+
});
40+
}
41+
42+
render() {
43+
return (
44+
<div>
45+
<Snackbar
46+
active={this.state.showSnackbar}
47+
onClose={this.handleSnackClose}>
48+
<span>This is a bottom snackbar.</span>
49+
</Snackbar>
50+
<Snackbar
51+
active={this.state.showTopSnackbar}
52+
onClose={this.handleSnackClose}
53+
position='top'>
54+
<span>This is a top snackbar.</span>
55+
</Snackbar>
56+
<Snackbar
57+
active={this.state.showIndefiniteSnackbar}
58+
onClose={this.handleSnackClose}
59+
autoClose={false}>
60+
<span>This is a indefinite snackbar.</span>
61+
</Snackbar>
62+
<div style={{margin: '10px'}}>
63+
<Button type="primary" onClick={this.openBottomSnackbar}>Open Bottom Snackbar</Button>
64+
</div>
65+
<div style={{margin: '10px'}}>
66+
<Button type="primary" onClick={this.openTopSnackbar}>Open Top Snackbar</Button>
67+
</div>
68+
<div style={{margin: '10px'}}>
69+
<Button type="primary" onClick={this.openIndefiniteSnackbar}>{this.state.showIndefiniteSnackbar ? 'Close' : 'Open'} indefinite Snackbar</Button>
70+
</div>
71+
</div>
72+
)
73+
}
74+
}
75+
`

docs/client/components/common/DefaultCode/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { defaultCode as CheckboxGroupDefaultCode } from './CheckboxGroup';
55
export { defaultCode as ToggleDefaultCode } from './Toggle';
66
export { defaultCode as RadioButtonGroupDefaultCode } from './RadioButtonGroup';
77
export { defaultCode as TextInputDefaultCode } from './TextInput';
8+
export { defaultCode as SnackbarDefaultCode } from './Snackbar';

docs/client/components/common/componentList.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import ToggleReadme from '../../../../src/toggle/readMe.md';
1111
import RadioButtonGroup from '../../../../src/radioButtonGroup';
1212
import TextInput from '../../../../src/textInput';
1313
import TextInputReadme from '../../../../src/textInput/readMe.md';
14+
import Snackbar from '../../../../src/snackbar';
15+
import SnackbarReadme from '../../../../src/snackbar/readMe.md';
1416

1517
import {
1618
CardDefaultCode,
@@ -20,6 +22,7 @@ import {
2022
ToggleDefaultCode,
2123
RadioButtonGroupDefaultCode,
2224
TextInputDefaultCode,
25+
SnackbarDefaultCode,
2326
} from './DefaultCode';
2427

2528
export const componentList = [
@@ -64,5 +67,11 @@ export const componentList = [
6467
docs: TextInputReadme,
6568
component: TextInput,
6669
defaultCode: TextInputDefaultCode,
70+
},
71+
{
72+
name: 'Snackbar',
73+
docs: SnackbarReadme,
74+
component: Snackbar,
75+
defaultCode: SnackbarDefaultCode,
6776
}
6877
];

src/index.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import Snackbar from './snackbar';
2222
import React from 'react';
2323
import ReactDOM from 'react-dom';
2424

25-
// export default {
26-
// Button,
27-
// Card,
28-
// Checkbox,
29-
// CheckboxGroup,
30-
// RadioButtonGroup,
31-
// Toggle,
32-
// };
25+
export default {
26+
Button,
27+
Card,
28+
Checkbox,
29+
CheckboxGroup,
30+
RadioButtonGroup,
31+
Toggle,
32+
Snackbar,
33+
};
3334

3435
import theme from './theme.scss';
3536

@@ -38,17 +39,34 @@ class SnackDisplay extends React.Component {
3839
super(props);
3940
this.state = {
4041
showSnackbar: false,
42+
showTopSnackbar: false,
43+
showIndefiniteSnackbar: false,
4144
}
4245
}
43-
handleButtonClick = () => {
46+
47+
openBottomSnackbar = () => {
4448
this.setState({
4549
showSnackbar: !this.state.showSnackbar
4650
});
4751
}
52+
53+
openTopSnackbar = () => {
54+
this.setState({
55+
showTopSnackbar: !this.state.showTopSnackbar
56+
});
57+
}
58+
59+
openIndefiniteSnackbar = () => {
60+
this.setState({
61+
showIndefiniteSnackbar: !this.state.showIndefiniteSnackbar
62+
});
63+
}
64+
4865

4966
handleSnackClose = () => {
5067
this.setState({
5168
showSnackbar: false,
69+
showTopSnackbar: false,
5270
});
5371
}
5472

src/snackbar/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class Snackbar extends React.Component {
6262
}
6363

6464
render() {
65-
const { theme, additionaClasses, children } = this.props;
65+
const { theme, additionaClasses, position, children } = this.props;
6666
const { active } = this.state;
67-
const classes = classnames(theme.snackbar, active ? 'active' : '', additionaClasses)
67+
const classes = classnames(theme.snackbar, additionaClasses)
6868
return (
69-
<div className={classes}>
70-
{ children }
69+
<div className={classnames(theme.snackbarWrapper, position, active ? 'active' : '')}>
70+
<div className={classes}>
71+
{ children }
72+
</div>
7173
</div>
7274
)
7375
}
@@ -78,12 +80,14 @@ Snackbar.propTypes = {
7880
timeout: PropTypes.number,
7981
onClose: PropTypes.func,
8082
autoClose: PropTypes.bool,
83+
position: PropTypes.string,
8184
}
8285

8386
Snackbar.defaultProps = {
8487
additionaClasses: null,
8588
timeout: 2000,
8689
autoClose: true,
90+
position: 'bottom',
8791
};
8892

8993
export default themr('CBSnackbar', defaultTheme)(Snackbar);

src/snackbar/theme.scss

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
@import '../globals/theme';
22

3+
:local(.snackbarWrapper) {
4+
position: fixed;
5+
width: 100%;
6+
right: 0;
7+
&.top {
8+
top: 10%;
9+
&:not(.active) {
10+
transform: translateY(-1000%);
11+
}
12+
13+
&.active {
14+
transform: translateY(0%);
15+
}
16+
}
17+
&.bottom {
18+
bottom: 10%;
19+
&:not(.active) {
20+
transform: translateY(1000%);
21+
}
22+
23+
&.active {
24+
transform: translateY(0%);
25+
}
26+
}
27+
}
28+
329
:local(.snackbar) {
430
background: $primary-color;
531
border-radius: 3px;
632
padding: 10px;
7-
position: absolute;
8-
bottom: 0;
9-
left: 50%;
10-
transform: translateX(-50%);
11-
12-
&:not(.active) {
13-
transform: translateY(100%);
14-
}
15-
16-
&.active {
17-
transform: translateY(0%);
18-
}
19-
}
33+
margin: 0 auto;
34+
width: 40%;
35+
}

0 commit comments

Comments
 (0)