1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { Directive, ElementRef, Input, IterableDiffers, KeyValueDiffers, Renderer2, ɵisListLikeIterable as isListLikeIterable, ɵstringify as stringify } from '@angular/core';
|
---|
9 | /**
|
---|
10 | * @ngModule CommonModule
|
---|
11 | *
|
---|
12 | * @usageNotes
|
---|
13 | * ```
|
---|
14 | * <some-element [ngClass]="'first second'">...</some-element>
|
---|
15 | *
|
---|
16 | * <some-element [ngClass]="['first', 'second']">...</some-element>
|
---|
17 | *
|
---|
18 | * <some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
|
---|
19 | *
|
---|
20 | * <some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>
|
---|
21 | *
|
---|
22 | * <some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>
|
---|
23 | * ```
|
---|
24 | *
|
---|
25 | * @description
|
---|
26 | *
|
---|
27 | * Adds and removes CSS classes on an HTML element.
|
---|
28 | *
|
---|
29 | * The CSS classes are updated as follows, depending on the type of the expression evaluation:
|
---|
30 | * - `string` - the CSS classes listed in the string (space delimited) are added,
|
---|
31 | * - `Array` - the CSS classes declared as Array elements are added,
|
---|
32 | * - `Object` - keys are CSS classes that get added when the expression given in the value
|
---|
33 | * evaluates to a truthy value, otherwise they are removed.
|
---|
34 | *
|
---|
35 | * @publicApi
|
---|
36 | */
|
---|
37 | export class NgClass {
|
---|
38 | constructor(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) {
|
---|
39 | this._iterableDiffers = _iterableDiffers;
|
---|
40 | this._keyValueDiffers = _keyValueDiffers;
|
---|
41 | this._ngEl = _ngEl;
|
---|
42 | this._renderer = _renderer;
|
---|
43 | this._iterableDiffer = null;
|
---|
44 | this._keyValueDiffer = null;
|
---|
45 | this._initialClasses = [];
|
---|
46 | this._rawClass = null;
|
---|
47 | }
|
---|
48 | set klass(value) {
|
---|
49 | this._removeClasses(this._initialClasses);
|
---|
50 | this._initialClasses = typeof value === 'string' ? value.split(/\s+/) : [];
|
---|
51 | this._applyClasses(this._initialClasses);
|
---|
52 | this._applyClasses(this._rawClass);
|
---|
53 | }
|
---|
54 | set ngClass(value) {
|
---|
55 | this._removeClasses(this._rawClass);
|
---|
56 | this._applyClasses(this._initialClasses);
|
---|
57 | this._iterableDiffer = null;
|
---|
58 | this._keyValueDiffer = null;
|
---|
59 | this._rawClass = typeof value === 'string' ? value.split(/\s+/) : value;
|
---|
60 | if (this._rawClass) {
|
---|
61 | if (isListLikeIterable(this._rawClass)) {
|
---|
62 | this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create();
|
---|
63 | }
|
---|
64 | else {
|
---|
65 | this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | ngDoCheck() {
|
---|
70 | if (this._iterableDiffer) {
|
---|
71 | const iterableChanges = this._iterableDiffer.diff(this._rawClass);
|
---|
72 | if (iterableChanges) {
|
---|
73 | this._applyIterableChanges(iterableChanges);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | else if (this._keyValueDiffer) {
|
---|
77 | const keyValueChanges = this._keyValueDiffer.diff(this._rawClass);
|
---|
78 | if (keyValueChanges) {
|
---|
79 | this._applyKeyValueChanges(keyValueChanges);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | _applyKeyValueChanges(changes) {
|
---|
84 | changes.forEachAddedItem((record) => this._toggleClass(record.key, record.currentValue));
|
---|
85 | changes.forEachChangedItem((record) => this._toggleClass(record.key, record.currentValue));
|
---|
86 | changes.forEachRemovedItem((record) => {
|
---|
87 | if (record.previousValue) {
|
---|
88 | this._toggleClass(record.key, false);
|
---|
89 | }
|
---|
90 | });
|
---|
91 | }
|
---|
92 | _applyIterableChanges(changes) {
|
---|
93 | changes.forEachAddedItem((record) => {
|
---|
94 | if (typeof record.item === 'string') {
|
---|
95 | this._toggleClass(record.item, true);
|
---|
96 | }
|
---|
97 | else {
|
---|
98 | throw new Error(`NgClass can only toggle CSS classes expressed as strings, got ${stringify(record.item)}`);
|
---|
99 | }
|
---|
100 | });
|
---|
101 | changes.forEachRemovedItem((record) => this._toggleClass(record.item, false));
|
---|
102 | }
|
---|
103 | /**
|
---|
104 | * Applies a collection of CSS classes to the DOM element.
|
---|
105 | *
|
---|
106 | * For argument of type Set and Array CSS class names contained in those collections are always
|
---|
107 | * added.
|
---|
108 | * For argument of type Map CSS class name in the map's key is toggled based on the value (added
|
---|
109 | * for truthy and removed for falsy).
|
---|
110 | */
|
---|
111 | _applyClasses(rawClassVal) {
|
---|
112 | if (rawClassVal) {
|
---|
113 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
---|
114 | rawClassVal.forEach((klass) => this._toggleClass(klass, true));
|
---|
115 | }
|
---|
116 | else {
|
---|
117 | Object.keys(rawClassVal).forEach(klass => this._toggleClass(klass, !!rawClassVal[klass]));
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 | /**
|
---|
122 | * Removes a collection of CSS classes from the DOM element. This is mostly useful for cleanup
|
---|
123 | * purposes.
|
---|
124 | */
|
---|
125 | _removeClasses(rawClassVal) {
|
---|
126 | if (rawClassVal) {
|
---|
127 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
---|
128 | rawClassVal.forEach((klass) => this._toggleClass(klass, false));
|
---|
129 | }
|
---|
130 | else {
|
---|
131 | Object.keys(rawClassVal).forEach(klass => this._toggleClass(klass, false));
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | _toggleClass(klass, enabled) {
|
---|
136 | klass = klass.trim();
|
---|
137 | if (klass) {
|
---|
138 | klass.split(/\s+/g).forEach(klass => {
|
---|
139 | if (enabled) {
|
---|
140 | this._renderer.addClass(this._ngEl.nativeElement, klass);
|
---|
141 | }
|
---|
142 | else {
|
---|
143 | this._renderer.removeClass(this._ngEl.nativeElement, klass);
|
---|
144 | }
|
---|
145 | });
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 | NgClass.decorators = [
|
---|
150 | { type: Directive, args: [{ selector: '[ngClass]' },] }
|
---|
151 | ];
|
---|
152 | NgClass.ctorParameters = () => [
|
---|
153 | { type: IterableDiffers },
|
---|
154 | { type: KeyValueDiffers },
|
---|
155 | { type: ElementRef },
|
---|
156 | { type: Renderer2 }
|
---|
157 | ];
|
---|
158 | NgClass.propDecorators = {
|
---|
159 | klass: [{ type: Input, args: ['class',] }],
|
---|
160 | ngClass: [{ type: Input, args: ['ngClass',] }]
|
---|
161 | };
|
---|
162 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdfY2xhc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21tb24vc3JjL2RpcmVjdGl2ZXMvbmdfY2xhc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxFQUFDLFNBQVMsRUFBVyxVQUFVLEVBQUUsS0FBSyxFQUFtQyxlQUFlLEVBQW1DLGVBQWUsRUFBRSxTQUFTLEVBQUUsbUJBQW1CLElBQUksa0JBQWtCLEVBQUUsVUFBVSxJQUFJLFNBQVMsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUl2UDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBMkJHO0FBRUgsTUFBTSxPQUFPLE9BQU87SUFNbEIsWUFDWSxnQkFBaUMsRUFBVSxnQkFBaUMsRUFDNUUsS0FBaUIsRUFBVSxTQUFvQjtRQUQvQyxxQkFBZ0IsR0FBaEIsZ0JBQWdCLENBQWlCO1FBQVUscUJBQWdCLEdBQWhCLGdCQU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