Skip to content

Commit 83c431c

Browse files
committed
first commit
1 parent 69bbce1 commit 83c431c

10 files changed

+107
-22
lines changed

.angular-cli.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"testTsconfig": "tsconfig.spec.json",
2020
"prefix": "app",
2121
"styles": [
22-
"styles.css"
22+
"styles.css",
23+
"../node_modules/pretty-checkbox/dist/pretty-checkbox.min.css",
24+
"../node_modules/mdi/css/materialdesignicons.min.css"
2325
],
2426
"scripts": [],
2527
"environmentSource": "environments/environment.ts",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"zone.js": "^0.8.14"
2727
},
2828
"devDependencies": {
29-
"@angular/cli": "1.6.1",
29+
"@angular/cli": "^1.6.1",
3030
"@angular/compiler-cli": "^5.0.0",
3131
"@angular/language-service": "^5.0.0",
3232
"@types/jasmine": "~2.5.53",

src/app/app.component.html

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
<!--The content below is only a placeholder and can be replaced.-->
2-
<div style="text-align:center">
3-
<h1>
4-
Welcome to {{ title }}!
5-
</h1>
6-
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
7-
</div>
8-
<h2>Here are some links to help you start: </h2>
9-
<ul>
10-
<li>
11-
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
12-
</li>
13-
<li>
14-
<h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
15-
</li>
16-
<li>
17-
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
18-
</li>
19-
</ul>
1+
<ngx-checkbox [label]="'Teste'" [(ngModel)]="isSelected" name="isSelected"></ngx-checkbox>
202

3+
<pre>{{ isSelected }}</pre>

src/app/app.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import { Component } from '@angular/core';
77
})
88
export class AppComponent {
99
title = 'app';
10+
isSelected: boolean = true;
1011
}

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { NgModule } from '@angular/core';
33

44

55
import { AppComponent } from './app.component';
6+
import { CustomCheckboxModule } from './custom-checkbox/custom-checkbox.module';
7+
import { FormsModule } from '@angular/forms';
68

79

810
@NgModule({
911
declarations: [
1012
AppComponent
1113
],
1214
imports: [
13-
BrowserModule
15+
BrowserModule, CustomCheckboxModule, FormsModule
1416
],
1517
providers: [],
1618
bootstrap: [AppComponent]

src/app/custom-checkbox/custom-checkbox.component.css

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div (click)="toggleCheckbox()" class="pretty p-icon p-round p-smooth">
2+
<input [value]="isSelected" type="checkbox" />
3+
<div class="state p-success">
4+
<i class="icon mdi mdi-check"></i>
5+
<label>{{ label }}</label>
6+
</div>
7+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { CustomCheckboxComponent } from './custom-checkbox.component';
4+
5+
describe('CustomCheckboxComponent', () => {
6+
let component: CustomCheckboxComponent;
7+
let fixture: ComponentFixture<CustomCheckboxComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ CustomCheckboxComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(CustomCheckboxComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Component, OnInit, Input, ViewChild, forwardRef } from '@angular/core';
2+
import { NG_VALUE_ACCESSOR, NgModel, ControlValueAccessor } from '@angular/forms';
3+
4+
@Component({
5+
selector: 'ngx-checkbox',
6+
templateUrl: './custom-checkbox.component.html',
7+
styleUrls: ['./custom-checkbox.component.css'],
8+
providers: [
9+
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CustomCheckboxComponent), multi: true }
10+
]
11+
})
12+
export class CustomCheckboxComponent implements OnInit, ControlValueAccessor {
13+
14+
writeValue(obj: any): void {
15+
this.isSelected = obj;
16+
}
17+
registerOnChange(fn: any): void {
18+
this._onChange = fn;
19+
}
20+
registerOnTouched(fn: any): void {
21+
this._onTouched = fn;
22+
}
23+
setDisabledState?(isDisabled: boolean): void {
24+
}
25+
26+
// call if value was changed inside our component
27+
private _onChange = (_: any) => { };
28+
// call if input was "touched" .. !
29+
private _onTouched = () => { };
30+
31+
@Input() label: String;
32+
33+
isSelected: boolean;
34+
35+
constructor() { }
36+
37+
ngOnInit() {
38+
console.log(this.isSelected);
39+
}
40+
41+
ngAfterViewInit() {
42+
console.log(this.isSelected);
43+
}
44+
45+
toggleCheckbox() {
46+
this.isSelected = !this.isSelected;
47+
this._onChange(this.isSelected);
48+
console.log(this.isSelected);
49+
}
50+
51+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { CustomCheckboxComponent } from './custom-checkbox.component';
4+
5+
@NgModule({
6+
imports: [
7+
CommonModule
8+
],
9+
exports: [
10+
CustomCheckboxComponent
11+
],
12+
declarations: [CustomCheckboxComponent]
13+
})
14+
export class CustomCheckboxModule { }

0 commit comments

Comments
 (0)