2018-03-04 00:12:48 +00:00
|
|
|
<span class="compose-box-length {{overLimit ? 'over-char-limit' : ''}}"
|
2018-04-30 00:45:03 +00:00
|
|
|
aria-label={{lengthLabel}}>
|
2018-03-13 03:18:34 +00:00
|
|
|
{{lengthToDisplayDeferred || '0'}}
|
2018-02-27 05:50:03 +00:00
|
|
|
</span>
|
|
|
|
<style>
|
|
|
|
.compose-box-length {
|
|
|
|
grid-area: length;
|
|
|
|
justify-self: right;
|
|
|
|
color: var(--main-theme-color);
|
|
|
|
font-size: 1.3em;
|
|
|
|
align-self: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.compose-box-length.over-char-limit {
|
|
|
|
color: var(--warning-color);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import { CHAR_LIMIT } from '../../_static/statuses'
|
|
|
|
import { mark, stop } from '../../_utils/marks'
|
2018-02-27 06:22:56 +00:00
|
|
|
import { store } from '../../_store/store'
|
2018-03-13 03:18:34 +00:00
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
2018-02-27 05:50:03 +00:00
|
|
|
|
|
|
|
export default {
|
2018-04-20 04:38:01 +00:00
|
|
|
oncreate () {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { lengthToDisplay } = this.get()
|
|
|
|
this.set({lengthToDisplayDeferred: lengthToDisplay})
|
2018-02-27 06:22:56 +00:00
|
|
|
// perf improvement for keyboard input latency
|
2018-03-13 03:18:34 +00:00
|
|
|
this.observe('lengthToDisplay', () => {
|
|
|
|
scheduleIdleTask(() => {
|
|
|
|
mark('set lengthToDisplayDeferred')
|
2018-04-30 00:33:58 +00:00
|
|
|
let { lengthToDisplay } = this.get() || {} // https://github.com/sveltejs/svelte/issues/1354
|
2018-04-19 16:37:05 +00:00
|
|
|
this.set({lengthToDisplayDeferred: lengthToDisplay})
|
2018-03-13 03:18:34 +00:00
|
|
|
stop('set lengthToDisplayDeferred')
|
2018-02-27 05:50:03 +00:00
|
|
|
})
|
2018-03-13 03:18:34 +00:00
|
|
|
}, {init: false})
|
2018-02-27 05:50:03 +00:00
|
|
|
},
|
2018-02-27 06:22:56 +00:00
|
|
|
store: () => store,
|
2018-02-27 05:50:03 +00:00
|
|
|
computed: {
|
2018-03-04 00:12:48 +00:00
|
|
|
lengthToDisplay: (length) => CHAR_LIMIT - length,
|
2018-03-13 03:18:34 +00:00
|
|
|
lengthLabel: (overLimit, lengthToDisplayDeferred) => {
|
2018-03-04 00:12:48 +00:00
|
|
|
if (overLimit) {
|
2018-03-13 03:18:34 +00:00
|
|
|
return `${lengthToDisplayDeferred} characters over limit`
|
2018-02-27 05:50:03 +00:00
|
|
|
} else {
|
2018-03-13 03:18:34 +00:00
|
|
|
return `${lengthToDisplayDeferred} characters remaining`
|
2018-02-27 05:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|