Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use material-ui Dialog PaperProps

Tags:

material-ui

I'm using v1.1.0 of material-ui in React 16.3.2. I'm trying to create a landing page similar to Showcase - Local Insights

where the dialog has opacity (Find foreclosures). I'm trying to use PaperProps for Dialog component described here Dialog doc

Here's a component I've created to try to do this.

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';

import Button from '@material-ui/core/Button';

import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';

import ForwardIcon from '@material-ui/icons/Forward';

import Input from '@material-ui/core/Input';
import FormControl from '@material-ui/core/FormControl';
import Slide from '@material-ui/core/Slide';


const styles = theme => ({
  dialogPaper: {
    opacity: 0.5,
    border: '#FF0000 1px solid',
  },
  button: {
    margin: '30px'
  }
});

function Transition(props) {
  return <Slide direction="up" {...props} />;
}

class SignInDialog extends React.Component {
  state = {
    open: false,
    username: ''
  };

  handleClickOpen = () => {
    this.setState({ open: true });
  };

  handleClose = () => {
    this.setState({ open: false });
  };

  handleChange = name => event => {
    this.setState({
      [name]: event.target.value,
    });
  };

  render() {
    const { classes } = this.props;

    return (
      <div>
        <Button variant="fab" color="primary" aria-label="add" className={classes.button} onClick={this.handleClickOpen}>
          <ForwardIcon />
        </Button>
        <Dialog
          PaperProps={styles.dialogPaper}
          open={this.state.open}
          TransitionComponent={Transition}
          onClose={this.handleClose}
          aria-labelledby="form-dialog-title"
        >
          <DialogTitle id="form-dialog-title">WELCOME</DialogTitle>
          <DialogContent>
            <p>SIGN IN</p>
            <FormControl className={classes.formControl}>
              <Input
                value={this.state.searchString}
                onChange={this.handleChange('search')}
                id="siginin-input"
                placeholder="Enter your username"
              />
            </FormControl>
          </DialogContent>
          <DialogActions>
            <Button onClick={this.handleClose} color="primary">
              Cancel
            </Button>
            <Button onClick={this.handleClose} color="primary">
              Continue
            </Button>
          </DialogActions>
        </Dialog>
      </div>
    );
  }
}

SignInDialog.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SignInDialog);

I haven't been able to figure out how to get the Dialog to take the styles. What is needed to get PaperProps to work?

like image 984
sysdev Avatar asked Jun 01 '18 18:06

sysdev


People also ask

How do I make material UI dialog full screen?

You just need to add fullScreen flag to modal component in order to achieve full screen. And if you don't want to use fullScreen, simply remove that fullScreen flag and don't need to use CSS here.

How do you style paper in material UI?

To set a background color on Material UI's Paper, you simply need to apply the background-color CSS property to the root element of the Paper. Setting the styles on the root element of any Material UI component can be done in multiple ways, but the most common is to use the useStyles hook.


1 Answers

If you want to use PaperProps you have to specify the props of the Paperfor which you are applying style.

<Dialog
          PaperProps={{ classes: {root: classes.dialogPaper } }}
          />

You can also use classes property and override the style

<Dialog
          classes={{paper:classes.dialogPaper}}
          />
like image 63
anonymous_siva Avatar answered Sep 19 '22 09:09

anonymous_siva