Skip to content

Commit

Permalink
feat: show options indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 9, 2024
1 parent 9442360 commit dcd0071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/components/RuleItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useClipboard } from '@vueuse/core'
import { vTooltip } from 'floating-vue'
import { getRuleLevel } from '~~/shared/rules'
import { getRuleLevel, getRuleOptions } from '~~/shared/rules'
import type { RuleConfigStates, RuleInfo, RuleLevel } from '~~/shared/types'
const props = defineProps<{
Expand Down Expand Up @@ -37,6 +37,7 @@ function capitalize(str?: string) {
<RuleLevelIcon
:level="s.level"
:config-index="s.configIndex"
:has-options="!!s.options?.length"
/>
<template #popper="{ shown }">
<RuleStateItem v-if="shown" :state="s" />
Expand All @@ -51,7 +52,7 @@ function capitalize(str?: string) {
>
<RuleLevelIcon
:level="getRuleLevel(value)!"
:class="getRuleLevel(value) === 'error' ? '' : ''"
:has-options="!!getRuleOptions(value)?.length"
/>
</div>
Expand Down
29 changes: 17 additions & 12 deletions app/components/RuleLevelIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { nth } from '~/composables/strings'
const props = defineProps<{
level: RuleLevel
hasOptions?: boolean
configIndex?: number
class?: string
}>()
Expand All @@ -14,19 +15,23 @@ const title = computed(() => {
return `Enabled as '${props.level}'`
return `Enabled as '${props.level}', in the ${nth(props.configIndex + 1)} config item`
})
const color = computed(() => ({
error: 'text-red op80',
warn: 'text-yellow5 op80 dark:text-yellow4',
off: 'text-gray op50',
}[props.level]))
const icon = computed(() => ({
error: 'i-ph-warning-circle-duotone',
warn: 'i-ph-warning-duotone',
off: 'i-ph-circle-half-tilt-duotone',
}[props.level]))
</script>

<template>
<div
v-if="level === 'error'" i-ph-warning-circle-duotone text-red op80
:title="title" :class="props.class"
/>
<div
v-if="level === 'warn'" i-ph-warning-duotone text-yellow5 op80 dark:text-yellow4
:title="title" :class="props.class"
/>
<div
v-if="level === 'off'" i-ph-circle-half-tilt-duotone text-gray op50
:title="title" :class="props.class"
/>
<div relative :class="[color, props.class]" :title="title">
<div :class="icon" />
<div v-if="hasOptions" op75 bg-current rounded-full h-6px w-6px absolute top--2px right--2px />
</div>
</template>

0 comments on commit dcd0071

Please sign in to comment.