Props definition with state

PHOTO EMBED

Wed May 22 2024 09:24:46 GMT+0000 (Coordinated Universal Time)

Saved by @Paloma #typescript

type Props = {
  state: 'success' | 'partial' | 'failure'
}

const props = defineProps<Props>()

const states: Record<Props['state'], { icon: IconDefinition; color: Color }> = {
  success: { icon: faCheckCircle, color: 'success' },
  partial: { icon: faCircleMinus, color: 'warning' },
  failure: { icon: faCircleXmark, color: 'error' },
}

const icon = computed(() => states[props.state].icon)
const color = computed(() => states[props.state].color)
content_copyCOPY