-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Expand file tree
/
Copy pathSnackbarBody.js
More file actions
140 lines (128 loc) · 3.17 KB
/
SnackbarBody.js
File metadata and controls
140 lines (128 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React, {PropTypes} from 'react';
import transitions from '../styles/transitions';
import withWidth, {SMALL} from '../utils/withWidth';
import FlatButton from '../FlatButton';
function getStyles(props, context) {
const {
open,
width,
} = props;
const {
muiTheme: {
baseTheme: {
spacing: {
desktopGutter,
desktopSubheaderHeight,
},
fontFamily,
},
snackbar: {
backgroundColor,
textColor,
actionColor,
},
},
} = context;
const isSmall = width === SMALL;
const styles = {
root: {
fontFamily: fontFamily,
backgroundColor: backgroundColor,
padding: `0 ${desktopGutter}px`,
height: desktopSubheaderHeight,
lineHeight: `${desktopSubheaderHeight}px`,
borderRadius: isSmall ? 0 : 2,
maxWidth: isSmall ? 'inherit' : 568,
minWidth: isSmall ? 'inherit' : 288,
flexGrow: isSmall ? 1 : 0,
margin: 'auto',
},
content: {
fontSize: 14,
color: textColor,
opacity: open ? 1 : 0,
transition: open ?
transitions.easeOut('500ms', 'opacity', '100ms') :
transitions.easeOut('400ms', 'opacity'),
},
action: {
color: actionColor,
float: 'right',
marginTop: 6,
marginRight: -16,
marginLeft: desktopGutter,
backgroundColor: 'transparent',
},
};
return styles;
}
export const SnackbarBody = (props, context) => {
const {
action,
contentStyle,
message,
open, // eslint-disable-line no-unused-vars
onActionTouchTap,
style,
...other,
} = props;
const {prepareStyles} = context.muiTheme;
const styles = getStyles(props, context);
const actionButton = action && (
<FlatButton
style={styles.action}
label={action}
onTouchTap={onActionTouchTap}
/>
);
return (
<div {...other} style={prepareStyles(Object.assign(styles.root, style))}>
<div style={prepareStyles(Object.assign(styles.content, contentStyle))}>
<span>{message}</span>
{actionButton}
</div>
</div>
);
};
SnackbarBody.propTypes = {
/**
* The label for the action on the snackbar.
*/
action: PropTypes.node,
/**
* Override the inline-styles of the content element.
*/
contentStyle: PropTypes.object,
/**
* The message to be displayed.
*
* (Note: If the message is an element or array, and the `Snackbar` may re-render while it is still open,
* ensure that the same object remains as the `message` property if you want to avoid the `Snackbar` hiding and
* showing again)
*/
message: PropTypes.node.isRequired,
/**
* Fired when the action button is touchtapped.
*
* @param {object} event Action button event.
*/
onActionTouchTap: PropTypes.func,
/**
* @ignore
* Controls whether the `Snackbar` is opened or not.
*/
open: PropTypes.bool.isRequired,
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
/**
* @ignore
* Width of the screen.
*/
width: PropTypes.number.isRequired,
};
SnackbarBody.contextTypes = {
muiTheme: PropTypes.object.isRequired,
};
export default withWidth()(SnackbarBody);