pinafore/routes/_components/compose/ComposeBox.html

164 lines
4.6 KiB
HTML
Raw Normal View History

2018-02-26 05:45:11 +01:00
<div class="lite-compose-box {{overLimit ? 'over-char-limit' : ''}}">
2018-02-27 06:50:03 +01:00
<div class="compose-box-current-user">
<Avatar account="{{verifyCredentials}}" className="compose-box-avatar" size="small"/>
<a class="compose-box-display-name" href="/accounts/{{verifyCredentials.id}}">
2018-02-26 01:26:43 +01:00
{{verifyCredentials.display_name || verifyCredentials.acct}}
</a>
2018-02-27 06:50:03 +01:00
<span class="compose-box-handle">
2018-02-26 01:26:43 +01:00
{{'@' + verifyCredentials.acct}}
</span>
<textarea
2018-02-27 06:50:03 +01:00
class="compose-box-input"
2018-02-26 01:26:43 +01:00
placeholder="What's on your mind?"
ref:textarea
bind:value=inputText
></textarea>
2018-02-27 06:50:03 +01:00
<ComposeLengthGauge :inputLength />
<ComposeToolbar />
<ComposeLengthIndicator :inputLength />
<button class="primary compose-box-button">
2018-02-26 01:26:43 +01:00
Toot!
</button>
</div>
</div>
<style>
.lite-compose-box {
display: grid;
flex-direction: row;
}
2018-02-27 06:50:03 +01:00
.compose-box-current-user {
2018-02-26 01:26:43 +01: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 01:26:43 +01:00
border-bottom: 1px solid var(--main-border);
width: 560px;
max-width: calc(100vw - 40px);
}
2018-02-27 06:50:03 +01:00
:global(.compose-box-avatar) {
2018-02-26 01:26:43 +01:00
grid-area: avatar;
margin-right: 15px;
}
2018-02-27 06:50:03 +01:00
.compose-box-display-name {
2018-02-26 01:26:43 +01:00
color: var(--deemphasized-text-color);
grid-area: display-name;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 1.1em;
margin-left: 5px;
font-weight: 600;
}
2018-02-27 06:50:03 +01:00
.compose-box-display-name,
.compose-box-display-name:hover,
.compose-box-display-name:visited {
2018-02-26 01:26:43 +01:00
color: var(--body-text-color);
}
2018-02-27 06:50:03 +01:00
:global(.compose-box-handle) {
2018-02-26 01:26:43 +01:00
grid-area: handle;
color: var(--deemphasized-text-color);
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 1.1em;
margin-left: 5px;
}
2018-02-27 06:50:03 +01:00
:global(.compose-box-input) {
2018-02-26 01:26:43 +01:00
grid-area: input;
margin: 10px 0 0 5px;
2018-02-26 09:24:28 +01:00
padding: 10px;
2018-02-26 01:26:43 +01:00
border: 1px solid var(--input-border);
min-height: 75px;
resize: none;
2018-02-26 02:21:17 +01:00
overflow: hidden;
2018-02-26 07:29:12 +01:00
word-wrap: break-word;
2018-02-26 06:12:22 +01: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 05:45:11 +01:00
width: calc(100% - 5px);
2018-02-26 01:26:43 +01:00
}
2018-02-27 06:50:03 +01:00
.compose-box-button {
2018-02-26 01:26:43 +01:00
grid-area: button;
justify-self: right;
text-transform: uppercase;
2018-02-26 02:21:17 +01:00
margin-top: 10px;
}
2018-02-26 01:26:43 +01:00
@media (max-width: 767px) {
2018-02-27 06:50:03 +01:00
.compose-box-current-user {
2018-02-26 01:26:43 +01:00
padding: 10px 10px;
max-width: calc(100vw - 20px);
width: 580px;
}
2018-02-27 06:50:03 +01:00
:global(.compose-box-avatar) {
2018-02-26 01:26:43 +01:00
grid-area: avatar;
margin-right: 5px;
}
}
</style>
<script>
import Avatar from '../Avatar.html'
import { store } from '../../_store/store'
2018-02-26 05:45:11 +01:00
import { autosize } from '../../_utils/autosize'
2018-02-26 01:26:43 +01:00
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
import debounce from 'lodash/debounce'
2018-02-26 01:47:45 +01:00
import { mark, stop } from '../../_utils/marks'
2018-02-27 06:50:03 +01:00
import ComposeToolbar from './ComposeToolbar.html'
import ComposeLengthGauge from './ComposeLengthGauge.html'
import ComposeLengthIndicator from './ComposeLengthIndicator.html'
2018-02-26 02:21:17 +01:00
2018-02-26 01:26:43 +01:00
export default {
oncreate() {
this.set({inputText: store.get('currentInputTextInCompose')})
2018-02-26 07:50:50 +01:00
requestAnimationFrame(() => {
mark('autosize()')
autosize(this.refs.textarea)
stop('autosize()')
})
const saveText = debounce(() => scheduleIdleTask(() => this.store.save()), 1000)
2018-02-26 01:26:43 +01: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 01:47:45 +01:00
mark('autosize.destroy()')
2018-02-26 01:26:43 +01:00
autosize.destroy(this.refs.textarea)
2018-02-26 01:47:45 +01:00
stop('autosize.destroy()')
2018-02-26 01:26:43 +01:00
},
data: () => ({
inputText: ''
}),
components: {
Avatar,
2018-02-27 06:50:03 +01:00
ComposeToolbar,
ComposeLengthGauge,
ComposeLengthIndicator
2018-02-26 01:26:43 +01:00
},
store: () => store,
computed: {
2018-02-26 02:21:17 +01:00
currentInputTextInCompose: ($currentInputTextInCompose) => $currentInputTextInCompose,
inputLength: (inputText) => inputText ? inputText.length : 0,
2018-02-26 01:26:43 +01:00
}
}
2018-02-26 09:24:28 +01:00
</script>