46 lines
		
	
	
		
			No EOL
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			No EOL
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<span class="compose-box-length {{overLimit ? 'over-char-limit' : ''}}"
 | 
						|
      aria-label="{{lengthLabel}}">
 | 
						|
      {{lengthToDisplayAfterRaf || '0'}}
 | 
						|
    </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'
 | 
						|
  import { store } from '../../_store/store'
 | 
						|
 | 
						|
  export default {
 | 
						|
    oncreate() {
 | 
						|
      // perf improvement for keyboard input latency
 | 
						|
      this.observe('lengthToDisplay', lengthToDisplay => {
 | 
						|
        requestAnimationFrame(() => {
 | 
						|
          mark('set lengthToDisplayAfterRaf')
 | 
						|
          this.set({lengthToDisplayAfterRaf: lengthToDisplay})
 | 
						|
          stop('set lengthToDisplayAfterRaf')
 | 
						|
        })
 | 
						|
      })
 | 
						|
    },
 | 
						|
    store: () => store,
 | 
						|
    computed: {
 | 
						|
      lengthToDisplay: (length) => CHAR_LIMIT - length,
 | 
						|
      lengthLabel: (overLimit, lengthToDisplay) => {
 | 
						|
        if (overLimit) {
 | 
						|
          return `${lengthToDisplay} characters over limit`
 | 
						|
        } else {
 | 
						|
          return `${lengthToDisplay} characters remaining`
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
</script> |