From 538d1d98459f5425cdc303e6a3ad2e2e481e6ae0 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 27 Sep 2020 23:45:20 +0100 Subject: [PATCH 1/6] [ToggleButtons] Move from lab to core --- docs/src/pages.js | 4 +- .../toggle-button/CustomizedDividers.js | 4 +- .../toggle-button/CustomizedDividers.tsx | 4 +- .../toggle-button/StandaloneToggleButton.js | 2 +- .../toggle-button/StandaloneToggleButton.tsx | 2 +- .../toggle-button/ToggleButtonNotEmpty.js | 4 +- .../toggle-button/ToggleButtonNotEmpty.tsx | 4 +- .../toggle-button/ToggleButtonSizes.js | 4 +- .../toggle-button/ToggleButtonSizes.tsx | 4 +- .../components/toggle-button/ToggleButtons.js | 4 +- .../toggle-button/ToggleButtons.tsx | 4 +- .../toggle-button/ToggleButtonsMultiple.js | 4 +- .../toggle-button/ToggleButtonsMultiple.tsx | 4 +- .../toggle-button/VerticalToggleButtons.js | 4 +- .../toggle-button/VerticalToggleButtons.tsx | 4 +- .../components/toggle-button/toggle-button.md | 19 +- .../pages/guides/migration-v4/migration-v4.md | 11 + .../src/ToggleButton/ToggleButton.d.ts | 81 +------ .../src/ToggleButton/ToggleButton.js | 199 ++---------------- .../ToggleButtonGroup/ToggleButtonGroup.d.ts | 72 +------ .../src/themeAugmentation/components.d.ts | 8 - .../src/ToggleButton/ToggleButton.d.ts | 79 +++++++ .../src/ToggleButton/ToggleButton.js | 177 ++++++++++++++++ .../src/ToggleButton/ToggleButton.test.js | 0 .../material-ui/src/ToggleButton/index.d.ts | 2 + .../material-ui/src/ToggleButton/index.js | 1 + .../ToggleButtonGroup/ToggleButtonGroup.d.ts | 70 ++++++ .../ToggleButtonGroup/ToggleButtonGroup.js | 133 ++++++++++++ .../ToggleButtonGroup.test.js | 0 .../src/ToggleButtonGroup/index.d.ts | 2 + .../src/ToggleButtonGroup/index.js | 1 + .../src/ToggleButtonGroup/isValueSelected.js | 0 .../ToggleButtonGroup/isValueSelected.test.js | 0 packages/material-ui/src/index.d.ts | 6 + packages/material-ui/src/index.js | 6 + .../material-ui/src/styles/overrides.d.ts | 4 + packages/material-ui/src/styles/props.d.ts | 4 + 37 files changed, 563 insertions(+), 368 deletions(-) create mode 100644 packages/material-ui/src/ToggleButton/ToggleButton.d.ts create mode 100644 packages/material-ui/src/ToggleButton/ToggleButton.js rename packages/{material-ui-lab => material-ui}/src/ToggleButton/ToggleButton.test.js (100%) create mode 100644 packages/material-ui/src/ToggleButton/index.d.ts create mode 100644 packages/material-ui/src/ToggleButton/index.js create mode 100644 packages/material-ui/src/ToggleButtonGroup/ToggleButtonGroup.d.ts create mode 100644 packages/material-ui/src/ToggleButtonGroup/ToggleButtonGroup.js rename packages/{material-ui-lab => material-ui}/src/ToggleButtonGroup/ToggleButtonGroup.test.js (100%) create mode 100644 packages/material-ui/src/ToggleButtonGroup/index.d.ts create mode 100644 packages/material-ui/src/ToggleButtonGroup/index.js rename packages/{material-ui-lab => material-ui}/src/ToggleButtonGroup/isValueSelected.js (100%) rename packages/{material-ui-lab => material-ui}/src/ToggleButtonGroup/isValueSelected.test.js (100%) diff --git a/docs/src/pages.js b/docs/src/pages.js index 29437f9601f95f..3f37e8278d0135 100644 --- a/docs/src/pages.js +++ b/docs/src/pages.js @@ -39,12 +39,13 @@ const pages = [ { pathname: '/components/floating-action-button' }, { pathname: '/components/pickers', title: 'Date / Time' }, { pathname: '/components/radio-buttons' }, + { pathname: '/components/rating' }, { pathname: '/components/selects' }, { pathname: '/components/slider' }, - { pathname: '/components/rating' }, { pathname: '/components/switches' }, { pathname: '/components/text-fields' }, { pathname: '/components/transfer-list' }, + { pathname: '/components/toggle-button' }, ], }, { @@ -126,7 +127,6 @@ const pages = [ { pathname: '/components/rating' }, { pathname: '/components/slider-styled' }, { pathname: '/components/timeline' }, - { pathname: '/components/toggle-button' }, { pathname: '/components/trap-focus' }, { pathname: '/components/tree-view' }, ], diff --git a/docs/src/pages/components/toggle-button/CustomizedDividers.js b/docs/src/pages/components/toggle-button/CustomizedDividers.js index 0cfd61fbf447af..7ce31a2a113613 100644 --- a/docs/src/pages/components/toggle-button/CustomizedDividers.js +++ b/docs/src/pages/components/toggle-button/CustomizedDividers.js @@ -11,8 +11,8 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import Divider from '@material-ui/core/Divider'; import Paper from '@material-ui/core/Paper'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; const useStyles = makeStyles((theme) => ({ paper: { diff --git a/docs/src/pages/components/toggle-button/CustomizedDividers.tsx b/docs/src/pages/components/toggle-button/CustomizedDividers.tsx index 7ad323c0b264d5..618b77b031c2da 100644 --- a/docs/src/pages/components/toggle-button/CustomizedDividers.tsx +++ b/docs/src/pages/components/toggle-button/CustomizedDividers.tsx @@ -16,8 +16,8 @@ import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import Divider from '@material-ui/core/Divider'; import Paper from '@material-ui/core/Paper'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; const useStyles = makeStyles((theme: Theme) => createStyles({ diff --git a/docs/src/pages/components/toggle-button/StandaloneToggleButton.js b/docs/src/pages/components/toggle-button/StandaloneToggleButton.js index b13824454b869f..a06bba21db07b5 100644 --- a/docs/src/pages/components/toggle-button/StandaloneToggleButton.js +++ b/docs/src/pages/components/toggle-button/StandaloneToggleButton.js @@ -1,6 +1,6 @@ import * as React from 'react'; import CheckIcon from '@material-ui/icons/Check'; -import ToggleButton from '@material-ui/lab/ToggleButton'; +import ToggleButton from '@material-ui/core/ToggleButton'; export default function StandaloneToggleButton() { const [selected, setSelected] = React.useState(false); diff --git a/docs/src/pages/components/toggle-button/StandaloneToggleButton.tsx b/docs/src/pages/components/toggle-button/StandaloneToggleButton.tsx index b13824454b869f..a06bba21db07b5 100644 --- a/docs/src/pages/components/toggle-button/StandaloneToggleButton.tsx +++ b/docs/src/pages/components/toggle-button/StandaloneToggleButton.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import CheckIcon from '@material-ui/icons/Check'; -import ToggleButton from '@material-ui/lab/ToggleButton'; +import ToggleButton from '@material-ui/core/ToggleButton'; export default function StandaloneToggleButton() { const [selected, setSelected] = React.useState(false); diff --git a/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.js b/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.js index ce70d7d0a705d3..735ab642d64a4b 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.js +++ b/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.js @@ -8,8 +8,8 @@ import LaptopIcon from '@material-ui/icons/Laptop'; import TvIcon from '@material-ui/icons/Tv'; import PhoneAndroidIcon from '@material-ui/icons/PhoneAndroid'; import Grid from '@material-ui/core/Grid'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; const useStyles = makeStyles((theme) => ({ toggleContainer: { diff --git a/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.tsx b/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.tsx index e443e6daafd5a4..4737884de46abc 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.tsx +++ b/docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.tsx @@ -8,8 +8,8 @@ import LaptopIcon from '@material-ui/icons/Laptop'; import TvIcon from '@material-ui/icons/Tv'; import PhoneAndroidIcon from '@material-ui/icons/PhoneAndroid'; import Grid from '@material-ui/core/Grid'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; const useStyles = makeStyles((theme) => ({ toggleContainer: { diff --git a/docs/src/pages/components/toggle-button/ToggleButtonSizes.js b/docs/src/pages/components/toggle-button/ToggleButtonSizes.js index 9eb2c14cc0bb5e..54f68830dac12d 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonSizes.js +++ b/docs/src/pages/components/toggle-button/ToggleButtonSizes.js @@ -4,8 +4,8 @@ import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter'; import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight'; import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify'; import Grid from '@material-ui/core/Grid'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtonSizes() { const [alignment, setAlignment] = React.useState('left'); diff --git a/docs/src/pages/components/toggle-button/ToggleButtonSizes.tsx b/docs/src/pages/components/toggle-button/ToggleButtonSizes.tsx index aa2d070b129967..2a722296c7dfcc 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonSizes.tsx +++ b/docs/src/pages/components/toggle-button/ToggleButtonSizes.tsx @@ -4,8 +4,8 @@ import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter'; import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight'; import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify'; import Grid from '@material-ui/core/Grid'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtonSizes() { const [alignment, setAlignment] = React.useState('left'); diff --git a/docs/src/pages/components/toggle-button/ToggleButtons.js b/docs/src/pages/components/toggle-button/ToggleButtons.js index 5a01beb879c412..5274a641fc5206 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtons.js +++ b/docs/src/pages/components/toggle-button/ToggleButtons.js @@ -3,8 +3,8 @@ import FormatAlignLeftIcon from '@material-ui/icons/FormatAlignLeft'; import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter'; import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight'; import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtons() { const [alignment, setAlignment] = React.useState('left'); diff --git a/docs/src/pages/components/toggle-button/ToggleButtons.tsx b/docs/src/pages/components/toggle-button/ToggleButtons.tsx index b61cbd9d55ce54..90db9fb370be21 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtons.tsx +++ b/docs/src/pages/components/toggle-button/ToggleButtons.tsx @@ -3,8 +3,8 @@ import FormatAlignLeftIcon from '@material-ui/icons/FormatAlignLeft'; import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter'; import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight'; import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtons() { const [alignment, setAlignment] = React.useState('left'); diff --git a/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.js b/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.js index 0b148c171e2eb4..a1ac9866af7641 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.js +++ b/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.js @@ -4,8 +4,8 @@ import FormatItalicIcon from '@material-ui/icons/FormatItalic'; import FormatUnderlinedIcon from '@material-ui/icons/FormatUnderlined'; import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtonsMultiple() { const [formats, setFormats] = React.useState(() => ['bold', 'italic']); diff --git a/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.tsx b/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.tsx index 5f8127ca9871fb..7628e3b67116f2 100644 --- a/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.tsx +++ b/docs/src/pages/components/toggle-button/ToggleButtonsMultiple.tsx @@ -4,8 +4,8 @@ import FormatItalicIcon from '@material-ui/icons/FormatItalic'; import FormatUnderlinedIcon from '@material-ui/icons/FormatUnderlined'; import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function ToggleButtonsMultiple() { const [formats, setFormats] = React.useState(() => ['bold', 'italic']); diff --git a/docs/src/pages/components/toggle-button/VerticalToggleButtons.js b/docs/src/pages/components/toggle-button/VerticalToggleButtons.js index e716b6e20f1ccf..c5fff0ef3ce6ea 100644 --- a/docs/src/pages/components/toggle-button/VerticalToggleButtons.js +++ b/docs/src/pages/components/toggle-button/VerticalToggleButtons.js @@ -2,8 +2,8 @@ import * as React from 'react'; import ViewListIcon from '@material-ui/icons/ViewList'; import ViewModuleIcon from '@material-ui/icons/ViewModule'; import ViewQuiltIcon from '@material-ui/icons/ViewQuilt'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function VerticalToggleButtons() { const [view, setView] = React.useState('list'); diff --git a/docs/src/pages/components/toggle-button/VerticalToggleButtons.tsx b/docs/src/pages/components/toggle-button/VerticalToggleButtons.tsx index e6b3d00c3f6cd1..18543f12422c94 100644 --- a/docs/src/pages/components/toggle-button/VerticalToggleButtons.tsx +++ b/docs/src/pages/components/toggle-button/VerticalToggleButtons.tsx @@ -2,8 +2,8 @@ import * as React from 'react'; import ViewListIcon from '@material-ui/icons/ViewList'; import ViewModuleIcon from '@material-ui/icons/ViewModule'; import ViewQuiltIcon from '@material-ui/icons/ViewQuilt'; -import ToggleButton from '@material-ui/lab/ToggleButton'; -import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; +import ToggleButton from '@material-ui/core/ToggleButton'; +import ToggleButtonGroup from '@material-ui/core/ToggleButtonGroup'; export default function VerticalToggleButtons() { const [view, setView] = React.useState('list'); diff --git a/docs/src/pages/components/toggle-button/toggle-button.md b/docs/src/pages/components/toggle-button/toggle-button.md index 1501dbc8d26b13..a378f14ded1621 100644 --- a/docs/src/pages/components/toggle-button/toggle-button.md +++ b/docs/src/pages/components/toggle-button/toggle-button.md @@ -3,7 +3,6 @@ title: Toggle Button React component components: ToggleButton, ToggleButtonGroup githubLabel: 'component: ToggleButton' materialDesign: https://material.io/components/buttons#toggle-button -packageName: '@material-ui/lab' --- # Toggle Buttons @@ -18,31 +17,31 @@ The `ToggleButtonGroup` controls the selected state of its child buttons when gi ## Exclusive selection -Text justification toggle buttons present options for left, right, center, full, and justified text with only one item available for selection at a time. -Selecting one option deselects any other. +With exclusive selection, selecting one option deselects any other. In this example text justification toggle buttons present options for left, right, center, full, and justified text with only one item available for selection at a time. {{"demo": "pages/components/toggle-button/ToggleButtons.js"}} ## Multiple selection -Logically-grouped options, like bold, italic, and underline, allow multiple options to be selected. +Multiple selection allows for logically-grouped options, like bold, italic, and underline, to have multiple options selected. {{"demo": "pages/components/toggle-button/ToggleButtonsMultiple.js"}} ## Sizes -Fancy larger or smaller buttons? Use the `size` prop. +For larger or smaller buttons use the `size` prop. {{"demo": "pages/components/toggle-button/ToggleButtonSizes.js"}} ## Vertical buttons +The buttons can be stacked vertically with the `orientation` prop set to "vertical". + {{"demo": "pages/components/toggle-button/VerticalToggleButtons.js"}} ## Enforce value set -If you want to enforce at least one button to be active, you can adapt your handleChange -function. +If you want to enforce that at least one button must be active, you can adapt your handleChange function. ```jsx const handleFormat = (event, newFormats) => { @@ -73,5 +72,11 @@ Here is an example of customizing the component. You can learn more about this i ## Accessibility +### ARIA + - ToggleButtonGroup has `role="group"`. You should provide an accessible label with `aria-label="label"`, `aria-labelledby="id"` or `