Skip to content
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

Prefer attributes over CSS classes #738

Merged
merged 55 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cbad094
prototype
rajsite Aug 5, 2022
2e3de26
prototype
rajsite Aug 5, 2022
5ad3731
prototype
rajsite Aug 8, 2022
ad9a247
prototype
rajsite Aug 8, 2022
e75d6c6
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Aug 8, 2022
43863ab
prototype
rajsite Aug 9, 2022
6187570
prototype
rajsite Aug 9, 2022
39a4f68
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Aug 9, 2022
2089e93
prototype
rajsite Aug 9, 2022
91283c7
prototype
rajsite Aug 9, 2022
873df4c
Change files
rajsite Aug 9, 2022
3068415
prototype
rajsite Aug 9, 2022
a69b185
prototype
rajsite Aug 9, 2022
6b7be63
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Aug 9, 2022
434c1b6
prototype
rajsite Aug 9, 2022
e773d09
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Aug 31, 2022
06db2c4
Merge woopsies
rajsite Aug 31, 2022
0cdd721
Lint
rajsite Aug 31, 2022
4b53eb7
merge commit updates
rajsite Sep 1, 2022
4f1d909
remove login page
rajsite Sep 1, 2022
db54055
remove aria-invalid todo, split to separate PR
rajsite Sep 2, 2022
44e44f4
lint
rajsite Sep 2, 2022
e01a60b
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Sep 5, 2022
877d6ac
error-visible angular
rajsite Sep 5, 2022
ce91ec7
icons angular
rajsite Sep 5, 2022
5c40042
lint
rajsite Sep 5, 2022
240eace
DesignSystem.tagFor consistency
rajsite Sep 6, 2022
81b34c3
breadcrumb angular
rajsite Sep 6, 2022
32383c4
button appearance-variant angular
rajsite Sep 6, 2022
809ce56
text-field full-bleed angular
rajsite Sep 6, 2022
146cd0a
tooltip severity changes
rajsite Sep 7, 2022
3b29f72
lint
rajsite Sep 7, 2022
fa29185
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Sep 11, 2022
f85536e
tooltip iconVisible
rajsite Sep 11, 2022
238f86b
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Sep 12, 2022
4ea2949
Blazor wrappers
rajsite Sep 13, 2022
ba6101c
Change files
rajsite Sep 13, 2022
94b4f26
Blazor tests
rajsite Sep 13, 2022
4e99b60
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Sep 20, 2022
3735cc9
lint
rajsite Sep 20, 2022
c67cc83
Update change files
rajsite Sep 21, 2022
e5fbbde
Remove ErrorPattern
rajsite Sep 21, 2022
a26d370
radio button group text customization story
rajsite Sep 21, 2022
f8a9704
Merge remote-tracking branch 'origin/main' into attribute-vs-classes
rajsite Sep 21, 2022
ca31485
enum tests
rajsite Sep 21, 2022
6b23544
test name cleanup
rajsite Sep 21, 2022
5c613b8
Update packages/nimble-components/src/patterns/error/types.ts
rajsite Sep 22, 2022
a3ac24c
Update tagFor guidance
rajsite Sep 22, 2022
6977e4e
Merge branch 'main' into attribute-vs-classes
rajsite Sep 22, 2022
edf538f
test comment
rajsite Sep 22, 2022
819b365
comment
rajsite Sep 22, 2022
352a81d
Merge branch 'main' into attribute-vs-classes
rajsite Sep 28, 2022
53e5c2f
Avoid self-reference to tag name
rajsite Sep 29, 2022
0e9073c
lint
rajsite Sep 29, 2022
e6ec903
Merge branch 'main' into attribute-vs-classes
rajsite Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import { NimbleTextAreaModule, NimbleTextFieldModule, NimbleNumberFieldModule, N
NimbleCardButtonModule, NimbleDialogModule, NimbleRadioGroupModule, NimbleRadioButtonModule } from '@ni/nimble-angular';
import { AppComponent } from './app.component';
import { CustomAppComponent } from './customapp/customapp.component';
import { LoginComponent } from './login/login.component';
import { HeaderComponent } from './header/header.component';
import { NavDrawerComponent } from './nav-drawer/nav-drawer.component';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
NavDrawerComponent,
CustomAppComponent
Expand Down Expand Up @@ -57,8 +55,7 @@ import { NavDrawerComponent } from './nav-drawer/nav-drawer.component';
NimbleRadioGroupModule,
NimbleRadioButtonModule,
RouterModule.forRoot([
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
rajsite marked this conversation as resolved.
Show resolved Hide resolved
{ path: '', redirectTo: '/customapp', pathMatch: 'full' },
{ path: 'customapp', component: CustomAppComponent }
],
{ useHash: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ <h2>This is a dialog</h2>
<nimble-button id="anchor1">Default</nimble-button>
<nimble-tooltip anchor="anchor1">Tooltip label</nimble-tooltip>
<nimble-button id="anchor2">Fail</nimble-button>
<nimble-tooltip anchor="anchor2" class="fail">Tooltip label</nimble-tooltip>
<nimble-tooltip anchor="anchor2" severity="error">Tooltip label</nimble-tooltip>
<nimble-button id="anchor3">Information</nimble-button>
<nimble-tooltip anchor="anchor3" class="information">Tooltip label</nimble-tooltip>
<nimble-tooltip anchor="anchor3" severity="information">Tooltip label</nimble-tooltip>
<nimble-button id="anchor4">Fail Icon </nimble-button>
<nimble-tooltip anchor="anchor4" class="fail icon-visible">Tooltip label</nimble-tooltip>
<nimble-tooltip anchor="anchor4" severity="error" icon-visible>Tooltip label</nimble-tooltip>
<nimble-button id="anchor5">Information Icon</nimble-button>
<nimble-tooltip anchor="anchor5" class="information icon-visible">Tooltip label</nimble-tooltip>
<nimble-tooltip anchor="anchor5" severity="information" icon-visible>Tooltip label</nimble-tooltip>
</div>
<div class="sub-container">
<div class="container-label">Tree View</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ <h1>User settings</h1>
<nimble-button appearance="outline" (click)="onMenuButtonClick()">Menu</nimble-button>
<nimble-menu class="menu" [hidden]="hideMenu">
<nimble-menu-item (change)="onUserSettingsSelected()">User Settings</nimble-menu-item>
<nimble-menu-item (change)="onLogoutSelected()">Logout</nimble-menu-item>
</nimble-menu>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export class HeaderComponent {
this.userSettingsDrawer.hide();
}

public onLogoutSelected(): void {
this.toggleMenuHidden();
void this.router.navigate(['/login']);
}

private toggleMenuHidden(): void {
this.hideMenu = !this.hideMenu;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ for (const key of Object.keys(icons)) {
const directiveFileContents = `${generatedFilePrefix}
import { Directive } from '@angular/core';
import type { ${className} } from '@ni/nimble-components/dist/esm/icons/${directoryName}';
import { NimbleIconBaseDirective } from '../../icon-base/nimble-icon-base.directive';

export type { ${className} };

Expand All @@ -61,7 +62,7 @@ export type { ${className} };
@Directive({
selector: '${elementName}'
})
export class ${directiveName} {
export class ${directiveName} extends NimbleIconBaseDirective {
}
`;
const directiveFileName = `${elementName}.directive`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Directive } from '@angular/core';
import { Directive, ElementRef, Input, Renderer2 } from '@angular/core';
import type { Breadcrumb } from '@ni/nimble-components/dist/esm/breadcrumb';
import { BreadcrumbAppearance } from '@ni/nimble-components/dist/esm/breadcrumb/types';

export type { Breadcrumb };
export { BreadcrumbAppearance };

/**
* Directive to provide Angular integration for the breadcrumb.
Expand All @@ -10,4 +12,13 @@ export type { Breadcrumb };
selector: 'nimble-breadcrumb'
})
export class NimbleBreadcrumbDirective {
public get appearance(): BreadcrumbAppearance {
return this.elementRef.nativeElement.appearance;
}

@Input() public set appearance(value: BreadcrumbAppearance) {
this.renderer.setProperty(this.elementRef.nativeElement, 'appearance', value);
}

public constructor(private readonly renderer: Renderer2, private readonly elementRef: ElementRef<Breadcrumb>) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { Component, ElementRef, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Breadcrumb, BreadcrumbAppearance, NimbleBreadcrumbDirective } from '../nimble-breadcrumb.directive';
import { NimbleBreadcrumbModule } from '../nimble-breadcrumb.module';

describe('Nimble breadcrumb', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [NimbleBreadcrumbModule]
});
});

it('custom element is defined', () => {
expect(customElements.get('nimble-breadcrumb')).not.toBeUndefined();
});

describe('with no values in template', () => {
@Component({
template: `
<nimble-breadcrumb #target></nimble-breadcrumb>
`
})
class TestHostComponent {
@ViewChild('target', { read: NimbleBreadcrumbDirective }) public directive: NimbleBreadcrumbDirective;
@ViewChild('target', { read: ElementRef }) public elementRef: ElementRef<Breadcrumb>;
}

let fixture: ComponentFixture<TestHostComponent>;
let directive: NimbleBreadcrumbDirective;
let nativeElement: Breadcrumb;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
imports: [NimbleBreadcrumbModule]
});
fixture = TestBed.createComponent(TestHostComponent);
fixture.detectChanges();
directive = fixture.componentInstance.directive;
nativeElement = fixture.componentInstance.elementRef.nativeElement;
});

it('has expected defaults for appearance', () => {
expect(directive.appearance).toBe(BreadcrumbAppearance.default);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.default);
});
});

describe('with template string values', () => {
@Component({
template: `
<nimble-breadcrumb #target
appearance="prominent"
>
</nimble-breadcrumb>`
})
class TestHostComponent {
@ViewChild('target', { read: NimbleBreadcrumbDirective }) public directive: NimbleBreadcrumbDirective;
@ViewChild('target', { read: ElementRef }) public elementRef: ElementRef<Breadcrumb>;
}

let fixture: ComponentFixture<TestHostComponent>;
let directive: NimbleBreadcrumbDirective;
let nativeElement: Breadcrumb;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
imports: [NimbleBreadcrumbModule]
});
fixture = TestBed.createComponent(TestHostComponent);
fixture.detectChanges();
directive = fixture.componentInstance.directive;
nativeElement = fixture.componentInstance.elementRef.nativeElement;
});

it('will use template string values for appearance', () => {
expect(directive.appearance).toBe(BreadcrumbAppearance.prominent);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.prominent);
});
});

describe('with property bound values', () => {
@Component({
template: `
<nimble-breadcrumb #target
[appearance]="appearance"
>
</nimble-breadcrumb>
`
})
class TestHostComponent {
@ViewChild('target', { read: NimbleBreadcrumbDirective }) public directive: NimbleBreadcrumbDirective;
@ViewChild('target', { read: ElementRef }) public elementRef: ElementRef<Breadcrumb>;
public appearance: BreadcrumbAppearance;
}

let fixture: ComponentFixture<TestHostComponent>;
let directive: NimbleBreadcrumbDirective;
let nativeElement: Breadcrumb;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
imports: [NimbleBreadcrumbModule]
});
fixture = TestBed.createComponent(TestHostComponent);
fixture.detectChanges();
directive = fixture.componentInstance.directive;
nativeElement = fixture.componentInstance.elementRef.nativeElement;
});

it('can be configured with property binding for appearance', () => {
expect(directive.appearance).toBe(BreadcrumbAppearance.default);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.default);

fixture.componentInstance.appearance = BreadcrumbAppearance.prominent;
fixture.detectChanges();

expect(directive.appearance).toBe(BreadcrumbAppearance.prominent);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.prominent);
});
});

describe('with attribute bound values', () => {
@Component({
template: `
<nimble-breadcrumb #target
[attr.appearance]="appearance"
>
</nimble-breadcrumb>
`
})
class TestHostComponent {
@ViewChild('target', { read: NimbleBreadcrumbDirective }) public directive: NimbleBreadcrumbDirective;
@ViewChild('target', { read: ElementRef }) public elementRef: ElementRef<Breadcrumb>;
public appearance: BreadcrumbAppearance;
}

let fixture: ComponentFixture<TestHostComponent>;
let directive: NimbleBreadcrumbDirective;
let nativeElement: Breadcrumb;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
imports: [NimbleBreadcrumbModule]
});
fixture = TestBed.createComponent(TestHostComponent);
fixture.detectChanges();
directive = fixture.componentInstance.directive;
nativeElement = fixture.componentInstance.elementRef.nativeElement;
});

it('can be configured with attribute binding for appearance', () => {
expect(directive.appearance).toBe(BreadcrumbAppearance.default);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.default);

fixture.componentInstance.appearance = BreadcrumbAppearance.prominent;
fixture.detectChanges();

expect(directive.appearance).toBe(BreadcrumbAppearance.prominent);
expect(nativeElement.appearance).toBe(BreadcrumbAppearance.prominent);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Directive, ElementRef, Input, Renderer2 } from '@angular/core';
import type { Button } from '@ni/nimble-components/dist/esm/button';
import type { ButtonAppearance, ButtonType } from '@ni/nimble-components/dist/esm/button/types';
import type { ButtonAppearance } from '@ni/nimble-components/dist/esm/button/types';
import { ButtonType, ButtonAppearanceVariant } from '@ni/nimble-components/dist/esm/button/types';
import { BooleanValueOrAttribute, toBooleanProperty } from '../utilities/template-value-helpers';

export type { Button, ButtonType };
export type { Button };
export { ButtonType, ButtonAppearanceVariant };

/**
* Directive to provide Angular integration for the button.
Expand All @@ -20,6 +22,16 @@ export class NimbleButtonDirective {
this.renderer.setProperty(this.elementRef.nativeElement, 'appearance', value);
}

public get appearanceVariant(): ButtonAppearanceVariant {
return this.elementRef.nativeElement.appearanceVariant;
}

// Renaming because property should have camel casing, but attribute should not
// eslint-disable-next-line @angular-eslint/no-input-rename
@Input('appearance-variant') public set appearanceVariant(value: ButtonAppearanceVariant) {
this.renderer.setProperty(this.elementRef.nativeElement, 'appearanceVariant', value);
}

public get disabled(): boolean {
return this.elementRef.nativeElement.disabled;
}
Expand All @@ -40,7 +52,7 @@ export class NimbleButtonDirective {
return this.elementRef.nativeElement.contentHidden;
}

// contentHidden property intentionally maps to the content-hidden attribute
// Renaming because property should have camel casing, but attribute should not
// eslint-disable-next-line @angular-eslint/no-input-rename
@Input('content-hidden') public set contentHidden(value: BooleanValueOrAttribute) {
this.renderer.setProperty(this.elementRef.nativeElement, 'contentHidden', toBooleanProperty(value));
Expand Down
Loading