2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2022-05-15 00:23:22 +02:00
|
|
|
<div ref="wrapper" class="relative">
|
2024-06-29 23:15:55 +02:00
|
|
|
<input
|
|
|
|
:id="inputId"
|
|
|
|
:name="inputName"
|
|
|
|
ref="input"
|
|
|
|
v-model="inputValue"
|
|
|
|
:type="actualType"
|
|
|
|
:step="step"
|
|
|
|
:min="min"
|
|
|
|
:readonly="readonly"
|
|
|
|
:disabled="disabled"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
dir="auto"
|
|
|
|
class="rounded bg-primary text-gray-200 focus:border-gray-300 focus:bg-bg focus:outline-none border border-gray-600 h-full w-full"
|
|
|
|
:class="classList"
|
|
|
|
@keyup="keyup"
|
|
|
|
@change="change"
|
|
|
|
@focus="focused"
|
|
|
|
@blur="blurred"
|
|
|
|
/>
|
2021-10-07 04:08:52 +02:00
|
|
|
<div v-if="clearable && inputValue" class="absolute top-0 right-0 h-full px-2 flex items-center justify-center">
|
|
|
|
<span class="material-icons text-gray-300 cursor-pointer" style="font-size: 1.1rem" @click.stop.prevent="clear">close</span>
|
|
|
|
</div>
|
2022-05-15 00:23:22 +02:00
|
|
|
<div v-if="type === 'password' && isHovering" class="absolute top-0 right-0 h-full px-4 flex items-center justify-center">
|
|
|
|
<span class="material-icons-outlined text-gray-400 cursor-pointer text-lg" @click.stop.prevent="showPassword = !showPassword">{{ !showPassword ? 'visibility' : 'visibility_off' }}</span>
|
|
|
|
</div>
|
2024-06-29 23:15:55 +02:00
|
|
|
<div v-else-if="showCopy" class="absolute top-0 right-0 h-full px-4 flex items-center justify-center">
|
|
|
|
<span class="material-icons-outlined text-gray-400 cursor-pointer text-lg" @click.stop.prevent="copyToClipboard">{{ !hasCopied ? 'content_copy' : 'done' }}</span>
|
|
|
|
</div>
|
2021-10-07 04:08:52 +02:00
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: [String, Number],
|
|
|
|
placeholder: String,
|
|
|
|
readonly: Boolean,
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: 'text'
|
|
|
|
},
|
2021-09-05 20:21:02 +02:00
|
|
|
disabled: Boolean,
|
|
|
|
paddingY: {
|
|
|
|
type: Number,
|
|
|
|
default: 2
|
|
|
|
},
|
|
|
|
paddingX: {
|
|
|
|
type: Number,
|
|
|
|
default: 3
|
2021-10-07 04:08:52 +02:00
|
|
|
},
|
2021-10-09 00:30:20 +02:00
|
|
|
noSpinner: Boolean,
|
|
|
|
textCenter: Boolean,
|
2022-12-29 05:00:40 +01:00
|
|
|
clearable: Boolean,
|
2023-04-09 22:37:49 +02:00
|
|
|
inputId: String,
|
2024-03-13 23:46:56 +01:00
|
|
|
inputName: String,
|
2024-06-29 23:15:55 +02:00
|
|
|
showCopy: Boolean,
|
2023-04-09 22:37:49 +02:00
|
|
|
step: [String, Number],
|
|
|
|
min: [String, Number]
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
data() {
|
2022-05-15 00:23:22 +02:00
|
|
|
return {
|
|
|
|
showPassword: false,
|
2022-08-18 01:44:21 +02:00
|
|
|
isHovering: false,
|
2024-06-29 23:15:55 +02:00
|
|
|
isFocused: false,
|
|
|
|
hasCopied: false
|
2022-05-15 00:23:22 +02:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
inputValue: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
2021-09-05 20:21:02 +02:00
|
|
|
},
|
|
|
|
classList() {
|
|
|
|
var _list = []
|
|
|
|
_list.push(`px-${this.paddingX}`)
|
|
|
|
_list.push(`py-${this.paddingY}`)
|
2021-10-09 00:30:20 +02:00
|
|
|
if (this.noSpinner) _list.push('no-spinner')
|
|
|
|
if (this.textCenter) _list.push('text-center')
|
2021-09-05 20:21:02 +02:00
|
|
|
return _list.join(' ')
|
2022-05-15 00:23:22 +02:00
|
|
|
},
|
|
|
|
actualType() {
|
|
|
|
if (this.type === 'password' && this.showPassword) return 'text'
|
|
|
|
return this.type
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-06-29 23:15:55 +02:00
|
|
|
copyToClipboard() {
|
|
|
|
if (this.hasCopied) return
|
|
|
|
this.$copyToClipboard(this.inputValue).then((success) => {
|
|
|
|
this.hasCopied = success
|
|
|
|
setTimeout(() => {
|
|
|
|
this.hasCopied = false
|
|
|
|
}, 2000)
|
|
|
|
})
|
|
|
|
},
|
2021-10-07 04:08:52 +02:00
|
|
|
clear() {
|
|
|
|
this.inputValue = ''
|
2023-10-28 21:32:11 +02:00
|
|
|
this.$emit('clear')
|
2021-10-07 04:08:52 +02:00
|
|
|
},
|
2021-08-21 23:23:35 +02:00
|
|
|
focused() {
|
2022-08-18 01:44:21 +02:00
|
|
|
this.isFocused = true
|
2021-08-21 23:23:35 +02:00
|
|
|
this.$emit('focus')
|
|
|
|
},
|
|
|
|
blurred() {
|
2022-08-18 01:44:21 +02:00
|
|
|
this.isFocused = false
|
2021-08-21 23:23:35 +02:00
|
|
|
this.$emit('blur')
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
change(e) {
|
|
|
|
this.$emit('change', e.target.value)
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
|
|
|
keyup(e) {
|
|
|
|
this.$emit('keyup', e)
|
2021-09-24 23:14:33 +02:00
|
|
|
},
|
|
|
|
blur() {
|
|
|
|
if (this.$refs.input) this.$refs.input.blur()
|
2022-05-15 00:23:22 +02:00
|
|
|
},
|
2022-08-04 01:38:08 +02:00
|
|
|
setFocus() {
|
|
|
|
if (this.$refs.input) this.$refs.input.focus()
|
|
|
|
},
|
2022-05-15 00:23:22 +02:00
|
|
|
mouseover() {
|
|
|
|
this.isHovering = true
|
|
|
|
},
|
|
|
|
mouseleave() {
|
|
|
|
this.isHovering = false
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
2022-05-15 00:23:22 +02:00
|
|
|
mounted() {
|
|
|
|
if (this.type === 'password' && this.$refs.wrapper) {
|
|
|
|
this.$refs.wrapper.addEventListener('mouseover', this.mouseover)
|
|
|
|
this.$refs.wrapper.addEventListener('mouseleave', this.mouseleave)
|
|
|
|
}
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
input {
|
|
|
|
border-style: inherit !important;
|
|
|
|
}
|
|
|
|
input:read-only {
|
2022-02-17 21:33:12 +01:00
|
|
|
color: #bbb;
|
2021-08-18 00:01:11 +02:00
|
|
|
background-color: #444;
|
|
|
|
}
|
2022-04-13 00:32:27 +02:00
|
|
|
input::-webkit-calendar-picker-indicator {
|
|
|
|
filter: invert(1);
|
|
|
|
}
|
2024-03-13 23:46:56 +01:00
|
|
|
</style>
|