|
| 1 | +import { useState } from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { color } from '../../Components/constants.json'; |
| 4 | + |
| 5 | +type MasteryBarProps = { percentage: number }; |
| 6 | + |
| 7 | +const MasteryBar = styled.div` |
| 8 | + position: relative; |
| 9 | + border-radius: 11px; |
| 10 | + background-color: ${color.bgGrey}; |
| 11 | + overflow: hidden; |
| 12 | +`; |
| 13 | + |
| 14 | +const InnerBar = styled.div<MasteryBarProps>` |
| 15 | + position: absolute; |
| 16 | + top: 0; |
| 17 | + left: 0; |
| 18 | + bottom: 0; |
| 19 | + background-color: ${({ percentage }) => |
| 20 | + percentage > 0.66 ? color.green : percentage > 0.33 ? color.yellow : color.red}; |
| 21 | + right: ${({ percentage }) => 100 - percentage * 100 + '%'}; |
| 22 | + > span { |
| 23 | + position: absolute; |
| 24 | + color: white; |
| 25 | + top: 4px; |
| 26 | + font-size: 14px; |
| 27 | + right: ${({ percentage }) => (percentage > 0.25 ? '5px' : '-33px')}; |
| 28 | + } |
| 29 | +`; |
| 30 | + |
| 31 | +function Mastery({ percentage }: MasteryBarProps) { |
| 32 | + return ( |
| 33 | + <MasteryBar> |
| 34 | + <InnerBar percentage={percentage}> |
| 35 | + <span>{Math.floor(percentage * 100)}%</span> |
| 36 | + </InnerBar> |
| 37 | + </MasteryBar> |
| 38 | + ); |
| 39 | +} |
| 40 | + |
| 41 | +const Container = styled.div` |
| 42 | + display: flex; |
| 43 | + align-items: center; |
| 44 | + width: 100%; |
| 45 | + margin-bottom: 6px; |
| 46 | +`; |
| 47 | + |
| 48 | +const Header = styled.div` |
| 49 | + display: flex; |
| 50 | + align-items: center; |
| 51 | + color: black; |
| 52 | + font-size: 16px; |
| 53 | + font-weight: 700; |
| 54 | + min-width: 150px; |
| 55 | + margin-right: 16px; |
| 56 | +`; |
| 57 | + |
| 58 | +const Dot = styled.div` |
| 59 | + background-color: ${color.green}; |
| 60 | + border-radius: 999px; |
| 61 | + width: 8px; |
| 62 | + height: 8px; |
| 63 | + margin-right: 6px; |
| 64 | +`; |
| 65 | + |
| 66 | +const Content = styled.div` |
| 67 | + display: flex; |
| 68 | + align-items: center; |
| 69 | + overflow: horizontal; |
| 70 | + > :not(last-child) { |
| 71 | + margin-right: 21px; |
| 72 | + height: 32px; |
| 73 | + min-width: 100px; |
| 74 | + } |
| 75 | +`; |
| 76 | + |
| 77 | +function StudentMasteryRow({ name, learningObjectives }: any) { |
| 78 | + return ( |
| 79 | + <Container> |
| 80 | + <Header> |
| 81 | + <Dot /> |
| 82 | + {name} |
| 83 | + </Header> |
| 84 | + <Content> |
| 85 | + {learningObjectives.map(({ percentage }: any) => ( |
| 86 | + <Mastery percentage={percentage} /> |
| 87 | + ))} |
| 88 | + </Content> |
| 89 | + </Container> |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +const LearningObjectiveName = styled.span` |
| 94 | + text-align: center; |
| 95 | +`; |
| 96 | + |
| 97 | +function StudentMasteryHeader({ learningObjectiveNames }: { learningObjectiveNames: string[] }) { |
| 98 | + return ( |
| 99 | + <Container style={{ marginBottom: 24 }}> |
| 100 | + <Header>Student</Header> |
| 101 | + <Content> |
| 102 | + {learningObjectiveNames.map((name) => ( |
| 103 | + <LearningObjectiveName>{name}</LearningObjectiveName> |
| 104 | + ))} |
| 105 | + </Content> |
| 106 | + </Container> |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +export default StudentMasteryRow; |
| 111 | +export { StudentMasteryHeader }; |
0 commit comments