From bfd4bd818e9ca092a1e447753dedd58bd713423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20FINDIKLI?= Date: Fri, 11 Dec 2020 14:25:13 +0300 Subject: [PATCH] Fixed #9641 - Chip Component --- src/app/components/chip/chip.css | 21 ++ src/app/components/chip/chip.spec.ts | 23 ++ src/app/components/chip/chip.ts | 57 +++++ src/app/components/chip/ng-package.json | 6 + src/app/components/chip/public_api.ts | 1 + src/app/showcase/app-routing.module.ts | 1 + src/app/showcase/app.menu.component.ts | 3 +- .../chip/chipdemo-routing.module.ts | 15 ++ .../showcase/components/chip/chipdemo.html | 210 ++++++++++++++++++ .../components/chip/chipdemo.module.ts | 25 +++ .../showcase/components/chip/chipdemo.scss | 4 + src/app/showcase/components/chip/chipdemo.ts | 8 + 12 files changed, 373 insertions(+), 1 deletion(-) create mode 100755 src/app/components/chip/chip.css create mode 100755 src/app/components/chip/chip.spec.ts create mode 100755 src/app/components/chip/chip.ts create mode 100644 src/app/components/chip/ng-package.json create mode 100644 src/app/components/chip/public_api.ts create mode 100644 src/app/showcase/components/chip/chipdemo-routing.module.ts create mode 100644 src/app/showcase/components/chip/chipdemo.html create mode 100644 src/app/showcase/components/chip/chipdemo.module.ts create mode 100644 src/app/showcase/components/chip/chipdemo.scss create mode 100644 src/app/showcase/components/chip/chipdemo.ts diff --git a/src/app/components/chip/chip.css b/src/app/components/chip/chip.css new file mode 100755 index 00000000000..40d2f56b5b4 --- /dev/null +++ b/src/app/components/chip/chip.css @@ -0,0 +1,21 @@ +.p-chip { + display: inline-flex; + align-items: center; +} + +.p-chip-text { + line-height: 1.5; +} + +.p-chip-icon.pi { + line-height: 1.5; +} + +.pi-chip-remove-icon { + line-height: 1.5; + cursor: pointer; +} + +.p-chip img { + border-radius: 50%; +} \ No newline at end of file diff --git a/src/app/components/chip/chip.spec.ts b/src/app/components/chip/chip.spec.ts new file mode 100755 index 00000000000..de201f235dd --- /dev/null +++ b/src/app/components/chip/chip.spec.ts @@ -0,0 +1,23 @@ +import { TestBed, ComponentFixture } from '@angular/core/testing'; +import { Chip, ChipModule } from './chip'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; + +describe('Chip', () => { + + let button: Chip; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + NoopAnimationsModule + ], + declarations: [ + ChipModule + ] + }); + + fixture = TestBed.createComponent(Chip); + button = fixture.componentInstance; + }); +}); diff --git a/src/app/components/chip/chip.ts b/src/app/components/chip/chip.ts new file mode 100755 index 00000000000..96d799e970b --- /dev/null +++ b/src/app/components/chip/chip.ts @@ -0,0 +1,57 @@ +import { NgModule, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'p-chip', + template: ` +
+ + + +
{{label}}
+ +
+ `, + changeDetection: ChangeDetectionStrategy.OnPush, + encapsulation: ViewEncapsulation.None, + styleUrls: ['./chip.css'] +}) +export class Chip { + + @Input() label: string; + + @Input() icon: string; + + @Input() image: string; + + @Input() style: any; + + @Input() styleClass: string; + + @Input() removable: boolean; + + @Input() removeIcon: string = "pi pi-times-circle"; + + @Output() remove: EventEmitter = new EventEmitter(); + + visible: boolean = true; + + containerClass() { + return { + 'p-chip p-component': true, + 'p-chip-image': this.image != null + }; + } + + close(event) { + this.visible = false; + this.remove.emit(event) + } +} + +@NgModule({ + imports: [CommonModule], + exports: [Chip], + declarations: [Chip] +}) +export class ChipModule { } diff --git a/src/app/components/chip/ng-package.json b/src/app/components/chip/ng-package.json new file mode 100644 index 00000000000..ab5467eb7e4 --- /dev/null +++ b/src/app/components/chip/ng-package.json @@ -0,0 +1,6 @@ +{ + "$schema": "ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "public_api.ts" + } + } \ No newline at end of file diff --git a/src/app/components/chip/public_api.ts b/src/app/components/chip/public_api.ts new file mode 100644 index 00000000000..8a86d21169f --- /dev/null +++ b/src/app/components/chip/public_api.ts @@ -0,0 +1 @@ +export * from './chip'; \ No newline at end of file diff --git a/src/app/showcase/app-routing.module.ts b/src/app/showcase/app-routing.module.ts index 4f40cc0a1ba..b70b8d74e8a 100755 --- a/src/app/showcase/app-routing.module.ts +++ b/src/app/showcase/app-routing.module.ts @@ -22,6 +22,7 @@ import { HomeComponent } from './components/home/home.component'; {path: 'carousel', loadChildren: () => import('./components/carousel/carouseldemo.module').then(m => m.CarouselDemoModule)}, {path: 'chart', loadChildren: () => import('./components/chart/chartdemo.module').then(m => m.ChartDemoModule)}, {path: 'checkbox', loadChildren: () => import('./components/checkbox/checkboxdemo.module').then(m => m.CheckboxDemoModule)}, + {path: 'chip', loadChildren: () => import('./components/chip/chipdemo.module').then(m => m.ChipDemoModule)}, {path: 'chips', loadChildren: () => import('./components/chips/chipsdemo.module').then(m => m.ChipsDemoModule)}, {path: 'codehighlighter', loadChildren: () => import('./components/codehighlighter/codehighlighterdemo.module').then(m => m.CodeHighlighterDemoModule)}, {path: 'colorpicker', loadChildren: () => import('./components/colorpicker/colorpickerdemo.module').then(m => m.ColorPickerDemoModule)}, diff --git a/src/app/showcase/app.menu.component.ts b/src/app/showcase/app.menu.component.ts index d146a19e5a5..802e73241c3 100644 --- a/src/app/showcase/app.menu.component.ts +++ b/src/app/showcase/app.menu.component.ts @@ -266,9 +266,10 @@ declare let gtag: Function;