| 
									
										
										
										
											2018-03-03 16:12:48 -08:00
										 |  |  | <div class="compose-box-length-gauge {{shouldAnimate ? 'should-animate' : ''}}  {{overLimit ? 'over-char-limit' : ''}}" | 
					
						
							| 
									
										
										
										
											2018-02-26 21:50:03 -08:00
										 |  |  |      style="transform: scaleX({{inputLengthAsFractionRoundedAfterRaf || 0}});" | 
					
						
							|  |  |  |      aria-hidden="true" | 
					
						
							|  |  |  | ></div> | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   .compose-box-length-gauge { | 
					
						
							|  |  |  |     grid-area: gauge; | 
					
						
							|  |  |  |     margin: 0 0 5px 5px; | 
					
						
							|  |  |  |     height: 2px; | 
					
						
							|  |  |  |     background: var(--main-theme-color); | 
					
						
							|  |  |  |     transform-origin: left; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .compose-box-length-gauge.should-animate { | 
					
						
							|  |  |  |     transition: transform 0.2s linear; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .compose-box-length-gauge.over-char-limit { | 
					
						
							|  |  |  |     background: 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-02-26 21:50:03 -08:00
										 |  |  |       this.observe('inputLengthAsFractionRounded', inputLengthAsFractionRounded => { | 
					
						
							|  |  |  |         requestAnimationFrame(() => { | 
					
						
							|  |  |  |           mark('set inputLengthAsFractionRoundedAfterRaf') | 
					
						
							|  |  |  |           this.set({inputLengthAsFractionRoundedAfterRaf: inputLengthAsFractionRounded}) | 
					
						
							|  |  |  |           stop('set inputLengthAsFractionRoundedAfterRaf') | 
					
						
							|  |  |  |           requestAnimationFrame(() => this.set({shouldAnimate: true})) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       lengthAsFraction: (length) => Math.min(CHAR_LIMIT, length) / CHAR_LIMIT, | 
					
						
							| 
									
										
										
										
											2018-03-03 14:51:48 -08:00
										 |  |  |       lengthAsFractionRounded: (lengthAsFraction) => { | 
					
						
							| 
									
										
										
										
											2018-02-26 21:50:03 -08:00
										 |  |  |         // We don't need to update the gauge for every decimal point, so round it to the nearest 0.02 | 
					
						
							| 
									
										
										
										
											2018-03-03 14:51:48 -08:00
										 |  |  |         let int = Math.round(lengthAsFraction * 100) | 
					
						
							| 
									
										
										
										
											2018-02-26 21:50:03 -08:00
										 |  |  |         int -= (int % 2) | 
					
						
							|  |  |  |         return int / 100 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </script> |