<template>
  <div class="input">
    <label>
      <span class="label"><slot></slot></span>
      <input type="text"
             :placeholder="placeholder"
             :class="{error: error}"
             v-bind:value="value"
             v-on:input="input">
    </label>
  </div>
</template>

<script>
export default {
  name: "text-input",
  props: ['value', 'placeholder', 'error'],
  methods: {
    input: function(event) {
      this.$emit('clearError', null);
      this.$emit('input', event.target.value)
    }
  }
}
</script>

<style scoped>
.label {
  font-size: 80%;
}

input {
  width: 100%;
  margin-top: 0.2rem;
}

input.error {
  background-color: rgba(255, 0, 0, 0.3);
  border-color: var(--error);
}
</style>
