Skip to content

Commit d5d9a23

Browse files
committed
feat: improve responsive chart
1 parent 7e0c308 commit d5d9a23

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

app/components/ChartModal.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<script setup lang="ts">
22
const open = defineModel<boolean>('open', { default: false })
33
4+
function close() {
5+
open.value = false
6+
}
7+
48
function handleKeydown(event: KeyboardEvent) {
59
if (event.key === 'Escape') {
6-
open.value = false
10+
close()
711
}
812
}
913
</script>
@@ -53,6 +57,8 @@ function handleKeydown(event: KeyboardEvent) {
5357
<slot />
5458
</div>
5559
</div>
60+
61+
<slot name="after" v-bind="{ close }" />
5662
</div>
5763
</div>
5864
</Transition>

app/components/PackageDownloadAnalytics.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,35 @@ const accent = computed(() => {
5050
return id ? (oklchToHex(accentColorValueById.value[id]!) ?? '#8A8A8A') : '#8A8A8A'
5151
})
5252
53+
const mobileBreakpointWidth = 640
54+
const isMobile = ref(false)
55+
56+
let resizeObserver: ResizeObserver | null = null
57+
58+
function updateIsMobileFromWidth(width: number) {
59+
isMobile.value = width < mobileBreakpointWidth
60+
}
61+
62+
onMounted(() => {
63+
if (!import.meta.client) return
64+
65+
updateIsMobileFromWidth(window.innerWidth)
66+
67+
resizeObserver = new ResizeObserver(entries => {
68+
const entry = entries[0]
69+
if (!entry) return
70+
updateIsMobileFromWidth(entry.contentRect.width)
71+
})
72+
73+
resizeObserver.observe(document.documentElement)
74+
})
75+
76+
onBeforeUnmount(() => {
77+
if (!resizeObserver) return
78+
resizeObserver.disconnect()
79+
resizeObserver = null
80+
})
81+
5382
type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly'
5483
type EvolutionData =
5584
| DailyDownloadPoint[]
@@ -417,6 +446,7 @@ const formatter = ({ value }: { value: number }) => formatCompactNumber(value, {
417446
const config = computed(() => ({
418447
theme: isDarkMode.value ? 'dark' : 'default',
419448
chart: {
449+
height: isMobile.value ? 850 : 600,
420450
userOptions: {
421451
buttons: {
422452
pdf: false,

app/components/PackageWeeklyDownloadStats.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ const config = computed(() => {
202202
:packageName="packageName"
203203
:createdIso="createdIso"
204204
/>
205+
206+
<template #after="{ close }">
207+
<div class="sm:hidden flex justify-center">
208+
<button
209+
type="button"
210+
@click="close"
211+
class="w-12 h-12 bg-bg-elevated border border-border rounded-full shadow-lg flex items-center justify-center text-fg-muted hover:text-fg transition-colors"
212+
:aria-label="$t('common.close')"
213+
>
214+
<span class="w-5 h-5 i-carbon-close" />
215+
</button>
216+
</div>
217+
</template>
205218
</ChartModal>
206219
</template>
207220

0 commit comments

Comments
 (0)