|
| 1 | +<template> |
| 2 | + <div |
| 3 | + ref="parent" |
| 4 | + :class="{'is-focused': isOpen, 'has-value': valueToShow}" |
| 5 | + class="field has-label" |
| 6 | + @click="isOpen ? close : open" |
| 7 | + > |
| 8 | + <label |
| 9 | + for="ctk-input" |
| 10 | + class="field-label" |
| 11 | + >{{ hint || label }}</label> |
| 12 | + <div class="flag-container field-country-flag"> |
| 13 | + <img |
| 14 | + :class="`flag-small flag flag-${value.toLowerCase()}`" |
| 15 | + :alt="value.toLowerCase()" |
| 16 | + src="./../assets/flags/blank.gif" |
| 17 | + > |
| 18 | + </div> |
| 19 | + <i |
| 20 | + aria-hidden="true" |
| 21 | + class="material-icons field-arrow" |
| 22 | + >arrow_drop_down</i> |
| 23 | + <input |
| 24 | + id="ctk-input" |
| 25 | + ref="ctkInput" |
| 26 | + :placeholder="label" |
| 27 | + :value="valueToShow" |
| 28 | + type="text" |
| 29 | + class="field-input dots-text" |
| 30 | + readonly |
| 31 | + @focus="open" |
| 32 | + @blur="close"> |
| 33 | + <input |
| 34 | + ref="ctkInput" |
| 35 | + :value="value" |
| 36 | + type="hidden"> |
| 37 | + <ul |
| 38 | + v-show="isOpen" |
| 39 | + class="ctk-input-select-list"> |
| 40 | + <li |
| 41 | + v-for="item in items" |
| 42 | + :class="{'selected': value === item.code }" |
| 43 | + :key="item.code" |
| 44 | + class="flex ctk-input-select-item" |
| 45 | + @click.stop="updateValue(item.code)" |
| 46 | + > |
| 47 | + <div class="flag-container mr-2"> |
| 48 | + <img |
| 49 | + :class="`flag-small flag flag-${item.code.toLowerCase()}`" |
| 50 | + :alt="item.code.toLowerCase()" |
| 51 | + src="./../assets/flags/blank.gif" |
| 52 | + > |
| 53 | + </div> |
| 54 | + <div> |
| 55 | + {{ item.dial_code }} - <b>{{ item.name }}</b> |
| 56 | + </div> |
| 57 | + </li> |
| 58 | + </ul> |
| 59 | + </div> |
| 60 | +</template> |
| 61 | + |
| 62 | +<script> |
| 63 | + export default { |
| 64 | + name: 'SelectCountry', |
| 65 | + props: { |
| 66 | + label: { |
| 67 | + type: String, |
| 68 | + default: 'Label' |
| 69 | + }, |
| 70 | + value: { |
| 71 | + type: null, |
| 72 | + default: null, |
| 73 | + require: true |
| 74 | + }, |
| 75 | + hint: { |
| 76 | + type: String, |
| 77 | + default: null |
| 78 | + }, |
| 79 | + errorHint: { |
| 80 | + type: Boolean, |
| 81 | + default: false |
| 82 | + }, |
| 83 | + items: { |
| 84 | + type: Array, |
| 85 | + required: true |
| 86 | + }, |
| 87 | + valueToShow: { |
| 88 | + type: String, |
| 89 | + default: null |
| 90 | + }, |
| 91 | + isOpen: { |
| 92 | + type: Boolean, |
| 93 | + default: false |
| 94 | + } |
| 95 | + }, |
| 96 | + data () { |
| 97 | + return { |
| 98 | + inputValue: null |
| 99 | + } |
| 100 | + }, |
| 101 | + methods: { |
| 102 | + open () { |
| 103 | + this.$emit('toggle', true) |
| 104 | + }, |
| 105 | + close () { |
| 106 | + setTimeout(() => { |
| 107 | + this.$emit('toggle', false) |
| 108 | + }, 300) |
| 109 | + }, |
| 110 | + updateValue (code) { |
| 111 | + this.$emit('input', code || this.value) |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +</script> |
| 116 | + |
| 117 | +<style lang="scss" scoped> |
| 118 | + .field { |
| 119 | + user-select: none; |
| 120 | + cursor: pointer; |
| 121 | + position: relative; |
| 122 | +
|
| 123 | + .flag-container{ |
| 124 | + margin: auto 0; |
| 125 | +
|
| 126 | + img{ |
| 127 | + position: absolute; |
| 128 | + } |
| 129 | + } |
| 130 | +
|
| 131 | + .field-label{ |
| 132 | + cursor: pointer; |
| 133 | + position: absolute; |
| 134 | + top: 3px; |
| 135 | + left: 13px; |
| 136 | + transform: translateY(0); |
| 137 | + opacity: 1; |
| 138 | + transition: all .25s cubic-bezier(.645,.045,.355,1); |
| 139 | + font-size: 11px; |
| 140 | + color: rgba(0,0,0, 0.54); |
| 141 | + } |
| 142 | + .field-country-flag { |
| 143 | + position: absolute; |
| 144 | + top: 19px; |
| 145 | + left: 13px; |
| 146 | + } |
| 147 | + .field-input{ |
| 148 | + user-select: none; |
| 149 | + cursor: pointer; |
| 150 | + transition-duration: 0.3s; |
| 151 | + position: relative; |
| 152 | + width: 100%; |
| 153 | + height: 42px; |
| 154 | + min-height: 42px; |
| 155 | + padding: 0 12px; |
| 156 | + padding-left: 40px; |
| 157 | + padding-top: 14px; |
| 158 | +
|
| 159 | + font-weight: 400; |
| 160 | + -webkit-appearance: none; |
| 161 | + outline: none; |
| 162 | +
|
| 163 | + background-color: transparent; |
| 164 | + border: 1px solid rgba(0,0,0, 0.2); |
| 165 | + border-radius: 4px; |
| 166 | + border-top-right-radius: 0; |
| 167 | + border-bottom-right-radius: 0; |
| 168 | + &.has-error { |
| 169 | + border-color: $danger !important; |
| 170 | + } |
| 171 | + } |
| 172 | + .field-arrow { |
| 173 | + cursor: pointer; |
| 174 | + position: absolute; |
| 175 | + right: 5px; |
| 176 | + top: 10px; |
| 177 | + color: rgba(0,0,0, 0.54); |
| 178 | + } |
| 179 | + &.is-focused { |
| 180 | + .field-input { |
| 181 | + border-color: $info; |
| 182 | + } |
| 183 | + .field-label { |
| 184 | + color: $info; |
| 185 | + } |
| 186 | + } |
| 187 | + .ctk-input-select-list { |
| 188 | + padding: 0; |
| 189 | + list-style: none; |
| 190 | + background: #FFF; |
| 191 | + max-height: 200px; |
| 192 | + overflow: auto; |
| 193 | + z-index: 9; |
| 194 | + max-width: 100%; |
| 195 | + position: absolute; |
| 196 | + top: 42px; |
| 197 | + border-radius: 4px; |
| 198 | + width: 100%; |
| 199 | + min-width: 230px; |
| 200 | + -webkit-box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); |
| 201 | + box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); |
| 202 | + .ctk-input-select-item { |
| 203 | + padding: 5px 10px; |
| 204 | + text-overflow: ellipsis; |
| 205 | + white-space: nowrap; |
| 206 | + overflow: hidden; |
| 207 | + cursor: pointer; |
| 208 | + &:hover { |
| 209 | + background-color: #F2F2F2; |
| 210 | + } |
| 211 | + &.selected { |
| 212 | + background: $info; |
| 213 | + color: #FFF; |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | +</style> |
0 commit comments