From ea2bd5aa822dfd4e46a0cdf3d68f90f7f2e6d757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Casas?= <57921784+vicasas@users.noreply.github.com> Date: Thu, 18 Mar 2021 18:25:17 -0300 Subject: [PATCH] [docs] Migrate Checkbox demos to emotion (#25394) --- .../components/checkboxes/CheckboxLabels.js | 103 +---------------- .../components/checkboxes/CheckboxLabels.tsx | 105 +----------------- .../pages/components/checkboxes/Checkboxes.js | 48 +------- .../components/checkboxes/Checkboxes.tsx | 48 +------- .../components/checkboxes/CheckboxesGroup.js | 25 +---- .../components/checkboxes/CheckboxesGroup.tsx | 27 +---- .../components/checkboxes/ColorCheckboxes.js | 23 ++++ .../components/checkboxes/ColorCheckboxes.tsx | 23 ++++ .../checkboxes/ControlledCheckbox.js | 18 +++ .../checkboxes/ControlledCheckbox.tsx | 18 +++ .../checkboxes/CustomizedCheckbox.js | 81 ++++++-------- .../checkboxes/CustomizedCheckbox.tsx | 81 ++++++-------- .../checkboxes/FormControlLabelPosition.js | 8 +- .../checkboxes/FormControlLabelPosition.tsx | 8 +- .../components/checkboxes/IconCheckboxes.js | 25 +++++ .../components/checkboxes/IconCheckboxes.tsx | 25 +++++ .../checkboxes/IndeterminateCheckbox.js | 26 +---- .../checkboxes/IndeterminateCheckbox.tsx | 26 +---- .../components/checkboxes/SizeCheckboxes.js | 20 ++++ .../components/checkboxes/SizeCheckboxes.tsx | 20 ++++ .../pages/components/checkboxes/checkboxes.md | 40 +++++-- 21 files changed, 321 insertions(+), 477 deletions(-) create mode 100644 docs/src/pages/components/checkboxes/ColorCheckboxes.js create mode 100644 docs/src/pages/components/checkboxes/ColorCheckboxes.tsx create mode 100644 docs/src/pages/components/checkboxes/ControlledCheckbox.js create mode 100644 docs/src/pages/components/checkboxes/ControlledCheckbox.tsx create mode 100644 docs/src/pages/components/checkboxes/IconCheckboxes.js create mode 100644 docs/src/pages/components/checkboxes/IconCheckboxes.tsx create mode 100644 docs/src/pages/components/checkboxes/SizeCheckboxes.js create mode 100644 docs/src/pages/components/checkboxes/SizeCheckboxes.tsx diff --git a/docs/src/pages/components/checkboxes/CheckboxLabels.js b/docs/src/pages/components/checkboxes/CheckboxLabels.js index df870497e042d8..e1cfb0f6791e19 100644 --- a/docs/src/pages/components/checkboxes/CheckboxLabels.js +++ b/docs/src/pages/components/checkboxes/CheckboxLabels.js @@ -1,117 +1,20 @@ import * as React from 'react'; -import { withStyles } from '@material-ui/core/styles'; -import { green } from '@material-ui/core/colors'; import FormGroup from '@material-ui/core/FormGroup'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import Checkbox from '@material-ui/core/Checkbox'; -import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; -import CheckBoxIcon from '@material-ui/icons/CheckBox'; -import Favorite from '@material-ui/icons/Favorite'; -import FavoriteBorder from '@material-ui/icons/FavoriteBorder'; - -const GreenCheckbox = withStyles({ - root: { - color: green[400], - '&$checked': { - color: green[600], - }, - }, - checked: {}, -})((props) => ); export default function CheckboxLabels() { - const [state, setState] = React.useState({ - checkedA: true, - checkedB: true, - checkedF: true, - checkedG: true, - }); - - const handleChange = (event) => { - setState({ - ...state, - [event.target.name]: event.target.checked, - }); - }; - return ( - + - } + control={} label="Secondary" /> - - } - label="Primary" - /> - } - label="Uncontrolled" - /> } + control={} label="Disabled" /> - } - label="Disabled" - /> - - } - label="Indeterminate" - /> - - } - label="Custom color" - /> - } - checkedIcon={} - name="checkedH" - /> - } - label="Custom icon" - /> - } - checkedIcon={} - name="checkedI" - /> - } - label="Custom size" - /> ); } diff --git a/docs/src/pages/components/checkboxes/CheckboxLabels.tsx b/docs/src/pages/components/checkboxes/CheckboxLabels.tsx index 09c88d970d50c3..e1cfb0f6791e19 100644 --- a/docs/src/pages/components/checkboxes/CheckboxLabels.tsx +++ b/docs/src/pages/components/checkboxes/CheckboxLabels.tsx @@ -1,117 +1,20 @@ import * as React from 'react'; -import { withStyles } from '@material-ui/core/styles'; -import { green } from '@material-ui/core/colors'; import FormGroup from '@material-ui/core/FormGroup'; import FormControlLabel from '@material-ui/core/FormControlLabel'; -import Checkbox, { CheckboxProps } from '@material-ui/core/Checkbox'; -import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; -import CheckBoxIcon from '@material-ui/icons/CheckBox'; -import Favorite from '@material-ui/icons/Favorite'; -import FavoriteBorder from '@material-ui/icons/FavoriteBorder'; - -const GreenCheckbox = withStyles({ - root: { - color: green[400], - '&$checked': { - color: green[600], - }, - }, - checked: {}, -})((props: CheckboxProps) => ); +import Checkbox from '@material-ui/core/Checkbox'; export default function CheckboxLabels() { - const [state, setState] = React.useState({ - checkedA: true, - checkedB: true, - checkedF: true, - checkedG: true, - }); - - const handleChange = (event: React.ChangeEvent) => { - setState({ - ...state, - [event.target.name]: event.target.checked, - }); - }; - return ( - + - } + control={} label="Secondary" /> - - } - label="Primary" - /> - } - label="Uncontrolled" - /> } + control={} label="Disabled" /> - } - label="Disabled" - /> - - } - label="Indeterminate" - /> - - } - label="Custom color" - /> - } - checkedIcon={} - name="checkedH" - /> - } - label="Custom icon" - /> - } - checkedIcon={} - name="checkedI" - /> - } - label="Custom size" - /> ); } diff --git a/docs/src/pages/components/checkboxes/Checkboxes.js b/docs/src/pages/components/checkboxes/Checkboxes.js index 491e7eba92d1e4..c5978c4b5eee2d 100644 --- a/docs/src/pages/components/checkboxes/Checkboxes.js +++ b/docs/src/pages/components/checkboxes/Checkboxes.js @@ -2,57 +2,15 @@ import * as React from 'react'; import Checkbox from '@material-ui/core/Checkbox'; export default function Checkboxes() { - const [checked, setChecked] = React.useState(true); - - const handleChange = (event) => { - setChecked(event.target.checked); - }; - return (
- - - + + - - -
); diff --git a/docs/src/pages/components/checkboxes/Checkboxes.tsx b/docs/src/pages/components/checkboxes/Checkboxes.tsx index f14e7e7979042c..c5978c4b5eee2d 100644 --- a/docs/src/pages/components/checkboxes/Checkboxes.tsx +++ b/docs/src/pages/components/checkboxes/Checkboxes.tsx @@ -2,57 +2,15 @@ import * as React from 'react'; import Checkbox from '@material-ui/core/Checkbox'; export default function Checkboxes() { - const [checked, setChecked] = React.useState(true); - - const handleChange = (event: React.ChangeEvent) => { - setChecked(event.target.checked); - }; - return (
- - - + + - - -
); diff --git a/docs/src/pages/components/checkboxes/CheckboxesGroup.js b/docs/src/pages/components/checkboxes/CheckboxesGroup.js index d7641968c2424d..4f7c427cb439d2 100644 --- a/docs/src/pages/components/checkboxes/CheckboxesGroup.js +++ b/docs/src/pages/components/checkboxes/CheckboxesGroup.js @@ -1,5 +1,5 @@ import * as React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import Box from '@material-ui/core/Box'; import FormLabel from '@material-ui/core/FormLabel'; import FormControl from '@material-ui/core/FormControl'; import FormGroup from '@material-ui/core/FormGroup'; @@ -7,17 +7,7 @@ import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormHelperText from '@material-ui/core/FormHelperText'; import Checkbox from '@material-ui/core/Checkbox'; -const useStyles = makeStyles((theme) => ({ - root: { - display: 'flex', - }, - formControl: { - margin: theme.spacing(3), - }, -})); - export default function CheckboxesGroup() { - const classes = useStyles(); const [state, setState] = React.useState({ gilad: true, jason: false, @@ -35,8 +25,8 @@ export default function CheckboxesGroup() { const error = [gilad, jason, antoine].filter((v) => v).length !== 2; return ( -
- + + Assign responsibility Be careful - + Pick two You can display an error -
+ ); } diff --git a/docs/src/pages/components/checkboxes/CheckboxesGroup.tsx b/docs/src/pages/components/checkboxes/CheckboxesGroup.tsx index bbf0eb5f633ca9..89724399874d1a 100644 --- a/docs/src/pages/components/checkboxes/CheckboxesGroup.tsx +++ b/docs/src/pages/components/checkboxes/CheckboxesGroup.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'; +import Box from '@material-ui/core/Box'; import FormLabel from '@material-ui/core/FormLabel'; import FormControl from '@material-ui/core/FormControl'; import FormGroup from '@material-ui/core/FormGroup'; @@ -7,19 +7,7 @@ import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormHelperText from '@material-ui/core/FormHelperText'; import Checkbox from '@material-ui/core/Checkbox'; -const useStyles = makeStyles((theme: Theme) => - createStyles({ - root: { - display: 'flex', - }, - formControl: { - margin: theme.spacing(3), - }, - }), -); - export default function CheckboxesGroup() { - const classes = useStyles(); const [state, setState] = React.useState({ gilad: true, jason: false, @@ -37,8 +25,8 @@ export default function CheckboxesGroup() { const error = [gilad, jason, antoine].filter((v) => v).length !== 2; return ( -
- + + Assign responsibility Be careful - + Pick two You can display an error -
+ ); } diff --git a/docs/src/pages/components/checkboxes/ColorCheckboxes.js b/docs/src/pages/components/checkboxes/ColorCheckboxes.js new file mode 100644 index 00000000000000..988b058d25ac0e --- /dev/null +++ b/docs/src/pages/components/checkboxes/ColorCheckboxes.js @@ -0,0 +1,23 @@ +import * as React from 'react'; +import { green } from '@material-ui/core/colors'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function ColorCheckboxes() { + return ( +
+ + + + +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/ColorCheckboxes.tsx b/docs/src/pages/components/checkboxes/ColorCheckboxes.tsx new file mode 100644 index 00000000000000..988b058d25ac0e --- /dev/null +++ b/docs/src/pages/components/checkboxes/ColorCheckboxes.tsx @@ -0,0 +1,23 @@ +import * as React from 'react'; +import { green } from '@material-ui/core/colors'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function ColorCheckboxes() { + return ( +
+ + + + +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/ControlledCheckbox.js b/docs/src/pages/components/checkboxes/ControlledCheckbox.js new file mode 100644 index 00000000000000..334075d9dd2180 --- /dev/null +++ b/docs/src/pages/components/checkboxes/ControlledCheckbox.js @@ -0,0 +1,18 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function ControlledCheckbox() { + const [checked, setChecked] = React.useState(true); + + const handleChange = (event) => { + setChecked(event.target.checked); + }; + + return ( + + ); +} diff --git a/docs/src/pages/components/checkboxes/ControlledCheckbox.tsx b/docs/src/pages/components/checkboxes/ControlledCheckbox.tsx new file mode 100644 index 00000000000000..be0474ca3a8a41 --- /dev/null +++ b/docs/src/pages/components/checkboxes/ControlledCheckbox.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function ControlledCheckbox() { + const [checked, setChecked] = React.useState(true); + + const handleChange = (event: React.ChangeEvent) => { + setChecked(event.target.checked); + }; + + return ( + + ); +} diff --git a/docs/src/pages/components/checkboxes/CustomizedCheckbox.js b/docs/src/pages/components/checkboxes/CustomizedCheckbox.js index 8051bb7a21a2f6..6e6e552d75d89f 100644 --- a/docs/src/pages/components/checkboxes/CustomizedCheckbox.js +++ b/docs/src/pages/components/checkboxes/CustomizedCheckbox.js @@ -1,63 +1,56 @@ import * as React from 'react'; -import clsx from 'clsx'; -import { makeStyles } from '@material-ui/core/styles'; +import { experimentalStyled as styled } from '@material-ui/core/styles'; import Checkbox from '@material-ui/core/Checkbox'; -const useStyles = makeStyles({ - root: { - '&:hover': { - backgroundColor: 'transparent', - }, +const Icon = styled('span')({ + borderRadius: 3, + width: 16, + height: 16, + boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)', + backgroundColor: '#f5f8fa', + backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))', + '.Mui-focusVisible &': { + outline: '2px auto rgba(19,124,189,.6)', + outlineOffset: 2, }, - icon: { - borderRadius: 3, + 'input:hover ~ &': { + backgroundColor: '#ebf1f5', + }, + 'input:disabled ~ &': { + boxShadow: 'none', + background: 'rgba(206,217,224,.5)', + }, +}); + +const CheckedIcon = styled(Icon)({ + backgroundColor: '#137cbd', + backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))', + '&:before': { + display: 'block', width: 16, height: 16, - boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)', - backgroundColor: '#f5f8fa', - backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))', - '$root.Mui-focusVisible &': { - outline: '2px auto rgba(19,124,189,.6)', - outlineOffset: 2, - }, - 'input:hover ~ &': { - backgroundColor: '#ebf1f5', - }, - 'input:disabled ~ &': { - boxShadow: 'none', - background: 'rgba(206,217,224,.5)', - }, + backgroundImage: + "url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" + + " fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " + + "1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E\")", + content: '""', }, - checkedIcon: { - backgroundColor: '#137cbd', - backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))', - '&:before': { - display: 'block', - width: 16, - height: 16, - backgroundImage: - "url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" + - " fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " + - "1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E\")", - content: '""', - }, - 'input:hover ~ &': { - backgroundColor: '#106ba3', - }, + 'input:hover ~ &': { + backgroundColor: '#106ba3', }, }); // Inspired by blueprintjs function StyledCheckbox(props) { - const classes = useStyles(); - return ( } - icon={} + checkedIcon={} + icon={} inputProps={{ 'aria-label': 'decorative checkbox' }} {...props} /> diff --git a/docs/src/pages/components/checkboxes/CustomizedCheckbox.tsx b/docs/src/pages/components/checkboxes/CustomizedCheckbox.tsx index 95bce25daded9d..6be50606d1d41c 100644 --- a/docs/src/pages/components/checkboxes/CustomizedCheckbox.tsx +++ b/docs/src/pages/components/checkboxes/CustomizedCheckbox.tsx @@ -1,63 +1,56 @@ import * as React from 'react'; -import clsx from 'clsx'; -import { makeStyles } from '@material-ui/core/styles'; +import { experimentalStyled as styled } from '@material-ui/core/styles'; import Checkbox, { CheckboxProps } from '@material-ui/core/Checkbox'; -const useStyles = makeStyles({ - root: { - '&:hover': { - backgroundColor: 'transparent', - }, +const Icon = styled('span')({ + borderRadius: 3, + width: 16, + height: 16, + boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)', + backgroundColor: '#f5f8fa', + backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))', + '.Mui-focusVisible &': { + outline: '2px auto rgba(19,124,189,.6)', + outlineOffset: 2, }, - icon: { - borderRadius: 3, + 'input:hover ~ &': { + backgroundColor: '#ebf1f5', + }, + 'input:disabled ~ &': { + boxShadow: 'none', + background: 'rgba(206,217,224,.5)', + }, +}); + +const CheckedIcon = styled(Icon)({ + backgroundColor: '#137cbd', + backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))', + '&:before': { + display: 'block', width: 16, height: 16, - boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)', - backgroundColor: '#f5f8fa', - backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))', - '$root.Mui-focusVisible &': { - outline: '2px auto rgba(19,124,189,.6)', - outlineOffset: 2, - }, - 'input:hover ~ &': { - backgroundColor: '#ebf1f5', - }, - 'input:disabled ~ &': { - boxShadow: 'none', - background: 'rgba(206,217,224,.5)', - }, + backgroundImage: + "url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" + + " fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " + + "1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E\")", + content: '""', }, - checkedIcon: { - backgroundColor: '#137cbd', - backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))', - '&:before': { - display: 'block', - width: 16, - height: 16, - backgroundImage: - "url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" + - " fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " + - "1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E\")", - content: '""', - }, - 'input:hover ~ &': { - backgroundColor: '#106ba3', - }, + 'input:hover ~ &': { + backgroundColor: '#106ba3', }, }); // Inspired by blueprintjs function StyledCheckbox(props: CheckboxProps) { - const classes = useStyles(); - return ( } - icon={} + checkedIcon={} + icon={} inputProps={{ 'aria-label': 'decorative checkbox' }} {...props} /> diff --git a/docs/src/pages/components/checkboxes/FormControlLabelPosition.js b/docs/src/pages/components/checkboxes/FormControlLabelPosition.js index 0949600180ba3f..a36704237c1448 100644 --- a/docs/src/pages/components/checkboxes/FormControlLabelPosition.js +++ b/docs/src/pages/components/checkboxes/FormControlLabelPosition.js @@ -12,25 +12,25 @@ export default function FormControlLabelPosition() { } + control={} label="Top" labelPlacement="top" /> } + control={} label="Start" labelPlacement="start" /> } + control={} label="Bottom" labelPlacement="bottom" /> } + control={} label="End" labelPlacement="end" /> diff --git a/docs/src/pages/components/checkboxes/FormControlLabelPosition.tsx b/docs/src/pages/components/checkboxes/FormControlLabelPosition.tsx index 0949600180ba3f..a36704237c1448 100644 --- a/docs/src/pages/components/checkboxes/FormControlLabelPosition.tsx +++ b/docs/src/pages/components/checkboxes/FormControlLabelPosition.tsx @@ -12,25 +12,25 @@ export default function FormControlLabelPosition() { } + control={} label="Top" labelPlacement="top" /> } + control={} label="Start" labelPlacement="start" /> } + control={} label="Bottom" labelPlacement="bottom" /> } + control={} label="End" labelPlacement="end" /> diff --git a/docs/src/pages/components/checkboxes/IconCheckboxes.js b/docs/src/pages/components/checkboxes/IconCheckboxes.js new file mode 100644 index 00000000000000..4a0c144bce9564 --- /dev/null +++ b/docs/src/pages/components/checkboxes/IconCheckboxes.js @@ -0,0 +1,25 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; +import FavoriteBorder from '@material-ui/icons/FavoriteBorder'; +import Favorite from '@material-ui/icons/Favorite'; +import BookmarkBorderIcon from '@material-ui/icons/BookmarkBorder'; +import BookmarkIcon from '@material-ui/icons/Bookmark'; + +export default function IconCheckboxes() { + return ( +
+ } + checkedIcon={} + name="checkedA" + inputProps={{ 'aria-label': 'favorite checkbox' }} + /> + } + checkedIcon={} + name="checkedB" + inputProps={{ 'aria-label': 'bookmarked checkbox' }} + /> +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/IconCheckboxes.tsx b/docs/src/pages/components/checkboxes/IconCheckboxes.tsx new file mode 100644 index 00000000000000..4a0c144bce9564 --- /dev/null +++ b/docs/src/pages/components/checkboxes/IconCheckboxes.tsx @@ -0,0 +1,25 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; +import FavoriteBorder from '@material-ui/icons/FavoriteBorder'; +import Favorite from '@material-ui/icons/Favorite'; +import BookmarkBorderIcon from '@material-ui/icons/BookmarkBorder'; +import BookmarkIcon from '@material-ui/icons/Bookmark'; + +export default function IconCheckboxes() { + return ( +
+ } + checkedIcon={} + name="checkedA" + inputProps={{ 'aria-label': 'favorite checkbox' }} + /> + } + checkedIcon={} + name="checkedB" + inputProps={{ 'aria-label': 'bookmarked checkbox' }} + /> +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/IndeterminateCheckbox.js b/docs/src/pages/components/checkboxes/IndeterminateCheckbox.js index 3719fed69d9af1..1a711cb6adad49 100644 --- a/docs/src/pages/components/checkboxes/IndeterminateCheckbox.js +++ b/docs/src/pages/components/checkboxes/IndeterminateCheckbox.js @@ -1,18 +1,9 @@ import * as React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import Box from '@material-ui/core/Box'; import Checkbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; -const useStyles = makeStyles((theme) => ({ - children: { - display: 'flex', - flexDirection: 'column', - marginLeft: theme.spacing(3), - }, -})); - export default function IndeterminateCheckbox() { - const classes = useStyles(); const [checked, setChecked] = React.useState([true, false]); const handleChange1 = (event) => { @@ -28,34 +19,29 @@ export default function IndeterminateCheckbox() { }; const children = ( -
+ - } + control={} /> - } + control={} /> -
+ ); return (
} + label="Parent" /> {children}
diff --git a/docs/src/pages/components/checkboxes/IndeterminateCheckbox.tsx b/docs/src/pages/components/checkboxes/IndeterminateCheckbox.tsx index 7af5ed0f72ac16..775aa0aec42a5f 100644 --- a/docs/src/pages/components/checkboxes/IndeterminateCheckbox.tsx +++ b/docs/src/pages/components/checkboxes/IndeterminateCheckbox.tsx @@ -1,18 +1,9 @@ import * as React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import Box from '@material-ui/core/Box'; import Checkbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; -const useStyles = makeStyles((theme) => ({ - children: { - display: 'flex', - flexDirection: 'column', - marginLeft: theme.spacing(3), - }, -})); - export default function IndeterminateCheckbox() { - const classes = useStyles(); const [checked, setChecked] = React.useState([true, false]); const handleChange1 = (event: React.ChangeEvent) => { @@ -28,34 +19,29 @@ export default function IndeterminateCheckbox() { }; const children = ( -
+ - } + control={} /> - } + control={} /> -
+ ); return (
} + label="Parent" /> {children}
diff --git a/docs/src/pages/components/checkboxes/SizeCheckboxes.js b/docs/src/pages/components/checkboxes/SizeCheckboxes.js new file mode 100644 index 00000000000000..98389907764242 --- /dev/null +++ b/docs/src/pages/components/checkboxes/SizeCheckboxes.js @@ -0,0 +1,20 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function SizeCheckboxes() { + return ( +
+ + + +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/SizeCheckboxes.tsx b/docs/src/pages/components/checkboxes/SizeCheckboxes.tsx new file mode 100644 index 00000000000000..98389907764242 --- /dev/null +++ b/docs/src/pages/components/checkboxes/SizeCheckboxes.tsx @@ -0,0 +1,20 @@ +import * as React from 'react'; +import Checkbox from '@material-ui/core/Checkbox'; + +export default function SizeCheckboxes() { + return ( +
+ + + +
+ ); +} diff --git a/docs/src/pages/components/checkboxes/checkboxes.md b/docs/src/pages/components/checkboxes/checkboxes.md index 463e9a12f12273..9358b4c824c74b 100644 --- a/docs/src/pages/components/checkboxes/checkboxes.md +++ b/docs/src/pages/components/checkboxes/checkboxes.md @@ -22,22 +22,46 @@ If you have a single option, avoid using a checkbox and use an on/off switch ins {{"demo": "pages/components/checkboxes/Checkboxes.js"}} -## Indeterminate +## Label -A checkbox input can only have two states in a form: checked or unchecked. It either submits its value or doesn't. -Visually, there are actually three states a checkbox can be in: checked, unchecked, or indeterminate. +You can provide a label to the `Checkbox` thanks to the `FormControlLabel` component. -{{"demo": "pages/components/checkboxes/IndeterminateCheckbox.js"}} +{{"demo": "pages/components/checkboxes/CheckboxLabels.js"}} -## Label +## Size -`Checkbox` can be provided with a label thanks to the `FormControlLabel` component. +Use the `size` prop or customize the font size of the svg icons to change the size of the checkboxes. -{{"demo": "pages/components/checkboxes/CheckboxLabels.js"}} +{{"demo": "pages/components/checkboxes/SizeCheckboxes.js"}} + +## Color + +{{"demo": "pages/components/checkboxes/ColorCheckboxes.js"}} + +## Icon + +{{"demo": "pages/components/checkboxes/IconCheckboxes.js"}} + +## Controlled + +You can control the checkbox with the `value` and `onChange` props: + +{{"demo": "pages/components/checkboxes/ControlledCheckbox.js"}} + +## Indeterminate + +A checkbox input can only have two states in a form: checked or unchecked. +It either submits its value or doesn't. +Visually, there are **three** states a checkbox can be in: checked, unchecked, or indeterminate. + +{{"demo": "pages/components/checkboxes/IndeterminateCheckbox.js"}} + +> ⚠️ When indeterminate is set, the value of the `checked` prop only impacts the form submitted values. +> It has no accessibility or UX implications. ## FormGroup -`FormGroup` is a helpful wrapper used to group selection controls components that provides an easier API. +`FormGroup` is a helpful wrapper used to group selection control components. {{"demo": "pages/components/checkboxes/CheckboxesGroup.js"}}