我在React 16.3.2中使用了材料-ui的v1.1.0。我正在尝试创建类似于Showcase - Local Insights
的着陆页对话框具有不透明度(查找止赎)。我正在尝试使用PaperProps for Dialog组件Dialog doc
这是我为尝试这样做而创建的组件。
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);
我无法弄清楚如何让Dialog采用这些风格。让PaperProps工作需要什么?
答案 0 :(得分:3)
如果您想使用PaperProps
,则必须指定要应用样式的Paper
的道具。
<Dialog
PaperProps={{ classes: {root: classes.dialogPaper } }}
/>
您还可以使用classes
属性并覆盖样式
<Dialog
classes={{paper:classes.dialogPaper}}
/>
上的工作模式
答案 1 :(得分:0)
覆盖纸道具的正确方法是使用classNames
<Dialog
PaperProps={{ className: classNames(classes.dialogPaper) }}/>