forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SelectField] First implementation (mui#8023)
- Loading branch information
1 parent
0fb26fa
commit 50261b9
Showing
93 changed files
with
1,598 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from 'material-ui/styles'; | ||
import Input, { InputLabel } from 'material-ui/Input'; | ||
import { MenuItem } from 'material-ui/Menu'; | ||
import { FormControl } from 'material-ui/Form'; | ||
import Select from 'material-ui/Select'; | ||
|
||
const styles = theme => ({ | ||
container: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}, | ||
formControl: { | ||
margin: theme.spacing.unit, | ||
minWidth: 120, | ||
maxWidth: 300, | ||
}, | ||
}); | ||
|
||
const ITEM_HEIGHT = 48; | ||
const ITEM_PADDING_TOP = 8; | ||
|
||
const names = [ | ||
'Oliver Hansen', | ||
'Van Henry', | ||
'April Tucker', | ||
'Ralph Hubbard', | ||
'Omar Alexander', | ||
'Carlos Abbott', | ||
'Miriam Wagner', | ||
'Bradley Wilkerson', | ||
'Virginia Andrews', | ||
'Kelly Snyder', | ||
]; | ||
|
||
class MultipleSelect extends React.Component { | ||
state = { | ||
name: [], | ||
}; | ||
|
||
handleChange = event => { | ||
this.setState({ name: event.target.value }); | ||
}; | ||
|
||
render() { | ||
const classes = this.props.classes; | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<FormControl className={classes.formControl}> | ||
<InputLabel htmlFor="name-multiple">Name</InputLabel> | ||
<Select | ||
multiple | ||
value={this.state.name} | ||
onChange={this.handleChange} | ||
input={<Input id="name-multiple" />} | ||
MenuProps={{ | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, | ||
width: 200, | ||
}, | ||
}, | ||
}} | ||
> | ||
{names.map(name => ( | ||
<MenuItem | ||
key={name} | ||
value={name} | ||
style={{ | ||
fontWeight: this.state.name.indexOf(name) !== -1 ? '500' : '400', | ||
}} | ||
> | ||
{name} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
MultipleSelect.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(MultipleSelect); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from 'material-ui/styles'; | ||
import Input, { InputLabel } from 'material-ui/Input'; | ||
import { FormControl, FormHelperText } from 'material-ui/Form'; | ||
import Select from 'material-ui/Select'; | ||
|
||
const styles = theme => ({ | ||
container: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}, | ||
formControl: { | ||
margin: theme.spacing.unit, | ||
minWidth: 120, | ||
}, | ||
}); | ||
|
||
class NativeSelect extends React.Component { | ||
state = { | ||
age: '', | ||
name: 'hai', | ||
}; | ||
|
||
handleChange = name => event => { | ||
this.setState({ [name]: event.target.value }); | ||
}; | ||
|
||
render() { | ||
const classes = this.props.classes; | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<FormControl className={classes.formControl}> | ||
<InputLabel htmlFor="age-native-simple">Age</InputLabel> | ||
<Select | ||
native | ||
value={this.state.age} | ||
onChange={this.handleChange('age')} | ||
input={<Input id="age-native-simple" />} | ||
> | ||
<option value="" /> | ||
<option value={10}>Ten</option> | ||
<option value={20}>Twenty</option> | ||
<option value={30}>Thirty</option> | ||
</Select> | ||
</FormControl> | ||
<FormControl className={classes.formControl}> | ||
<InputLabel htmlFor="age-native-helper">Age</InputLabel> | ||
<Select | ||
native | ||
value={this.state.age} | ||
onChange={this.handleChange('age')} | ||
input={<Input id="age-native-helper" />} | ||
> | ||
<option value="" /> | ||
<option value={10}>Ten</option> | ||
<option value={20}>Twenty</option> | ||
<option value={30}>Thirty</option> | ||
</Select> | ||
<FormHelperText>Some important helper text</FormHelperText> | ||
</FormControl> | ||
<FormControl className={classes.formControl} disabled> | ||
<InputLabel htmlFor="name-native-disabled">Name</InputLabel> | ||
<Select | ||
native | ||
value={this.state.name} | ||
onChange={this.handleChange('name')} | ||
input={<Input id="name-native-disabled" />} | ||
> | ||
<option value="" /> | ||
<optgroup label="Author"> | ||
<option value="hai">Hai</option> | ||
</optgroup> | ||
<optgroup label="Contributors"> | ||
<option value="olivier">Olivier</option> | ||
<option value="kevin">Kevin</option> | ||
</optgroup> | ||
</Select> | ||
<FormHelperText>Disabled</FormHelperText> | ||
</FormControl> | ||
<FormControl className={classes.formControl} error> | ||
<InputLabel htmlFor="name-native-error">Name</InputLabel> | ||
<Select | ||
native | ||
value={this.state.name} | ||
onChange={this.handleChange('name')} | ||
input={<Input id="name-native-error" />} | ||
> | ||
<option value="" /> | ||
<optgroup label="Author"> | ||
<option value="hai">Hai</option> | ||
</optgroup> | ||
<optgroup label="Contributors"> | ||
<option value="olivier">Olivier</option> | ||
<option value="kevin">Kevin</option> | ||
</optgroup> | ||
</Select> | ||
<FormHelperText>Error</FormHelperText> | ||
</FormControl> | ||
<FormControl className={classes.formControl}> | ||
<InputLabel htmlFor="name-input">Name</InputLabel> | ||
<Input id="name-input" /> | ||
<FormHelperText>Alignement with an input</FormHelperText> | ||
</FormControl> | ||
<FormControl className={classes.formControl}> | ||
<InputLabel htmlFor="uncontrolled-native">Name</InputLabel> | ||
<Select native defaultValue={30} input={<Input id="uncontrolled-native" />}> | ||
<option value="" /> | ||
<option value={10}>Ten</option> | ||
<option value={20}>Twenty</option> | ||
<option value={30}>Thirty</option> | ||
</Select> | ||
<FormHelperText>Uncontrolled</FormHelperText> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
NativeSelect.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(NativeSelect); |
Oops, something went wrong.