Sunday 1 July 2018
react + Material-UI reference
reference:
https://material-ui.com/demos/app-bar/
text fields
https://material-ui.com/demos/text-fields/#textfield
themes
https://www.creative-tim.com/bootstrap-themes/react-themes
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import MenuItem from '@material-ui/core/MenuItem';
import TextField from '@material-ui/core/TextField';
import Avatar from '@material-ui/core/Avatar';
import classNames from 'classnames';
const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 200,
},
menu: {
width: 200,
},
row: {
display: 'flex',
justifyContent: 'center',
},
avatar: {
marginRight: 10,
marginTop: -5,
},
smallAvatar: {
width: 30,
height: 30,
});
const currencies = [
{
value: 'USD',
label: '$',
},
{
value: 'EUR',
label: '€',
},
{
value: 'BTC',
label: '฿',
},
{
value: 'JPY',
label: '¥',
},
];
class TextFields extends React.Component {
state = {
name: 'Cat in the Hat',
age: '',
multiline: 'Controlled',
currency: 'EUR',
};
handleChange = name => event => {
this.setState({
[name]: event.target.value,
});
};
render() {
const { classes } = this.props;
return (
<form className={classes.container} noValidate autoComplete="off">
<TextField
id="select-currency"
select
label="Select"
className={classes.textField}
value={this.state.currency}
onChange={this.handleChange('currency')}
SelectProps={{
MenuProps: {
className: classes.menu,
},
}}
helperText="Please select your currency"
margin="normal"
>
{currencies.map(option => (
<MenuItem key={option.value} value={option.value}>
<div className={classes.row}>
<Avatar className={classNames(classes.avatar, classes.smallAvatar)}>
H</Avatar>
{option.label}
</div>
</MenuItem>
))}
</TextField>
</form>
);
}
}
TextFields.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(TextFields);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment