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

[docs] Improvements for Radio Group Rating Docs #32843

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 14 additions & 6 deletions docs/data/material/components/rating/RadioGroupRating.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Rating from '@mui/material/Rating';
import SentimentVeryDissatisfiedIcon from '@mui/icons-material/SentimentVeryDissatisfied';
import SentimentDissatisfiedIcon from '@mui/icons-material/SentimentDissatisfied';
import SentimentSatisfiedIcon from '@mui/icons-material/SentimentSatisfied';
import SentimentSatisfiedAltIcon from '@mui/icons-material/SentimentSatisfiedAltOutlined';
import SentimentVerySatisfiedIcon from '@mui/icons-material/SentimentVerySatisfied';

const StyledRating = styled(Rating)(({ theme }) => ({
'& .MuiRating-iconEmpty .MuiSvgIcon-root': {
color: theme.palette.action.disabled,
},
}));

const customIcons = {
1: {
icon: <SentimentVeryDissatisfiedIcon />,
icon: <SentimentVeryDissatisfiedIcon color="error" />,
label: 'Very Dissatisfied',
},
2: {
icon: <SentimentDissatisfiedIcon />,
icon: <SentimentDissatisfiedIcon color="error" />,
label: 'Dissatisfied',
},
3: {
icon: <SentimentSatisfiedIcon />,
icon: <SentimentSatisfiedIcon color="primary" />,
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
label: 'Neutral',
},
4: {
icon: <SentimentSatisfiedAltIcon />,
icon: <SentimentSatisfiedAltIcon color="success" />,
label: 'Satisfied',
},
5: {
icon: <SentimentVerySatisfiedIcon />,
icon: <SentimentVerySatisfiedIcon color="success" />,
label: 'Very Satisfied',
},
};
Expand All @@ -41,10 +48,11 @@ IconContainer.propTypes = {

export default function RadioGroupRating() {
return (
<Rating
<StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value) => customIcons[value].label}
highlightSelectedOnly
/>
);
Expand Down
20 changes: 14 additions & 6 deletions docs/data/material/components/rating/RadioGroupRating.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Rating, { IconContainerProps } from '@mui/material/Rating';
import SentimentVeryDissatisfiedIcon from '@mui/icons-material/SentimentVeryDissatisfied';
import SentimentDissatisfiedIcon from '@mui/icons-material/SentimentDissatisfied';
import SentimentSatisfiedIcon from '@mui/icons-material/SentimentSatisfied';
import SentimentSatisfiedAltIcon from '@mui/icons-material/SentimentSatisfiedAltOutlined';
import SentimentVerySatisfiedIcon from '@mui/icons-material/SentimentVerySatisfied';

const StyledRating = styled(Rating)(({ theme }) => ({
'& .MuiRating-iconEmpty .MuiSvgIcon-root': {
color: theme.palette.action.disabled,
},
}));

const customIcons: {
[index: string]: {
icon: React.ReactElement;
label: string;
};
} = {
1: {
icon: <SentimentVeryDissatisfiedIcon />,
icon: <SentimentVeryDissatisfiedIcon color="error" />,
label: 'Very Dissatisfied',
},
2: {
icon: <SentimentDissatisfiedIcon />,
icon: <SentimentDissatisfiedIcon color="error" />,
label: 'Dissatisfied',
},
3: {
icon: <SentimentSatisfiedIcon />,
icon: <SentimentSatisfiedIcon color="primary" />,
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
label: 'Neutral',
},
4: {
icon: <SentimentSatisfiedAltIcon />,
icon: <SentimentSatisfiedAltIcon color="success" />,
label: 'Satisfied',
},
5: {
icon: <SentimentVerySatisfiedIcon />,
icon: <SentimentVerySatisfiedIcon color="success" />,
label: 'Very Satisfied',
},
};
Expand All @@ -41,10 +48,11 @@ function IconContainer(props: IconContainerProps) {

export default function RadioGroupRating() {
return (
<Rating
<StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value: number) => customIcons[value].label}
highlightSelectedOnly
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Rating
<StyledRating
name="highlight-selected-only"
defaultValue={2}
IconContainerComponent={IconContainer}
getLabelText={(value: number) => customIcons[value].label}
highlightSelectedOnly
/>