-
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(Button): Avvia l'implementazione della componente per i bottoni
ref #44
- Loading branch information
Mario Traetta
committed
Jul 25, 2018
1 parent
a1e7791
commit 4c50edc
Showing
10 changed files
with
2,524 additions
and
2,363 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
3 changes: 3 additions & 0 deletions
3
projects/design-angular-kit/src/lib/button/button.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,3 @@ | ||
<button type="button" [class]="buttonClass" [disabled]="disabled"> | ||
<ng-content></ng-content> | ||
</button> |
25 changes: 25 additions & 0 deletions
25
projects/design-angular-kit/src/lib/button/button.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 { ButtonComponent } from './button.component'; | ||
|
||
describe('ButtonComponent', () => { | ||
let component: ButtonComponent; | ||
let fixture: ComponentFixture<ButtonComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ButtonComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
82 changes: 82 additions & 0 deletions
82
projects/design-angular-kit/src/lib/button/button.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,82 @@ | ||
import { Component, OnInit, Input, HostBinding, Output, HostListener } from '@angular/core'; | ||
import { ThemeColor, THEME_COLORS } from '../models/ThemeColor'; | ||
import { ButtonSize, BUTTON_SIZES } from '../models/ButtonSize'; | ||
import { EventEmitter } from 'events'; | ||
|
||
|
||
@Component({ | ||
selector: 'it-button', | ||
templateUrl: './button.component.html', | ||
styleUrls: ['./button.component.css'] | ||
}) | ||
export class ButtonComponent implements OnInit { | ||
|
||
@Input() | ||
get disabled(): boolean { return this._disabled; } | ||
set disabled(value: boolean) { this._disabled = value != null && `${value}` !== 'false'; } | ||
private _disabled = false; | ||
|
||
@Input() | ||
get outline(): boolean { return this._outline; } | ||
set outline(value: boolean) { this._outline = value != null && `${value}` !== 'false'; } | ||
private _outline = false; | ||
|
||
@Input() | ||
get block(): boolean { return this._block; } | ||
set block(value: boolean) { this._block = value != null && `${value}` !== 'false'; } | ||
private _block = false; | ||
|
||
@Input() | ||
get color(): any { | ||
return this._color; | ||
} | ||
set color(value: any) { | ||
if (ThemeColor.is(value)) { | ||
this._color = value; | ||
} | ||
} | ||
private _color; | ||
|
||
@Input() | ||
get size(): any { | ||
return this._size; | ||
} | ||
set size(value: any) { | ||
if (ButtonSize.is(value)) { | ||
this._size = value; | ||
} | ||
} | ||
private _size; | ||
|
||
protected get buttonClass() { | ||
let cssClass = 'btn'; | ||
|
||
if (this.color) { | ||
if (this.outline) { | ||
cssClass += ` btn-outline-${this.color}`; | ||
} else { | ||
cssClass += ` btn-${this.color}`; | ||
} | ||
} | ||
|
||
if (this.size) { | ||
cssClass += ` btn-${this.size}`; | ||
} | ||
|
||
if (this.block) { | ||
cssClass += ' btn-block'; | ||
} | ||
|
||
if (this.disabled) { | ||
cssClass += ' disabled'; | ||
} | ||
|
||
return cssClass; | ||
} | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
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,17 @@ | ||
import * as t from 'io-ts'; | ||
|
||
export const ButtonSize = t.keyof({ | ||
lg: null, | ||
sm: null, | ||
xs: null, | ||
}); | ||
|
||
const LG = 'lg'; | ||
const SM = 'sm'; | ||
const XS = 'xs'; | ||
|
||
export const BUTTON_SIZES = { | ||
LG: LG, | ||
SM: SM, | ||
XS: XS, | ||
}; |
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,32 @@ | ||
import * as t from 'io-ts'; | ||
|
||
export const ThemeColor = t.keyof({ | ||
primary: null, | ||
secondary: null, | ||
danger: null, | ||
warning: null, | ||
info: null, | ||
success: null, | ||
light: null, | ||
dark: null, | ||
}); | ||
|
||
const PRIMARY = 'primary'; | ||
const SECONDARY = 'secondary'; | ||
const DANGER = 'danger'; | ||
const WARNING = 'warning'; | ||
const INFO = 'info'; | ||
const SUCCESS = 'success'; | ||
const LIGHT = 'light'; | ||
const DARK = 'dark'; | ||
|
||
export const THEME_COLORS = { | ||
PRIMARY: PRIMARY, | ||
SECONDARY: SECONDARY, | ||
DANGER: DANGER, | ||
WARNING: WARNING, | ||
INFO: INFO, | ||
SUCCESS: SUCCESS, | ||
LIGHT: LIGHT, | ||
DARK: DARK | ||
}; |
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