-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
[docs] Add ToggleButton demo for not accepting null value #19582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import React from 'react'; | ||
| import { makeStyles } from '@material-ui/core/styles'; | ||
| 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 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'; | ||
|
|
||
| const useStyles = makeStyles(theme => ({ | ||
| toggleContainer: { | ||
| margin: theme.spacing(2, 0), | ||
| }, | ||
| })); | ||
|
|
||
| export default function ToggleButtons() { | ||
| const [alignment, setAlignment] = React.useState('left'); | ||
| const [formats, setFormats] = React.useState(() => ['phone']); | ||
|
|
||
| const handleFormat = (event, newFormats) => { | ||
| if (newFormats.length) { | ||
| setFormats(newFormats); | ||
| } | ||
| }; | ||
|
|
||
| const handleAlignment = (event, newAlignment) => { | ||
| if (newAlignment !== null) { | ||
| setAlignment(newAlignment); | ||
| } | ||
| }; | ||
|
|
||
| const classes = useStyles(); | ||
|
|
||
| return ( | ||
| <Grid container spacing={2}> | ||
| <Grid item sm={12} md={6}> | ||
| <div className={classes.toggleContainer}> | ||
| <ToggleButtonGroup | ||
| value={alignment} | ||
| exclusive | ||
| onChange={handleAlignment} | ||
| aria-label="text alignment" | ||
| > | ||
| <ToggleButton value="left" aria-label="left aligned"> | ||
| <FormatAlignLeftIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="center" aria-label="centered"> | ||
| <FormatAlignCenterIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="right" aria-label="right aligned"> | ||
| <FormatAlignRightIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="justify" aria-label="justified" disabled> | ||
| <FormatAlignJustifyIcon /> | ||
| </ToggleButton> | ||
| </ToggleButtonGroup> | ||
| </div> | ||
| </Grid> | ||
| <Grid item sm={12} md={6}> | ||
| <div className={classes.toggleContainer}> | ||
| <ToggleButtonGroup value={formats} onChange={handleFormat} aria-label="device"> | ||
| <ToggleButton value="laptop" aria-label="laptop"> | ||
| <LaptopIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="tv" aria-label="tv"> | ||
| <TvIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="phone" aria-label="phone"> | ||
| <PhoneAndroidIcon /> | ||
| </ToggleButton> | ||
| </ToggleButtonGroup> | ||
| </div> | ||
| </Grid> | ||
| </Grid> | ||
| ); | ||
| } |
80 changes: 80 additions & 0 deletions
80
docs/src/pages/components/toggle-button/ToggleButtonNotEmpty.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import React from 'react'; | ||
| import { makeStyles } from '@material-ui/core/styles'; | ||
| 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 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'; | ||
|
|
||
| const useStyles = makeStyles(theme => ({ | ||
| toggleContainer: { | ||
| margin: theme.spacing(2, 0), | ||
| }, | ||
| })); | ||
|
|
||
| export default function ToggleButtons() { | ||
| const [alignment, setAlignment] = React.useState('left'); | ||
| const [formats, setFormats] = React.useState(() => ['phone']); | ||
|
|
||
| const handleFormat = (event: React.MouseEvent<HTMLElement>, newFormats: string[]) => { | ||
| if (newFormats.length) { | ||
| setFormats(newFormats); | ||
| } | ||
| }; | ||
|
|
||
| const handleAlignment = (event: React.MouseEvent<HTMLElement>, newAlignment: string | null) => { | ||
| if (newAlignment !== null) { | ||
| setAlignment(newAlignment); | ||
| } | ||
| }; | ||
|
|
||
| const classes = useStyles(); | ||
|
|
||
| return ( | ||
| <Grid container spacing={2}> | ||
| <Grid item sm={12} md={6}> | ||
| <div className={classes.toggleContainer}> | ||
| <ToggleButtonGroup | ||
| value={alignment} | ||
| exclusive | ||
| onChange={handleAlignment} | ||
| aria-label="text alignment" | ||
| > | ||
| <ToggleButton value="left" aria-label="left aligned"> | ||
| <FormatAlignLeftIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="center" aria-label="centered"> | ||
| <FormatAlignCenterIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="right" aria-label="right aligned"> | ||
| <FormatAlignRightIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="justify" aria-label="justified" disabled> | ||
| <FormatAlignJustifyIcon /> | ||
| </ToggleButton> | ||
| </ToggleButtonGroup> | ||
| </div> | ||
| </Grid> | ||
| <Grid item sm={12} md={6}> | ||
| <div className={classes.toggleContainer}> | ||
| <ToggleButtonGroup value={formats} onChange={handleFormat} aria-label="device"> | ||
| <ToggleButton value="laptop" aria-label="laptop"> | ||
| <LaptopIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="tv" aria-label="tv"> | ||
| <TvIcon /> | ||
| </ToggleButton> | ||
| <ToggleButton value="phone" aria-label="phone"> | ||
| <PhoneAndroidIcon /> | ||
| </ToggleButton> | ||
| </ToggleButtonGroup> | ||
| </div> | ||
| </Grid> | ||
| </Grid> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.