11import clsx from 'clsx' ;
2+ import './contribution-graph.css' ;
23
34interface Props {
45 caption ?: string ;
@@ -25,7 +26,7 @@ export function ContributionGraph(props: Props) {
2526 ] ) ;
2627 return memo ;
2728 } , [ ] as Array < [ number , boolean ] > ) ;
28- const max = Math . max ( ...totals . map ( ( [ t ] ) => t ) ) ;
29+ const max = Math . max ( ...totals . map ( ( [ t ] ) => t ) , 6 ) ;
2930
3031 const months = props . contributions [ 0 ] ! . reduce ( ( memo , [ day ] ) => {
3132 if ( day . getMonth ( ) === memo [ memo . length - 1 ] ?. date . getMonth ( ) ) {
@@ -37,17 +38,17 @@ export function ContributionGraph(props: Props) {
3738 } , [ ] as Array < { colSpan : number ; date : Date } > ) ;
3839
3940 return (
40- < div class = "not-prose overflow-scroll text-[10px] leading-none" >
41- < table class = "mb-4 min-w-min max-w-full border-separate border-spacing-[2px]" >
42- { props . caption ? < caption class = "text-black dark:text-white" > { props . caption } </ caption > : null }
41+ < div class = "contribution-graph not-prose overflow-scroll text-[10px] leading-none" >
42+ < table >
43+ { props . caption ? < caption > { props . caption } </ caption > : null }
4344 < thead >
4445 < tr >
4546 < th > </ th >
4647 { months . map ( ( { colSpan, date } ) =>
4748 colSpan < 3 ? (
4849 < th colSpan = { colSpan } />
4950 ) : (
50- < th role = "columnheader" class = "text-left text-gray-600 dark:text-gray-400" colSpan = { colSpan } >
51+ < th role = "columnheader" colSpan = { colSpan } >
5152 < span aria-hidden > { monthFormat ( date ) } </ span >
5253 < span class = "sr-only" > { monthFormatFull ( date ) } </ span >
5354 </ th >
@@ -59,7 +60,7 @@ export function ContributionGraph(props: Props) {
5960 { props . contributions . map ( ( dayOfWeek , w ) => {
6061 return (
6162 < tr >
62- < th role = "rowheader" class = "h-2 w-6 overflow-hidden p-0 pe-1 text-end text-gray-600 dark:text-gray-400" >
63+ < th role = "rowheader" >
6364 { ! ( w % 2 ) || w === 7 ? null : (
6465 < >
6566 < span class = "sr-only" > { dayFullFormat ( dayOfWeek [ 0 ] ! [ 0 ] ) } </ span >
@@ -70,10 +71,7 @@ export function ContributionGraph(props: Props) {
7071 { dayOfWeek . map ( ( [ day , contributions , inRange ] ) => {
7172 const title = `${ contributions } contributions on ${ formatter ( day ) } ` ;
7273 return (
73- < td
74- class = { clsx ( 'h-2 w-2 rounded-[0.5px] sm:h-3 sm:w-3' , opacity [ contributions ] , getColor ( inRange ) ) }
75- title = { title }
76- >
74+ < td class = { clsx ( 'day' , opacity [ contributions ] , getColor ( inRange ) ) } title = { title } >
7775 < div class = "h-2 w-2" />
7876 < span class = "sr-only" > { title } </ span >
7977 </ td >
@@ -84,36 +82,31 @@ export function ContributionGraph(props: Props) {
8482 } ) }
8583 </ tbody >
8684 </ table >
87- < table class = "mb-4 min-w-min max-w-full border-separate border-spacing-[2px]" >
88- < caption class = "text-black dark:text-white" > Number of contributions by week</ caption >
85+ < table >
86+ < caption > Number of contributions by week</ caption >
8987 < tr role = "presentation" >
90- < td class = "w-6 overflow-hidden p-0 pe-1 " />
88+ < th role = "rowheader " />
9189 { totals . map ( ( [ value , inRange ] ) => {
9290 return (
93- < td class = "w-2 rounded-[0.5px] p-0 sm:w-3 " >
94- < div class = "flex h-20 flex-col justify-end " >
91+ < td class = "total-bar-cell " >
92+ < div class = "total-bar-container " >
9593 < div
9694 style = { { 'flex-basis' : `${ Math . ceil ( ( value / max ) * 100 ) } %` } }
97- class = { clsx (
98- 'w-2 shrink rounded-sm sm:w-3' ,
99- opacity [ Math . floor ( ( value / max ) * 10 ) ] ,
100- getColor ( inRange )
101- ) }
95+ class = { clsx ( 'total-bar' , opacity [ Math . floor ( ( value / max ) * 10 ) ] , getColor ( inRange ) ) }
10296 />
10397 </ div >
10498 </ td >
10599 ) ;
106100 } ) }
107101 </ tr >
108102 < tr >
109- < td class = "w-6 overflow-hidden pe-1" >
103+ < th role = "rowheader" >
104+ < span aria-hidden > Tot.</ span >
110105 < span class = "sr-only" > Total</ span >
111- </ td >
106+ </ th >
112107 { totals . map ( ( value ) => (
113- < td class = "p-0" >
114- < span class = "h-4 shrink-0 text-[9px] leading-none text-black writing-vertical-lr dark:text-white" >
115- { value }
116- </ span >
108+ < td class = "total-bar-cell" >
109+ < span class = "total" > { value } </ span >
117110 </ td >
118111 ) ) }
119112 </ tr >
@@ -127,7 +120,7 @@ function weekInRange(week: number, range: [number, number] = [-1, 1000]) {
127120}
128121
129122function getColor ( inRange : boolean ) {
130- return inRange ? 'bg-teal-500 p-0 dark:bg-teal-300 ' : 'bg-slate-300 p-0 dark:bg-slate-700 ' ;
123+ return inRange ? 'in-range ' : '' ;
131124}
132125function randomInt ( min : number , max : number ) {
133126 return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
0 commit comments