瀏覽代碼

Add fancy textarea

sbkwgh 8 年之前
父節點
當前提交
b8de9e5e60
共有 1 個文件被更改,包括 72 次插入0 次删除
  1. 72 0
      src/components/FancyTextarea.vue

+ 72 - 0
src/components/FancyTextarea.vue

@@ -0,0 +1,72 @@
+<template>
+	<div class='fancy_textarea'>
+		<div
+			class='fancy_textarea__placeholder'
+			:class='{"fancy_textarea__placeholder--active": active || value.length}'
+		>
+			{{placeholder}}
+		</div>
+		<textarea
+			class='input fancy_textarea__textarea'
+			v-bind:value='value'
+			v-bind:style='{width: width || "10rem"}'
+			v-on:input='updateValue($event.target.value)'
+			@focus='addActive'
+			@blur='removeActive'
+		>
+		</textarea>
+	</div>
+</template>
+
+<script>
+	export default {
+		name: 'FancyTextarea',
+		props: ['value', 'placeholder', 'width'],
+		data () {
+			return {
+				active: false
+			}
+		},
+		methods: {
+			updateValue (val) {
+				this.$emit('input', val);
+			},
+			addActive () {
+				this.active = true;
+			},
+			removeActive () {
+				this.active = false;
+			}
+		}
+	}
+</script>
+
+<style lang='scss' scoped>
+	@import '../assets/scss/variables.scss';
+
+	.fancy_textarea {
+		position: relative;
+		margin-top: 0.25rem;
+		margin-bottom: 0.5rem;
+
+		@at-root #{&}__textarea {
+			height: 5rem;
+		}
+
+		@at-root #{&}__placeholder {
+			position: absolute;
+			top: 0.35rem;
+			background-color: #fff;
+			left: 0.35rem;
+			color: $color__gray--darkest;
+			pointer-events: none;
+			transition: top 0.2s, font-size 0.2s;
+
+			@at-root #{&}--active {
+				top: -0.5rem;
+				font-size: 0.75rem;
+				transition: top 0.2s, font-size 0.2s;
+			}
+		}
+	}
+</style>