Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import Rating from '@mui/material/Rating';
|
|
import Box from '@mui/material/Box';
|
|
import StarIcon from '@mui/icons-material/Star';
|
|
|
|
const labels: { [index: string]: string } = {
|
|
0.5: 'Useless',
|
|
1: 'Useless+',
|
|
1.5: 'Poor',
|
|
2: 'Poor+',
|
|
2.5: 'Ok',
|
|
3: 'Ok+',
|
|
3.5: 'Good',
|
|
4: 'Good+',
|
|
4.5: 'Excellent',
|
|
5: 'Excellent+',
|
|
};
|
|
|
|
function getLabelText(value: number) {
|
|
return `${value} Star${value !== 1 ? 's' : ''}, ${labels[value]}`;
|
|
}
|
|
|
|
export default function HoverRating() {
|
|
const [value, setValue] = React.useState<number | null>(2);
|
|
const [hover, setHover] = React.useState(-1);
|
|
|
|
return (
|
|
<Box sx={{ width: 200, display: 'flex', alignItems: 'center' }}>
|
|
<Rating
|
|
name="hover-feedback"
|
|
value={value}
|
|
precision={0.5}
|
|
getLabelText={getLabelText}
|
|
onChange={(event, newValue) => {
|
|
setValue(newValue);
|
|
}}
|
|
onChangeActive={(event, newHover) => {
|
|
setHover(newHover);
|
|
}}
|
|
emptyIcon={<StarIcon style={{ opacity: 0.55 }} fontSize="inherit" />}
|
|
/>
|
|
{value !== null && (
|
|
<Box sx={{ ml: 2 }}>{labels[hover !== -1 ? hover : value]}</Box>
|
|
)}
|
|
</Box>
|
|
);
|
|
}
|