AmInputNumber.vue
295 lines
| 1 | <template> |
| 2 | <el-input-number |
| 3 | :id="id" |
| 4 | ref="amInputNumber" |
| 5 | v-model="model" |
| 6 | class="am-input-number" |
| 7 | :class="[`am-input-number__${size}`]" |
| 8 | :style="cssVars" |
| 9 | :min="min" |
| 10 | :max="max" |
| 11 | :step="step" |
| 12 | :step-strictly="stepStrictly" |
| 13 | :precision="precision" |
| 14 | :readonly="readonly" |
| 15 | :disabled="disabled" |
| 16 | :controls="controls" |
| 17 | :controls-position="controlsPosition" |
| 18 | :name="name" |
| 19 | :aria-label="ariaLabel" |
| 20 | :place-holder="placeHolder" |
| 21 | @blur="(e) => $emit('blur', e)" |
| 22 | @focus="(e) => $emit('focus', e)" |
| 23 | @change="(currentValue, oldValue) => $emit('change', currentValue, oldValue)" |
| 24 | /> |
| 25 | </template> |
| 26 | |
| 27 | <script setup> |
| 28 | // * Import from Vue |
| 29 | import { ref, toRefs, inject, computed } from 'vue' |
| 30 | |
| 31 | // * Composables |
| 32 | import { useColorTransparency } from '../../../assets/js/common/colorManipulation' |
| 33 | |
| 34 | /** |
| 35 | * Component Props |
| 36 | */ |
| 37 | const props = defineProps({ |
| 38 | id: { |
| 39 | type: String, |
| 40 | }, |
| 41 | modelValue: { |
| 42 | type: Number, |
| 43 | }, |
| 44 | min: { |
| 45 | type: Number, |
| 46 | required: true, |
| 47 | }, |
| 48 | max: { |
| 49 | type: Number, |
| 50 | default: Infinity, |
| 51 | }, |
| 52 | step: { |
| 53 | type: Number, |
| 54 | default: 1, |
| 55 | }, |
| 56 | stepStrictly: { |
| 57 | type: Boolean, |
| 58 | default: false, |
| 59 | }, |
| 60 | precision: { |
| 61 | type: Number, |
| 62 | }, |
| 63 | size: { |
| 64 | type: String, |
| 65 | default: 'default', |
| 66 | validator(value) { |
| 67 | return ['default', 'medium', 'small'].includes(value) |
| 68 | }, |
| 69 | }, |
| 70 | readonly: { |
| 71 | type: Boolean, |
| 72 | default: false, |
| 73 | }, |
| 74 | disabled: { |
| 75 | type: Boolean, |
| 76 | default: false, |
| 77 | }, |
| 78 | controls: { |
| 79 | type: Boolean, |
| 80 | default: true, |
| 81 | }, |
| 82 | controlsPosition: { |
| 83 | // right |
| 84 | type: String, |
| 85 | }, |
| 86 | name: { |
| 87 | type: String, |
| 88 | default: '', |
| 89 | }, |
| 90 | ariaLabel: { |
| 91 | type: String, |
| 92 | default: 'input-number', |
| 93 | }, |
| 94 | placeHolder: { |
| 95 | type: String, |
| 96 | default: '', |
| 97 | }, |
| 98 | }) |
| 99 | |
| 100 | /** |
| 101 | * Component Emits |
| 102 | * */ |
| 103 | const emits = defineEmits([ |
| 104 | 'change', |
| 105 | 'visible-change', |
| 106 | 'clear', |
| 107 | 'blur', |
| 108 | 'focus', |
| 109 | 'update:modelValue', |
| 110 | ]) |
| 111 | |
| 112 | /** |
| 113 | * Component model |
| 114 | */ |
| 115 | let { modelValue } = toRefs(props) |
| 116 | let model = computed({ |
| 117 | get: () => modelValue.value, |
| 118 | set: (val) => { |
| 119 | emits('update:modelValue', val) |
| 120 | }, |
| 121 | }) |
| 122 | |
| 123 | /** |
| 124 | * Component reference |
| 125 | */ |
| 126 | const amInputNumber = ref(null) |
| 127 | |
| 128 | // * Colors |
| 129 | let amColors = inject( |
| 130 | 'amColors', |
| 131 | ref({ |
| 132 | colorPrimary: '#1246D6', |
| 133 | colorSuccess: '#019719', |
| 134 | colorError: '#B4190F', |
| 135 | colorWarning: '#CCA20C', |
| 136 | colorMainBgr: '#FFFFFF', |
| 137 | colorMainHeadingText: '#33434C', |
| 138 | colorMainText: '#1A2C37', |
| 139 | colorSbBgr: '#17295A', |
| 140 | colorSbText: '#FFFFFF', |
| 141 | colorInpBgr: '#FFFFFF', |
| 142 | colorInpBorder: '#D1D5D7', |
| 143 | colorInpText: '#1A2C37', |
| 144 | colorInpPlaceHolder: '#1A2C37', |
| 145 | colorDropBgr: '#FFFFFF', |
| 146 | colorDropBorder: '#D1D5D7', |
| 147 | colorDropText: '#0E1920', |
| 148 | colorBtnPrim: '#265CF2', |
| 149 | colorBtnPrimText: '#FFFFFF', |
| 150 | colorBtnSec: '#1A2C37', |
| 151 | colorBtnSecText: '#FFFFFF', |
| 152 | }), |
| 153 | ) |
| 154 | let cssVars = computed(() => { |
| 155 | return { |
| 156 | '--am-c-inp-number-bgr': amColors.value.colorInpBgr, |
| 157 | '--am-c-inp-number-border': amColors.value.colorInpBorder, |
| 158 | '--am-c-inp-number-text': amColors.value.colorInpText, |
| 159 | '--am-c-inp-number-text-op10': useColorTransparency(amColors.value.colorInpText, 0.1), |
| 160 | '--am-c-inp-number-text-op03': useColorTransparency(amColors.value.colorInpText, 0.03), |
| 161 | '--am-c-inp-number-text-op40': useColorTransparency(amColors.value.colorInpText, 0.4), |
| 162 | '--am-c-inp-number-text-op60': useColorTransparency(amColors.value.colorInpText, 0.6), |
| 163 | '--am-c-inp-number-placeholder': amColors.value.colorInpPlaceHolder, |
| 164 | } |
| 165 | }) |
| 166 | </script> |
| 167 | |
| 168 | <style lang="scss"> |
| 169 | @mixin am-inp-number-block { |
| 170 | .am-input-number { |
| 171 | --am-c-inp-number-bgr: var(--am-c-inp-bgr); |
| 172 | --am-c-inp-number-border: var(--am-c-inp-border); |
| 173 | --am-c-inp-number-text: var(--am-c-inp-text); |
| 174 | --am-c-inp-number-placeholder: var(--am-c-inp-placeholder); |
| 175 | --am-rad-inp-number: var(--am-rad-inp); |
| 176 | --am-fs-inp-number: var(--am-fs-inp); |
| 177 | |
| 178 | &__default { |
| 179 | --am-input-number-height: 40px; |
| 180 | --am-input-number-padding: 8px 34px; |
| 181 | } |
| 182 | |
| 183 | &__medium { |
| 184 | --am-input-number-height: 36px; |
| 185 | --am-input-number-padding: 6px 34px; |
| 186 | } |
| 187 | |
| 188 | &__small { |
| 189 | --am-input-number-height: 32px; |
| 190 | --am-input-number-padding: 4px 34px; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | .el-input-number { |
| 195 | .el-input { |
| 196 | &__wrapper { |
| 197 | height: var(--am-input-number-height); |
| 198 | border: none; |
| 199 | border-radius: var(--am-rad-inp-number); |
| 200 | background-color: var(--am-c-inp-number-bgr); |
| 201 | box-shadow: 0 0 0 1px var(--am-c-inp-number-border); |
| 202 | padding: var(--am-input-number-padding); |
| 203 | box-sizing: border-box; |
| 204 | transition: all 0.3s ease-in-out; |
| 205 | |
| 206 | &.is-focus { |
| 207 | --am-c-inp-number-border: var(--am-c-primary); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | &__inner { |
| 212 | font-size: var(--am-fs-inp-number); |
| 213 | line-height: 1.6; |
| 214 | color: var(--am-c-inp-number-text); |
| 215 | border: none; |
| 216 | background: none; |
| 217 | padding: 0; |
| 218 | margin: 0; |
| 219 | max-width: 100%; |
| 220 | width: 100%; |
| 221 | |
| 222 | &::-webkit-input-placeholder { |
| 223 | /* Chrome/Opera/Safari */ |
| 224 | color: var(--am-c-inp-number-placeholder); |
| 225 | } |
| 226 | &::-moz-placeholder { |
| 227 | /* Firefox 19+ */ |
| 228 | color: var(--am-c-inp-number-placeholder); |
| 229 | } |
| 230 | &:-ms-input-placeholder { |
| 231 | /* IE 10+ */ |
| 232 | color: var(--am-c-inp-number-placeholder); |
| 233 | } |
| 234 | &:-moz-placeholder { |
| 235 | /* Firefox 18- */ |
| 236 | color: var(--am-c-inp-number-placeholder); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | &__decrease { |
| 242 | border-right-color: transparent; |
| 243 | } |
| 244 | |
| 245 | &__increase { |
| 246 | border-left-color: transparent; |
| 247 | } |
| 248 | |
| 249 | &__decrease, |
| 250 | &__increase { |
| 251 | background-color: transparent; |
| 252 | |
| 253 | &:hover { |
| 254 | .el-icon { |
| 255 | color: var(--am-c-inp-number-text); |
| 256 | border-radius: 4px; |
| 257 | background-color: var(--am-c-inp-number-text-op10); |
| 258 | } |
| 259 | |
| 260 | ~ .el-input:not(.is-disabled) .el-input__wrapper { |
| 261 | --am-c-inp-number-border: var(--am-c-primary); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | .el-icon { |
| 266 | width: 22px; |
| 267 | height: 22px; |
| 268 | color: var(--am-c-inp-number-text); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | &.is-disabled { |
| 273 | .el-icon { |
| 274 | color: var(--am-c-inp-number-text-op40); |
| 275 | } |
| 276 | |
| 277 | .el-input__wrapper { |
| 278 | background-color: var(--am-c-inp-number-text-op03); |
| 279 | color: var(--am-c-inp-number-text-op60); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // public |
| 286 | .amelia-v2-booking #amelia-container { |
| 287 | @include am-inp-number-block; |
| 288 | } |
| 289 | |
| 290 | // admin |
| 291 | #amelia-app-backend-new { |
| 292 | @include am-inp-number-block; |
| 293 | } |
| 294 | </style> |
| 295 |