-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(badge): initial commit for badge
- Loading branch information
Showing
20 changed files
with
262 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<p> | ||
badge-demo works! | ||
</p> | ||
<h2 lyTyp="display1" gutter>Basic badge</h2> | ||
<demo-view path="docs/components/basic-badge/basic-badge"> | ||
<aui-basic-badge></aui-basic-badge> | ||
</demo-view> | ||
|
||
|
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/docs/components/badge-demo/badge-demo.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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BadgeDemoComponent } from './badge-demo.component'; | ||
|
||
describe('BadgeDemoComponent', () => { | ||
let component: BadgeDemoComponent; | ||
let fixture: ComponentFixture<BadgeDemoComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ BadgeDemoComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BadgeDemoComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
src/app/docs/components/badge-demo/badge-demo.component.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,15 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'aui-badge-demo', | ||
templateUrl: './badge-demo.component.html', | ||
styleUrls: ['./badge-demo.component.scss'] | ||
}) | ||
export class BadgeDemoComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/app/docs/components/badge-demo/basic-badge/basic-badge.component.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p> | ||
demo 1: | ||
</p> | ||
<button ly-button LyBadge="9">button</button> | ||
<p> | ||
demo 2: | ||
</p> | ||
<button ly-button> | ||
button | ||
<ly-badge bg="primary">9</ly-badge> | ||
</button> |
25 changes: 25 additions & 0 deletions
25
src/app/docs/components/badge-demo/basic-badge/basic-badge.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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BasicBadgeComponent } from './basic-badge.component'; | ||
|
||
describe('BasicBadgeComponent', () => { | ||
let component: BasicBadgeComponent; | ||
let fixture: ComponentFixture<BasicBadgeComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ BasicBadgeComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BasicBadgeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/app/docs/components/badge-demo/basic-badge/basic-badge.component.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,14 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'aui-basic-badge', | ||
templateUrl: './basic-badge.component.html' | ||
}) | ||
export class BasicBadgeComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/app/docs/components/badge-demo/basic-badge/basic-badge.module.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,13 @@ | ||
import { BasicBadgeModule } from './basic-badge.module'; | ||
|
||
describe('BasicBadgeModule', () => { | ||
let basicBadgeModule: BasicBadgeModule; | ||
|
||
beforeEach(() => { | ||
basicBadgeModule = new BasicBadgeModule(); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
expect(basicBadgeModule).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/app/docs/components/badge-demo/basic-badge/basic-badge.module.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,16 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { BasicBadgeComponent } from './basic-badge.component'; | ||
import { LyBadgeModule } from '@alyle/ui/badge'; | ||
import { LyButtonModule } from '@alyle/ui/button'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
LyButtonModule, | ||
LyBadgeModule | ||
], | ||
exports: [BasicBadgeComponent], | ||
declarations: [BasicBadgeComponent] | ||
}) | ||
export class BasicBadgeModule { } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { LyCommonModule } from '@alyle/ui'; | ||
import { LyBadge } from './badge'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, LyCommonModule], | ||
exports: [LyBadge, LyCommonModule], | ||
declarations: [LyBadge] | ||
}) | ||
export class LyBadgeModule { } |
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,103 @@ | ||
import { Directive, Input, ElementRef, Optional, Renderer2, OnInit } from '@angular/core'; | ||
import { ThemeVariables, LyCommon, LyTheme2 } from '@alyle/ui'; | ||
|
||
const DEFAULT_POSITION = 'end top'; | ||
|
||
const styles = (theme: ThemeVariables) => { | ||
return { | ||
root: { | ||
position: 'absolute', | ||
width: '22px', | ||
height: '22px', | ||
borderRadius: '100%', | ||
lineHeight: '22px', | ||
textAlign: 'center' | ||
}, | ||
sdasdasd: { | ||
color: 'red' | ||
} | ||
}; | ||
}; | ||
@Directive({ | ||
selector: 'ly-badge, [LyBadge]' | ||
}) | ||
export class LyBadge implements OnInit { | ||
classes = this._theme.addStyleSheet(styles, 'lyBadge'); | ||
private _badge: string | number; | ||
private _position: string | number; | ||
private _positionClass: string; | ||
|
||
/** The content for the badge */ | ||
@Input() | ||
set LyBadge(val: string | number) { | ||
if (val !== this.content) { | ||
this._badge = val; | ||
this._el.nativeElement.innerText = val; | ||
} | ||
} | ||
get content() { | ||
return this._badge; | ||
} | ||
|
||
/** The position for the badge */ | ||
@Input() | ||
set LyBadgePosition(val: 'start top' | 'start bottom' | 'end top' | 'end bottom') { | ||
if (val !== this.position) { | ||
this._positionClass = this._theme.addStyle(`ly-badge.position:${val}`, (theme: ThemeVariables) => { | ||
const positionStyles: { | ||
top?: number | ||
left?: number | ||
right?: number | ||
bottom?: number | ||
} = {}; | ||
if (val === 'start top') { | ||
positionStyles.left = 0; | ||
positionStyles.top = 0; | ||
} else if (val === 'start bottom') { | ||
positionStyles.left = 0; | ||
positionStyles.bottom = 0; | ||
} else if (val === 'end top') { | ||
positionStyles.right = 0; | ||
positionStyles.top = 0; | ||
} | ||
return positionStyles; | ||
}, | ||
this._el.nativeElement, this._positionClass); | ||
} | ||
|
||
} | ||
get position() { | ||
return this._position; | ||
} | ||
|
||
/** The color of the badge */ | ||
@Input() LyBadgeBg: string; | ||
|
||
constructor( | ||
private _el: ElementRef, | ||
private _theme: LyTheme2, | ||
private _renderer: Renderer2, | ||
@Optional() _common: LyCommon | ||
) { | ||
if (_common) { | ||
_common.setAutoContrast(); | ||
} | ||
this._renderer.addClass(this._el.nativeElement, this.classes.root); | ||
} | ||
|
||
ngOnInit() { | ||
if (!this.LyBadgePosition) { | ||
this.LyBadgePosition = DEFAULT_POSITION; | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
* demo 1: | ||
* <button badgeRef="badge">button</button> | ||
* <ly-badge class="hhjk" #badge bg="background:primary" color="primary">8</ly-badge> | ||
* | ||
* demo 2: | ||
* <button LyBadge="8" LyBadgePosition="start top" LyBadgeBg="primary">button</button> | ||
*/ |
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 @@ | ||
export * from './public_api'; |
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,2 @@ | ||
export * from './badge'; | ||
export * from './badge.module'; |
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