Skip to content

Commit

Permalink
fix(componente): aggiungi esplicitamente il tipo del campo disabled d…
Browse files Browse the repository at this point in the history
…el checkbox
  • Loading branch information
ciccio86 committed Jun 26, 2018
1 parent 05f0dd5 commit 1955e11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class CheckboxComponent implements ControlValueAccessor {
* Se la checkbox è disabilitata.
*/
@Input()
get disabled() { return this._disabled; }
set disabled(value: any) {
get disabled(): boolean { return this._disabled; }
set disabled(value: boolean) {
if (value !== this.disabled) {
this._disabled = value;
this._changeDetectorRef.markForCheck();
Expand Down
15 changes: 8 additions & 7 deletions src/assets/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"classes": [
{
"name": "CheckboxChange",
"id": "class-CheckboxChange-16d9cd816880e71a292735047cb2346e",
"id": "class-CheckboxChange-061d883b3f4d581a0a4d05a1d1a8bf78",
"file": "projects/design-angular-kit/src/lib/checkbox/checkbox.component.ts",
"type": "class",
"sourceCode": "import { Component, Input, Output, EventEmitter, ChangeDetectorRef, forwardRef, ChangeDetectionStrategy } from '@angular/core';\nimport { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';\n\nlet identifier = 0;\n\nexport class CheckboxChange {\n source: CheckboxComponent;\n checked: boolean;\n}\n\n/**\n * Una checkbox con design bootstrap italia. Supporta tutte le funzionalità di una checkbox HTML5,\n * ed espone una API simile. Una `<it-checkbox>` può essere checked, unchecked, o disabled.\n */\n@Component({\n selector: 'it-checkbox',\n templateUrl: './checkbox.component.html',\n styleUrls: ['./checkbox.component.css'],\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxComponent), multi: true }],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class CheckboxComponent implements ControlValueAccessor {\n /**\n * Se la checkbox è selezionata.\n */\n @Input()\n get checked(): boolean { return this._checked; }\n set checked(value: boolean) {\n if (value !== this.checked) {\n this._checked = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _checked = false;\n\n /**\n * L'etichetta della checkbox.\n */\n @Input()\n label: string;\n\n /**\n * Se la checkbox è disabilitata.\n */\n @Input()\n get disabled() { return this._disabled; }\n set disabled(value: any) {\n if (value !== this.disabled) {\n this._disabled = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _disabled = false;\n\n /**\n * Evento emesso quando il valore `checked` della checkbox cambia.\n */\n @Output() readonly change: EventEmitter<CheckboxChange> =\n new EventEmitter<CheckboxChange>();\n\n inputId = `checkbox-${identifier++}`;\n\n private _onTouched: () => any = () => {};\n\n private _controlValueAccessorChangeFn: (value: any) => void = () => { };\n\n constructor(\n private _changeDetectorRef: ChangeDetectorRef\n ) { }\n\n writeValue(value: any) {\n this.checked = !!value;\n }\n\n registerOnChange(fn: (value: any) => void) {\n this._controlValueAccessorChangeFn = fn;\n }\n\n registerOnTouched(fn: any) {\n this._onTouched = fn;\n }\n\n handleChange(event: Event) {\n event.stopPropagation();\n if (!this.disabled) {\n this._toggle();\n this._emitChangeEvent();\n }\n }\n\n private _toggle(): void {\n this.checked = !this.checked;\n }\n\n private _emitChangeEvent() {\n const event = new CheckboxChange();\n event.source = this;\n event.checked = this.checked;\n\n this._controlValueAccessorChangeFn(this.checked);\n this.change.emit(event);\n }\n}\n",
"sourceCode": "import { Component, Input, Output, EventEmitter, ChangeDetectorRef, forwardRef, ChangeDetectionStrategy } from '@angular/core';\nimport { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';\n\nlet identifier = 0;\n\nexport class CheckboxChange {\n source: CheckboxComponent;\n checked: boolean;\n}\n\n/**\n * Una checkbox con design bootstrap italia. Supporta tutte le funzionalità di una checkbox HTML5,\n * ed espone una API simile. Una `<it-checkbox>` può essere checked, unchecked, o disabled.\n */\n@Component({\n selector: 'it-checkbox',\n templateUrl: './checkbox.component.html',\n styleUrls: ['./checkbox.component.css'],\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxComponent), multi: true }],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class CheckboxComponent implements ControlValueAccessor {\n /**\n * Se la checkbox è selezionata.\n */\n @Input()\n get checked(): boolean { return this._checked; }\n set checked(value: boolean) {\n if (value !== this.checked) {\n this._checked = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _checked = false;\n\n /**\n * L'etichetta della checkbox.\n */\n @Input()\n label: string;\n\n /**\n * Se la checkbox è disabilitata.\n */\n @Input()\n get disabled(): boolean { return this._disabled; }\n set disabled(value: boolean) {\n if (value !== this.disabled) {\n this._disabled = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _disabled = false;\n\n /**\n * Evento emesso quando il valore `checked` della checkbox cambia.\n */\n @Output() readonly change: EventEmitter<CheckboxChange> =\n new EventEmitter<CheckboxChange>();\n\n inputId = `checkbox-${identifier++}`;\n\n private _onTouched: () => any = () => {};\n\n private _controlValueAccessorChangeFn: (value: any) => void = () => { };\n\n constructor(\n private _changeDetectorRef: ChangeDetectorRef\n ) { }\n\n writeValue(value: any) {\n this.checked = !!value;\n }\n\n registerOnChange(fn: (value: any) => void) {\n this._controlValueAccessorChangeFn = fn;\n }\n\n registerOnTouched(fn: any) {\n this._onTouched = fn;\n }\n\n handleChange(event: Event) {\n event.stopPropagation();\n if (!this.disabled) {\n this._toggle();\n this._emitChangeEvent();\n }\n }\n\n private _toggle(): void {\n this.checked = !this.checked;\n }\n\n private _emitChangeEvent() {\n const event = new CheckboxChange();\n event.source = this;\n event.checked = this.checked;\n\n this._controlValueAccessorChangeFn(this.checked);\n this.change.emit(event);\n }\n}\n",
"properties": [
{
"name": "checked",
Expand Down Expand Up @@ -37,7 +37,7 @@
"components": [
{
"name": "CheckboxComponent",
"id": "component-CheckboxComponent-16d9cd816880e71a292735047cb2346e",
"id": "component-CheckboxComponent-061d883b3f4d581a0a4d05a1d1a8bf78",
"file": "projects/design-angular-kit/src/lib/checkbox/checkbox.component.ts",
"changeDetection": "ChangeDetectionStrategy.OnPush",
"encapsulation": [],
Expand Down Expand Up @@ -68,7 +68,8 @@
{
"name": "disabled",
"description": "<p>Se la checkbox è disabilitata.</p>\n",
"line": 46
"line": 46,
"type": "boolean"
},
{
"name": "label",
Expand Down Expand Up @@ -268,7 +269,7 @@
"hostListeners": [],
"description": "<p>Una checkbox con design bootstrap italia. Supporta tutte le funzionalità di una checkbox HTML5,\ned espone una API simile. Una <code>&lt;it-checkbox&gt;</code> può essere checked, unchecked, o disabled.</p>\n",
"type": "component",
"sourceCode": "import { Component, Input, Output, EventEmitter, ChangeDetectorRef, forwardRef, ChangeDetectionStrategy } from '@angular/core';\nimport { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';\n\nlet identifier = 0;\n\nexport class CheckboxChange {\n source: CheckboxComponent;\n checked: boolean;\n}\n\n/**\n * Una checkbox con design bootstrap italia. Supporta tutte le funzionalità di una checkbox HTML5,\n * ed espone una API simile. Una `<it-checkbox>` può essere checked, unchecked, o disabled.\n */\n@Component({\n selector: 'it-checkbox',\n templateUrl: './checkbox.component.html',\n styleUrls: ['./checkbox.component.css'],\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxComponent), multi: true }],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class CheckboxComponent implements ControlValueAccessor {\n /**\n * Se la checkbox è selezionata.\n */\n @Input()\n get checked(): boolean { return this._checked; }\n set checked(value: boolean) {\n if (value !== this.checked) {\n this._checked = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _checked = false;\n\n /**\n * L'etichetta della checkbox.\n */\n @Input()\n label: string;\n\n /**\n * Se la checkbox è disabilitata.\n */\n @Input()\n get disabled() { return this._disabled; }\n set disabled(value: any) {\n if (value !== this.disabled) {\n this._disabled = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _disabled = false;\n\n /**\n * Evento emesso quando il valore `checked` della checkbox cambia.\n */\n @Output() readonly change: EventEmitter<CheckboxChange> =\n new EventEmitter<CheckboxChange>();\n\n inputId = `checkbox-${identifier++}`;\n\n private _onTouched: () => any = () => {};\n\n private _controlValueAccessorChangeFn: (value: any) => void = () => { };\n\n constructor(\n private _changeDetectorRef: ChangeDetectorRef\n ) { }\n\n writeValue(value: any) {\n this.checked = !!value;\n }\n\n registerOnChange(fn: (value: any) => void) {\n this._controlValueAccessorChangeFn = fn;\n }\n\n registerOnTouched(fn: any) {\n this._onTouched = fn;\n }\n\n handleChange(event: Event) {\n event.stopPropagation();\n if (!this.disabled) {\n this._toggle();\n this._emitChangeEvent();\n }\n }\n\n private _toggle(): void {\n this.checked = !this.checked;\n }\n\n private _emitChangeEvent() {\n const event = new CheckboxChange();\n event.source = this;\n event.checked = this.checked;\n\n this._controlValueAccessorChangeFn(this.checked);\n this.change.emit(event);\n }\n}\n",
"sourceCode": "import { Component, Input, Output, EventEmitter, ChangeDetectorRef, forwardRef, ChangeDetectionStrategy } from '@angular/core';\nimport { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';\n\nlet identifier = 0;\n\nexport class CheckboxChange {\n source: CheckboxComponent;\n checked: boolean;\n}\n\n/**\n * Una checkbox con design bootstrap italia. Supporta tutte le funzionalità di una checkbox HTML5,\n * ed espone una API simile. Una `<it-checkbox>` può essere checked, unchecked, o disabled.\n */\n@Component({\n selector: 'it-checkbox',\n templateUrl: './checkbox.component.html',\n styleUrls: ['./checkbox.component.css'],\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxComponent), multi: true }],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class CheckboxComponent implements ControlValueAccessor {\n /**\n * Se la checkbox è selezionata.\n */\n @Input()\n get checked(): boolean { return this._checked; }\n set checked(value: boolean) {\n if (value !== this.checked) {\n this._checked = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _checked = false;\n\n /**\n * L'etichetta della checkbox.\n */\n @Input()\n label: string;\n\n /**\n * Se la checkbox è disabilitata.\n */\n @Input()\n get disabled(): boolean { return this._disabled; }\n set disabled(value: boolean) {\n if (value !== this.disabled) {\n this._disabled = value;\n this._changeDetectorRef.markForCheck();\n }\n }\n private _disabled = false;\n\n /**\n * Evento emesso quando il valore `checked` della checkbox cambia.\n */\n @Output() readonly change: EventEmitter<CheckboxChange> =\n new EventEmitter<CheckboxChange>();\n\n inputId = `checkbox-${identifier++}`;\n\n private _onTouched: () => any = () => {};\n\n private _controlValueAccessorChangeFn: (value: any) => void = () => { };\n\n constructor(\n private _changeDetectorRef: ChangeDetectorRef\n ) { }\n\n writeValue(value: any) {\n this.checked = !!value;\n }\n\n registerOnChange(fn: (value: any) => void) {\n this._controlValueAccessorChangeFn = fn;\n }\n\n registerOnTouched(fn: any) {\n this._onTouched = fn;\n }\n\n handleChange(event: Event) {\n event.stopPropagation();\n if (!this.disabled) {\n this._toggle();\n this._emitChangeEvent();\n }\n }\n\n private _toggle(): void {\n this.checked = !this.checked;\n }\n\n private _emitChangeEvent() {\n const event = new CheckboxChange();\n event.source = this;\n event.checked = this.checked;\n\n this._controlValueAccessorChangeFn(this.checked);\n this.change.emit(event);\n }\n}\n",
"constructorObj": {
"name": "constructor",
"description": "",
Expand Down Expand Up @@ -325,15 +326,15 @@
"args": [
{
"name": "value",
"type": "any"
"type": "boolean"
}
],
"returnType": "void",
"line": 47,
"jsdoctags": [
{
"name": "value",
"type": "any",
"type": "boolean",
"tagName": {
"text": "param"
}
Expand Down

0 comments on commit 1955e11

Please sign in to comment.