Add truncate component

This commit is contained in:
Marliana Lara
2017-07-06 12:11:29 -04:00
parent 73ea0b348a
commit 3cc522de8f
5 changed files with 56 additions and 18 deletions
+4 -2
View File
@@ -19,6 +19,7 @@ import panelBody from './panel/body.directive';
import popover from './popover/popover.directive';
import tab from './tabs/tab.directive';
import tabGroup from './tabs/group.directive';
import truncate from './truncate/truncate.directive';
import BaseInputController from './input/base.controller';
import ComponentsStrings from './components.strings';
@@ -46,7 +47,8 @@ angular
.directive('atPopover', popover)
.directive('atTab', tab)
.directive('atTabGroup', tabGroup)
.service('BaseInputController', BaseInputController)
.service('ComponentsStrings', ComponentsStrings);
.directive('atTruncate', truncate)
.service('ComponentsStrings', ComponentsStrings)
.service('BaseInputController', BaseInputController);
@@ -0,0 +1,43 @@
function atTruncateLink (scope, el, attr, ctrl) {
let truncateController = ctrl;
let string = attr.atTruncate;
let maxlength = attr.maxlength;
truncateController.init(scope, string, maxlength);
}
function AtTruncateController ($filter) {
let vm = this;
let string,
maxlength;
vm.init = (scope, _string_, _maxlength_) => {
string = _string_;
maxlength = _maxlength_;
vm.truncatedString = $filter('limitTo')(string, maxlength, 0);
}
}
function atTruncate($filter) {
return {
restrict: 'EA',
replace: true,
transclude: true,
template: '<span>{{vm.truncatedString}}</span>',
controller: AtTruncateController,
controllerAs: 'vm',
link: atTruncateLink,
scope: {
maxLength: '@'
}
}
}
atTruncate.$inject = [
'$filter'
];
export default atTruncate;