AmInput.vue
425 lines
| 1 | <template> |
| 2 | <div |
| 3 | class="am-input-wrapper" |
| 4 | :style="cssVars" |
| 5 | > |
| 6 | <el-input |
| 7 | :id="id" |
| 8 | ref="amInput" |
| 9 | v-model="model" |
| 10 | :type="type" |
| 11 | :clearable="clearable" |
| 12 | :suffix-icon="iconEnd" |
| 13 | :prefix-icon="iconStart" |
| 14 | :class="[ |
| 15 | type === 'text' || type === 'email' ? 'am-input' : 'am-textarea textarea', |
| 16 | size ? (type === 'text-area' ? 'am-textarea__size' : 'am-input') + '__' + size : '', |
| 17 | {'is-icon-start': iconStart}, |
| 18 | {'is-icon-end': iconEnd} |
| 19 | ]" |
| 20 | :disabled="disabled" |
| 21 | :controls="controls" |
| 22 | :controls-position="controlsPosition" |
| 23 | :name="name" |
| 24 | :label="label" |
| 25 | :rows="rows" |
| 26 | :placeholder="placeholder" |
| 27 | :readonly="readOnly" |
| 28 | :show-password="showPassword" |
| 29 | :validate-event="validateEvent" |
| 30 | :formatter="formatter" |
| 31 | :parser="parser" |
| 32 | @blur="(e) => $emit('blur', e)" |
| 33 | @focus="(e) => $emit('focus', e)" |
| 34 | @change="(currentValue, oldValue) => $emit('change', currentValue, oldValue)" |
| 35 | @input="(currentValue, oldValue) => $emit('input', currentValue, oldValue)" |
| 36 | @keyup.enter="(e) => $emit('enter', e)" |
| 37 | @clear="() => emits('clear')" |
| 38 | > |
| 39 | </el-input> |
| 40 | </div> |
| 41 | </template> |
| 42 | |
| 43 | <script setup> |
| 44 | import { computed, ref, toRefs, inject } from 'vue'; |
| 45 | import { format, unformat } from 'v-money3'; |
| 46 | import { useColorTransparency } from "../../../assets/js/common/colorManipulation"; |
| 47 | import { useCurrencyOptions } from "../../../assets/js/common/formatting"; |
| 48 | |
| 49 | /** |
| 50 | * Component Props |
| 51 | */ |
| 52 | const props = defineProps({ |
| 53 | id: { |
| 54 | type: String |
| 55 | }, |
| 56 | modelValue: { |
| 57 | type: [String, Number, null, undefined] |
| 58 | }, |
| 59 | type: { |
| 60 | type: String, |
| 61 | default: 'text' |
| 62 | }, |
| 63 | size: { |
| 64 | type: String, |
| 65 | default: 'default', |
| 66 | validator(value) { |
| 67 | return ['default', 'medium', 'small'].includes(value) |
| 68 | } |
| 69 | }, |
| 70 | disabled: { |
| 71 | type: Boolean, |
| 72 | default: false |
| 73 | }, |
| 74 | controls: { |
| 75 | type: Boolean, |
| 76 | default: true |
| 77 | }, |
| 78 | controlsPosition: { |
| 79 | // right |
| 80 | type: String, |
| 81 | default: '' |
| 82 | }, |
| 83 | name: { |
| 84 | type: String, |
| 85 | default: '' |
| 86 | }, |
| 87 | label: { |
| 88 | type: String, |
| 89 | default: '' |
| 90 | }, |
| 91 | placeholder: { |
| 92 | type: String, |
| 93 | default: '' |
| 94 | }, |
| 95 | rows: { |
| 96 | type: Number, |
| 97 | default: 3 |
| 98 | }, |
| 99 | iconStart: { |
| 100 | type: [String, Object], |
| 101 | default: '' |
| 102 | }, |
| 103 | iconEnd: { |
| 104 | type: [String, Object], |
| 105 | default: '' |
| 106 | }, |
| 107 | clearable: { |
| 108 | type: Boolean, |
| 109 | default: false |
| 110 | }, |
| 111 | readOnly: { |
| 112 | type: Boolean, |
| 113 | default: false |
| 114 | }, |
| 115 | showPassword: { |
| 116 | type: Boolean, |
| 117 | default: false |
| 118 | }, |
| 119 | validateEvent: { |
| 120 | type: Boolean, |
| 121 | default: true |
| 122 | }, |
| 123 | formatter: { |
| 124 | type: Function |
| 125 | }, |
| 126 | parser: { |
| 127 | type: Function |
| 128 | }, |
| 129 | isMoney: { |
| 130 | type: Boolean, |
| 131 | default: false |
| 132 | } |
| 133 | }) |
| 134 | |
| 135 | /** |
| 136 | * Component Emits |
| 137 | * */ |
| 138 | const emits = defineEmits(['change', 'input', 'visible-change', 'clear', 'blur', 'focus', 'update:modelValue', 'enter']) |
| 139 | |
| 140 | /** |
| 141 | * Component model |
| 142 | */ |
| 143 | let { modelValue } = toRefs(props) |
| 144 | |
| 145 | let model = computed({ |
| 146 | get: () => { |
| 147 | return props.isMoney ? format(modelValue.value, useCurrencyOptions()) : modelValue.value |
| 148 | }, |
| 149 | set: (val) => { |
| 150 | emits( |
| 151 | 'update:modelValue', |
| 152 | props.isMoney ? unformat(val, { ...useCurrencyOptions(), modelModifiers: { number: true } }) : val |
| 153 | ) |
| 154 | } |
| 155 | }) |
| 156 | |
| 157 | // * Color Vars |
| 158 | let amColors = inject('amColors', ref({ |
| 159 | colorPrimary: '#1246D6', |
| 160 | colorSuccess: '#019719', |
| 161 | colorError: '#B4190F', |
| 162 | colorWarning: '#CCA20C', |
| 163 | colorMainBgr: '#FFFFFF', |
| 164 | colorMainHeadingText: '#33434C', |
| 165 | colorMainText: '#1A2C37', |
| 166 | colorSbBgr: '#17295A', |
| 167 | colorSbText: '#FFFFFF', |
| 168 | colorInpBgr: '#FFFFFF', |
| 169 | colorInpBorder: '#D1D5D7', |
| 170 | colorInpText: '#1A2C37', |
| 171 | colorInpPlaceHolder: '#808A90', |
| 172 | colorDropBgr: '#FFFFFF', |
| 173 | colorDropBorder: '#D1D5D7', |
| 174 | colorDropText: '#0E1920', |
| 175 | colorBtnPrim: '#265CF2', |
| 176 | colorBtnPrimText: '#FFFFFF', |
| 177 | colorBtnSec: '#1A2C37', |
| 178 | colorBtnSecText: '#FFFFFF', |
| 179 | })) |
| 180 | |
| 181 | // * Css Variables |
| 182 | let cssVars = computed(() => { |
| 183 | return { |
| 184 | '--am-c-inp-text-op03': useColorTransparency(amColors.value.colorInpText, 0.03), |
| 185 | '--am-c-inp-text-op60': useColorTransparency(amColors.value.colorInpText, 0.6), |
| 186 | } |
| 187 | }) |
| 188 | |
| 189 | /** |
| 190 | * Component reference |
| 191 | */ |
| 192 | const amInput = ref(null) |
| 193 | </script> |
| 194 | |
| 195 | <style lang="scss"> |
| 196 | @mixin am-input-block { |
| 197 | // Input Wrapper |
| 198 | .am-input-wrapper { |
| 199 | --am-input-c-bgr: var(--am-c-inp-bgr); |
| 200 | --am-input-c-border: var(--am-c-inp-border); |
| 201 | --am-input-c-text: var(--am-c-inp-text); |
| 202 | --am-input-c-placeholder: var(--am-c-inp-placeholder); |
| 203 | --am-input-border-radius: var(--am-input-border-radius); |
| 204 | --am-input-font-size: var(--am-fs-input); |
| 205 | --am-input-color-border: var(--am-c-inp-border); |
| 206 | --am-input-padding: 8px 12px; |
| 207 | width: 100%; |
| 208 | position: relative; |
| 209 | |
| 210 | // Input & Textarea |
| 211 | .am-input, .am-textarea { |
| 212 | width: 100%; |
| 213 | box-sizing: border-box; |
| 214 | min-width: 100%; |
| 215 | max-width: 100%; |
| 216 | |
| 217 | .el-input { |
| 218 | &__inner { |
| 219 | min-height: unset; |
| 220 | |
| 221 | &:not([type='text-area']) { |
| 222 | width: 100%; |
| 223 | height: var(--am-input-height); |
| 224 | font-size: var(--am-input-font-size); |
| 225 | border: 1px solid var(--am-input-c-border); |
| 226 | color: var(--am-input-c-text); |
| 227 | background-color: var(--am-input-c-bgr); |
| 228 | border-radius: 6px; |
| 229 | padding: var(--am-input-padding); |
| 230 | } |
| 231 | |
| 232 | &:focus { |
| 233 | --am-input-c-border: var(--am-c-btn-prim); |
| 234 | } |
| 235 | |
| 236 | // Placeholder |
| 237 | &::-webkit-input-placeholder { |
| 238 | color: var(--am-c-inp-placeholder); |
| 239 | } |
| 240 | &:-ms-input-placeholder { |
| 241 | color: var(--am-c-inp-placeholder); |
| 242 | } |
| 243 | &::placeholder { |
| 244 | color: var(--am-c-inp-placeholder); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | &__prefix { |
| 249 | &-inner { |
| 250 | align-items: center; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | &__suffix { |
| 255 | &-inner { |
| 256 | align-items: center; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | .el-textarea__inner { |
| 262 | color: var(--am-c-inp-text); |
| 263 | |
| 264 | &:focus { |
| 265 | background-color: var(--am-input-c-bgr); |
| 266 | } |
| 267 | |
| 268 | } |
| 269 | |
| 270 | &__default{ |
| 271 | --am-input-height: 40px; |
| 272 | --am-input-padding: 8px 12px; |
| 273 | |
| 274 | input { |
| 275 | line-height: 40px; |
| 276 | } |
| 277 | |
| 278 | // Icon |
| 279 | &.is-icon-start { |
| 280 | --am-input-padding: 8px 12px 8px 41px; |
| 281 | } |
| 282 | |
| 283 | &.is-icon-end { |
| 284 | --am-input-padding: 8px 41px 8px 12px; |
| 285 | } |
| 286 | |
| 287 | &.is-icon-start.is-icon-end { |
| 288 | --am-input-padding: 8px 41px; |
| 289 | } |
| 290 | |
| 291 | &.is-icon-start, &.is-icon-end { |
| 292 | i { |
| 293 | font-size: 24px; |
| 294 | color: var(--am-c-inp-text); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | &__medium { |
| 300 | --am-input-height: 36px; |
| 301 | --am-input-padding: 6px 10px; |
| 302 | |
| 303 | input { |
| 304 | height: 36px; |
| 305 | line-height: 36px; |
| 306 | } |
| 307 | |
| 308 | // Icon |
| 309 | &.is-icon-start { |
| 310 | --am-input-padding: 6px 10px 6px 34px; |
| 311 | } |
| 312 | |
| 313 | &.is-icon-end { |
| 314 | --am-input-padding: 6px 34px 6px 10px; |
| 315 | } |
| 316 | |
| 317 | &.is-icon-start.is-icon-end { |
| 318 | --am-input-padding: 8px 34px; |
| 319 | } |
| 320 | |
| 321 | &.is-icon-start, &.is-icon-end { |
| 322 | i { |
| 323 | font-size: 24px; |
| 324 | color: var(--am-c-inp-text); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | &__small { |
| 330 | --am-input-height: 32px; |
| 331 | --am-input-padding: 4px 8px; |
| 332 | |
| 333 | input { |
| 334 | height: 32px; |
| 335 | line-height: 32px; |
| 336 | font-size: 15px; |
| 337 | } |
| 338 | |
| 339 | // Icon |
| 340 | &.is-icon-start { |
| 341 | --am-input-padding: 4px 8px 4px 34px; |
| 342 | } |
| 343 | |
| 344 | &.is-icon-end { |
| 345 | --am-input-padding: 4px 34px 4px 8px; |
| 346 | } |
| 347 | |
| 348 | &.is-icon-start.is-icon-end { |
| 349 | --am-input-padding: 4px 34px; |
| 350 | } |
| 351 | |
| 352 | &.is-icon-start, &.is-icon-end { |
| 353 | i { |
| 354 | font-size: 24px; |
| 355 | color: var(--am-c-inp-text); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // Native Input & Native Textarea |
| 361 | input, textarea { |
| 362 | border: 1px solid var(--am-input-color-border); |
| 363 | background: var(--am-input-c-bgr); |
| 364 | border-radius: 6px; |
| 365 | padding: 8px 12px; |
| 366 | margin: 0; |
| 367 | font-size: 15px; |
| 368 | -webkit-transition: box-shadow 0.15s; |
| 369 | transition: box-shadow 0.15s; |
| 370 | |
| 371 | // Active & Focus |
| 372 | &:active, &:focus { |
| 373 | --am-input-color-border: var(--am-c-btn-prim); |
| 374 | outline: none; |
| 375 | box-shadow: 0 2px 2px var(--am-c-inp-text-op03); |
| 376 | padding: 8px 12px; |
| 377 | } |
| 378 | |
| 379 | // Placeholder |
| 380 | &::-webkit-input-placeholder, &:-ms-input-placeholder, &::placeholder { |
| 381 | color: var(--am-input-c-placeholder); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // Disabled |
| 386 | &.is-disabled { |
| 387 | input { |
| 388 | --am-input-c-bgr: var(--am-c-inp-text-op03); |
| 389 | --am-input-c-text: var(--am-c-inp-text-op60); |
| 390 | box-shadow: none; |
| 391 | cursor: not-allowed; |
| 392 | |
| 393 | // Placeholder |
| 394 | &::-webkit-input-placeholder, &:-ms-input-placeholder, &::placeholder { |
| 395 | // TODO |
| 396 | color: var(--am-input-c-placeholder); |
| 397 | } |
| 398 | |
| 399 | // Hover |
| 400 | &:hover { |
| 401 | box-shadow: unset; |
| 402 | } |
| 403 | |
| 404 | // Active & Focus |
| 405 | &:active, &:focus { |
| 406 | --am-input-c-border: var(--am-c-inp-border); |
| 407 | box-shadow: unset; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // public |
| 416 | .amelia-v2-booking #amelia-container { |
| 417 | @include am-input-block; |
| 418 | } |
| 419 | |
| 420 | // admin |
| 421 | #amelia-app-backend-new { |
| 422 | @include am-input-block; |
| 423 | } |
| 424 | </style> |
| 425 |