Skip to content

Commit

Permalink
Merge pull request #32 from casejs/feature/truncate
Browse files Browse the repository at this point in the history
truncate text yields
  • Loading branch information
brunobuddy authored Jul 11, 2023
2 parents 6b64653 + aaaf463 commit 8dbadc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NgModule } from '@angular/core'
import { ReactiveFormsModule } from '@angular/forms'

import { AppRoutingModule } from '../app-routing.module'
import { TruncatePipe } from '../pipes/truncate.pipe'
import { SettingsService } from '../services/settings.service'
import { DynamicEntityCreateEditComponent } from './components/dynamic-entity-create-edit/dynamic-entity-create-edit.component'
import { DynamicEntityDetailComponent } from './components/dynamic-entity-detail/dynamic-entity-detail.component'
Expand Down Expand Up @@ -49,6 +50,7 @@ import { YieldComponent } from './yields/yield.component'
CurrencyYieldComponent,
DateYieldComponent,
EmailYieldComponent,
TruncatePipe,
FilterComponent,
MultiSelectInputComponent
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input } from '@angular/core'

@Component({
selector: 'app-text-yield',
template: `{{ value }}`,
template: `{{ value | truncate : ['30'] }}`,
styleUrls: ['./text-yield.component.scss']
})
export class TextYieldComponent {
Expand Down
12 changes: 12 additions & 0 deletions packages/case/client/src/app/pipes/truncate.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core'

@Pipe({
name: 'truncate'
})
export class TruncatePipe implements PipeTransform {
transform(value: string, args: string[]): string {
const limit = args.length > 0 ? parseInt(args[0], 10) : 20
const trail = args.length > 1 ? args[1] : '...'
return value.length > limit ? value.substring(0, limit) + trail : value
}
}

0 comments on commit 8dbadc2

Please sign in to comment.