164 lines
4.9 KiB
JavaScript
164 lines
4.9 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.SnackbarBody = undefined;
|
|
|
|
var _extends2 = require('babel-runtime/helpers/extends');
|
|
|
|
var _extends3 = _interopRequireDefault(_extends2);
|
|
|
|
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
|
|
|
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
|
|
|
var _simpleAssign = require('simple-assign');
|
|
|
|
var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
|
|
|
|
var _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
var _transitions = require('../styles/transitions');
|
|
|
|
var _transitions2 = _interopRequireDefault(_transitions);
|
|
|
|
var _withWidth = require('../utils/withWidth');
|
|
|
|
var _withWidth2 = _interopRequireDefault(_withWidth);
|
|
|
|
var _FlatButton = require('../FlatButton');
|
|
|
|
var _FlatButton2 = _interopRequireDefault(_FlatButton);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function getStyles(props, context) {
|
|
var open = props.open,
|
|
width = props.width;
|
|
var _context$muiTheme = context.muiTheme,
|
|
_context$muiTheme$bas = _context$muiTheme.baseTheme,
|
|
_context$muiTheme$bas2 = _context$muiTheme$bas.spacing,
|
|
desktopGutter = _context$muiTheme$bas2.desktopGutter,
|
|
desktopSubheaderHeight = _context$muiTheme$bas2.desktopSubheaderHeight,
|
|
fontFamily = _context$muiTheme$bas.fontFamily,
|
|
_context$muiTheme$sna = _context$muiTheme.snackbar,
|
|
backgroundColor = _context$muiTheme$sna.backgroundColor,
|
|
textColor = _context$muiTheme$sna.textColor,
|
|
actionColor = _context$muiTheme$sna.actionColor;
|
|
|
|
|
|
var isSmall = width === _withWidth.SMALL;
|
|
|
|
var 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,
|
|
width: isSmall ? 'calc(100vw - ' + desktopGutter * 2 + 'px)' : 'auto',
|
|
flexGrow: isSmall ? 1 : 0
|
|
},
|
|
content: {
|
|
fontSize: 14,
|
|
color: textColor,
|
|
opacity: open ? 1 : 0,
|
|
transition: open ? _transitions2.default.easeOut('500ms', 'opacity', '100ms') : _transitions2.default.easeOut('400ms', 'opacity')
|
|
},
|
|
action: {
|
|
color: actionColor,
|
|
float: 'right',
|
|
marginTop: 6,
|
|
marginRight: -16,
|
|
marginLeft: desktopGutter,
|
|
backgroundColor: 'transparent'
|
|
}
|
|
};
|
|
|
|
return styles;
|
|
}
|
|
|
|
var SnackbarBody = exports.SnackbarBody = function SnackbarBody(props, context) {
|
|
var action = props.action,
|
|
contentStyle = props.contentStyle,
|
|
message = props.message,
|
|
open = props.open,
|
|
onActionTouchTap = props.onActionTouchTap,
|
|
style = props.style,
|
|
other = (0, _objectWithoutProperties3.default)(props, ['action', 'contentStyle', 'message', 'open', 'onActionTouchTap', 'style']);
|
|
var prepareStyles = context.muiTheme.prepareStyles;
|
|
|
|
var styles = getStyles(props, context);
|
|
|
|
var actionButton = action && _react2.default.createElement(_FlatButton2.default, {
|
|
style: styles.action,
|
|
label: action,
|
|
onTouchTap: onActionTouchTap
|
|
});
|
|
|
|
return _react2.default.createElement(
|
|
'div',
|
|
(0, _extends3.default)({}, other, { style: prepareStyles((0, _simpleAssign2.default)(styles.root, style)) }),
|
|
_react2.default.createElement(
|
|
'div',
|
|
{ style: prepareStyles((0, _simpleAssign2.default)(styles.content, contentStyle)) },
|
|
_react2.default.createElement(
|
|
'span',
|
|
null,
|
|
message
|
|
),
|
|
actionButton
|
|
)
|
|
);
|
|
};
|
|
|
|
process.env.NODE_ENV !== "production" ? SnackbarBody.propTypes = {
|
|
/**
|
|
* The label for the action on the snackbar.
|
|
*/
|
|
action: _react.PropTypes.node,
|
|
/**
|
|
* Override the inline-styles of the content element.
|
|
*/
|
|
contentStyle: _react.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: _react.PropTypes.node.isRequired,
|
|
/**
|
|
* Fired when the action button is touchtapped.
|
|
*
|
|
* @param {object} event Action button event.
|
|
*/
|
|
onActionTouchTap: _react.PropTypes.func,
|
|
/**
|
|
* @ignore
|
|
* Controls whether the `Snackbar` is opened or not.
|
|
*/
|
|
open: _react.PropTypes.bool.isRequired,
|
|
/**
|
|
* Override the inline-styles of the root element.
|
|
*/
|
|
style: _react.PropTypes.object,
|
|
/**
|
|
* @ignore
|
|
* Width of the screen.
|
|
*/
|
|
width: _react.PropTypes.number.isRequired
|
|
} : void 0;
|
|
|
|
SnackbarBody.contextTypes = {
|
|
muiTheme: _react.PropTypes.object.isRequired
|
|
};
|
|
|
|
exports.default = (0, _withWidth2.default)()(SnackbarBody); |