-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daffio): add active router styles to nav header items (#3127)
- Loading branch information
Showing
7 changed files
with
76 additions
and
25 deletions.
There are no files selected for viewing
49 changes: 38 additions & 11 deletions
49
apps/daffio/src/app/core/header/components/header-item/header-item.directive.spec.ts
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 |
---|---|---|
@@ -1,38 +1,65 @@ | ||
import { Component } from '@angular/core'; | ||
import { | ||
Component, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
waitForAsync, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffioHeaderItemDirective } from './header-item.directive'; | ||
|
||
@Component({ template: '<div daffioHeaderItem>Item</div>' }) | ||
|
||
class WrapperComponent {} | ||
@Component({ | ||
template: `<a daffioHeaderItem [active]="active">Header Item</a>`, | ||
}) | ||
class WrapperComponent { | ||
active: boolean; | ||
} | ||
|
||
describe('DaffioHeaderItemComponent', () => { | ||
let component: WrapperComponent; | ||
describe('DaffioHeaderItemDirective', () => { | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let de: DebugElement; | ||
let wrapper: WrapperComponent; | ||
let component: DaffioHeaderItemDirective; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
WrapperComponent, | ||
DaffioHeaderItemDirective, | ||
WrapperComponent, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
component = fixture.componentInstance; | ||
|
||
wrapper = fixture.componentInstance; | ||
de = fixture.debugElement.query(By.css('[daffioHeaderItem]')); | ||
component = de.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('should add a class of "daffio-header-item" to the host element', () => { | ||
expect(de.classes).toEqual(jasmine.objectContaining({ | ||
'daffio-header-item': true, | ||
})); | ||
}); | ||
|
||
it('should be able to take `active` as an input', () => { | ||
expect(component.active).toEqual(wrapper.active); | ||
}); | ||
|
||
it('should add a class of "active" to the host element when active is true', () => { | ||
wrapper.active = true; | ||
fixture.detectChanges(); | ||
|
||
expect(de.classes['active']).toBeTrue(); | ||
}); | ||
}); |
6 changes: 5 additions & 1 deletion
6
apps/daffio/src/app/core/header/components/header-item/header-item.directive.ts
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { | ||
Directive, | ||
HostBinding, | ||
Input, | ||
} from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[daffioHeaderItem]', | ||
}) | ||
export class DaffioHeaderItemDirective { | ||
@HostBinding('class.daffio-header__item') class = true; | ||
@HostBinding('class.daffio-header-item') class = true; | ||
|
||
/** Whether or not the header item is active */ | ||
@Input() @HostBinding('class.active') active = false; | ||
} |
12 changes: 12 additions & 0 deletions
12
apps/daffio/src/app/core/header/components/header/header-theme.scss
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,12 @@ | ||
@use 'sass:map'; | ||
@use 'theme' as daff-theme; | ||
|
||
@mixin daffio-header-theme($theme) { | ||
$primary: map.get($theme, primary); | ||
|
||
.daffio-header-item { | ||
&.active { | ||
color: daff-theme.daff-color($primary); | ||
} | ||
} | ||
} |
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