Skip to content

Commit

Permalink
[docs] Simplify some demos (mui#19608)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes authored and EsoterikStare committed Mar 30, 2020
1 parent 66beeec commit 5e797e9
Show file tree
Hide file tree
Showing 22 changed files with 519 additions and 333 deletions.
22 changes: 0 additions & 22 deletions docs/src/pages/components/buttons/UploadButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ export default function UploadButtons() {
Upload
</Button>
</label>
<input
accept="image/*"
className={classes.input}
id="text-button-file"
multiple
type="file"
/>
<label htmlFor="text-button-file">
<Button component="span">Upload</Button>
</label>
<input
accept="image/*"
className={classes.input}
id="outlined-button-file"
multiple
type="file"
/>
<label htmlFor="outlined-button-file">
<Button variant="outlined" component="span">
Upload
</Button>
</label>
<input accept="image/*" className={classes.input} id="icon-button-file" type="file" />
<label htmlFor="icon-button-file">
<IconButton color="primary" aria-label="upload picture" component="span">
Expand Down
22 changes: 0 additions & 22 deletions docs/src/pages/components/buttons/UploadButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,6 @@ export default function UploadButtons() {
Upload
</Button>
</label>
<input
accept="image/*"
className={classes.input}
id="text-button-file"
multiple
type="file"
/>
<label htmlFor="text-button-file">
<Button component="span">Upload</Button>
</label>
<input
accept="image/*"
className={classes.input}
id="outlined-button-file"
multiple
type="file"
/>
<label htmlFor="outlined-button-file">
<Button variant="outlined" component="span">
Upload
</Button>
</label>
<input accept="image/*" className={classes.input} id="icon-button-file" type="file" />
<label htmlFor="icon-button-file">
<IconButton color="primary" aria-label="upload picture" component="span">
Expand Down
6 changes: 5 additions & 1 deletion docs/src/pages/components/checkboxes/checkboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ If you have multiple options appearing in a list,
you can preserve space by using checkboxes instead of on/off switches.
If you have a single option, avoid using a checkbox and use an on/off switch instead.

## Basic checkboxes

{{"demo": "pages/components/checkboxes/Checkboxes.js"}}

`Checkbox` can also be used with a label description thanks to the `FormControlLabel` component.
## Checkbox with FormControlLabel

`Checkbox` can be provided with a label thanks to the `FormControlLabel` component.

{{"demo": "pages/components/checkboxes/CheckboxLabels.js"}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';

export default function FormControlLabelPosition() {
const [value, setValue] = React.useState('female');
const [value, setValue] = React.useState('top');

const handleChange = event => {
setValue(event.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';

export default function FormControlLabelPosition() {
const [value, setValue] = React.useState('female');
const [value, setValue] = React.useState('top');

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue((event.target as HTMLInputElement).value);
Expand Down
65 changes: 9 additions & 56 deletions docs/src/pages/components/radio-buttons/RadioButtonsGroup.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,26 @@
import React from 'react';
import { makeStyles } 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 => ({
formControl: {
margin: theme.spacing(3),
},
}));

export default function RadioButtonsGroup() {
const classes = useStyles();
const [value, setValue] = React.useState('female');

const handleChange = event => {
setValue(event.target.value);
};

return (
<div>
<FormControl component="fieldset" className={classes.formControl}>
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender1" value={value} onChange={handleChange}>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="(Disabled option)"
/>
</RadioGroup>
</FormControl>
<FormControl component="fieldset" className={classes.formControl}>
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender2" value={value} onChange={handleChange}>
<FormControlLabel
value="female"
control={<Radio color="primary" />}
label="Female"
labelPlacement="start"
/>
<FormControlLabel
value="male"
control={<Radio color="primary" />}
label="Male"
labelPlacement="start"
/>
<FormControlLabel
value="other"
control={<Radio color="primary" />}
label="Other"
labelPlacement="start"
/>
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="(Disabled option)"
labelPlacement="start"
/>
</RadioGroup>
<FormHelperText>labelPlacement start</FormHelperText>
</FormControl>
</div>
<FormControl component="fieldset">
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender1" value={value} onChange={handleChange}>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel value="disabled" disabled control={<Radio />} label="(Disabled option)" />
</RadioGroup>
</FormControl>
);
}
67 changes: 9 additions & 58 deletions docs/src/pages/components/radio-buttons/RadioButtonsGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,26 @@
import React from 'react';
import { makeStyles, Theme, createStyles } 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) =>
createStyles({
formControl: {
margin: theme.spacing(3),
},
}),
);

export default function RadioButtonsGroup() {
const classes = useStyles();
const [value, setValue] = React.useState('female');

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue((event.target as HTMLInputElement).value);
};

return (
<div>
<FormControl component="fieldset" className={classes.formControl}>
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender1" value={value} onChange={handleChange}>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="(Disabled option)"
/>
</RadioGroup>
</FormControl>
<FormControl component="fieldset" className={classes.formControl}>
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender2" value={value} onChange={handleChange}>
<FormControlLabel
value="female"
control={<Radio color="primary" />}
label="Female"
labelPlacement="start"
/>
<FormControlLabel
value="male"
control={<Radio color="primary" />}
label="Male"
labelPlacement="start"
/>
<FormControlLabel
value="other"
control={<Radio color="primary" />}
label="Other"
labelPlacement="start"
/>
<FormControlLabel
value="disabled"
disabled
control={<Radio />}
label="(Disabled option)"
labelPlacement="start"
/>
</RadioGroup>
<FormHelperText>labelPlacement start</FormHelperText>
</FormControl>
</div>
<FormControl component="fieldset">
<FormLabel component="legend">Gender</FormLabel>
<RadioGroup aria-label="gender" name="gender1" value={value} onChange={handleChange}>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
<FormControlLabel value="disabled" disabled control={<Radio />} label="(Disabled option)" />
</RadioGroup>
</FormControl>
);
}
6 changes: 4 additions & 2 deletions docs/src/pages/components/radio-buttons/radio-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ If available options can be collapsed, consider using a dropdown menu because it

Radio buttons should have the most commonly used option selected by default.

## RadioGroup

`RadioGroup` is a helpful wrapper used to group `Radio` components that provides an easier API, and proper keyboard accessibility to the group.

{{"demo": "pages/components/radio-buttons/RadioButtonsGroup.js"}}

## Standalone Radio Buttons
## Standalone radio buttons

`Radio` can also be used standalone, without the wrapper.
`Radio` can also be used standalone, without the RadioGroup wrapper.

{{"demo": "pages/components/radio-buttons/RadioButtons.js"}}

Expand Down
5 changes: 4 additions & 1 deletion docs/src/pages/components/slider/ContinuousSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default function ContinuousSlider() {
<VolumeUp />
</Grid>
</Grid>
<Slider disabled defaultValue={30} aria-labelledby="continuous-slider" />
<Typography id="disabled-slider" gutterBottom>
Disabled slider
</Typography>
<Slider disabled defaultValue={30} aria-labelledby="disabled-slider" />
</div>
);
}
5 changes: 4 additions & 1 deletion docs/src/pages/components/slider/ContinuousSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default function ContinuousSlider() {
<VolumeUp />
</Grid>
</Grid>
<Slider disabled defaultValue={30} aria-labelledby="continuous-slider" />
<Typography id="disabled-slider" gutterBottom>
Disabled slider
</Typography>
<Slider disabled defaultValue={30} aria-labelledby="disabled-slider" />
</div>
);
}
Loading

0 comments on commit 5e797e9

Please sign in to comment.