2018-06-13 21:29:01 +00:00
|
|
|
<template>
|
2018-06-14 09:53:02 +00:00
|
|
|
<div class="ui-input" :class="[{ focused, filled }, styl]">
|
|
|
|
<div class="icon" ref="icon"><slot name="icon"></slot></div>
|
2018-06-14 22:56:56 +00:00
|
|
|
<div class="input" @click="focus" @mousedown="focus">
|
2018-06-14 05:52:37 +00:00
|
|
|
<div class="password-meter" v-if="withPasswordMeter" v-show="passwordStrength != ''" :data-strength="passwordStrength">
|
|
|
|
<div class="value" ref="passwordMetar"></div>
|
|
|
|
</div>
|
2018-06-13 21:29:01 +00:00
|
|
|
<span class="label" ref="label"><slot></slot></span>
|
2018-06-14 05:52:37 +00:00
|
|
|
<div class="prefix" ref="prefix"><slot name="prefix"></slot></div>
|
2018-06-14 09:53:02 +00:00
|
|
|
<template v-if="type != 'file'">
|
|
|
|
<input ref="input"
|
|
|
|
:type="type"
|
|
|
|
:value="v"
|
|
|
|
:required="required"
|
|
|
|
:readonly="readonly"
|
|
|
|
:pattern="pattern"
|
|
|
|
:autocomplete="autocomplete"
|
|
|
|
@input="$emit('input', $event.target.value)"
|
|
|
|
@focus="focused = true"
|
|
|
|
@blur="focused = false">
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<input ref="input"
|
|
|
|
type="text"
|
|
|
|
:value="placeholder"
|
|
|
|
readonly
|
|
|
|
@click="chooseFile">
|
|
|
|
<input ref="file"
|
|
|
|
type="file"
|
|
|
|
:value="value"
|
|
|
|
@change="onChangeFile">
|
|
|
|
</template>
|
2018-06-14 05:52:37 +00:00
|
|
|
<div class="suffix"><slot name="suffix"></slot></div>
|
2018-06-13 21:29:01 +00:00
|
|
|
</div>
|
2018-06-14 00:51:55 +00:00
|
|
|
<div class="text"><slot name="text"></slot></div>
|
2018-06-13 21:29:01 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-06-14 05:52:37 +00:00
|
|
|
const getPasswordStrength = require('syuilo-password-strength');
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
export default Vue.extend({
|
2018-06-14 00:51:55 +00:00
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
readonly: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
2018-06-14 05:52:37 +00:00
|
|
|
},
|
|
|
|
pattern: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
autocomplete: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
withPasswordMeter: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2018-06-14 00:51:55 +00:00
|
|
|
}
|
|
|
|
},
|
2018-06-13 21:29:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2018-06-14 09:53:02 +00:00
|
|
|
v: this.value,
|
2018-06-14 05:52:37 +00:00
|
|
|
focused: false,
|
2018-06-14 09:53:02 +00:00
|
|
|
passwordStrength: '',
|
|
|
|
styl: 'fill'
|
|
|
|
};
|
2018-06-13 21:29:01 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
filled(): boolean {
|
2018-06-14 09:53:02 +00:00
|
|
|
return this.v != '' && this.v != null;
|
|
|
|
},
|
|
|
|
placeholder(): string {
|
|
|
|
if (this.type != 'file') return null;
|
|
|
|
if (this.v == null) return null;
|
|
|
|
|
|
|
|
if (typeof this.v == 'string') return this.v;
|
|
|
|
|
|
|
|
if (Array.isArray(this.v)) {
|
|
|
|
return this.v.map(file => file.name).join(', ');
|
|
|
|
} else {
|
|
|
|
return this.v.name;
|
|
|
|
}
|
2018-06-13 21:29:01 +00:00
|
|
|
}
|
|
|
|
},
|
2018-06-14 05:52:37 +00:00
|
|
|
watch: {
|
|
|
|
value(v) {
|
2018-06-14 09:53:02 +00:00
|
|
|
this.v = v;
|
|
|
|
},
|
|
|
|
v(v) {
|
2018-06-14 05:52:37 +00:00
|
|
|
if (this.withPasswordMeter) {
|
|
|
|
if (v == '') {
|
|
|
|
this.passwordStrength = '';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const strength = getPasswordStrength(v);
|
|
|
|
this.passwordStrength = strength > 0.7 ? 'high' : strength > 0.3 ? 'medium' : 'low';
|
|
|
|
(this.$refs.passwordMetar as any).style.width = `${strength * 100}%`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-06-14 22:56:56 +00:00
|
|
|
inject: {
|
|
|
|
isCardChild: { default: false }
|
|
|
|
},
|
2018-06-14 09:53:02 +00:00
|
|
|
created() {
|
|
|
|
if (this.isCardChild) {
|
|
|
|
this.styl = 'line';
|
|
|
|
}
|
|
|
|
},
|
2018-06-13 21:29:01 +00:00
|
|
|
mounted() {
|
2018-06-14 05:52:37 +00:00
|
|
|
if (this.$refs.prefix) {
|
|
|
|
this.$refs.label.style.left = (this.$refs.prefix.offsetLeft + this.$refs.prefix.offsetWidth) + 'px';
|
|
|
|
}
|
2018-06-13 21:29:01 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
focus() {
|
|
|
|
this.$refs.input.focus();
|
2018-06-14 09:53:02 +00:00
|
|
|
},
|
|
|
|
chooseFile() {
|
|
|
|
this.$refs.file.click();
|
|
|
|
},
|
|
|
|
onChangeFile() {
|
|
|
|
this.v = Array.from((this.$refs.file as any).files);
|
|
|
|
this.$emit('input', this.v);
|
|
|
|
this.$emit('change', this.v);
|
2018-06-13 21:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
@import '~const.styl'
|
|
|
|
|
2018-06-14 09:53:02 +00:00
|
|
|
root(isDark, fill)
|
2018-06-14 05:52:37 +00:00
|
|
|
margin 32px 0
|
2018-06-13 21:29:01 +00:00
|
|
|
|
2018-06-14 09:53:02 +00:00
|
|
|
> .icon
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
width 24px
|
|
|
|
text-align center
|
|
|
|
line-height 32px
|
2018-06-14 12:38:39 +00:00
|
|
|
color isDark ? rgba(#fff, 0.7) : rgba(#000, 0.54)
|
2018-06-14 09:53:02 +00:00
|
|
|
|
|
|
|
&:not(:empty) + .input
|
|
|
|
margin-left 28px
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
> .input
|
|
|
|
display flex
|
2018-06-14 22:56:56 +00:00
|
|
|
cursor text
|
2018-06-14 09:53:02 +00:00
|
|
|
|
|
|
|
if fill
|
|
|
|
padding 6px 12px
|
|
|
|
background rgba(#000, 0.035)
|
|
|
|
border-radius 6px
|
|
|
|
else
|
|
|
|
&:before
|
|
|
|
content ''
|
|
|
|
display block
|
|
|
|
position absolute
|
|
|
|
bottom 0
|
|
|
|
left 0
|
|
|
|
right 0
|
|
|
|
height 1px
|
2018-06-14 12:38:39 +00:00
|
|
|
background isDark ? rgba(#fff, 0.7) : rgba(#000, 0.42)
|
2018-06-14 09:53:02 +00:00
|
|
|
|
|
|
|
&:after
|
|
|
|
content ''
|
|
|
|
display block
|
|
|
|
position absolute
|
|
|
|
bottom 0
|
|
|
|
left 0
|
|
|
|
right 0
|
|
|
|
height 2px
|
|
|
|
background $theme-color
|
|
|
|
opacity 0
|
|
|
|
transform scaleX(0.12)
|
|
|
|
transition border 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1)
|
|
|
|
will-change border opacity transform
|
2018-06-13 21:29:01 +00:00
|
|
|
|
2018-06-14 05:52:37 +00:00
|
|
|
> .password-meter
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
height 100%
|
|
|
|
border-radius 6px
|
|
|
|
overflow hidden
|
|
|
|
opacity 0.3
|
|
|
|
|
|
|
|
&[data-strength='']
|
|
|
|
display none
|
|
|
|
|
|
|
|
&[data-strength='low']
|
|
|
|
> .value
|
|
|
|
background #d73612
|
|
|
|
|
|
|
|
&[data-strength='medium']
|
|
|
|
> .value
|
|
|
|
background #d7ca12
|
|
|
|
|
|
|
|
&[data-strength='high']
|
|
|
|
> .value
|
|
|
|
background #61bb22
|
|
|
|
|
|
|
|
> .value
|
|
|
|
display block
|
|
|
|
width 0%
|
|
|
|
height 100%
|
|
|
|
background transparent
|
|
|
|
border-radius 6px
|
|
|
|
transition all 0.1s ease
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
> .label
|
|
|
|
position absolute
|
2018-06-14 09:53:02 +00:00
|
|
|
top fill ? 6px : 0
|
2018-06-13 21:29:01 +00:00
|
|
|
left 0
|
|
|
|
pointer-events none
|
|
|
|
transition 0.4s cubic-bezier(0.25, 0.8, 0.25, 1)
|
|
|
|
transition-duration 0.3s
|
|
|
|
font-size 16px
|
|
|
|
line-height 32px
|
2018-06-14 12:38:39 +00:00
|
|
|
color isDark ? rgba(#fff, 0.7) : rgba(#000, 0.54)
|
2018-06-13 21:29:01 +00:00
|
|
|
pointer-events none
|
2018-06-14 05:52:37 +00:00
|
|
|
//will-change transform
|
|
|
|
transform-origin top left
|
|
|
|
transform scale(1)
|
2018-06-13 21:29:01 +00:00
|
|
|
|
|
|
|
> input
|
|
|
|
display block
|
|
|
|
flex 1
|
|
|
|
width 100%
|
2018-06-15 00:33:25 +00:00
|
|
|
margin 0
|
2018-06-13 21:29:01 +00:00
|
|
|
padding 0
|
2018-06-13 22:22:50 +00:00
|
|
|
font inherit
|
2018-06-14 09:53:02 +00:00
|
|
|
font-weight fill ? bold : normal
|
2018-06-13 21:29:01 +00:00
|
|
|
font-size 16px
|
|
|
|
line-height 32px
|
2018-06-14 12:38:39 +00:00
|
|
|
color isDark ? #fff : #000
|
2018-06-13 21:29:01 +00:00
|
|
|
background transparent
|
|
|
|
border none
|
|
|
|
border-radius 0
|
|
|
|
outline none
|
|
|
|
box-shadow none
|
|
|
|
|
2018-06-14 09:53:02 +00:00
|
|
|
&[type='file']
|
|
|
|
display none
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
> .prefix
|
|
|
|
> .suffix
|
|
|
|
display block
|
|
|
|
align-self center
|
|
|
|
justify-self center
|
|
|
|
font-size 16px
|
|
|
|
line-height 32px
|
2018-06-14 12:38:39 +00:00
|
|
|
color isDark ? rgba(#fff, 0.7) : rgba(#000, 0.54)
|
2018-06-14 05:52:37 +00:00
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
> *
|
|
|
|
display block
|
|
|
|
min-width 16px
|
2018-06-13 21:29:01 +00:00
|
|
|
|
|
|
|
> .prefix
|
|
|
|
padding-right 4px
|
|
|
|
|
|
|
|
> .suffix
|
|
|
|
padding-left 4px
|
|
|
|
|
2018-06-14 00:51:55 +00:00
|
|
|
> .text
|
2018-06-14 05:52:37 +00:00
|
|
|
margin 6px 0
|
|
|
|
font-size 13px
|
2018-06-14 00:51:55 +00:00
|
|
|
|
2018-06-14 05:52:37 +00:00
|
|
|
*
|
2018-06-14 00:51:55 +00:00
|
|
|
margin 0
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
&.focused
|
|
|
|
> .input
|
2018-06-14 09:53:02 +00:00
|
|
|
if fill
|
|
|
|
background rgba(#000, 0.05)
|
|
|
|
else
|
|
|
|
&:after
|
|
|
|
opacity 1
|
|
|
|
transform scaleX(1)
|
2018-06-13 21:29:01 +00:00
|
|
|
|
|
|
|
> .label
|
|
|
|
color $theme-color
|
|
|
|
|
|
|
|
&.focused
|
|
|
|
&.filled
|
|
|
|
> .input
|
|
|
|
> .label
|
2018-06-14 12:38:39 +00:00
|
|
|
top fill ? -24px : -17px
|
2018-06-13 21:29:01 +00:00
|
|
|
left 0 !important
|
2018-06-14 12:38:39 +00:00
|
|
|
transform scale(0.75)
|
2018-06-13 21:29:01 +00:00
|
|
|
|
2018-06-14 09:53:02 +00:00
|
|
|
.ui-input[data-darkmode]
|
|
|
|
&.fill
|
|
|
|
root(true, true)
|
|
|
|
&:not(.fill)
|
|
|
|
root(true, false)
|
|
|
|
|
|
|
|
.ui-input:not([data-darkmode])
|
|
|
|
&.fill
|
|
|
|
root(false, true)
|
|
|
|
&:not(.fill)
|
|
|
|
root(false, false)
|
|
|
|
|
2018-06-13 21:29:01 +00:00
|
|
|
</style>
|