InputEditor.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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__overlay' :class='{ "input_editor__overlay--show" : loading }'>
  10. <loading-icon></loading-icon>
  11. </div>
  12. <div class='input_editor__reply_username' v-if='replyUsername'>Replying to <strong>{{replyUsername}}</strong></div>
  13. <div class='input_editor__close input_editor__format_button' @click='closeEditor'>&times;</div>
  14. <tab-view :tabs='["Editor", "Preview"]' v-model='showTab' :small-tabs='true'>
  15. <template slot='Editor'>
  16. <input-editor-core
  17. :value='value'
  18. :error='error'
  19. @input='emitInput'
  20. @mentions='emitMentions'
  21. @focus='setFocusInput(true)'
  22. @blur='setFocusInput(false)'
  23. ></input-editor-core>
  24. </template>
  25. <template slot='Preview'>
  26. <input-editor-preview :value='value' :mentions='mentions'></input-editor-preview>
  27. </template>
  28. </tab-view>
  29. <div class='input_editor__submit_bar'>
  30. <button class='button button--thin_text' @click='submit'>Submit</button>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import InputEditorCore from './InputEditorCore'
  36. import InputEditorPreview from './InputEditorPreview'
  37. import LoadingIcon from './LoadingIcon'
  38. import TabView from './TabView'
  39. export default {
  40. name: 'InputEditor',
  41. props: ['value', 'error', 'replyUsername', 'show', 'loading'],
  42. components: {
  43. InputEditorCore,
  44. InputEditorPreview,
  45. LoadingIcon,
  46. TabView
  47. },
  48. data () {
  49. return {
  50. showTab: 0,
  51. mentions: [],
  52. focusInput: false
  53. }
  54. },
  55. methods: {
  56. submit () {
  57. if(this.value.trim().length) {
  58. this.$emit('submit');
  59. }
  60. },
  61. closeEditor () {
  62. this.emitInput('')
  63. this.$emit('close')
  64. },
  65. emitMentions (mentions) {
  66. this.mentions = mentions
  67. this.$emit('mentions', mentions)
  68. },
  69. emitInput (val) {
  70. this.$emit('input', val)
  71. },
  72. setFocusInput (val) {
  73. this.focusInput = val
  74. }
  75. },
  76. watch: {
  77. show (val) {
  78. let textarea
  79. if(val) this.showTab = 0
  80. textarea = this.$el.querySelector('textarea')
  81. if(textarea) textarea.focus()
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang='scss' scoped>
  87. @import '../assets/scss/variables.scss';
  88. .input_editor {
  89. width: 35rem;
  90. border: 0.125rem solid $color__gray--darker;
  91. border-bottom: none;
  92. border-radius: 0.25rem 0.25rem 0 0;
  93. margin-bottom: 0;
  94. pointer-events: all;
  95. transition: margin-bottom 0.2s, filter 0.2s, border-color 0.2s;
  96. outline: none;
  97. position: fixed;
  98. z-index: 2;
  99. bottom: 0;
  100. @at-root #{&}--focus-input {
  101. border-color: $color__gray--darkest;
  102. }
  103. @at-root #{&}--hidden {
  104. pointer-events: none;
  105. opacity: 0;
  106. margin-bottom: -3rem;
  107. transition: margin-bottom 0.2s, opacity 0.2s;
  108. }
  109. @at-root #{&}__overlay {
  110. position: absolute;
  111. left: 0;
  112. top: 0;
  113. height: 100%;
  114. width: 100%;
  115. z-index: 5;
  116. background-color: rgba(0, 0, 0, 0.15);
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. pointer-events: none;
  121. opacity: 0;
  122. transition: all 0.2s;
  123. @at-root #{&}--show {
  124. pointer-events: all;
  125. opacity: 1;
  126. }
  127. }
  128. @at-root #{&}__close {
  129. position: absolute;
  130. right: 0.3rem;
  131. top: 0.5rem;
  132. height: 1.5rem;
  133. width: 1.5rem;
  134. text-align: center;
  135. line-height: 1.4rem;
  136. cursor: pointer;
  137. @include user-select(none);
  138. @include text($font--role-default, 1rem, 600);
  139. color: $color__darkgray--primary;
  140. border: thin solid $color__gray--primary;
  141. border-radius: 0.25rem;
  142. transition: background-color 0.2s;
  143. margin: 0;
  144. &:hover {
  145. background-color: $color__gray--darker;
  146. }
  147. &:active {
  148. background-color: $color__gray--darkest;
  149. }
  150. }
  151. @at-root #{&}__reply_username {
  152. position: absolute;
  153. width: 100%;
  154. text-align: center;
  155. top: 0.5rem;
  156. }
  157. @at-root #{&}__submit_bar {
  158. display: flex;
  159. justify-content: flex-end;
  160. height: 2rem;
  161. align-items: center;
  162. padding-right: 0.3rem;
  163. background-color: $color__gray--primary;
  164. button {
  165. font-size: 0.8rem;
  166. height: 1.5rem;
  167. padding: 0 0.25rem;
  168. border-radius: 3px;
  169. border-color: $color__gray--darkest;
  170. }
  171. }
  172. }
  173. @media (max-width: 420px) {
  174. .input_editor {
  175. width: 100%;
  176. left: 0;
  177. @at-root #{&}__reply_username {
  178. top: auto;
  179. bottom: 0.5rem;
  180. left: 0.5rem;
  181. width: auto;
  182. }
  183. }
  184. }
  185. </style>