UNPKG

material-ui

Version:

React Components that Implement Google's Material Design.

170 lines (140 loc) 5.16 kB
'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 _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); 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, borderRadius = _context$muiTheme.borderRadius; var isSmall = width === _withWidth.SMALL; var styles = { root: { fontFamily: fontFamily, backgroundColor: backgroundColor, padding: '0 ' + desktopGutter + 'px', height: desktopSubheaderHeight, lineHeight: desktopSubheaderHeight + 'px', borderRadius: isSmall ? 0 : borderRadius, 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 = function SnackbarBody(props, context) { var action = props.action, contentStyle = props.contentStyle, message = props.message, open = props.open, onActionClick = props.onActionClick, style = props.style, other = (0, _objectWithoutProperties3.default)(props, ['action', 'contentStyle', 'message', 'open', 'onActionClick', 'style']); var prepareStyles = context.muiTheme.prepareStyles; var styles = getStyles(props, context); var actionButton = action && _react2.default.createElement(_FlatButton2.default, { style: styles.action, label: action, onClick: onActionClick }); 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 ) ); }; exports.SnackbarBody = SnackbarBody; SnackbarBody.propTypes = process.env.NODE_ENV !== "production" ? { /** * The label for the action on the snackbar. */ action: _propTypes2.default.node, /** * Override the inline-styles of the content element. */ contentStyle: _propTypes2.default.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: _propTypes2.default.node.isRequired, /** * Fired when the action button is clicked. * * @param {object} event Action button event. */ onActionClick: _propTypes2.default.func, /** * @ignore * Controls whether the `Snackbar` is opened or not. */ open: _propTypes2.default.bool.isRequired, /** * Override the inline-styles of the root element. */ style: _propTypes2.default.object, /** * @ignore * Width of the screen. */ width: _propTypes2.default.number.isRequired } : {}; SnackbarBody.contextTypes = { muiTheme: _propTypes2.default.object.isRequired }; exports.default = (0, _withWidth2.default)()(SnackbarBody);