Skip to content

Commit

Permalink
feat(Button): Avvia l'implementazione della componente per i bottoni
Browse files Browse the repository at this point in the history
ref #44
  • Loading branch information
Mario Traetta committed Jul 25, 2018
1 parent a1e7791 commit 4c50edc
Show file tree
Hide file tree
Showing 10 changed files with 2,524 additions and 2,363 deletions.
4,721 changes: 2,360 additions & 2,361 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@angular/router": "^6.0.3",
"bootstrap-italia": "^0.9.1",
"core-js": "^2.5.4",
"io-ts": "^1.2.1",
"ngx-highlightjs": "^2.1.1",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
Expand Down
Empty file.
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>
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 projects/design-angular-kit/src/lib/button/button.component.ts
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() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { FormsModule } from '@angular/forms';
import { CheckboxComponent } from './checkbox/checkbox.component';
import { RadioButtonComponent, RadioGroupDirective } from './radio/radio.component';
import { ToggleComponent } from './toggle/toggle.component';
import { ButtonComponent } from './button/button.component';

@NgModule({
imports: [
CommonModule,
FormsModule
],
declarations: [CheckboxComponent, ToggleComponent, RadioGroupDirective, RadioButtonComponent],
exports: [CheckboxComponent, ToggleComponent, RadioGroupDirective, RadioButtonComponent]
declarations: [CheckboxComponent, ToggleComponent, RadioGroupDirective, RadioButtonComponent, ButtonComponent],
exports: [CheckboxComponent, ToggleComponent, RadioGroupDirective, RadioButtonComponent, ButtonComponent]
})
export class DesignAngularKitModule { }
17 changes: 17 additions & 0 deletions projects/design-angular-kit/src/lib/models/ButtonSize.ts
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,
};
32 changes: 32 additions & 0 deletions projects/design-angular-kit/src/lib/models/ThemeColor.ts
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
};
1 change: 1 addition & 0 deletions projects/design-angular-kit/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
export * from './lib/checkbox/checkbox.component';
export * from './lib/toggle/toggle.component';
export * from './lib/radio/radio.component';
export * from './lib/button/button.component';
export * from './lib/design-angular-kit.module';

0 comments on commit 4c50edc

Please sign in to comment.