| 1 |
<template> |
| 2 |
<ElInputNumber |
| 3 |
ref="elInputNumberRef" |
| 4 |
v-bind="{ ...$attrs, ...$props }" |
| 5 |
v-model="localModelValue" |
| 6 |
value-on-clear="min" |
| 7 |
:placeholder="''" |
| 8 |
class="ivyforms-input-number" |
| 9 |
:class="[ |
| 10 |
{ |
| 11 |
'ivyforms-full-width': fullWidth, |
| 12 |
'is-filled': props.filled, |
| 13 |
'is-secondary': props.secondary, |
| 14 |
}, |
| 15 |
]" |
| 16 |
> |
| 17 |
<template #decrease-icon> |
| 18 |
<IvyIcon |
| 19 |
priority="tertiary" |
| 20 |
name="minus" |
| 21 |
size="s" |
| 22 |
type="outline" |
| 23 |
color="var(--map-base-dusk-symbol-2)" |
| 24 |
/> |
| 25 |
</template> |
| 26 |
<template #increase-icon> |
| 27 |
<IvyIcon |
| 28 |
priority="tertiary" |
| 29 |
name="plus" |
| 30 |
size="s" |
| 31 |
type="outline" |
| 32 |
color="var(--map-base-dusk-symbol-2)" |
| 33 |
/> |
| 34 |
</template> |
| 35 |
</ElInputNumber> |
| 36 |
</template> |
| 37 |
|
| 38 |
<script setup lang="ts"> |
| 39 |
import { computed, ref } from 'vue' |
| 40 |
|
| 41 |
interface Props { |
| 42 |
modelValue: number | undefined | null |
| 43 |
min?: number |
| 44 |
max?: number |
| 45 |
fullWidth?: boolean |
| 46 |
filled?: boolean |
| 47 |
secondary?: boolean |
| 48 |
} |
| 49 |
|
| 50 |
const props = withDefaults(defineProps<Props>(), { |
| 51 |
fullWidth: true, |
| 52 |
min: Number.MIN_SAFE_INTEGER, |
| 53 |
max: Number.MAX_SAFE_INTEGER, |
| 54 |
}) |
| 55 |
|
| 56 |
const emit = defineEmits(['update:modelValue', 'input']) |
| 57 |
|
| 58 |
const elInputNumberRef = ref() |
| 59 |
|
| 60 |
const localModelValue = computed({ |
| 61 |
get() { |
| 62 |
return props.modelValue === null ? undefined : props.modelValue |
| 63 |
}, |
| 64 |
set(value) { |
| 65 |
emit('update:modelValue', value === undefined || value === null ? null : value) |
| 66 |
}, |
| 67 |
}) |
| 68 |
|
| 69 |
const focus = () => { |
| 70 |
elInputNumberRef.value?.focus() |
| 71 |
} |
| 72 |
|
| 73 |
defineExpose({ |
| 74 |
focus, |
| 75 |
}) |
| 76 |
</script> |
| 77 |
|
| 78 |
<style lang="scss"> |
| 79 |
// Error and warning states (for use in form item context) |
| 80 |
.el-form-item { |
| 81 |
&.is-error { |
| 82 |
.ivyforms-input-number { |
| 83 |
&.el-input-number { |
| 84 |
.el-input__wrapper { |
| 85 |
border: 1px solid var(--map-status-error-symbol-0); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
&.is-warning { |
| 92 |
.ivyforms-input-number { |
| 93 |
&.el-input-number { |
| 94 |
.el-input__wrapper { |
| 95 |
border: 1px solid var(--map-status-warning-stroke-0); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
.ivyforms-input-number { |
| 103 |
display: flex; |
| 104 |
height: 40px; |
| 105 |
min-height: 40px; |
| 106 |
background: var(--map-base-dusk-o05); |
| 107 |
|
| 108 |
// Element Input Number |
| 109 |
&.el-input-number { |
| 110 |
// Decrease and Increase Buttons |
| 111 |
.el-input-number__decrease, |
| 112 |
.el-input-number__increase { |
| 113 |
border: 0; |
| 114 |
background: transparent; |
| 115 |
|
| 116 |
// Icon |
| 117 |
svg path { |
| 118 |
@include transition(fill); |
| 119 |
} |
| 120 |
|
| 121 |
// Hover |
| 122 |
&:hover { |
| 123 |
// Wrapper |
| 124 |
~ .el-input:not(.is-disabled) .el-input__wrapper { |
| 125 |
border-color: var(--map-base-dusk-stroke-0); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
// Disabled |
| 130 |
&.is-disabled { |
| 131 |
opacity: 0.5; |
| 132 |
|
| 133 |
// Button |
| 134 |
button { |
| 135 |
cursor: not-allowed; |
| 136 |
|
| 137 |
// Transition |
| 138 |
.ivyforms-button-action__transition { |
| 139 |
display: none; |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
// Input Wrapper |
| 146 |
.el-input__wrapper { |
| 147 |
height: 40px; |
| 148 |
min-height: 40px; |
| 149 |
border-radius: 8px; |
| 150 |
padding: 0 40px; |
| 151 |
box-shadow: none !important; |
| 152 |
border: 1px solid var(--map-base-dusk-stroke--2); |
| 153 |
background-color: transparent; |
| 154 |
|
| 155 |
// Hover |
| 156 |
&:hover { |
| 157 |
border-color: var(--map-base-dusk-stroke-0); |
| 158 |
} |
| 159 |
|
| 160 |
// Active |
| 161 |
&:active, |
| 162 |
&:focus, |
| 163 |
&.is-focus, |
| 164 |
&.is-active { |
| 165 |
border-color: var(--map-base-brand-fill-0); |
| 166 |
} |
| 167 |
|
| 168 |
// Native Input |
| 169 |
.el-input__inner { |
| 170 |
box-shadow: none !important; |
| 171 |
border: 0; |
| 172 |
padding: 0; |
| 173 |
font-size: 16px; |
| 174 |
color: var(--map-base-text-0); |
| 175 |
background-color: transparent; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
// Decrease Button |
| 180 |
.el-input-number__decrease { |
| 181 |
@include flipProperty(left, right, 12px); |
| 182 |
} |
| 183 |
|
| 184 |
// Increase Button |
| 185 |
.el-input-number__increase { |
| 186 |
@include flipProperty(right, left, 12px); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
// Full Width |
| 191 |
&.ivyforms-full-width { |
| 192 |
width: 100%; |
| 193 |
} |
| 194 |
|
| 195 |
// Secondary |
| 196 |
&.is-secondary { |
| 197 |
&.el-input-number { |
| 198 |
.el-input__wrapper { |
| 199 |
&:active, |
| 200 |
&:focus, |
| 201 |
&.is-focus, |
| 202 |
&.is-active { |
| 203 |
border: 1px solid var(--map-base-purple-stroke-0) !important; |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
</style> |
| 210 |
|