From 5ac5e7f2d47f720bc1eeb53d590730c5245595ac Mon Sep 17 00:00:00 2001 From: Brandon Herrera Date: Mon, 22 Apr 2019 02:09:31 -0400 Subject: [PATCH] [docs] Add some Selection-Controls TypeScript demos (#15408) * Added Typescript Version for FormControlLabelPosition Componenet * Added Typescript Version for RadioButtons Componenet * Added Typescript Version for RadioButtonsGroup Componenet * Add TypeScript demo for SwitchLabels componenet * Add TypeScript demo for SwitchesGroup componenet * any -> unknown --- .../FormControlLabelPosition.tsx | 48 ++++++++++ .../demos/selection-controls/RadioButtons.tsx | 72 ++++++++++++++ .../selection-controls/RadioButtonsGroup.tsx | 93 +++++++++++++++++++ .../demos/selection-controls/SwitchLabels.tsx | 42 +++++++++ .../selection-controls/SwitchesGroup.tsx | 44 +++++++++ 5 files changed, 299 insertions(+) create mode 100644 docs/src/pages/demos/selection-controls/FormControlLabelPosition.tsx create mode 100644 docs/src/pages/demos/selection-controls/RadioButtons.tsx create mode 100644 docs/src/pages/demos/selection-controls/RadioButtonsGroup.tsx create mode 100644 docs/src/pages/demos/selection-controls/SwitchLabels.tsx create mode 100644 docs/src/pages/demos/selection-controls/SwitchesGroup.tsx diff --git a/docs/src/pages/demos/selection-controls/FormControlLabelPosition.tsx b/docs/src/pages/demos/selection-controls/FormControlLabelPosition.tsx new file mode 100644 index 00000000000000..782eb88febf838 --- /dev/null +++ b/docs/src/pages/demos/selection-controls/FormControlLabelPosition.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import Radio from '@material-ui/core/Radio'; +import RadioGroup from '@material-ui/core/RadioGroup'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormControl from '@material-ui/core/FormControl'; +import FormLabel from '@material-ui/core/FormLabel'; + +function FormControlLabelPosition() { + const [value, setValue] = React.useState('female'); + + function handleChange(event: React.ChangeEvent) { + setValue((event.target as HTMLInputElement).value); + } + + return ( + + labelPlacement + + } + label="Top" + labelPlacement="top" + /> + } + label="Start" + labelPlacement="start" + /> + } + label="Bottom" + labelPlacement="bottom" + /> + } + label="End" + labelPlacement="end" + /> + + + ); +} + +export default FormControlLabelPosition; diff --git a/docs/src/pages/demos/selection-controls/RadioButtons.tsx b/docs/src/pages/demos/selection-controls/RadioButtons.tsx new file mode 100644 index 00000000000000..e839a9d25c2449 --- /dev/null +++ b/docs/src/pages/demos/selection-controls/RadioButtons.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import { withStyles } from '@material-ui/core/styles'; +import green from '@material-ui/core/colors/green'; +import Radio, { RadioProps } from '@material-ui/core/Radio'; +import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked'; +import RadioButtonCheckedIcon from '@material-ui/icons/RadioButtonChecked'; + +const GreenRadio = withStyles({ + root: { + '&:not($checked)': { + color: green[400], + }, + '&$checked': { + color: green[600], + }, + }, + checked: {}, +})((props: RadioProps) => ); + +function RadioButtons() { + const [selectedValue, setSelectedValue] = React.useState('a'); + + function handleChange(event: React.ChangeEvent) { + setSelectedValue(event.target.value); + } + + return ( +
+ + + + + } + checkedIcon={} + /> +
+ ); +} + +export default RadioButtons; diff --git a/docs/src/pages/demos/selection-controls/RadioButtonsGroup.tsx b/docs/src/pages/demos/selection-controls/RadioButtonsGroup.tsx new file mode 100644 index 00000000000000..dbd40c9dc2fc71 --- /dev/null +++ b/docs/src/pages/demos/selection-controls/RadioButtonsGroup.tsx @@ -0,0 +1,93 @@ +import React from 'react'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import Radio from '@material-ui/core/Radio'; +import RadioGroup from '@material-ui/core/RadioGroup'; +import FormHelperText from '@material-ui/core/FormHelperText'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormControl from '@material-ui/core/FormControl'; +import FormLabel from '@material-ui/core/FormLabel'; + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + display: 'flex', + }, + formControl: { + margin: theme.spacing(3), + }, + group: { + margin: theme.spacing(1, 0), + }, +})); + +function RadioButtonsGroup() { + const classes = useStyles(); + const [value, setValue] = React.useState('female'); + + function handleChange(event: React.ChangeEvent) { + setValue((event.target as HTMLInputElement).value); + } + + return ( +
+ + Gender + + } label="Female" /> + } label="Male" /> + } label="Other" /> + } + label="(Disabled option)" + /> + + + + Gender + + } + label="Female" + labelPlacement="start" + /> + } + label="Male" + labelPlacement="start" + /> + } + label="Other" + labelPlacement="start" + /> + } + label="(Disabled option)" + labelPlacement="start" + /> + + labelPlacement start + +
+ ); +} + +export default RadioButtonsGroup; diff --git a/docs/src/pages/demos/selection-controls/SwitchLabels.tsx b/docs/src/pages/demos/selection-controls/SwitchLabels.tsx new file mode 100644 index 00000000000000..d71e1f5a3b4347 --- /dev/null +++ b/docs/src/pages/demos/selection-controls/SwitchLabels.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import FormGroup from '@material-ui/core/FormGroup'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; +import Switch from '@material-ui/core/Switch'; + +function SwitchLabels() { + const [state, setState] = React.useState({ + checkedA: true, + checkedB: true, + }); + + const handleChange = (name: string) => (event: React.ChangeEvent) => { + setState({ ...state, [name]: event.target.checked }); + }; + + return ( + + + } + label="Secondary" + /> + + } + label="Primary" + /> + } label="Uncontrolled" /> + } label="Disabled" /> + } label="Disabled" /> + + ); +} + +export default SwitchLabels; diff --git a/docs/src/pages/demos/selection-controls/SwitchesGroup.tsx b/docs/src/pages/demos/selection-controls/SwitchesGroup.tsx new file mode 100644 index 00000000000000..3243d7e35dad03 --- /dev/null +++ b/docs/src/pages/demos/selection-controls/SwitchesGroup.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import FormLabel from '@material-ui/core/FormLabel'; +import FormControl from '@material-ui/core/FormControl'; +import FormGroup from '@material-ui/core/FormGroup'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormHelperText from '@material-ui/core/FormHelperText'; +import Switch from '@material-ui/core/Switch'; + +function SwitchesGroup() { + const [state, setState] = React.useState({ + gilad: true, + jason: false, + antoine: true, + }); + + const handleChange = (name: string) => (event: React.ChangeEvent) => { + setState({ ...state, [name]: event.target.checked }); + }; + + return ( + + Assign responsibility + + } + label="Gilad Gray" + /> + } + label="Jason Killian" + /> + + } + label="Antoine Llorca" + /> + + Be careful + + ); +} + +export default SwitchesGroup;