LCOV - code coverage report
Current view: top level - src/components/common - ColorCustomizationSelector.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 18 18
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2            6 :   <div class="color-customization-selector-container flex items-center gap-2">
       3              :     <ToggleGroup v-model="selectedColorName" type="single" :allow-empty="false">
       4           77 :       <ToggleGroupItem
       5              :         v-for="option in colorOptionsWithCustom"
       6              :         :key="option.name"
       7              :         :value="option.name"
       8              :         :aria-label="
       9              :           option.name === '_custom' ? t('color.custom') : option.name
      10              :         "
      11              :       >
      12              :         <div
      13              :           v-if="option.name !== '_custom'"
      14              :           :style="{
      15              :             width: '20px',
      16              :             height: '20px',
      17              :             backgroundColor: option.value,
      18              :             borderRadius: '50%'
      19              :           }"
      20              :         />
      21              :         <i v-else class="icon-[lucide--palette] size-4.5" />
      22              :       </ToggleGroupItem>
      23              :     </ToggleGroup>
      24              :     <AppColorPicker
      25              :       v-if="selectedColorName === '_custom'"
      26              :       v-model="customColorValue"
      27              :     />
      28              :   </div>
      29              : </template>
      30              : 
      31              : <script setup lang="ts">
      32              : import { computed, ref, watch } from 'vue'
      33              : import { useI18n } from 'vue-i18n'
      34              : 
      35              : import AppColorPicker from '@/components/common/AppColorPicker.vue'
      36              : import ToggleGroup from '@comfyorg/design-system/toggle-group/ToggleGroup'
      37              : import ToggleGroupItem from '@comfyorg/design-system/toggle-group/ToggleGroupItem'
      38              : 
      39            3 : const { t } = useI18n()
      40              : 
      41              : const {
      42              :   modelValue,
      43              :   colorOptions,
      44              :   allowCustom = true
      45              : } = defineProps<{
      46              :   modelValue: string | null
      47              :   colorOptions: { name: Exclude<string, '_custom'>; value: string }[]
      48              :   allowCustom?: boolean
      49              : }>()
      50              : 
      51            3 : const customColorOption = { name: '_custom', value: '' }
      52            3 : const colorOptionsWithCustom = computed(() => [
      53              :   ...colorOptions,
      54              :   ...(allowCustom ? [customColorOption] : [])
      55              : ])
      56              : 
      57            3 : const emit = defineEmits<{
      58              :   'update:modelValue': [value: string | null]
      59              : }>()
      60              : 
      61            3 : const initialColorOption = colorOptions.find(
      62              :   (option) => option.value === modelValue
      63              : )
      64            3 : const selectedColorName = ref(
      65              :   initialColorOption?.name ?? customColorOption.name
      66              : )
      67            3 : const customColorValue = ref(initialColorOption ? '' : (modelValue ?? ''))
      68              : 
      69            3 : watch(selectedColorName, (newName, oldName) => {
      70            2 :   const newOption = colorOptionsWithCustom.value.find(
      71              :     (option) => option.name === newName
      72              :   )
      73            2 :   if (!newOption) return
      74              : 
      75            2 :   if (newName === customColorOption.name) {
      76            1 :     customColorValue.value =
      77              :       colorOptionsWithCustom.value.find((option) => option.name === oldName)
      78              :         ?.value ?? ''
      79              :   } else {
      80            1 :     emit('update:modelValue', newOption.value)
      81              :   }
      82              : })
      83              : 
      84            3 : watch(customColorValue, (newValue) => {
      85            2 :   if (selectedColorName.value === customColorOption.name) {
      86            2 :     emit('update:modelValue', newValue || null)
      87              :   }
      88              : })
      89              : </script>
        

Generated by: LCOV version 2.0-1