UNPKG

5.05 kBSource Map (JSON)View Raw
1{"version":3,"file":"button-checkbox.directive.js","sourceRoot":"","sources":["../../src/buttons/button-checkbox.directive.ts"],"names":[],"mappings":"OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAU,UAAU,EAAE,MAAM,eAAe;OACxF,EAAwB,iBAAiB,EAAE,MAAM,gBAAgB;AAExE,oEAAoE;AAEpE,OAAO,IAAM,+BAA+B,GAAQ;IAClD,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,UAAU,CAAC,cAAM,OAAA,uBAAuB,EAAvB,CAAuB,CAAC;IACtD,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF;;GAEG;AAEH;IAAA;QACE,2CAA2C;QACnC,oBAAe,GAAQ,IAAI,CAAC;QACpC,0CAA0C;QAClC,qBAAgB,GAAQ,KAAK,CAAC;QAE9B,UAAK,GAAY,KAAK,CAAC;QAKrB,aAAQ,GAAQ,QAAQ,CAAC,SAAS,CAAC;QACnC,cAAS,GAAQ,QAAQ,CAAC,SAAS,CAAC;IAgEhD,CAAC;IA9DC,gBAAgB;IAET,yCAAO,GAAd;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,MAAM,CAAC;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,0CAAQ,GAAf;QACE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,sBAAc,8CAAS;aAAvB;YACE,MAAM,CAAC,OAAO,IAAI,CAAC,eAAe,KAAK,WAAW;kBAC9C,IAAI,CAAC,eAAe;kBACpB,IAAI,CAAC;QACX,CAAC;;;OAAA;IAED,sBAAc,+CAAU;aAAxB;YAC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I,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,cAAc,EAAG,EAAE,EAAE;QAC3D,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,OAAO,EAAG,EAAE,EAAE;KACtD,CAAC;IACF,8BAAC;AAAD,CAAC,AA5ED,IA4EC","sourcesContent":["import { Directive, HostBinding, HostListener, Input, OnInit, forwardRef } from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\n\n// TODO: config: activeClass - Class to apply to the checked buttons\n\nexport const CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => ButtonCheckboxDirective),\n multi: true\n};\n\n/**\n * Add checkbox functionality to any element\n */\n\nexport class ButtonCheckboxDirective implements ControlValueAccessor, OnInit {\n /** Truthy value, will be set to ngModel */\n public btnCheckboxTrue: any = true;\n /** Falsy value, will be set to ngModel */\n public btnCheckboxFalse: any = false;\n\n public state: boolean = false;\n\n protected value: any;\n protected isDisabled: boolean;\n\n protected onChange: any = Function.prototype;\n protected onTouched: any = Function.prototype;\n\n // view -> model\n \n public onClick(): void {\n if (this.isDisabled) {\n return;\n }\n\n this.toggle(!this.state);\n this.onChange(this.value);\n }\n\n public ngOnInit(): any {\n this.toggle(this.trueValue === this.value);\n }\n\n protected get trueValue(): boolean {\n return typeof this.btnCheckboxTrue !== 'undefined'\n ? this.btnCheckboxTrue\n : true;\n }\n\n protected get falseValue(): boolean {\n return typeof this.btnCheckboxFalse !== 'undefined'\n ? this.btnCheckboxFalse\n : false;\n }\n\n public toggle(state: boolean): void {\n this.state = state;\n this.value = this.state ? this.trueValue : this.falseValue;\n }\n\n // ControlValueAccessor\n // model -> view\n public writeValue(value: any): void {\n this.state = this.trueValue === value;\n this.value = value ? this.trueValue : this.falseValue;\n }\n\n public setDisabledState(isDisabled: boolean): void {\n this.isDisabled = isDisabled;\n }\n\n public registerOnChange(fn: (_: any) => {}): void {\n this.onChange = fn;\n }\n\n public registerOnTouched(fn: () => {}): void {\n this.onTouched = fn;\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Directive, args: [{selector: '[btnCheckbox]', providers: [CHECKBOX_CONTROL_VALUE_ACCESSOR]}, ] },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n];\nstatic propDecorators: {[key: string]: DecoratorInvocation[]} = {\n'btnCheckboxTrue': [{ type: Input },],\n'btnCheckboxFalse': [{ type: Input },],\n'state': [{ type: HostBinding, args: ['class.active', ] },],\n'onClick': [{ type: HostListener, args: ['click', ] },],\n};\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}
\No newline at end of file