From 7578beb271f1afe6265d6ca503d1adeacd1794c3 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Sun, 8 Jun 2025 15:47:25 +0200 Subject: [PATCH] fix css variables not updating correctly when system theme changes --- .../Common/Reporting/ReportingChart.vue | 16 ++++-- .../Common/Reporting/ReportingPieChart.vue | 4 +- .../Dashboard/ActivityGraphCard.vue | 13 ++--- .../Dashboard/DayOverviewCardChart.vue | 15 +++--- .../Dashboard/ProjectsChartCard.vue | 4 +- .../Components/Dashboard/ThisWeekOverview.vue | 14 +++--- resources/js/utils/theme.ts | 7 --- resources/js/utils/useCssVariable.ts | 49 +++++++++++++++++++ 8 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 resources/js/utils/useCssVariable.ts diff --git a/resources/js/Components/Common/Reporting/ReportingChart.vue b/resources/js/Components/Common/Reporting/ReportingChart.vue index 14ef04b8..db2b6563 100644 --- a/resources/js/Components/Common/Reporting/ReportingChart.vue +++ b/resources/js/Components/Common/Reporting/ReportingChart.vue @@ -17,7 +17,7 @@ import { TooltipComponent, } from 'echarts/components'; import type { AggregatedTimeEntries, Organization } from '@/packages/api/src'; -import { useCssVar } from '@vueuse/core'; +import { useCssVariable } from '@/utils/useCssVariable'; use([ CanvasRenderer, @@ -47,8 +47,10 @@ const xAxisLabels = computed(() => { formatDate(el.key ?? '', organization?.value?.date_format) ); }); -const accentColor = useCssVar('--theme-color-chart', null, { observe: true }); -const labelColor = useCssVar('--color-text-secondary', null, { observe: true }); +const accentColor = useCssVariable('--theme-color-chart'); +const labelColor = useCssVariable('--color-text-secondary'); +const markLineColor = useCssVariable('--color-border-secondary'); +const splitLineColor = useCssVariable('--color-border-tertiary'); const seriesData = computed(() => { return props?.groupedData?.map((el) => { @@ -111,7 +113,7 @@ const option = computed(() => ({ data: xAxisLabels.value, markLine: { lineStyle: { - color: 'rgba(125,156,188,0.1)', + color: markLineColor.value, type: 'dashed', }, }, @@ -135,9 +137,13 @@ const option = computed(() => ({ }, yAxis: { type: 'value', + axisLabel: { + color: labelColor.value, + fontFamily: 'Outfit, sans-serif', + }, splitLine: { lineStyle: { - color: 'rgba(125,156,188,0.2)', // Set desired color here + color: splitLineColor.value, }, }, }, diff --git a/resources/js/Components/Common/Reporting/ReportingPieChart.vue b/resources/js/Components/Common/Reporting/ReportingPieChart.vue index 63994c12..88ba8c56 100644 --- a/resources/js/Components/Common/Reporting/ReportingPieChart.vue +++ b/resources/js/Components/Common/Reporting/ReportingPieChart.vue @@ -11,7 +11,7 @@ import { TooltipComponent, } from 'echarts/components'; import { formatHumanReadableDuration } from '@/packages/ui/src/utils/time'; -import { useCssVar } from '@vueuse/core'; +import { useCssVariable } from '@/utils/useCssVariable'; import type { Organization } from '@/packages/api/src'; use([ @@ -36,7 +36,7 @@ type ReportingChartDataEntry = { const props = defineProps<{ data: ReportingChartDataEntry | null; }>(); -const labelColor = useCssVar('--color-text-secondary', null, { observe: true }); +const labelColor = useCssVariable('--color-text-secondary'); const seriesData = computed(() => { return props.data?.map((el) => { diff --git a/resources/js/Components/Dashboard/ActivityGraphCard.vue b/resources/js/Components/Dashboard/ActivityGraphCard.vue index 30ac01fd..d80a4d82 100644 --- a/resources/js/Components/Dashboard/ActivityGraphCard.vue +++ b/resources/js/Components/Dashboard/ActivityGraphCard.vue @@ -19,7 +19,7 @@ import { formatHumanReadableDuration, getDayJsInstance, } from '@/packages/ui/src/utils/time'; -import { useCssVar } from '@vueuse/core'; +import { useCssVariable } from '@/utils/useCssVariable'; import { useQuery } from '@tanstack/vue-query'; import { getCurrentOrganizationId } from '@/utils/useUser'; import { api, type Organization } from '@/packages/api/src'; @@ -64,12 +64,9 @@ const max = computed(() => { } }); -const backgroundColor = useCssVar('--color-card-background', null, { - observe: true, -}); -const itemBackgroundColor = useCssVar('--color-bg-tertiary', null, { - observe: true, -}); +const backgroundColor = useCssVariable('--theme-color-card-background'); +const itemBackgroundColor = useCssVariable('--color-bg-tertiary'); +const borderColor = useCssVariable('--color-border'); const option = computed(() => { return { @@ -120,7 +117,7 @@ const option = computed(() => { [], itemStyle: { borderRadius: 5, - borderColor: 'rgba(255,255,255,0.05)', + borderColor: borderColor.value, borderWidth: 1, }, tooltip: { diff --git a/resources/js/Components/Dashboard/DayOverviewCardChart.vue b/resources/js/Components/Dashboard/DayOverviewCardChart.vue index 0de64a41..5eefac6f 100644 --- a/resources/js/Components/Dashboard/DayOverviewCardChart.vue +++ b/resources/js/Components/Dashboard/DayOverviewCardChart.vue @@ -1,13 +1,14 @@