Skip to content
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

[Radio][Joy] support componentsProps as a function #34022

Merged
merged 7 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/data/joy/components/radio/ExampleAlignmentButtons.js
Expand Up @@ -56,10 +56,10 @@ export default function RadioButtonsGroup() {
variant={alignment === item ? 'solid' : 'plain'}
componentsProps={{
input: { 'aria-label': item },
}}
sx={{
[`& .${radioClasses.action}`]: { borderRadius: 0, transition: 'none' },
[`& .${radioClasses.label}`]: { lineHeight: 0 },
action: {
sx: { borderRadius: 0, transition: 'none' },
},
label: { sx: { lineHeight: 0 } },
}}
/>
</Box>
Expand Down
14 changes: 9 additions & 5 deletions docs/data/joy/components/radio/ExampleProductAttributes.js
Expand Up @@ -48,15 +48,19 @@ export default function ExampleProductAttributes() {
color={color}
checkedIcon={<Done fontSize="xl2" />}
value={color}
componentsProps={{ input: { 'aria-label': color } }}
componentsProps={{
input: { 'aria-label': color },
radio: {
sx: {
display: 'contents',
'--variant-borderWidth': '2px',
},
},
}}
sx={{
'--joy-focus-outlineOffset': '4px',
'--joy-palette-focusVisible': (theme) =>
theme.vars.palette[color][500],
[`& .${radioClasses.radio}`]: {
display: 'contents',
'--variant-borderWidth': '2px',
},
[`& .${radioClasses.action}.${radioClasses.focusVisible}`]: {
outlineWidth: '2px',
},
Expand Down
58 changes: 58 additions & 0 deletions docs/data/joy/components/radio/ExampleSegmentedControls.js
@@ -0,0 +1,58 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Typography from '@mui/joy/Typography';

export default function RadioButtonsGroup() {
const [justify, setJustify] = React.useState('flex-start');
return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Typography id="segmented-controls-example" fontWeight="lg" fontSize="sm">
Justify:
</Typography>
<RadioGroup
row
aria-labelledby="segmented-controls-example"
name="justify"
value={justify}
onChange={(event) => setJustify(event.target.value)}
sx={{
minHeight: 48,
padding: '4px',
borderRadius: 'md',
bgcolor: 'neutral.softBg',
'--RadioGroup-gap': '4px',
'--Radio-action-radius': '8px',
}}
>
{['flex-start', 'center', 'flex-end'].map((item) => (
<Radio
color="neutral"
value={item}
disableIcon
label={item}
variant="plain"
sx={{
px: 2,
alignItems: 'center',
}}
componentsProps={{
action: ({ checked }) => ({
sx: {
...(checked && {
bgcolor: 'background.surface',
boxShadow: 'md',
'&:hover': {
bgcolor: 'background.surface',
},
}),
},
}),
}}
/>
))}
</RadioGroup>
</Box>
);
}
37 changes: 20 additions & 17 deletions docs/data/joy/components/radio/IconlessRadio.js
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import FormLabel from '@mui/joy/FormLabel';
import Radio, { radioClasses } from '@mui/joy/Radio';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';

Expand Down Expand Up @@ -33,23 +33,26 @@ export default function IconlessRadio() {
overlay
disableIcon
value={value}
sx={(theme) => ({
'& label': {
fontWeight: 'lg',
fontSize: 'md',
color: 'text.secondary',
},
[`&.${radioClasses.checked}`]: {
'& label': { color: 'text.primary' },
'--joy-palette-primary-outlinedBorder':
theme.vars.palette.primary[500],
'--joy-palette-primary-outlinedHoverBorder':
theme.vars.palette.primary[500],
[`& .${radioClasses.action}`]: {
'--variant-borderWidth': '2px',
componentsProps={{
label: ({ checked }) => ({
sx: {
fontWeight: 'lg',
fontSize: 'md',
color: checked ? 'text.primary' : 'text.secondary',
},
},
})}
}),
action: ({ checked }) => ({
sx: (theme) => ({
...(checked && {
'--variant-borderWidth': '2px',
'&&': {
// && to increase the specificity to win the base :hover styles
borderColor: theme.vars.palette.primary[500],
},
}),
}),
}),
}}
/>
</Sheet>
))}
Expand Down
61 changes: 28 additions & 33 deletions docs/data/joy/components/radio/RadioPositionEnd.js
Expand Up @@ -2,53 +2,48 @@ import * as React from 'react';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Radio, { radioClasses } from '@mui/joy/Radio';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Person from '@mui/icons-material/Person';
import People from '@mui/icons-material/People';
import Apartment from '@mui/icons-material/Apartment';

export default function RadioPositionEnd() {
return (
<RadioGroup name="people" overlay defaultValue="person">
<RadioGroup name="people" defaultValue="Individual">
<List
sx={(theme) => ({
sx={{
minWidth: 240,
'--List-gap': '0.5rem',
'--List-item-paddingY': '1rem',
'--List-item-radius': '8px',
'--List-decorator-size': '32px',
[`& .${radioClasses.root}`]: {
flexGrow: 1,
flexDirection: 'row-reverse',
[`&.${radioClasses.checked}`]: {
[`& .${radioClasses.action}`]: {
inset: -1,
border: '2px solid',
borderColor: theme.vars.palette.primary[500],
},
},
},
})}
}}
>
<ListItem variant="outlined">
<ListItemDecorator>
<Person />
</ListItemDecorator>
<Radio value="person" label="Individual" />
</ListItem>
<ListItem variant="outlined">
<ListItemDecorator>
<People />
</ListItemDecorator>
<Radio value="team" label="Team" />
</ListItem>
<ListItem variant="outlined">
<ListItemDecorator>
<Apartment />
</ListItemDecorator>
<Radio value="interprise" label="Interprise" />
</ListItem>
{['Individual', 'Team', 'Interprise'].map((item, index) => (
<ListItem variant="outlined" key={item}>
<ListItemDecorator>
{[<Person />, <People />, <Apartment />][index]}
</ListItemDecorator>
<Radio
overlay
value={item}
label={item}
sx={{ flexGrow: 1, flexDirection: 'row-reverse' }}
componentsProps={{
action: ({ checked }) => ({
sx: (theme) => ({
...(checked && {
inset: -1,
border: '2px solid',
borderColor: theme.vars.palette.primary[500],
}),
}),
}),
}}
/>
</ListItem>
))}
</List>
</RadioGroup>
);
Expand Down
6 changes: 5 additions & 1 deletion docs/data/joy/components/radio/radio.md
Expand Up @@ -117,9 +117,13 @@ Visit the [WAI-ARIA documentation](https://www.w3.org/WAI/ARIA/apg/patterns/radi

## Common examples

### Segmented controls

{{"demo": "ExampleSegmentedControls.js"}}

### Alignment buttons

Simply provide an icon as a label to the `Radio` to make the radio buttons concise. You need to provide `aria-label` to the input slot for users who rely on screen readers.
Provide an icon as a label to the `Radio` to make the radio buttons concise. You need to provide `aria-label` to the input slot for users who rely on screen readers.

{{"demo": "ExampleAlignmentButtons.js"}}

Expand Down