-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(indicator): positioning enhancements (#249)
- Loading branch information
1 parent
f401de8
commit 61ad282
Showing
14 changed files
with
192 additions
and
58 deletions.
There are no files selected for viewing
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,4 +0,0 @@ | ||
nx-indicator { | ||
position: absolute; | ||
margin-left: 8px; | ||
} | ||
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
6 changes: 3 additions & 3 deletions
6
...la/documentation/examples/button/button-icon-indicator/button-icon-indicator-example.html
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,14 +1,14 @@ | ||
<button nxIconButton="tertiary small-medium" aria-label="notifications, new notifications available" type="button" class="nx-margin-bottom-0 nx-margin-right-xs"> | ||
<nx-icon name="bell-o"></nx-icon> | ||
<nx-indicator></nx-indicator> | ||
<nx-indicator position="over-icon"></nx-indicator> | ||
</button> | ||
|
||
<button nxIconButton="tertiary small-medium" aria-label="notifications, 1 new notification available" type="button" class="nx-margin-bottom-0 nx-margin-right-xs"> | ||
<nx-icon name="bell-o"></nx-icon> | ||
<nx-indicator>1</nx-indicator> | ||
<nx-indicator position="over-icon">1</nx-indicator> | ||
</button> | ||
|
||
<button nxIconButton="tertiary small-medium" aria-label="notifications, more than 99 notifications available" type="button" class="nx-margin-bottom-0"> | ||
<nx-icon name="bell-o"></nx-icon> | ||
<nx-indicator>99+</nx-indicator> | ||
<nx-indicator position="over-icon">99+</nx-indicator> | ||
</button> |
11 changes: 1 addition & 10 deletions
11
...mentation/examples/context-menu/context-menu-indicator/context-menu-indicator-example.css
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,12 +1,3 @@ | ||
.button-content { | ||
position: relative; | ||
} | ||
|
||
nx-indicator { | ||
position: absolute; | ||
} | ||
|
||
nx-indicator:not(:empty) { | ||
top: -4px; | ||
left: calc(100% - 4px); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...entation/examples/context-menu/context-menu-indicator/context-menu-indicator-example.html
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
10 changes: 0 additions & 10 deletions
10
...ntation/examples/tabs/tabs-nav-bar-with-indicator/tabs-nav-bar-with-indicator-example.css
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,13 +1,3 @@ | ||
.tab-header-content { | ||
position: relative; | ||
} | ||
|
||
nx-indicator { | ||
position: absolute; | ||
top: 0; | ||
left: 100%; | ||
} | ||
|
||
nx-indicator:not(:empty) { | ||
top: -4px; | ||
} |
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
81 changes: 81 additions & 0 deletions
81
projects/ng-aquila/src/indicator/indicator.component.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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
import { Component, Type, ViewChild, Directive } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
|
||
import {NxIndicatorComponent} from './indicator.component'; | ||
import {NxIndicatorModule} from './indicator.module'; | ||
|
||
// For better readablity here, We can safely ignore some conventions in our specs | ||
// tslint:disable:component-class-suffix | ||
|
||
@Directive() | ||
abstract class IndicatorTest { | ||
@ViewChild(NxIndicatorComponent) indicatorInstance: NxIndicatorComponent; | ||
} | ||
|
||
describe('NxIndicatorComponent', () => { | ||
let fixture: ComponentFixture<IndicatorTest>; | ||
let testInstance: IndicatorTest; | ||
let indicatorInstance: NxIndicatorComponent; | ||
let indicatorNativeElement: HTMLButtonElement; | ||
|
||
function createTestComponent(component: Type<IndicatorTest>) { | ||
fixture = TestBed.createComponent(component); | ||
fixture.detectChanges(); | ||
testInstance = fixture.componentInstance; | ||
indicatorInstance = testInstance.indicatorInstance; | ||
indicatorNativeElement = (fixture.nativeElement.querySelector('nx-indicator') as HTMLButtonElement); | ||
} | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
BasicIndicator | ||
], | ||
imports: [ | ||
NxIndicatorModule | ||
] | ||
}).compileComponents(); | ||
})); | ||
|
||
it('creates the component', waitForAsync(() => { | ||
createTestComponent(BasicIndicator); | ||
expect(indicatorInstance).toBeTruthy(); | ||
})); | ||
|
||
describe('basic indicator', () => { | ||
beforeEach(() => { | ||
createTestComponent(BasicIndicator); | ||
}); | ||
|
||
it('has no positioning classes by default', () => { | ||
expect(indicatorNativeElement.classList.contains('nx-indicator')).toBe(true); | ||
expect(indicatorNativeElement.classList.length).toBe(1); | ||
}); | ||
|
||
it('sets positioning class when passed through input', () => { | ||
indicatorInstance.position = 'over-icon'; | ||
fixture.detectChanges(); | ||
|
||
expect(indicatorNativeElement.classList.contains('nx-indicator--over-icon')).toBe(true); | ||
}); | ||
|
||
it('sets multiple positioning classes when passed through input', () => { | ||
indicatorInstance.position = 'over-text with-overlap'; | ||
fixture.detectChanges(); | ||
|
||
expect(indicatorNativeElement.classList.contains('nx-indicator--over-text')).toBe(true); | ||
expect(indicatorNativeElement.classList.contains('nx-indicator--with-overlap')).toBe(true); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<nx-indicator [position]='position'>1</nx-indicator> | ||
`, | ||
}) | ||
class BasicIndicator extends IndicatorTest { | ||
position = ''; | ||
} |
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,10 +1,35 @@ | ||
|
||
import { Component, ChangeDetectionStrategy } from '@angular/core'; | ||
import { Component, ChangeDetectionStrategy, Input } from '@angular/core'; | ||
|
||
export type NxIndicatorPosition = 'over-text' | 'over-icon' | 'after-text' | 'with-overlap'; | ||
@Component({ | ||
selector: 'nx-indicator', | ||
template: '<ng-content></ng-content>', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
styleUrls: ['./indicator.component.scss'] | ||
styleUrls: ['./indicator.component.scss'], | ||
host: { | ||
'[class.nx-indicator]': 'true', | ||
'[class.nx-indicator--over-text]': 'this._hasPosition("over-text")', | ||
'[class.nx-indicator--over-icon]': 'this._hasPosition("over-icon")', | ||
'[class.nx-indicator--after-text]': 'this._hasPosition("after-text")', | ||
'[class.nx-indicator--with-overlap]': 'this._hasPosition("with-overlap")', | ||
} | ||
}) | ||
export class NxIndicatorComponent { } | ||
export class NxIndicatorComponent { | ||
private _position: NxIndicatorPosition[] = []; | ||
|
||
/** Sets the indicator positioning preset. | ||
* Should be one or more of 'over-text', 'over-icon', 'after-text', 'with-overlap' | ||
*/ | ||
@Input() | ||
set position(value: string) { | ||
this._position = value.split(' ') as NxIndicatorPosition[]; | ||
} | ||
get position(): string { | ||
return this._position.join(' '); | ||
} | ||
|
||
_hasPosition(position: NxIndicatorPosition) { | ||
return this._position.indexOf(position) > -1; | ||
} | ||
} |
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