Skip to content

Commit 200875e

Browse files
chore: add type constraints for icon class names (#1538)
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent 54aa86a commit 200875e

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

app/components/Button/Base.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import type { IconClass } from '~/types'
3+
24
const props = withDefaults(
35
defineProps<{
46
disabled?: boolean
@@ -8,7 +10,7 @@ const props = withDefaults(
810
ariaKeyshortcuts?: string
911
block?: boolean
1012
11-
classicon?: string
13+
classicon?: IconClass
1214
}>(),
1315
{
1416
type: 'button',

app/components/Link/Base.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import type { NuxtLinkProps } from '#app'
3+
import type { IconClass } from '~/types'
34
45
const props = withDefaults(
56
defineProps<
@@ -26,7 +27,7 @@ const props = withDefaults(
2627
*/
2728
rel?: never
2829
29-
classicon?: string
30+
classicon?: IconClass
3031
3132
to?: NuxtLinkProps['to']
3233

app/components/Tag/Static.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
2+
import type { IconClass } from '~/types'
3+
24
const props = withDefaults(
35
defineProps<{
46
as?: string | Component
57
variant?: 'ghost' | 'default'
68
7-
classicon?: string
9+
classicon?: IconClass
810
}>(),
911
{ as: 'span', variant: 'default' },
1012
)

app/pages/package/[[org]]/[name].vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
SkillsListResponse,
1010
} from '#shared/types'
1111
import type { JsrPackageInfo } from '#shared/types/jsr'
12+
import type { IconClass } from '~/types'
1213
import { assertValidPackageName } from '#shared/utils/npm'
1314
import { joinURL } from 'ufo'
1415
import { areUrlsEquivalent } from '#shared/utils/url'
@@ -246,7 +247,7 @@ const { copied: copiedPkgName, copy: copyPkgName } = useClipboard({
246247
247248
//copy version name
248249
const { copied: copiedVersion, copy: copyVersion } = useClipboard({
249-
source: resolvedVersion.value ?? '',
250+
source: () => resolvedVersion.value ?? '',
250251
copiedDuring: 2000,
251252
})
252253
@@ -398,7 +399,7 @@ const repositoryUrl = computed(() => {
398399
399400
const { meta: repoMeta, repoRef, stars, starsLink, forks, forksLink } = useRepoMeta(repositoryUrl)
400401
401-
const PROVIDER_ICONS: Record<string, string> = {
402+
const PROVIDER_ICONS: Record<string, IconClass> = {
402403
github: 'i-simple-icons:github',
403404
gitlab: 'i-simple-icons:gitlab',
404405
bitbucket: 'i-simple-icons:bitbucket',
@@ -411,7 +412,7 @@ const PROVIDER_ICONS: Record<string, string> = {
411412
radicle: 'i-lucide:network', // Radicle is a P2P network, using network icon
412413
}
413414
414-
const repoProviderIcon = computed(() => {
415+
const repoProviderIcon = computed((): IconClass => {
415416
const provider = repoRef.value?.provider
416417
if (!provider) return 'i-simple-icons:github'
417418
return PROVIDER_ICONS[provider] ?? 'i-lucide:code'

app/types/icon.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type IconClass =
2+
| `i-carbon:${string}`
3+
| `i-lucide:${string}`
4+
| `i-simple-icons:${string}`
5+
| `i-svg-spinners:${string}`
6+
| `i-custom:${string}`

app/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './icon'
12
export * from './navigation'

0 commit comments

Comments
 (0)