|
| 1 | +<script setup lang="ts"> |
| 2 | +import { Input } from '@/shared/ui/input' |
| 3 | +import { Button } from '@/shared/ui/button' |
| 4 | +import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/shared/ui/select' |
| 5 | +import { EventLinkType, type EventLink } from '@/modules/events/types' |
| 6 | +import { Icon } from '@iconify/vue' |
| 7 | +
|
| 8 | +const props = defineProps<{ |
| 9 | + modelValue: EventLink[] |
| 10 | +}>() |
| 11 | +
|
| 12 | +const emit = defineEmits<{ |
| 13 | + (e: 'update:modelValue', val: EventLink[]): void |
| 14 | +}>() |
| 15 | +
|
| 16 | +function update(index: number, patch: Partial<EventLink>) { |
| 17 | + const updated = [...props.modelValue] |
| 18 | + updated[index] = { ...updated[index], ...patch } |
| 19 | + emit('update:modelValue', updated) |
| 20 | +} |
| 21 | +
|
| 22 | +function addLink() { |
| 23 | + emit('update:modelValue', [ |
| 24 | + ...props.modelValue, |
| 25 | + { type: EventLinkType.Other, url: '', label: '' }, |
| 26 | + ]) |
| 27 | +} |
| 28 | +
|
| 29 | +function removeLink(index: number) { |
| 30 | + const updated = [...props.modelValue] |
| 31 | + updated.splice(index, 1) |
| 32 | + emit('update:modelValue', updated) |
| 33 | +} |
| 34 | +</script> |
| 35 | + |
| 36 | +<template> |
| 37 | + <div class="space-y-2"> |
| 38 | + <div |
| 39 | + v-for="(link, i) in modelValue" |
| 40 | + :key="i" |
| 41 | + class="grid grid-cols-[auto_1fr_1fr_auto] items-center gap-2" |
| 42 | + > |
| 43 | + <!-- Link Type --> |
| 44 | + <Select |
| 45 | + :model-value="link.type" |
| 46 | + @update:model-value="val => update(i, { type: val as EventLinkType })" |
| 47 | + > |
| 48 | + <SelectTrigger class="w-[90px]"> |
| 49 | + <SelectValue /> |
| 50 | + </SelectTrigger> |
| 51 | + <SelectContent> |
| 52 | + <SelectItem v-for="type in Object.values(EventLinkType)" :key="type" :value="type"> |
| 53 | + {{ type }} |
| 54 | + </SelectItem> |
| 55 | + </SelectContent> |
| 56 | + </Select> |
| 57 | + |
| 58 | + <!-- URL --> |
| 59 | + <Input |
| 60 | + type="url" |
| 61 | + placeholder="https://..." |
| 62 | + :model-value="link.url" |
| 63 | + @update:model-value="val => update(i, { url: String(val) })" |
| 64 | + /> |
| 65 | + |
| 66 | + <!-- Label --> |
| 67 | + <Input |
| 68 | + placeholder="Label (optional)" |
| 69 | + :model-value="link.label" |
| 70 | + @update:model-value="val => update(i, { label: String(val) })" |
| 71 | + /> |
| 72 | + |
| 73 | + <!-- Remove --> |
| 74 | + <Button |
| 75 | + type="button" |
| 76 | + variant="ghost" |
| 77 | + size="icon" |
| 78 | + class="text-muted-foreground hover:text-destructive h-8 w-8 shrink-0" |
| 79 | + @click="removeLink(i)" |
| 80 | + > |
| 81 | + <Icon icon="radix-icons:cross-2" class="h-4 w-4" /> |
| 82 | + </Button> |
| 83 | + </div> |
| 84 | + |
| 85 | + <Button type="button" variant="outline" size="sm" @click="addLink"> |
| 86 | + <Icon icon="radix-icons:plus" class="mr-1 h-4 w-4" /> |
| 87 | + Add link |
| 88 | + </Button> |
| 89 | + </div> |
| 90 | +</template> |
0 commit comments