1
0
mirror of https://github.com/nolanlawson/pinafore synced 2025-02-11 00:40:39 +01:00

46 lines
1.3 KiB
HTML
Raw Normal View History

2018-03-03 16:12:48 -08:00
<span class="compose-box-length {{overLimit ? 'over-char-limit' : ''}}"
2018-03-03 14:51:48 -08:00
aria-label="{{lengthLabel}}">
{{lengthToDisplayAfterRaf || '0'}}
2018-02-26 21:50:03 -08: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-26 22:22:56 -08:00
import { store } from '../../_store/store'
2018-02-26 21:50:03 -08:00
export default {
oncreate() {
2018-02-26 22:22:56 -08:00
// perf improvement for keyboard input latency
2018-03-03 14:51:48 -08:00
this.observe('lengthToDisplay', lengthToDisplay => {
2018-02-26 21:50:03 -08:00
requestAnimationFrame(() => {
2018-03-03 14:51:48 -08:00
mark('set lengthToDisplayAfterRaf')
this.set({lengthToDisplayAfterRaf: lengthToDisplay})
stop('set lengthToDisplayAfterRaf')
2018-02-26 21:50:03 -08:00
})
})
},
2018-02-26 22:22:56 -08:00
store: () => store,
2018-02-26 21:50:03 -08:00
computed: {
2018-03-03 16:12:48 -08:00
lengthToDisplay: (length) => CHAR_LIMIT - length,
lengthLabel: (overLimit, lengthToDisplay) => {
if (overLimit) {
2018-03-03 14:51:48 -08:00
return `${lengthToDisplay} characters over limit`
2018-02-26 21:50:03 -08:00
} else {
2018-03-03 14:51:48 -08:00
return `${lengthToDisplay} characters remaining`
2018-02-26 21:50:03 -08:00
}
}
}
}
</script>