diff --git a/docs/src/pages/demos/selects/ControlledOpenSelect.tsx b/docs/src/pages/demos/selects/ControlledOpenSelect.tsx new file mode 100644 index 00000000000000..a12be90ce117af --- /dev/null +++ b/docs/src/pages/demos/selects/ControlledOpenSelect.tsx @@ -0,0 +1,67 @@ +import React from 'react'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import InputLabel from '@material-ui/core/InputLabel'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; +import Button from '@material-ui/core/Button'; + +const useStyles = makeStyles((theme: Theme) => ({ + button: { + display: 'block', + marginTop: theme.spacing(2), + }, + formControl: { + margin: theme.spacing(1), + minWidth: 120, + }, +})); + +function ControlledOpenSelect() { + const classes = useStyles(); + const [age, setAge] = React.useState(''); + const [open, setOpen] = React.useState(false); + + function handleChange(event: React.ChangeEvent<{ value: unknown }>) { + setAge(event.target.value as number); + } + + function handleClose() { + setOpen(false); + } + + function handleOpen() { + setOpen(true); + } + + return ( +
+ + + Age + + +
+ ); +} + +export default ControlledOpenSelect; diff --git a/docs/src/pages/demos/selects/CustomizedSelects.tsx b/docs/src/pages/demos/selects/CustomizedSelects.tsx new file mode 100644 index 00000000000000..487332ccb5c387 --- /dev/null +++ b/docs/src/pages/demos/selects/CustomizedSelects.tsx @@ -0,0 +1,110 @@ +import React from 'react'; +import { makeStyles, withStyles } from '@material-ui/styles'; +import InputLabel from '@material-ui/core/InputLabel'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; +import NativeSelect from '@material-ui/core/NativeSelect'; +import InputBase from '@material-ui/core/InputBase'; +import { Theme } from '@material-ui/core/styles'; + +const BootstrapInput = withStyles((theme: Theme) => ({ + root: { + 'label + &': { + marginTop: theme.spacing(3), + }, + }, + input: { + borderRadius: 4, + position: 'relative', + backgroundColor: theme.palette.background.paper, + border: '1px solid #ced4da', + fontSize: 16, + width: 'auto', + padding: '10px 26px 10px 12px', + transition: theme.transitions.create(['border-color', 'box-shadow']), + // Use the system font instead of the default Roboto font. + fontFamily: [ + '-apple-system', + 'BlinkMacSystemFont', + '"Segoe UI"', + 'Roboto', + '"Helvetica Neue"', + 'Arial', + 'sans-serif', + '"Apple Color Emoji"', + '"Segoe UI Emoji"', + '"Segoe UI Symbol"', + ].join(','), + '&:focus': { + borderRadius: 4, + borderColor: '#80bdff', + boxShadow: '0 0 0 0.2rem rgba(0,123,255,.25)', + }, + }, +}))(InputBase); + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + display: 'flex', + flexWrap: 'wrap', + }, + margin: { + margin: theme.spacing(1), + }, + bootstrapFormLabel: { + fontSize: 18, + }, +})); + +function CustomizedSelects() { + const classes = useStyles(); + const [age, setAge] = React.useState(''); + const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => { + setAge(event.target.value as string); + }; + return ( +
+ + + Age + + + + + + Age + + + + + + Age + + } + > + + + + + +
+ ); +} + +export default CustomizedSelects; diff --git a/docs/src/pages/demos/selects/DialogSelect.tsx b/docs/src/pages/demos/selects/DialogSelect.tsx new file mode 100644 index 00000000000000..cf1e2160d25358 --- /dev/null +++ b/docs/src/pages/demos/selects/DialogSelect.tsx @@ -0,0 +1,97 @@ +import React from 'react'; +import { makeStyles, Theme } 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 InputLabel from '@material-ui/core/InputLabel'; +import Input from '@material-ui/core/Input'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; + +const useStyles = makeStyles((theme: Theme) => ({ + container: { + display: 'flex', + flexWrap: 'wrap', + }, + formControl: { + margin: theme.spacing(1), + minWidth: 120, + }, +})); + +function DialogSelect() { + const classes = useStyles(); + const [state, setState] = React.useState({ + open: false, + age: '', + }); + + const handleChange = (name: keyof typeof state) => ( + event: React.ChangeEvent<{ value: unknown }>, + ) => { + setState({ ...state, [name]: Number(event.target.value) }); + }; + + function handleClickOpen() { + setState({ ...state, open: true }); + } + + function handleClose() { + setState({ ...state, open: false }); + } + + return ( +
+ + + Fill the form + +
+ + Age + + + + Age + + +
+
+ + + + +
+
+ ); +} + +export default DialogSelect; diff --git a/docs/src/pages/demos/selects/MultipleSelect.tsx b/docs/src/pages/demos/selects/MultipleSelect.tsx new file mode 100644 index 00000000000000..fc221faf3e8a23 --- /dev/null +++ b/docs/src/pages/demos/selects/MultipleSelect.tsx @@ -0,0 +1,197 @@ +import React from 'react'; +import clsx from 'clsx'; +import { makeStyles, useTheme, Theme } from '@material-ui/core/styles'; +import Input from '@material-ui/core/Input'; +import InputLabel from '@material-ui/core/InputLabel'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormControl from '@material-ui/core/FormControl'; +import ListItemText from '@material-ui/core/ListItemText'; +import Select from '@material-ui/core/Select'; +import Checkbox from '@material-ui/core/Checkbox'; +import Chip from '@material-ui/core/Chip'; + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + display: 'flex', + flexWrap: 'wrap', + }, + formControl: { + margin: theme.spacing(1), + minWidth: 120, + maxWidth: 300, + }, + chips: { + display: 'flex', + flexWrap: 'wrap', + }, + chip: { + margin: 2, + }, + noLabel: { + marginTop: theme.spacing(3), + }, +})); + +const ITEM_HEIGHT = 48; +const ITEM_PADDING_TOP = 8; +const MenuProps = { + PaperProps: { + style: { + maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, + width: 250, + }, + }, +}; + +const names = [ + 'Oliver Hansen', + 'Van Henry', + 'April Tucker', + 'Ralph Hubbard', + 'Omar Alexander', + 'Carlos Abbott', + 'Miriam Wagner', + 'Bradley Wilkerson', + 'Virginia Andrews', + 'Kelly Snyder', +]; + +function getStyles(name: string, personName: string[], theme: Theme) { + return { + fontWeight: + personName.indexOf(name) === -1 + ? theme.typography.fontWeightRegular + : theme.typography.fontWeightMedium, + }; +} + +function MultipleSelect() { + const classes = useStyles(); + const theme = useTheme(); + const [personName, setPersonName] = React.useState([]); + + function handleChange(event: React.ChangeEvent<{ value: unknown }>) { + setPersonName(event.target.value as string[]); + } + + function handleChangeMultiple(event: React.ChangeEvent<{ value: unknown }>) { + const { options } = event.target as HTMLSelectElement; + const value: string[] = []; + for (let i = 0, l = options.length; i < l; i += 1) { + if (options[i].selected) { + value.push(options[i].value); + } + } + setPersonName(value); + } + + return ( +
+ + Name + + + + Tag + + + + Chip + + + + + + + + Native + + + +
+ ); +} + +export default MultipleSelect; diff --git a/docs/src/pages/demos/selects/NativeSelects.tsx b/docs/src/pages/demos/selects/NativeSelects.tsx new file mode 100644 index 00000000000000..dffcec0eda62e5 --- /dev/null +++ b/docs/src/pages/demos/selects/NativeSelects.tsx @@ -0,0 +1,228 @@ +import React from 'react'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import Input from '@material-ui/core/Input'; +import OutlinedInput from '@material-ui/core/OutlinedInput'; +import FilledInput from '@material-ui/core/FilledInput'; +import InputLabel from '@material-ui/core/InputLabel'; +import FormHelperText from '@material-ui/core/FormHelperText'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; +import NativeSelect from '@material-ui/core/NativeSelect'; + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + display: 'flex', + flexWrap: 'wrap', + }, + formControl: { + margin: theme.spacing(1), + minWidth: 120, + }, + selectEmpty: { + marginTop: theme.spacing(2), + }, +})); + +function NativeSelects() { + const classes = useStyles(); + const [state, setState] = React.useState<{ age: string | number; name: string }>({ + age: '', + name: 'hai', + }); + + const inputLabel = React.useRef(null); + const [labelWidth, setLabelWidth] = React.useState(0); + React.useEffect(() => { + setLabelWidth(inputLabel.current!.offsetWidth); + }, []); + + const handleChange = (name: keyof typeof state) => ( + event: React.ChangeEvent<{ value: unknown }>, + ) => { + setState({ + ...state, + [name]: event.target.value, + }); + }; + + return ( +
+ + Age + + + + Age + } + > + + + + + Some important helper text + + + + + + + + + Without label + + + + Age + + } + > + + + + + + Label + placeholder + + + Name + } + > + + + + + + + + + Disabled + + + Name + } + > + + + + + + + + + Error + + + Name + }> + + + + + Uncontrolled + + + + + + + + + Placeholder + + + Age + + Required + + + + Age + + + + + Age + + +
+ ); +} + +export default NativeSelects; diff --git a/docs/src/pages/demos/selects/SimpleSelect.tsx b/docs/src/pages/demos/selects/SimpleSelect.tsx new file mode 100644 index 00000000000000..724bf8ea76b9de --- /dev/null +++ b/docs/src/pages/demos/selects/SimpleSelect.tsx @@ -0,0 +1,260 @@ +import React from 'react'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import Input from '@material-ui/core/Input'; +import OutlinedInput from '@material-ui/core/OutlinedInput'; +import FilledInput from '@material-ui/core/FilledInput'; +import InputLabel from '@material-ui/core/InputLabel'; +import MenuItem from '@material-ui/core/MenuItem'; +import FormHelperText from '@material-ui/core/FormHelperText'; +import FormControl from '@material-ui/core/FormControl'; +import Select from '@material-ui/core/Select'; + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + display: 'flex', + flexWrap: 'wrap', + }, + formControl: { + margin: theme.spacing(1), + minWidth: 120, + }, + selectEmpty: { + marginTop: theme.spacing(2), + }, +})); + +function SimpleSelect() { + const classes = useStyles(); + const [values, setValues] = React.useState({ + age: '', + name: 'hai', + }); + + const inputLabel = React.useRef(null); + const [labelWidth, setLabelWidth] = React.useState(0); + React.useEffect(() => { + setLabelWidth(inputLabel.current!.offsetWidth); + }, []); + + function handleChange(event: React.ChangeEvent<{ name?: string; value: unknown }>) { + setValues(oldValues => ({ + ...oldValues, + [event.target.name as string]: event.target.value, + })); + } + + return ( +
+ + Age + + + + Age + + Some important helper text + + + + Without label + + + + Age + + + Label + placeholder + + + Name + + Disabled + + + Name + } + > + + None + + Hai + Olivier + Kevin + + Error + + + Name + + Read only + + + Age + + Auto width + + + + Placeholder + + + Age + + Required + + + + Age + + + + + Age + + +
+ ); +} + +export default SimpleSelect;