-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ToggleButton][Joy] Add
ToggleButton
component (#37716)
- Loading branch information
1 parent
a748b51
commit 5131b59
Showing
40 changed files
with
2,094 additions
and
181 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
docs/data/joy/components/toggle-button-group/ExclusiveSelection.js
This file contains 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,30 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
|
||
export default function ExclusiveSelection() { | ||
const [value, setValue] = React.useState('default'); | ||
return ( | ||
<ToggleButtonGroup | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="default">Default</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
docs/data/joy/components/toggle-button-group/ExclusiveSelection.tsx
This file contains 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,30 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
|
||
export default function ExclusiveSelection() { | ||
const [value, setValue] = React.useState<string | null>('default'); | ||
return ( | ||
<ToggleButtonGroup | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="default">Default</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
docs/data/joy/components/toggle-button-group/ToggleButtons.js
This file contains 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,41 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import Stack from '@mui/joy/Stack'; | ||
import FormatBold from '@mui/icons-material/FormatBold'; | ||
|
||
export default function ToggleButtons() { | ||
const [pressed, setPressed] = React.useState(false); | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<Button | ||
variant="outlined" | ||
color="neutral" | ||
onClick={() => setPressed(!pressed)} | ||
aria-pressed={pressed ? 'true' : 'false'} | ||
sx={(theme) => ({ | ||
[`&[aria-pressed="true"]`]: { | ||
...theme.variants.outlinedActive.neutral, | ||
borderColor: theme.vars.palette.neutral.outlinedHoverBorder, | ||
}, | ||
})} | ||
> | ||
Button | ||
</Button> | ||
<IconButton | ||
variant="outlined" | ||
color="neutral" | ||
onClick={() => setPressed(!pressed)} | ||
aria-pressed={pressed ? 'true' : 'false'} | ||
sx={(theme) => ({ | ||
[`&[aria-pressed="true"]`]: { | ||
...theme.variants.outlinedActive.neutral, | ||
borderColor: theme.vars.palette.neutral.outlinedHoverBorder, | ||
}, | ||
})} | ||
> | ||
<FormatBold /> | ||
</IconButton> | ||
</Stack> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
docs/data/joy/components/toggle-button-group/ToggleButtons.tsx
This file contains 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,41 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import Stack from '@mui/joy/Stack'; | ||
import FormatBold from '@mui/icons-material/FormatBold'; | ||
|
||
export default function ToggleButtons() { | ||
const [pressed, setPressed] = React.useState(false); | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<Button | ||
variant="outlined" | ||
color="neutral" | ||
onClick={() => setPressed(!pressed)} | ||
aria-pressed={pressed ? 'true' : 'false'} | ||
sx={(theme) => ({ | ||
[`&[aria-pressed="true"]`]: { | ||
...theme.variants.outlinedActive.neutral, | ||
borderColor: theme.vars.palette.neutral.outlinedHoverBorder, | ||
}, | ||
})} | ||
> | ||
Button | ||
</Button> | ||
<IconButton | ||
variant="outlined" | ||
color="neutral" | ||
onClick={() => setPressed(!pressed)} | ||
aria-pressed={pressed ? 'true' : 'false'} | ||
sx={(theme) => ({ | ||
[`&[aria-pressed="true"]`]: { | ||
...theme.variants.outlinedActive.neutral, | ||
borderColor: theme.vars.palette.neutral.outlinedHoverBorder, | ||
}, | ||
})} | ||
> | ||
<FormatBold /> | ||
</IconButton> | ||
</Stack> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
docs/data/joy/components/toggle-button-group/ToggleGroup.js
This file contains 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,30 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
|
||
export default function ToggleGroup() { | ||
const [value, setValue] = React.useState(['default']); | ||
return ( | ||
<ToggleButtonGroup | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="default">Default</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
docs/data/joy/components/toggle-button-group/ToggleGroup.tsx
This file contains 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,30 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
|
||
export default function ToggleGroup() { | ||
const [value, setValue] = React.useState(['default']); | ||
return ( | ||
<ToggleButtonGroup | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="default">Default</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
docs/data/joy/components/toggle-button-group/ToggleGroupColors.js
This file contains 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,64 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import FormControl from '@mui/joy/FormControl'; | ||
import FormLabel from '@mui/joy/FormLabel'; | ||
import RadioGroup from '@mui/joy/RadioGroup'; | ||
import Radio from '@mui/joy/Radio'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import Stack from '@mui/joy/Stack'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
|
||
export default function ToggleGroupColors() { | ||
const [variant, setVariant] = React.useState('plain'); | ||
const [color, setColor] = React.useState('neutral'); | ||
return ( | ||
<Stack spacing={2}> | ||
<ToggleButtonGroup | ||
variant={variant || undefined} | ||
color={color || undefined} | ||
value="pressed" | ||
> | ||
<Button value="pressed">I'm pressed</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
<FormControl> | ||
<FormLabel>Variant</FormLabel> | ||
<RadioGroup | ||
orientation="horizontal" | ||
value={variant} | ||
onChange={(event) => setVariant(event.target.value)} | ||
> | ||
<Radio value="plain" label="plain" /> | ||
<Radio value="outlined" label="outlined" /> | ||
<Radio value="soft" label="soft" /> | ||
<Radio value="solid" label="solid" /> | ||
</RadioGroup> | ||
</FormControl> | ||
<FormControl> | ||
<FormLabel>Color</FormLabel> | ||
<RadioGroup | ||
orientation="horizontal" | ||
value={color} | ||
onChange={(event) => setColor(event.target.value)} | ||
> | ||
<Radio value="primary" label="primary" /> | ||
<Radio value="neutral" label="neutral" /> | ||
<Radio value="danger" label="danger" /> | ||
<Radio value="success" label="success" /> | ||
<Radio value="warning" label="warning" /> | ||
</RadioGroup> | ||
</FormControl> | ||
</Stack> | ||
); | ||
} |
65 changes: 65 additions & 0 deletions
65
docs/data/joy/components/toggle-button-group/ToggleGroupColors.tsx
This file contains 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,65 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import IconButton from '@mui/joy/IconButton'; | ||
import FormControl from '@mui/joy/FormControl'; | ||
import FormLabel from '@mui/joy/FormLabel'; | ||
import RadioGroup from '@mui/joy/RadioGroup'; | ||
import Radio from '@mui/joy/Radio'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
import Stack from '@mui/joy/Stack'; | ||
import FormatBoldIcon from '@mui/icons-material/FormatBold'; | ||
import FormatItalicIcon from '@mui/icons-material/FormatItalic'; | ||
import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; | ||
import { VariantProp, ColorPaletteProp } from '@mui/joy/styles'; | ||
|
||
export default function ToggleGroupColors() { | ||
const [variant, setVariant] = React.useState<VariantProp | null>('plain'); | ||
const [color, setColor] = React.useState<ColorPaletteProp | null>('neutral'); | ||
return ( | ||
<Stack spacing={2}> | ||
<ToggleButtonGroup | ||
variant={variant || undefined} | ||
color={color || undefined} | ||
value="pressed" | ||
> | ||
<Button value="pressed">I'm pressed</Button> | ||
<IconButton value="bold"> | ||
<FormatBoldIcon /> | ||
</IconButton> | ||
<IconButton value="italic"> | ||
<FormatItalicIcon /> | ||
</IconButton> | ||
<IconButton value="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</IconButton> | ||
</ToggleButtonGroup> | ||
<FormControl> | ||
<FormLabel>Variant</FormLabel> | ||
<RadioGroup | ||
orientation="horizontal" | ||
value={variant} | ||
onChange={(event) => setVariant(event.target.value as VariantProp)} | ||
> | ||
<Radio value="plain" label="plain" /> | ||
<Radio value="outlined" label="outlined" /> | ||
<Radio value="soft" label="soft" /> | ||
<Radio value="solid" label="solid" /> | ||
</RadioGroup> | ||
</FormControl> | ||
<FormControl> | ||
<FormLabel>Color</FormLabel> | ||
<RadioGroup | ||
orientation="horizontal" | ||
value={color} | ||
onChange={(event) => setColor(event.target.value as ColorPaletteProp)} | ||
> | ||
<Radio value="primary" label="primary" /> | ||
<Radio value="neutral" label="neutral" /> | ||
<Radio value="danger" label="danger" /> | ||
<Radio value="success" label="success" /> | ||
<Radio value="warning" label="warning" /> | ||
</RadioGroup> | ||
</FormControl> | ||
</Stack> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
docs/data/joy/components/toggle-button-group/ToggleGroupSizes.js
This file contains 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,20 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup'; | ||
|
||
export default function ToggleGroupSizes() { | ||
const [value, setValue] = React.useState('md'); | ||
return ( | ||
<ToggleButtonGroup | ||
size={value || undefined} | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="sm">Small</Button> | ||
<Button value="md">Medium</Button> | ||
<Button value="lg">Large</Button> | ||
</ToggleButtonGroup> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
docs/data/joy/components/toggle-button-group/ToggleGroupSizes.tsx
This file contains 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,24 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/joy/Button'; | ||
import ToggleButtonGroup, { | ||
ToggleButtonGroupStaticProps, | ||
} from '@mui/joy/ToggleButtonGroup'; | ||
|
||
export default function ToggleGroupSizes() { | ||
const [value, setValue] = React.useState< | ||
ToggleButtonGroupStaticProps['size'] | null | ||
>('md'); | ||
return ( | ||
<ToggleButtonGroup | ||
size={value || undefined} | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="sm">Small</Button> | ||
<Button value="md">Medium</Button> | ||
<Button value="lg">Large</Button> | ||
</ToggleButtonGroup> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
docs/data/joy/components/toggle-button-group/ToggleGroupSizes.tsx.preview
This file contains 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,11 @@ | ||
<ToggleButtonGroup | ||
size={value || undefined} | ||
value={value} | ||
onChange={(event, newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<Button value="sm">Small</Button> | ||
<Button value="md">Medium</Button> | ||
<Button value="lg">Large</Button> | ||
</ToggleButtonGroup> |
Oops, something went wrong.