Last active
October 11, 2020 19:46
-
-
Save camskene/eb41dba370818e244a2d73cc80813765 to your computer and use it in GitHub Desktop.
TruncateText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Truncate Text'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
font-size: 16px; | |
} | |
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', sans-serif; | |
font-size: 1rem; | |
} | |
.clamp-1 { | |
display: -webkit-box; | |
-webkit-line-clamp: 1; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} | |
.clamp-2 { | |
display: -webkit-box; | |
-webkit-line-clamp: 2; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} | |
.clamp-3 { | |
display: -webkit-box; | |
-webkit-line-clamp: 3; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} | |
.clamp-4 { | |
display: -webkit-box; | |
-webkit-line-clamp: 4; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} | |
.clamp-5 { | |
display: -webkit-box; | |
-webkit-line-clamp: 5; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} | |
.clamp-6 { | |
display: -webkit-box; | |
-webkit-line-clamp: 6; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { action } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class TruncateTextComponent extends Component { | |
@tracked hasTextOverflow; | |
get numLines() { | |
return parseInt(this.args.numLines ?? 1, 10); | |
} | |
get maxLines() { | |
return this.numLines + this.wiggleRoom; | |
} | |
get wiggleRoom() { | |
return parseInt(this.args.wiggleRoom ?? 0, 10); | |
} | |
@action | |
onDidInsert(element) { | |
this.resizeObserver(element); | |
} | |
@action | |
willTextOverflow(element) { | |
let { scrollHeight, clientHeight } = element; | |
let hasTextOverflow = scrollHeight !== clientHeight; | |
console.log(hasTextOverflow, scrollHeight, clientHeight); | |
return hasTextOverflow; | |
} | |
@action | |
resizeObserver(element) { | |
let ro = new ResizeObserver((entries) => { | |
for (let entry of entries) { | |
this.hasTextOverflow = this.willTextOverflow(entry.target); | |
} | |
}); | |
ro.observe(element); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": true, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"@ember/render-modifiers": "1.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment