/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/data/material/components/rating/RadioGroupRating.js
59 строк
2 KB
Silviu Alexandru Avram
[accessibility] Make Slider and some docs examples visible in HighContrast Mode (#48320)
21 апр 2026, 15:38
Не верифицирован
21 апр 2026, 15:38
2dc145f
Код
Авторство
О чём код?
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.vars || theme).palette.action.disabled, }, })); const customIcons = { 1: { icon: <SentimentVeryDissatisfiedIcon color="error" />, label: 'Very Dissatisfied', }, 2: { icon: <SentimentDissatisfiedIcon color="error" />, label: 'Dissatisfied', }, 3: { icon: <SentimentSatisfiedIcon color="warning" />, label: 'Neutral', }, 4: { icon: <SentimentSatisfiedAltIcon color="success" />, label: 'Satisfied', }, 5: { icon: <SentimentVerySatisfiedIcon color="success" />, label: 'Very Satisfied', }, }; function IconContainer(props) { const { value, ...other } = props; return <span {...other}>{customIcons[value].icon}</span>; } IconContainer.propTypes = { value: PropTypes.number.isRequired, }; export default function RadioGroupRating() { return ( <StyledRating name="highlight-selected-only" defaultValue={2} getLabelText={(value) => customIcons[value].label} slotProps={{ icon: { component: IconContainer } }} highlightSelectedOnly /> ); }