| </template> |
| 9 | <template v-else> |
| 10 | <div v-for="(item, index) in modelValue" :key="index" class="item-row"> |
| 11 | <el-input |
| 12 | :model-value="item" |
| 13 | :placeholder="placeholder" |
| 14 | @update:model-value="updateItem(index, $event)" |
| 15 | /> |
| 16 | <button class="item-remove" @click="removeItem(index)"> |
| 17 | <svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 18 | <path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z" fill="currentColor"/> |
| 19 | </svg> |
| 20 | </button> |
| 21 | </div> |
| 22 | <button class="list-add-btn" @click="addItem"> |
| 23 | <svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 24 | <path d="M8 2a.5.5 0 01.5.5v5h5a.5.5 0 010 1h-5v5a.5.5 0 01-1 0v-5h-5a.5.5 0 010-1h5v-5A.5.5 0 018 2z" fill="currentColor"/> |
| 25 | </svg> |
| 26 | Add |
| 27 | </button> |
| 28 | </template> |
| 29 | </div> |
| 30 | </template> |
| 31 |
| 32 | <script setup lang="ts"> |
| 33 | const props = withDefaults( |
| 34 | defineProps<{ |
| 35 | modelValue: string[] |
| 36 | placeholder?: string |
| 37 | readonly?: boolean |
| 38 | }>(), |
| 39 | { |
| 40 | placeholder: 'Enter value', |
| 41 | readonly: false, |
| 42 | }, |
| 43 | ) |
| 44 |
| 45 | const emit = defineEmits<{ |
| 46 | 'update:modelValue': [value: string[]] |
| 47 | }>() |
| 48 |
| 49 | const addItem = () => { |
| 50 | emit('update:modelValue', [...(props.modelValue || []), '']) |
| 51 | } |
| 52 |
| 53 | const removeItem = (index: number) => { |
| 54 | const newValue = [...props.modelValue] |
| 55 | newValue.splice(index, 1) |
| 56 | emit('update:modelValue', newValue) |
| 57 | } |
| 58 |
| 59 | const updateItem = (index: number, value: string) => { |
| 60 | const newValue = [...props.modelValue] |
| 61 | newValue[index] = value |
| 62 | emit('update:modelValue', newValue) |
| 63 | } |
| 64 | </script> |
| 65 |
| 66 | <style scoped> |
| 67 | .string-list-editor { |
| 68 | width: 100%; |
| 69 | } |
| 70 |
| 71 | .item-row { |
| 72 | display: flex; |
| 73 | align-items: center; |
| 74 | gap: 8px; |
| 75 | margin-bottom: 8px; |
| 76 | } |
| 77 |
| 78 | .item-row .el-input { |
| 79 | flex: 1; |
| 80 | } |
| 81 |
| 82 | .item-remove { |
| 83 | display: flex; |
| 84 | align-items: center; |
| 85 | justify-content: center; |
| 86 | width: 28px; |
| 87 | height: 28px; |
| 88 | border: none; |
| 89 | border-radius: 6px; |
| 90 | background: transparent; |
| 91 | color: var(--color-text-muted); |
| 92 | cursor: pointer; |
| 93 | flex-shrink: 0; |
| 94 | transition: all 0.15s; |
| 95 | } |
| 96 |
| 97 | .item-remove svg { |
| 98 | width: 14px; |
| 99 | height: 14px; |
| 100 | } |
| 101 |
| 102 | .item-remove:hover { |
| 103 | background: var(--color-bg-hover); |
| 104 | color: var(--color-text-primary); |
| 105 | } |
| 106 |
| 107 | .list-add-btn { |
| 108 | display: inline-flex; |
| 109 | align-items: center; |
| 110 | gap: 6px; |
| 111 | padding: 5px 12px; |
| 112 | border: 1px solid var(--color-border); |
| 113 | border-radius: 6px; |
| 114 | background: transparent; |
| 115 | color: var(--color-text-secondary); |
| 116 | font-size: 13px; |
| 117 | cursor: pointer; |
| 118 | transition: all 0.15s; |
| 119 | } |
| 120 |
| 121 | .list-add-btn svg { |
| 122 | width: 13px; |
| 123 | height: 13px; |
| 124 | } |
| 125 |
| 126 | .list-add-btn:hover { |
| 127 | background: var(--color-bg-hover); |
| 128 | } |
| 129 |
| 130 | .list-empty { |
| 131 | color: var(--color-text-muted); |
| 132 | font-size: 13px; |
| 133 | } |
| 134 |
| 135 | .list-readonly-item { |
| 136 | font-size: 13px; |
| 137 | color: var(--color-text-primary); |
| 138 | font-family: ui-monospace, SFMono-Regular, Menlo, monospace; |
| 139 | padding: 2px 0; |
| 140 | } |
| 141 | </style> |