Skip to content

Commit ba9c5cc

Browse files
committed
refactor: badge types constant should be shared
1 parent 263bb3f commit ba9c5cc

File tree

3 files changed

+27
-50
lines changed

3 files changed

+27
-50
lines changed

docs/app/components/BadgeGenerator.vue

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup>
2+
import { BADGE_TYPES } from '#shared/utils/badges'
23
import { useClipboard } from '@vueuse/core'
34
45
const pkg = useState('badge-pkg', () => 'nuxt')
@@ -7,30 +8,6 @@ const isValid = ref(true)
78
89
const { copy, copied } = useClipboard({ copiedDuring: 2000 })
910
10-
const types = [
11-
'version',
12-
'license',
13-
'size',
14-
'downloads',
15-
'downloads-day',
16-
'downloads-week',
17-
'downloads-month',
18-
'downloads-year',
19-
'vulnerabilities',
20-
'dependencies',
21-
'created',
22-
'updated',
23-
'engines',
24-
'types',
25-
'maintainers',
26-
'deprecated',
27-
'quality',
28-
'popularity',
29-
'maintenance',
30-
'score',
31-
'name',
32-
]
33-
3411
watch([pkg, type], () => {
3512
isValid.value = true
3613
})
@@ -76,7 +53,7 @@ const copyToClipboard = async () => {
7653
v-model="type"
7754
class="w-full h-10.5 px-4 py-2 rounded-lg border border-gray-200 dark:border-white/10 bg-white dark:bg-black/20 focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 outline-none text-sm transition-all appearance-none cursor-pointer"
7855
>
79-
<option v-for="t in types" :key="t" :value="t" class="dark:bg-gray-900">
56+
<option v-for="t in BADGE_TYPES" :key="t" :value="t" class="dark:bg-gray-900">
8057
{{ formatLabel(t) }}
8158
</option>
8259
</select>

docs/app/components/BadgeGeneratorParameters.vue

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup>
2+
import { BADGE_TYPES } from '#shared/utils/badges'
23
import { useClipboard } from '@vueuse/core'
34
45
const pkg = useState('badge-pkg', () => 'nuxt')
@@ -14,30 +15,6 @@ const badgeColor = useState('badge-color', () => '')
1415
const usePkgName = useState('badge-use-name', () => false)
1516
const badgeStyle = useState('badge-style', () => 'default')
1617
17-
const types = [
18-
'version',
19-
'license',
20-
'size',
21-
'downloads',
22-
'downloads-day',
23-
'downloads-week',
24-
'downloads-month',
25-
'downloads-year',
26-
'vulnerabilities',
27-
'dependencies',
28-
'created',
29-
'updated',
30-
'engines',
31-
'types',
32-
'maintainers',
33-
'deprecated',
34-
'quality',
35-
'popularity',
36-
'maintenance',
37-
'score',
38-
'name',
39-
]
40-
4118
const styles = ['default', 'shieldsio']
4219
4320
const validateHex = hex => {
@@ -122,7 +99,7 @@ const copyToClipboard = async () => {
12299
v-model="type"
123100
class="w-full h-10.5 px-4 py-2 rounded-lg border border-gray-200 dark:border-white/10 bg-white dark:bg-black/20 focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 outline-none text-sm transition-all appearance-none cursor-pointer"
124101
>
125-
<option v-for="t in types" :key="t" :value="t" class="dark:bg-gray-900">
102+
<option v-for="t in BADGE_TYPES" :key="t" :value="t" class="dark:bg-gray-900">
126103
{{ formatLabel(t) }}
127104
</option>
128105
</select>

docs/shared/utils/badges.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const BADGE_TYPES = Object.freeze([
2+
'version',
3+
'license',
4+
'size',
5+
'downloads',
6+
'downloads-day',
7+
'downloads-week',
8+
'downloads-month',
9+
'downloads-year',
10+
'vulnerabilities',
11+
'dependencies',
12+
'created',
13+
'updated',
14+
'engines',
15+
'types',
16+
'maintainers',
17+
'deprecated',
18+
'quality',
19+
'popularity',
20+
'maintenance',
21+
'score',
22+
'name',
23+
] as const)

0 commit comments

Comments
 (0)