-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ACS-9012] Add the option to truncate disaplay value in text column
- Loading branch information
1 parent
0014fed
commit 8f25c18
Showing
10 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
Title: Truncate pipe | ||
Added: v7.0.0-alpha.7 | ||
Status: Active | ||
Last reviewed: 2024-11-28 | ||
--- | ||
|
||
# Truncate Pipe | ||
|
||
Truncates the text when it exceeds specified max lenght. It also appends provided ellipsis at the end of the string. | ||
|
||
## Basic Usage | ||
|
||
<!-- {% raw %} --> | ||
|
||
```HTML | ||
<div> | ||
{{ textToTruncate | truncate:100:'***' }} | ||
</div> | ||
``` | ||
|
||
<!-- {% endraw %} --> | ||
|
||
| Name | Type | Default value | Description | | ||
|--------|--------|---------------|-------------------------------------------------| | ||
| maxTextLength | `number` | 250 | Max length of the text that should be displayed prio to truncating. | | ||
| ellipsis | `string` | `...` | String which will be appended to the text when truncating will happen. | |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { TruncatePipe } from './truncate.pipe'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { CoreTestingModule } from '../testing/core.testing.module'; | ||
import { Injector, runInInjectionContext } from '@angular/core'; | ||
|
||
describe('TruncatePipe', () => { | ||
let pipe: TruncatePipe; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CoreTestingModule] | ||
}); | ||
const injector = TestBed.inject(Injector); | ||
runInInjectionContext(injector, () => { | ||
pipe = new TruncatePipe(); | ||
}); | ||
}); | ||
|
||
it('should truncate texts longer than maxTextLength value', () => { | ||
const text = 'This is a long text'; | ||
expect(pipe.transform(text, 10)).toBe('This is a ...'); | ||
}); | ||
|
||
it('should not truncate texts shorter than maxTextLength value', () => { | ||
const text = 'Short text'; | ||
expect(pipe.transform(text, 20)).toBe('Short text'); | ||
}); | ||
|
||
it('should truncate texts longer than 250 chars and append "..." by default', () => { | ||
let text = | ||
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes,'; | ||
text += ' nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.'; | ||
let truncatedString = | ||
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, '; | ||
truncatedString += 'nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium ...'; | ||
expect(pipe.transform(text)).toBe(truncatedString); | ||
}); | ||
|
||
it('should append custom ellipsis when ellipsis param is provided', () => { | ||
const text = 'This is a long text'; | ||
expect(pipe.transform(text, 10, '***')).toBe('This is a ***'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'truncate' | ||
}) | ||
export class TruncatePipe implements PipeTransform { | ||
transform(value: string, maxTextLength = 250, ellipsis = '...') { | ||
return value.length > maxTextLength ? value.substr(0, maxTextLength) + ellipsis : value; | ||
} | ||
} |
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