Skip to content

Commit c51fb34

Browse files
committed
refactor: move basic styles into reusable tag component
1 parent bacb5dc commit c51fb34

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

app/components/Filter/Panel.vue

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
249249
type="button"
250250
role="radio"
251251
:aria-checked="filters.downloadRange === range.value"
252-
:class="
253-
filters.downloadRange === range.value
254-
? 'bg-fg text-bg border-fg hover:text-bg/50'
255-
: ''
256-
"
252+
:status="filters.downloadRange === range.value ? 'active' : 'default'"
257253
@click="emit('update:downloadRange', range.value)"
258254
>
259255
{{ $t(getDownloadRangeLabelKey(range.value)) }}
@@ -277,11 +273,7 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
277273
type="button"
278274
role="radio"
279275
:aria-checked="filters.updatedWithin === option.value"
280-
:class="
281-
filters.updatedWithin === option.value
282-
? 'bg-fg text-bg border-fg hover:text-bg/70'
283-
: ''
284-
"
276+
:status="filters.updatedWithin === option.value ? 'active' : 'default'"
285277
@click="emit('update:updatedWithin', option.value)"
286278
>
287279
{{ $t(getUpdatedWithinLabelKey(option.value)) }}
@@ -305,10 +297,7 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
305297
role="radio"
306298
disabled
307299
:aria-checked="filters.security === option.value"
308-
class="opacity-50 cursor-not-allowed"
309-
:class="
310-
filters.security === option.value ? 'bg-fg text-bg border-fg hover:text-bg/70' : ''
311-
"
300+
:status="filters.security === option.value ? 'active' : 'default'"
312301
>
313302
{{ $t(getSecurityLabelKey(option.value)) }}
314303
</TagClickable>
@@ -326,9 +315,7 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
326315
:key="keyword"
327316
type="button"
328317
:aria-pressed="filters.keywords.includes(keyword)"
329-
:class="
330-
filters.keywords.includes(keyword) ? 'bg-fg text-bg border-fg hover:text-bg/70' : ''
331-
"
318+
:status="filters.keywords.includes(keyword) ? 'active' : 'default'"
332319
@click="emit('toggleKeyword', keyword)"
333320
>
334321
{{ keyword }}

app/components/Tag/Clickable.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<script setup lang="ts">
2-
const props = withDefaults(defineProps<{ as?: string | Component }>(),{ as: 'button' })
2+
const props = withDefaults(
3+
defineProps<{ as?: string | Component; status?: 'default' | 'active'; disabled?: boolean }>(),
4+
{
5+
status: 'default',
6+
as: 'button',
7+
},
8+
)
39
</script>
410

511
<template>
612
<component
713
:is="props.as"
8-
class="inline-flex items-center px-2 py-0.5 text-xs font-mono text-fg-muted bg-bg-muted border border-border rounded transition-colors duration-200 hover:(text-fg border-border-hover) focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
14+
class="inline-flex items-center px-2 py-0.5 text-xs font-mono border rounded transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
15+
:class="{
16+
'bg-bg-muted text-fg-muted border-border hover:(text-fg border-border-hover)':
17+
props.status === 'default',
18+
'bg-fg text-bg border-fg hover:(text-text-bg/50)': props.status === 'active',
19+
'opacity-50 cursor-not-allowed': props.disabled,
20+
}"
21+
:disabled="props.disabled"
922
>
1023
<slot />
1124
</component>

app/components/Tag/Static.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
const props = withDefaults(defineProps<{ as?: string | Component }>(),{ as: 'span' })
2+
const props = withDefaults(defineProps<{ as?: string | Component }>(), { as: 'span' })
33
</script>
44

55
<template>

0 commit comments

Comments
 (0)