semaphore/routes/_components/compose/ComposeBox.html

118 lines
3.4 KiB
HTML
Raw Normal View History

2018-02-27 05:54:21 +00:00
<div class="compose-box {{overLimit ? 'over-char-limit' : ''}}">
<ComposeAuthor :verifyCredentials />
<textarea
class="compose-box-input"
placeholder="What's on your mind?"
ref:textarea
bind:value=inputText
></textarea>
<ComposeLengthGauge :inputLength />
<ComposeToolbar />
<ComposeLengthIndicator :inputLength />
<button class="primary compose-box-button">
Toot!
</button>
2018-02-26 00:26:43 +00:00
</div>
<style>
2018-02-27 05:54:21 +00:00
.compose-box {
2018-02-26 00:26:43 +00:00
border-radius: 4px;
padding: 20px;
display: grid;
align-items: flex-start;
grid-template-areas:
"avatar display-name handle handle"
"avatar input input input"
"avatar gauge gauge gauge"
"avatar toolbar toolbar length"
"avatar button button button";
grid-template-columns: min-content minmax(0, max-content) 1fr 1fr;
2018-02-26 00:26:43 +00:00
border-bottom: 1px solid var(--main-border);
width: 560px;
max-width: calc(100vw - 40px);
}
2018-02-27 05:50:03 +00:00
:global(.compose-box-input) {
2018-02-26 00:26:43 +00:00
grid-area: input;
margin: 10px 0 0 5px;
2018-02-26 08:24:28 +00:00
padding: 10px;
2018-02-26 00:26:43 +00:00
border: 1px solid var(--input-border);
min-height: 75px;
resize: none;
2018-02-26 01:21:17 +00:00
overflow: hidden;
2018-02-26 06:29:12 +00:00
word-wrap: break-word;
2018-02-26 05:12:22 +00:00
/* Text must be at least 16px or else iOS Safari zooms in */
font-size: 1.2em;
/* Hack to make Edge stretch the element all the way to the right.
* Also desktop Safari makes the gauge stretch too far to the right without it.
*/
2018-02-26 04:45:11 +00:00
width: calc(100% - 5px);
2018-02-26 00:26:43 +00:00
}
2018-02-27 05:50:03 +00:00
.compose-box-button {
2018-02-26 00:26:43 +00:00
grid-area: button;
justify-self: right;
text-transform: uppercase;
2018-02-26 01:21:17 +00:00
margin-top: 10px;
}
2018-02-26 00:26:43 +00:00
@media (max-width: 767px) {
2018-02-27 05:54:21 +00:00
.compose-box {
2018-02-26 00:26:43 +00:00
padding: 10px 10px;
max-width: calc(100vw - 20px);
width: 580px;
}
}
</style>
<script>
import { store } from '../../_store/store'
2018-02-26 04:45:11 +00:00
import { autosize } from '../../_utils/autosize'
2018-02-26 00:26:43 +00:00
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
import debounce from 'lodash/debounce'
2018-02-26 00:47:45 +00:00
import { mark, stop } from '../../_utils/marks'
2018-02-27 05:50:03 +00:00
import ComposeToolbar from './ComposeToolbar.html'
import ComposeLengthGauge from './ComposeLengthGauge.html'
import ComposeLengthIndicator from './ComposeLengthIndicator.html'
2018-02-27 05:54:21 +00:00
import ComposeAuthor from './ComposeAuthor.html'
2018-02-26 01:21:17 +00:00
2018-02-26 00:26:43 +00:00
export default {
oncreate() {
this.set({inputText: store.get('currentInputTextInCompose')})
2018-02-26 06:50:50 +00:00
requestAnimationFrame(() => {
mark('autosize()')
autosize(this.refs.textarea)
stop('autosize()')
})
const saveText = debounce(() => scheduleIdleTask(() => this.store.save()), 1000)
2018-02-26 00:26:43 +00:00
this.observe('inputText', inputText => {
let inputTextInCompose = this.store.get('inputTextInCompose')
let currentInstance = this.store.get('currentInstance')
inputTextInCompose[currentInstance] = inputText || ''
this.store.set({inputTextInCompose: inputTextInCompose})
saveText()
}, {init: false})
},
ondestroy() {
2018-02-26 00:47:45 +00:00
mark('autosize.destroy()')
2018-02-26 00:26:43 +00:00
autosize.destroy(this.refs.textarea)
2018-02-26 00:47:45 +00:00
stop('autosize.destroy()')
2018-02-26 00:26:43 +00:00
},
data: () => ({
inputText: ''
}),
components: {
2018-02-27 05:54:21 +00:00
ComposeAuthor,
2018-02-27 05:50:03 +00:00
ComposeToolbar,
ComposeLengthGauge,
ComposeLengthIndicator
2018-02-26 00:26:43 +00:00
},
store: () => store,
computed: {
2018-02-26 01:21:17 +00:00
currentInputTextInCompose: ($currentInputTextInCompose) => $currentInputTextInCompose,
inputLength: (inputText) => inputText ? inputText.length : 0,
2018-02-26 00:26:43 +00:00
}
}
2018-02-26 08:24:28 +00:00
</script>