@@ -158,9 +158,24 @@ export function GraphSection() {
158158 model : null as string | null ,
159159 modelDropdownOpen : false ,
160160 keyDropdownOpen : false ,
161+ colorScheme : "light" as "light" | "dark" ,
161162 } )
162163 const initialData = createAsync ( ( ) => queryCosts ( params . id ! , store . year , store . month ) )
163164
165+ createEffect ( ( ) => {
166+ if ( typeof window === "undefined" ) return
167+
168+ const mediaQuery = window . matchMedia ( "(prefers-color-scheme: dark)" )
169+ setStore ( { colorScheme : mediaQuery . matches ? "dark" : "light" } )
170+
171+ const handleColorSchemeChange = ( e : MediaQueryListEvent ) => {
172+ setStore ( { colorScheme : e . matches ? "dark" : "light" } )
173+ }
174+
175+ mediaQuery . addEventListener ( "change" , handleColorSchemeChange )
176+ onCleanup ( ( ) => mediaQuery . removeEventListener ( "change" , handleColorSchemeChange ) )
177+ } )
178+
164179 const onPreviousMonth = async ( ) => {
165180 const month = store . month === 0 ? 11 : store . month - 1
166181 const year = store . month === 0 ? store . year - 1 : store . year
@@ -210,6 +225,15 @@ export function GraphSection() {
210225 const dates = getDates ( )
211226 if ( ! data ?. usage ?. length ) return null
212227
228+ store . colorScheme
229+ const styles = getComputedStyle ( document . documentElement )
230+ const colorTextMuted = styles . getPropertyValue ( "--color-text-muted" ) . trim ( )
231+ const colorBorderMuted = styles . getPropertyValue ( "--color-border-muted" ) . trim ( )
232+ const colorBgElevated = styles . getPropertyValue ( "--color-bg-elevated" ) . trim ( )
233+ const colorText = styles . getPropertyValue ( "--color-text" ) . trim ( )
234+ const colorTextSecondary = styles . getPropertyValue ( "--color-text-secondary" ) . trim ( )
235+ const colorBorder = styles . getPropertyValue ( "--color-border" ) . trim ( )
236+
213237 const dailyData = new Map < string , Map < string , number > > ( )
214238 for ( const dateKey of dates ) dailyData . set ( dateKey , new Map ( ) )
215239
@@ -252,7 +276,7 @@ export function GraphSection() {
252276 ticks : {
253277 maxRotation : 0 ,
254278 autoSkipPadding : 20 ,
255- color : "rgba(255, 255, 255, 0.5)" ,
279+ color : colorTextMuted ,
256280 font : {
257281 family : "monospace" ,
258282 size : 11 ,
@@ -263,10 +287,10 @@ export function GraphSection() {
263287 stacked : true ,
264288 beginAtZero : true ,
265289 grid : {
266- color : "rgba(255, 255, 255, 0.1)" ,
290+ color : colorBorderMuted ,
267291 } ,
268292 ticks : {
269- color : "rgba(255, 255, 255, 0.5)" ,
293+ color : colorTextMuted ,
270294 font : {
271295 family : "monospace" ,
272296 size : 11 ,
@@ -282,10 +306,10 @@ export function GraphSection() {
282306 tooltip : {
283307 mode : "index" ,
284308 intersect : false ,
285- backgroundColor : "rgba(0, 0, 0, 0.9)" ,
286- titleColor : "rgba(255, 255, 255, 0.9)" ,
287- bodyColor : "rgba(255, 255, 255, 0.8)" ,
288- borderColor : "rgba(255, 255, 255, 0.1)" ,
309+ backgroundColor : colorBgElevated ,
310+ titleColor : colorText ,
311+ bodyColor : colorTextSecondary ,
312+ borderColor : colorBorder ,
289313 borderWidth : 1 ,
290314 padding : 12 ,
291315 displayColors : true ,
@@ -301,7 +325,7 @@ export function GraphSection() {
301325 display : true ,
302326 position : "bottom" ,
303327 labels : {
304- color : "rgba(255, 255, 255, 0.7)" ,
328+ color : colorTextSecondary ,
305329 font : {
306330 size : 12 ,
307331 } ,
0 commit comments