InputEditor.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div
  3. class='input_editor input_editor--float'
  4. :class='{
  5. "input_editor--hidden": !show,
  6. "input_editor--focus-input": focusInput
  7. }'
  8. >
  9. <div class='input_editor__reply_username' v-if='replyUsername'>Replying to <strong>{{replyUsername}}</strong></div>
  10. <div class='input_editor__close input_editor__format_button' @click='closeEditor'>&times;</div>
  11. <tab-view :tabs='["Editor", "Preview"]' v-model='showTab' :small-tabs='true'>
  12. <template slot='Editor'>
  13. <input-editor-core
  14. :value='value'
  15. :error='error'
  16. @input='emitInput'
  17. @focus='setFocusInput(true)'
  18. @blur='setFocusInput(false)'
  19. ></input-editor-core>
  20. </template>
  21. <template slot='Preview'>
  22. <input-editor-preview :value='value'></input-editor-preview>
  23. </template>
  24. </tab-view>
  25. <div class='input_editor__submit_bar'>
  26. <button class='button' @click='submit'>Submit</button>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import InputEditorCore from './InputEditorCore'
  32. import InputEditorPreview from './InputEditorPreview'
  33. import TabView from './TabView'
  34. export default {
  35. name: 'InputEditor',
  36. props: ['value', 'error', 'replyUsername', 'show'],
  37. components: {
  38. InputEditorCore,
  39. InputEditorPreview,
  40. TabView
  41. },
  42. data () {
  43. return {
  44. showTab: 0,
  45. focusInput: false
  46. }
  47. },
  48. methods: {
  49. submit () {
  50. if(this.value.trim().length) {
  51. this.$emit('submit');
  52. }
  53. },
  54. closeEditor () {
  55. this.emitInput('')
  56. this.$emit('close')
  57. },
  58. emitInput (val) {
  59. this.$emit('input', val)
  60. },
  61. setFocusInput (val) {
  62. this.focusInput = val
  63. }
  64. },
  65. watch: {
  66. show () {
  67. this.$el.querySelector('textarea').focus()
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang='scss' scoped>
  73. @import '../assets/scss/variables.scss';
  74. .input_editor {
  75. width: 35rem;
  76. border: 0.125rem solid $color__gray--darker;
  77. border-bottom: none;
  78. margin-bottom: 0;
  79. pointer-events: all;
  80. transition: margin-bottom 0.2s, filter 0.2s, border-color 0.2s;
  81. outline: none;
  82. position: fixed;
  83. z-index: 2;
  84. bottom: 0;
  85. @at-root #{&}--focus-input {
  86. border-color: $color__gray--darkest;
  87. }
  88. @at-root #{&}--hidden {
  89. pointer-events: none;
  90. opacity: 0;
  91. margin-bottom: -3rem;
  92. transition: margin-bottom 0.2s, opacity 0.2s;
  93. }
  94. @at-root #{&}__close {
  95. position: absolute;
  96. right: 0.3rem;
  97. top: 0.5rem;
  98. height: 1.5rem;
  99. width: 1.5rem;
  100. text-align: center;
  101. line-height: 1.4rem;
  102. cursor: pointer;
  103. @include user-select(none);
  104. @include text($font--role-default, 1rem, 600);
  105. color: $color__darkgray--primary;
  106. border: thin solid $color__gray--primary;
  107. transition: background-color 0.2s;
  108. margin: 0;
  109. &:hover {
  110. background-color: $color__gray--darker;
  111. }
  112. &:active {
  113. background-color: $color__gray--darkest;
  114. }
  115. }
  116. @at-root #{&}__reply_username {
  117. position: absolute;
  118. width: 100%;
  119. text-align: center;
  120. top: 0.5rem;
  121. }
  122. @at-root #{&}__submit_bar {
  123. display: flex;
  124. justify-content: flex-end;
  125. height: 2rem;
  126. align-items: center;
  127. padding-right: 0.3rem;
  128. background-color: $color__gray--primary;
  129. button {
  130. font-size: 0.8rem;
  131. height: 1.5rem;
  132. padding: 0 0.25rem;
  133. border-color: $color__gray--darkest;
  134. }
  135. }
  136. }
  137. </style>