summaryrefslogtreecommitdiff
path: root/src/client/app/common/views/components/ui/textarea.vue
blob: 60fe1cdd8221114357d07d3477fcb6203e3e7a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
<div class="ui-textarea" :class="{ focused, filled }">
	<div class="input">
		<span class="label" ref="label"><slot></slot></span>
		<textarea ref="input"
				:value="value"
				:required="required"
				:readonly="readonly"
				:pattern="pattern"
				:autocomplete="autocomplete"
				@input="$emit('input', $event.target.value)"
				@focus="focused = true"
				@blur="focused = false">
		</textarea>
	</div>
	<div class="text"><slot name="text"></slot></div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
const getPasswordStrength = require('syuilo-password-strength');

export default Vue.extend({
	props: {
		value: {
			required: false
		},
		required: {
			type: Boolean,
			required: false
		},
		readonly: {
			type: Boolean,
			required: false
		},
		pattern: {
			type: String,
			required: false
		},
		autocomplete: {
			type: String,
			required: false
		}
	},
	data() {
		return {
			focused: false,
			passwordStrength: ''
		}
	},
	computed: {
		filled(): boolean {
			return this.value != '' && this.value != null;
		}
	},
	methods: {
		focus() {
			this.$refs.input.focus();
		}
	}
});
</script>

<style lang="stylus" scoped>
@import '~const.styl'

root(isDark, fill)
	margin 42px 0 32px 0

	> .input
		padding 12px

		if fill
			background rgba(#000, 0.035)
			border-radius 6px
		else
			&:before
				content ''
				display block
				position absolute
				top 0
				bottom 0
				left 0
				right 0
				background none
				border solid 1px isDark ? rgba(#fff, 0.7) : rgba(#000, 0.42)
				border-radius 3px
				pointer-events none

			&:after
				content ''
				display block
				position absolute
				top 0
				bottom 0
				left 0
				right 0
				background none
				border solid 2px $theme-color
				border-radius 3px
				opacity 0
				transition opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1)
				pointer-events none

		> .label
			position absolute
			top 6px
			left 12px
			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
			color isDark ? rgba(#fff, 0.7) : rgba(#000, 0.54)
			pointer-events none
			//will-change transform
			transform-origin top left
			transform scale(1)

		> textarea
			display block
			width 100%
			min-height 100px
			padding 0
			font inherit
			font-weight fill ? bold : normal
			font-size 16px
			color isDark ? #fff : #000
			background transparent
			border none
			border-radius 0
			outline none
			box-shadow none

	> .text
		margin 6px 0
		font-size 13px

		*
			margin 0

	&.focused
		> .input
			if fill
				background rgba(#000, 0.05)
			else
				&:after
					opacity 1

			> .label
				color $theme-color

	&.focused
	&.filled
		> .input
			> .label
				top -24px
				left 0 !important
				transform scale(0.75)

.ui-textarea[data-darkmode]
	&.fill
		root(true, true)
	&:not(.fill)
		root(true, false)

.ui-textarea:not([data-darkmode])
	&.fill
		root(false, true)
	&:not(.fill)
		root(false, false)

</style>