Skip to content

Commit 3028b53

Browse files
committed
🧬 refactor: extract themePreview
1 parent 5b0f1dd commit 3028b53

File tree

5 files changed

+243
-38
lines changed

5 files changed

+243
-38
lines changed

‎src/components/RepoCard/index.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
</div>
2626
</CardBlock>
2727

28+
<ThemePreview v-model:theme="selectedTheme" category="repo" />
29+
2830
<MdPreview :apiUrl="assembledApi" />
2931

3032
<div class="flex items-center justify-center">
@@ -51,10 +53,12 @@ import icRoundDashboardCustomize from '~icons/ic/round-dashboard-customize'
5153
import { useThrottleFn } from '@vueuse/core'
5254
import CardBlock from '../cardBlock.vue'
5355
import MdPreview from '../mdPreview.vue'
56+
import ThemePreview from '../themePreview.vue'
5457
5558
const username = inject('username', '') as any
5659
const repoName = ref('')
5760
const shouldShowOwner = ref(false)
61+
const selectedTheme = ref('default_repocard')
5862
5963
const allQueries = computed(() => {
6064
let str: string[] = [`username=${username.value}`, `repo=${repoName.value}`]
@@ -63,6 +67,8 @@ const allQueries = computed(() => {
6367
str.push('show_owner=true')
6468
}
6569
70+
if (selectedTheme.value !== 'default_repocard') str.push(`theme=${selectedTheme.value}`)
71+
6672
return str.join('&')
6773
})
6874

‎src/components/StatsCard/index.vue

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,7 @@
4848
</div>
4949
</CardBlock>
5050

51-
<CardBlock title="Theme" class="field--theme">
52-
<template #icon>
53-
<mdiThemeLightDark class="mr-2 text-[#F19F19]" />
54-
</template>
55-
<div class="mb-2">
56-
<label class="cursor-pointer text-gray-600 inline-flex items-center">
57-
<select v-model="selectedTheme" class="px-2 py-1">
58-
<option v-for="theme in themeOptions" :value="theme">{{ theme.name }}</option>
59-
</select>
60-
</label>
61-
</div>
62-
<figure class="m-0 my-2">
63-
<img
64-
:src="getPreviewImg(selectedTheme.value)"
65-
class="max-w-[400px] w-full"
66-
alt="theme-preview">
67-
</figure>
68-
<a href="https://github.com/anuraghazra/github-readme-stats/blob/master/themes/README.md" class="text-xs text-gray-400" target="_blank">
69-
<i>- theme preview (github-readme-stats/themes/README.md)</i>
70-
</a>
71-
</CardBlock>
72-
73-
<!-- ^^^ manipulator ^^^ -->
51+
<ThemePreview v-model:theme="selectedTheme" category="stats" />
7452

7553
<MdPreview :apiUrl="assembledApi" />
7654

@@ -91,16 +69,15 @@
9169
</template>
9270

9371
<script lang="ts" setup>
94-
import mdiCardAccountDetailsStarOutline from '~icons/mdi/card-account-details-star-outline';
95-
import icBaselineStyle from '~icons/ic/baseline-style';
96-
import bxHide from '~icons/bx/hide';
97-
import mdiThemeLightDark from '~icons/mdi/theme-light-dark';
98-
import icRoundDashboardCustomize from '~icons/ic/round-dashboard-customize';
99-
import fluentArrowReset24Filled from '~icons/fluent/arrow-reset-24-filled';
72+
import mdiCardAccountDetailsStarOutline from '~icons/mdi/card-account-details-star-outline'
73+
import icBaselineStyle from '~icons/ic/baseline-style'
74+
import bxHide from '~icons/bx/hide'
75+
import icRoundDashboardCustomize from '~icons/ic/round-dashboard-customize'
76+
import fluentArrowReset24Filled from '~icons/fluent/arrow-reset-24-filled'
10077
import { useThrottleFn } from '@vueuse/core'
101-
import { Themes, getPreviewImg } from '../../enums/themes';
102-
import CardBlock from '../cardBlock.vue';
78+
import CardBlock from '../cardBlock.vue'
10379
import MdPreview from '../mdPreview.vue'
80+
import ThemePreview from '../themePreview.vue'
10481
10582
const username = inject('username', '') as any
10683
@@ -146,12 +123,7 @@ const initCustomize = () => ({
146123
}
147124
})
148125
const customization = ref(initCustomize())
149-
150-
const themeOptions = Object.entries(Themes).map(([key, value]) => ({
151-
name: key,
152-
value
153-
}))
154-
const selectedTheme = ref(themeOptions[0])
126+
const selectedTheme = ref('default')
155127
156128
const allQueries = computed(() => {
157129
// username
@@ -177,7 +149,7 @@ const allQueries = computed(() => {
177149
}
178150
179151
// theme
180-
if (selectedTheme.value.name !== 'default') str.push(`theme=${selectedTheme.value.value}`)
152+
if (selectedTheme.value !== 'default') str.push(`theme=${selectedTheme.value}`)
181153
182154
return str.join('&')
183155
})

‎src/components/themePreview.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<CardBlock title="Theme" class="field--theme">
3+
<template #icon>
4+
<mdiThemeLightDark class="mr-2 text-[#F19F19]" />
5+
</template>
6+
<div class="mb-2">
7+
<label class="cursor-pointer text-gray-600 inline-flex items-center">
8+
<select :value="props.theme" @change="onThemeChange" class="px-2 py-1">
9+
<option v-for="theme in themeOptions" :value="theme">{{ theme }}</option>
10+
</select>
11+
</label>
12+
</div>
13+
<figure class="m-0 my-2">
14+
<img
15+
:src="props.category === 'stats' ? statsPreview(props.theme) : repoPreview(props.theme)"
16+
class="max-w-[400px] w-full"
17+
alt="theme-preview">
18+
</figure>
19+
<a href="https://github.com/anuraghazra/github-readme-stats/blob/master/themes/README.md" class="text-xs text-gray-400" target="_blank">
20+
<i>- theme preview (github-readme-stats/themes/README.md)</i>
21+
</a>
22+
</CardBlock>
23+
</template>
24+
25+
<script lang="ts" setup>
26+
import CardBlock from './cardBlock.vue'
27+
import mdiThemeLightDark from '~icons/mdi/theme-light-dark'
28+
import { Themes as statsThemes, getPreviewImg as statsPreview } from '../enums/statsThemes'
29+
import { Themes as repoThemes, getPreviewImg as repoPreview } from '../enums/repoThemes'
30+
31+
const props = defineProps(['theme', 'category'])
32+
33+
const themeOptions = computed(() => {
34+
return props.category === 'stats' ? statsThemes : repoThemes
35+
})
36+
37+
const emit = defineEmits(['update:theme'])
38+
39+
const onThemeChange = (e: Event) => {
40+
const target = e.target as HTMLSelectElement
41+
const themeSelected = target.value
42+
emit('update:theme', themeSelected)
43+
}
44+
</script>

0 commit comments

Comments
 (0)