forked from openedx/frontend-app-learning
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassingGradeTooltip.jsx
More file actions
59 lines (49 loc) · 1.69 KB
/
Copy pathPassingGradeTooltip.jsx
File metadata and controls
59 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import PropTypes from 'prop-types';
import { getLocale, isRtl, useIntl } from '@edx/frontend-platform/i18n';
import { OverlayTrigger, Popover } from '@openedx/paragon';
import messages from '../messages';
const PassingGradeTooltip = ({ passingGrade, tooltipClassName }) => {
const intl = useIntl();
const isLocaleRtl = isRtl(getLocale());
let passingGradeDirection = passingGrade < 50 ? '' : '-';
if (isLocaleRtl) {
passingGradeDirection = passingGrade < 50 ? '-' : '';
}
return (
<>
<OverlayTrigger
show
placement="bottom"
overlay={(
<Popover id="minimum-grade-tooltip" className={`bg-primary-500 ${tooltipClassName}`} aria-hidden="true">
<Popover.Content>
{passingGrade}{isLocaleRtl && '\u200f'}%
</Popover.Content>
</Popover>
)}
>
<g>
<circle cx={`${isLocaleRtl ? 100 - passingGrade : passingGrade}%`} cy="50%" r="8.5" fill="transparent" />
<circle className="grade-bar--passing" cx={`${isLocaleRtl ? 100 - passingGrade : passingGrade}%`} cy="50%" r="4.5" />
</g>
</OverlayTrigger>
<text
className="x-small"
textAnchor={passingGrade < 50 ? 'start' : 'end'}
x={`${isLocaleRtl ? 100 - passingGrade : passingGrade}%`}
y="90px"
style={{ transform: `translateX(${passingGradeDirection}3.4em)` }}
>
{intl.formatMessage(messages.passingGradeLabel)}
</text>
</>
);
};
PassingGradeTooltip.defaultProps = {
tooltipClassName: '',
};
PassingGradeTooltip.propTypes = {
passingGrade: PropTypes.number.isRequired,
tooltipClassName: PropTypes.string,
};
export default PassingGradeTooltip;