Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 | 1x 6x 6x 3x 3x 2x 2x 9x 9x 8x 1x 1x | // @flow import React, { Component } from 'react'; import MuiSnackbar from 'material-ui/Snackbar'; import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; type Props = { /** Label for the action on the snackbar */ action?: Node, /** * The number of milliseconds to wait before automatically dismissing. If no value is specified * the snackbar will dismiss normally. If a value is provided the snackbar can still be dismissed * normally. If a snackbar is dismissed before the timer expires, the timer will be cleared. */ autoHideDuration?: number, /** Override the inline styles of the body element */ bodyStyle?: object, /** CSS class name of the root element */ className?: string, /** Override the inline styles of the content element */ contentStyle?: object, /** Dash event handler for click events */ fireEvent?: () => void, /** The element's ID */ id: string, /** * 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: Node, /** An integer that represents the number of times that action button has been clicked */ n_clicks?: number, /** Controls whether the Snackbar is opened or not */ open: boolean, /** Dash callback to update props on the server */ setProps?: (props: {open?: boolean}) => void, /** Override the inline styles of the root element */ style?: object, }; type State = { open: boolean, }; const defaultProps = { action: null, autoHideDuration: 3000, bodyStyle: {}, className: '', contentStyle: {}, fireEvent: () => {}, n_clicks: 0, setProps: () => {}, style: {}, }; export default class Snackbar extends Component<Props, State> { constructor(props: Props) { super(props); this.state = {open: props.open}; } componentWillReceiveProps(nextProps: Props): void { Eif (nextProps.open !== null) this.setState({open: nextProps.open}); } handleOpen = () => { const { setProps } = this.props; if (typeof setProps === 'function') setProps({open: true}); this.setState({open: true}); }; handleClose = () => { const { setProps } = this.props; if (typeof setProps === 'function') setProps({open: false}); this.setState({open: false}); }; handleActionClick = () => { Eif (this.props.setProps) this.props.setProps({n_clicks: this.props.n_clicks + 1}); Eif (this.props.fireEvent) this.props.fireEvent({event: 'click'}); }; render() { const { action, autoHideDuration, bodyStyle, className, contentStyle, id, message, style } = this.props; if (this.props.fireEvent) { return ( <div id={id}> <MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}> <MuiSnackbar action={action} autoHideDuration={autoHideDuration} bodyStyle={bodyStyle} className={className} contentStyle={contentStyle} message={message} onActionClick={this.handleActionClick} onRequestClose={this.handleClose} open={this.state.open} style={style} /> </MuiThemeProvider> </div> ); } return ( <div id={id}> <MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}> <MuiSnackbar action={action} autoHideDuration={autoHideDuration} bodyStyle={bodyStyle} className={className} contentStyle={contentStyle} message={message} onRequestClose={this.handleClose} open={this.state.open} style={style} /> </MuiThemeProvider> </div>); } } Snackbar.defaultProps = defaultProps; |