/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { Directive, HostListener, Input } from '@angular/core'; import { CdkTree, CdkTreeNode } from './tree'; /** * Node toggle to expand/collapse the node. */ export class CdkTreeNodeToggle { constructor(_tree, _treeNode) { this._tree = _tree; this._treeNode = _treeNode; this._recursive = false; } /** Whether expand/collapse the node recursively. */ get recursive() { return this._recursive; } set recursive(value) { this._recursive = coerceBooleanProperty(value); } // We have to use a `HostListener` here in order to support both Ivy and ViewEngine. // In Ivy the `host` bindings will be merged when this class is extended, whereas in // ViewEngine they're overwritten. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default. // tslint:disable-next-line:no-host-decorator-in-concrete _toggle(event) { this.recursive ? this._tree.treeControl.toggleDescendants(this._treeNode.data) : this._tree.treeControl.toggle(this._treeNode.data); event.stopPropagation(); } } CdkTreeNodeToggle.decorators = [ { type: Directive, args: [{ selector: '[cdkTreeNodeToggle]' },] } ]; CdkTreeNodeToggle.ctorParameters = () => [ { type: CdkTree }, { type: CdkTreeNode } ]; CdkTreeNodeToggle.propDecorators = { recursive: [{ type: Input, args: ['cdkTreeNodeToggleRecursive',] }], _toggle: [{ type: HostListener, args: ['click', ['$event'],] }] }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9nZ2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay90cmVlL3RvZ2dsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQWUscUJBQXFCLEVBQUMsTUFBTSx1QkFBdUIsQ0FBQztBQUMxRSxPQUFPLEVBQUMsU0FBUyxFQUFFLFlBQVksRUFBRSxLQUFLLEVBQUMsTUFBTSxlQUFlLENBQUM7Q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