1
- import { Skeleton } from '@mui/material' ;
2
- import React from 'react' ;
1
+ import { Skeleton , ToggleButton , ToggleButtonGroup } from '@mui/material' ;
2
+ import React , { useState } from 'react' ;
3
3
4
4
import BarGraph from '@/components/graph/BarGraph/barGraph' ;
5
5
import LineGraph from '@/components/graph/LineGraph/lineGraph' ;
@@ -42,6 +42,16 @@ type Props = {
42
42
} ;
43
43
44
44
function SingleGradesInfo ( { title, course, grades } : Props ) {
45
+ const [ chartType , setChartType ] = useState < 'line' | 'bar' > ( 'line' ) ;
46
+
47
+ const handleChartToggle = (
48
+ event : React . MouseEvent < HTMLElement > ,
49
+ newChartType : 'line' | 'bar'
50
+ ) => {
51
+ if ( newChartType !== null ) {
52
+ setChartType ( newChartType ) ;
53
+ }
54
+ } ;
45
55
if ( typeof grades === 'undefined' || grades . state === 'error' ) return null ;
46
56
if ( grades . state === 'loading' ) {
47
57
return (
@@ -59,6 +69,26 @@ function SingleGradesInfo({ title, course, grades }: Props) {
59
69
const gpaValues = [ 4 , 4 , 3.67 , 3.33 , 3 , 2.67 , 2.33 , 2 , 1.67 , 1.33 , 1 , 0.67 , 0 ] ;
60
70
61
71
return (
72
+
73
+ < div >
74
+ { /* Toggle Button to switch chart type */ }
75
+ < div className = "flex justify-end mb-4 pr-2" >
76
+ < ToggleButtonGroup
77
+ value = { chartType }
78
+ exclusive
79
+ onChange = { handleChartToggle }
80
+ size = "small"
81
+ orientation = "vertical"
82
+ aria-label = "chart type" >
83
+
84
+ < ToggleButton value = "line" aria-label = "line chart" >
85
+ Line
86
+ </ ToggleButton >
87
+ < ToggleButton value = "bar" aria-label = "bar chart" >
88
+ Bar
89
+ </ ToggleButton >
90
+ </ ToggleButtonGroup >
91
+ </ div >
62
92
< div className = "p-2" >
63
93
< div className = "h-64" >
64
94
< BarGraph
@@ -83,7 +113,9 @@ function SingleGradesInfo({ title, course, grades }: Props) {
83
113
/>
84
114
</ div >
85
115
</ div >
116
+ </ div >
86
117
) ;
87
118
}
88
119
120
+
89
121
export default SingleGradesInfo ;
0 commit comments