-
Notifications
You must be signed in to change notification settings - Fork 12
Add Angular support for nimble-chip component #2822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ca74cf
Add nimble chip directive
6d2e92d
Change files
0ee19e1
Typo
5b8d523
Use private email for change file
4ae72ce
Update the component status for chip Angular support
fd90479
Remove event and address comments
16abea7
Merge branch 'main' into users/vivin/add-directive-for-nimble-chip
rajsite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-angular-9ecc4cd6-b0a5-467e-b0e8-ef1705ef2c54.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Angular integration for nimble-chip component", | ||
| "packageName": "@ni/nimble-angular", | ||
| "email": "123377523+vivinkrishna-ni@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
packages/angular-workspace/nimble-angular/chip/ng-package.json
This file contains hidden or 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,6 @@ | ||
| { | ||
| "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json", | ||
| "lib": { | ||
| "entryFile": "public-api.ts" | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
packages/angular-workspace/nimble-angular/chip/nimble-chip.directive.ts
This file contains hidden or 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,43 @@ | ||
| import { Directive, ElementRef, Input, Renderer2 } from '@angular/core'; | ||
| import { type Chip, chipTag } from '@ni/nimble-components/dist/esm/chip'; | ||
| import { ChipAppearance } from '@ni/nimble-components/dist/esm/chip/types'; | ||
| import { type BooleanValueOrAttribute, toBooleanProperty } from '@ni/nimble-angular/internal-utilities'; | ||
|
|
||
| export type { Chip }; | ||
| export { chipTag }; | ||
| export { ChipAppearance }; | ||
|
|
||
| /** | ||
| * Directive to provide Angular integration for the chip. | ||
| */ | ||
| @Directive({ | ||
| selector: 'nimble-chip', | ||
| standalone: false | ||
| }) | ||
| export class NimbleChipDirective { | ||
| public get removable(): boolean { | ||
| return this.elementRef.nativeElement.removable; | ||
| } | ||
|
|
||
| @Input() public set removable(value: BooleanValueOrAttribute) { | ||
| this.renderer.setProperty(this.elementRef.nativeElement, 'removable', toBooleanProperty(value)); | ||
| } | ||
|
|
||
| public get disabled(): boolean { | ||
| return this.elementRef.nativeElement.disabled; | ||
| } | ||
|
|
||
| @Input() public set disabled(value: BooleanValueOrAttribute) { | ||
| this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', toBooleanProperty(value)); | ||
| } | ||
|
|
||
| public get appearance(): ChipAppearance { | ||
| return this.elementRef.nativeElement.appearance; | ||
| } | ||
|
|
||
| @Input() public set appearance(value: ChipAppearance) { | ||
| this.renderer.setProperty(this.elementRef.nativeElement, 'appearance', value); | ||
| } | ||
|
|
||
| public constructor(private readonly renderer: Renderer2, private readonly elementRef: ElementRef<Chip>) {} | ||
| } |
12 changes: 12 additions & 0 deletions
12
packages/angular-workspace/nimble-angular/chip/nimble-chip.module.ts
This file contains hidden or 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,12 @@ | ||
| import { NgModule } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { NimbleChipDirective } from './nimble-chip.directive'; | ||
|
|
||
| import '@ni/nimble-components/dist/esm/chip'; | ||
|
|
||
| @NgModule({ | ||
| declarations: [NimbleChipDirective], | ||
| imports: [CommonModule], | ||
| exports: [NimbleChipDirective] | ||
| }) | ||
| export class NimbleChipModule { } |
This file contains hidden or 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,2 @@ | ||
| export * from './nimble-chip.directive'; | ||
| export * from './nimble-chip.module'; |
3 changes: 3 additions & 0 deletions
3
packages/angular-workspace/nimble-angular/chip/testing/chip.pageobject.ts
This file contains hidden or 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,3 @@ | ||
| import { ChipPageObject } from '@ni/nimble-components/dist/esm/chip/testing/chip.pageobject'; | ||
|
|
||
| export { ChipPageObject }; |
6 changes: 6 additions & 0 deletions
6
packages/angular-workspace/nimble-angular/chip/testing/ng-package.json
This file contains hidden or 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,6 @@ | ||
| { | ||
| "$schema": "../../../../../node_modules/ng-packagr/ng-package.schema.json", | ||
| "lib": { | ||
| "entryFile": "public-api.ts" | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/angular-workspace/nimble-angular/chip/testing/public-api.ts
This file contains hidden or 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 @@ | ||
| export { ChipPageObject } from './chip.pageobject'; |
244 changes: 244 additions & 0 deletions
244
packages/angular-workspace/nimble-angular/chip/tests/nimble-chip.directive.spec.ts
This file contains hidden or 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,244 @@ | ||
| import { Component, ElementRef, ViewChild } from '@angular/core'; | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import type { BooleanValueOrAttribute } from '@ni/nimble-angular/internal-utilities'; | ||
| import { type Chip, ChipAppearance, NimbleChipDirective } from '../nimble-chip.directive'; | ||
| import { NimbleChipModule } from '../nimble-chip.module'; | ||
|
|
||
| describe('Nimble chip', () => { | ||
| describe('module', () => { | ||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [NimbleChipModule] | ||
| }); | ||
| }); | ||
|
|
||
| it('custom element is defined', () => { | ||
| expect(customElements.get('nimble-chip')).not.toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with no values in template', () => { | ||
| @Component({ | ||
| template: ` | ||
| <nimble-chip #chip></nimble-chip> | ||
| `, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('chip', { read: NimbleChipDirective }) public directive: NimbleChipDirective; | ||
| @ViewChild('chip', { read: ElementRef }) public elementRef: ElementRef<Chip>; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: NimbleChipDirective; | ||
| let nativeElement: Chip; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [NimbleChipModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('has expected defaults for removable', () => { | ||
| expect(directive.removable).toBeFalse(); | ||
| expect(nativeElement.removable).toBeFalse(); | ||
| }); | ||
|
|
||
| it('has expected defaults for disabled', () => { | ||
| expect(directive.disabled).toBeFalse(); | ||
| expect(nativeElement.disabled).toBeFalse(); | ||
| }); | ||
|
|
||
| it('has expected defaults for appearance', () => { | ||
| expect(directive.appearance).toBe(ChipAppearance.outline); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.outline); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with template string values', () => { | ||
| @Component({ | ||
| template: ` | ||
| <nimble-chip #chip | ||
| removable | ||
| disabled | ||
| appearance="block"> | ||
| </nimble-chip>`, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('chip', { read: NimbleChipDirective }) public directive: NimbleChipDirective; | ||
| @ViewChild('chip', { read: ElementRef }) public elementRef: ElementRef<Chip>; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: NimbleChipDirective; | ||
| let nativeElement: Chip; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [NimbleChipModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('will use template string values for removable', () => { | ||
| expect(directive.removable).toBeTrue(); | ||
| expect(nativeElement.removable).toBeTrue(); | ||
| }); | ||
|
|
||
| it('will use template string values for disabled', () => { | ||
| expect(directive.disabled).toBeTrue(); | ||
| expect(nativeElement.disabled).toBeTrue(); | ||
| }); | ||
|
|
||
| it('will use template string values for appearance', () => { | ||
| expect(directive.appearance).toBe(ChipAppearance.block); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.block); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with property bound values', () => { | ||
| @Component({ | ||
| template: ` | ||
| <nimble-chip #chip | ||
| [removable]="removable" | ||
| [disabled]="disabled" | ||
| [appearance]="appearance"> | ||
| </nimble-chip> | ||
| `, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('chip', { read: NimbleChipDirective }) public directive: NimbleChipDirective; | ||
| @ViewChild('chip', { read: ElementRef }) public elementRef: ElementRef<Chip>; | ||
| public removable = false; | ||
| public disabled = false; | ||
| public appearance: ChipAppearance = ChipAppearance.outline; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: NimbleChipDirective; | ||
| let nativeElement: Chip; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [NimbleChipModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('can be configured with property binding for removable', () => { | ||
| expect(directive.removable).toBeFalse(); | ||
| expect(nativeElement.removable).toBeFalse(); | ||
|
|
||
| fixture.componentInstance.removable = true; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.removable).toBeTrue(); | ||
| expect(nativeElement.removable).toBeTrue(); | ||
| }); | ||
|
|
||
| it('can be configured with property binding for disabled', () => { | ||
| expect(directive.disabled).toBeFalse(); | ||
| expect(nativeElement.disabled).toBeFalse(); | ||
|
|
||
| fixture.componentInstance.disabled = true; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.disabled).toBeTrue(); | ||
| expect(nativeElement.disabled).toBeTrue(); | ||
| }); | ||
|
|
||
| it('can be configured with property binding for appearance', () => { | ||
| expect(directive.appearance).toBe(ChipAppearance.outline); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.outline); | ||
|
|
||
| fixture.componentInstance.appearance = ChipAppearance.block; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.appearance).toBe(ChipAppearance.block); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.block); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with attribute bound values', () => { | ||
| @Component({ | ||
| template: ` | ||
| <nimble-chip #chip | ||
| [attr.removable]="removable" | ||
| [attr.disabled]="disabled" | ||
| [attr.appearance]="appearance"> | ||
| </nimble-chip> | ||
| `, | ||
| standalone: false | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild('chip', { read: NimbleChipDirective }) public directive: NimbleChipDirective; | ||
| @ViewChild('chip', { read: ElementRef }) public elementRef: ElementRef<Chip>; | ||
| public removable: BooleanValueOrAttribute = null; | ||
| public disabled: BooleanValueOrAttribute = null; | ||
| public appearance: ChipAppearance = ChipAppearance.outline; | ||
| } | ||
|
|
||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let directive: NimbleChipDirective; | ||
| let nativeElement: Chip; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| declarations: [TestHostComponent], | ||
| imports: [NimbleChipModule] | ||
| }); | ||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| fixture.detectChanges(); | ||
| directive = fixture.componentInstance.directive; | ||
| nativeElement = fixture.componentInstance.elementRef.nativeElement; | ||
| }); | ||
|
|
||
| it('can be configured with attribute binding for removable', () => { | ||
| expect(directive.removable).toBeFalse(); | ||
| expect(nativeElement.removable).toBeFalse(); | ||
|
|
||
| fixture.componentInstance.removable = ''; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.removable).toBeTrue(); | ||
| expect(nativeElement.removable).toBeTrue(); | ||
| }); | ||
|
|
||
| it('can be configured with attribute binding for disabled', () => { | ||
| expect(directive.disabled).toBeFalse(); | ||
| expect(nativeElement.disabled).toBeFalse(); | ||
|
|
||
| fixture.componentInstance.disabled = ''; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.disabled).toBeTrue(); | ||
| expect(nativeElement.disabled).toBeTrue(); | ||
| }); | ||
|
|
||
| it('can be configured with attribute binding for appearance', () => { | ||
| expect(directive.appearance).toBe(ChipAppearance.outline); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.outline); | ||
|
|
||
| fixture.componentInstance.appearance = ChipAppearance.block; | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(directive.appearance).toBe(ChipAppearance.block); | ||
| expect(nativeElement.appearance).toBe(ChipAppearance.block); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.