1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __metadata = (this && this.__metadata) || function (k, v) {
|
8 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9 | };
|
10 | import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, Renderer, ViewEncapsulation, forwardRef, NgModule } from '@angular/core';
|
11 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
12 |
|
13 |
|
14 |
|
15 | var nextId = 0;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export var MD_CHECKBOX_CONTROL_VALUE_ACCESSOR = {
|
21 | provide: NG_VALUE_ACCESSOR,
|
22 | useExisting: forwardRef(function () { return MdCheckbox; }),
|
23 | multi: true
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 | export var TransitionCheckState;
|
29 | (function (TransitionCheckState) {
|
30 |
|
31 | TransitionCheckState[TransitionCheckState["Init"] = 0] = "Init";
|
32 |
|
33 | TransitionCheckState[TransitionCheckState["Checked"] = 1] = "Checked";
|
34 |
|
35 | TransitionCheckState[TransitionCheckState["Unchecked"] = 2] = "Unchecked";
|
36 |
|
37 | TransitionCheckState[TransitionCheckState["Indeterminate"] = 3] = "Indeterminate";
|
38 | })(TransitionCheckState || (TransitionCheckState = {}));
|
39 |
|
40 | export var MdCheckboxChange = (function () {
|
41 | function MdCheckboxChange() {
|
42 | }
|
43 | return MdCheckboxChange;
|
44 | }());
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export var MdCheckbox = (function () {
|
54 | function MdCheckbox(_renderer, _elementRef) {
|
55 | this._renderer = _renderer;
|
56 | this._elementRef = _elementRef;
|
57 | |
58 |
|
59 |
|
60 |
|
61 | this.ariaLabel = '';
|
62 | |
63 |
|
64 |
|
65 | this.ariaLabelledby = null;
|
66 |
|
67 | this.id = "md-checkbox-" + ++nextId;
|
68 |
|
69 | this.align = 'start';
|
70 | |
71 |
|
72 |
|
73 |
|
74 | this.disabled = false;
|
75 | |
76 |
|
77 |
|
78 |
|
79 | this.tabindex = 0;
|
80 |
|
81 | this.name = null;
|
82 |
|
83 | this.change = new EventEmitter();
|
84 |
|
85 | this.onTouched = function () { };
|
86 | this._currentAnimationClass = '';
|
87 | this._currentCheckState = TransitionCheckState.Init;
|
88 | this._checked = false;
|
89 | this._indeterminate = false;
|
90 | this._controlValueAccessorChangeFn = function (value) { };
|
91 | this.hasFocus = false;
|
92 | }
|
93 | Object.defineProperty(MdCheckbox.prototype, "inputId", {
|
94 |
|
95 | get: function () {
|
96 | return "input-" + this.id;
|
97 | },
|
98 | enumerable: true,
|
99 | configurable: true
|
100 | });
|
101 | Object.defineProperty(MdCheckbox.prototype, "checked", {
|
102 | |
103 |
|
104 |
|
105 |
|
106 | get: function () {
|
107 | return this._checked;
|
108 | },
|
109 | set: function (checked) {
|
110 | if (checked != this.checked) {
|
111 | this._indeterminate = false;
|
112 | this._checked = checked;
|
113 | this._transitionCheckState(this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
|
114 | }
|
115 | },
|
116 | enumerable: true,
|
117 | configurable: true
|
118 | });
|
119 | Object.defineProperty(MdCheckbox.prototype, "indeterminate", {
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | get: function () {
|
130 | return this._indeterminate;
|
131 | },
|
132 | set: function (indeterminate) {
|
133 | this._indeterminate = indeterminate;
|
134 | if (this._indeterminate) {
|
135 | this._transitionCheckState(TransitionCheckState.Indeterminate);
|
136 | }
|
137 | else {
|
138 | this._transitionCheckState(this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
|
139 | }
|
140 | },
|
141 | enumerable: true,
|
142 | configurable: true
|
143 | });
|
144 | |
145 |
|
146 |
|
147 |
|
148 | MdCheckbox.prototype.writeValue = function (value) {
|
149 | this.checked = !!value;
|
150 | };
|
151 | |
152 |
|
153 |
|
154 |
|
155 | MdCheckbox.prototype.registerOnChange = function (fn) {
|
156 | this._controlValueAccessorChangeFn = fn;
|
157 | };
|
158 | |
159 |
|
160 |
|
161 |
|
162 | MdCheckbox.prototype.registerOnTouched = function (fn) {
|
163 | this.onTouched = fn;
|
164 | };
|
165 | MdCheckbox.prototype._transitionCheckState = function (newState) {
|
166 | var oldState = this._currentCheckState;
|
167 | var renderer = this._renderer;
|
168 | var elementRef = this._elementRef;
|
169 | if (oldState === newState) {
|
170 | return;
|
171 | }
|
172 | if (this._currentAnimationClass.length > 0) {
|
173 | renderer.setElementClass(elementRef.nativeElement, this._currentAnimationClass, false);
|
174 | }
|
175 | this._currentAnimationClass = this._getAnimationClassForCheckStateTransition(oldState, newState);
|
176 | this._currentCheckState = newState;
|
177 | if (this._currentAnimationClass.length > 0) {
|
178 | renderer.setElementClass(elementRef.nativeElement, this._currentAnimationClass, true);
|
179 | }
|
180 | };
|
181 | MdCheckbox.prototype._emitChangeEvent = function () {
|
182 | var event = new MdCheckboxChange();
|
183 | event.source = this;
|
184 | event.checked = this.checked;
|
185 | this._controlValueAccessorChangeFn(this.checked);
|
186 | this.change.emit(event);
|
187 | };
|
188 |
|
189 | MdCheckbox.prototype._onInputFocus = function () {
|
190 | this.hasFocus = true;
|
191 | };
|
192 |
|
193 | MdCheckbox.prototype._onInputBlur = function () {
|
194 | this.hasFocus = false;
|
195 | this.onTouched();
|
196 | };
|
197 | |
198 |
|
199 |
|
200 | MdCheckbox.prototype.toggle = function () {
|
201 | this.checked = !this.checked;
|
202 | };
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 | MdCheckbox.prototype._onInteractionEvent = function (event) {
|
209 |
|
210 |
|
211 |
|
212 | event.stopPropagation();
|
213 | if (!this.disabled) {
|
214 | this.toggle();
|
215 |
|
216 |
|
217 |
|
218 | this._emitChangeEvent();
|
219 | }
|
220 | };
|
221 | MdCheckbox.prototype._onInputClick = function (event) {
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | event.stopPropagation();
|
230 | };
|
231 | MdCheckbox.prototype._getAnimationClassForCheckStateTransition = function (oldState, newState) {
|
232 | var animSuffix;
|
233 | switch (oldState) {
|
234 | case TransitionCheckState.Init:
|
235 |
|
236 |
|
237 | if (newState === TransitionCheckState.Checked) {
|
238 | animSuffix = 'unchecked-checked';
|
239 | }
|
240 | else {
|
241 | return '';
|
242 | }
|
243 | break;
|
244 | case TransitionCheckState.Unchecked:
|
245 | animSuffix = newState === TransitionCheckState.Checked ?
|
246 | 'unchecked-checked' : 'unchecked-indeterminate';
|
247 | break;
|
248 | case TransitionCheckState.Checked:
|
249 | animSuffix = newState === TransitionCheckState.Unchecked ?
|
250 | 'checked-unchecked' : 'checked-indeterminate';
|
251 | break;
|
252 | case TransitionCheckState.Indeterminate:
|
253 | animSuffix = newState === TransitionCheckState.Checked ?
|
254 | 'indeterminate-checked' : 'indeterminate-unchecked';
|
255 | }
|
256 | return "md-checkbox-anim-" + animSuffix;
|
257 | };
|
258 | __decorate([
|
259 | Input('aria-label'),
|
260 | __metadata('design:type', String)
|
261 | ], MdCheckbox.prototype, "ariaLabel", void 0);
|
262 | __decorate([
|
263 | Input('aria-labelledby'),
|
264 | __metadata('design:type', String)
|
265 | ], MdCheckbox.prototype, "ariaLabelledby", void 0);
|
266 | __decorate([
|
267 | Input(),
|
268 | __metadata('design:type', String)
|
269 | ], MdCheckbox.prototype, "id", void 0);
|
270 | __decorate([
|
271 | Input(),
|
272 | __metadata('design:type', Object)
|
273 | ], MdCheckbox.prototype, "align", void 0);
|
274 | __decorate([
|
275 | Input(),
|
276 | __metadata('design:type', Boolean)
|
277 | ], MdCheckbox.prototype, "disabled", void 0);
|
278 | __decorate([
|
279 | Input(),
|
280 | __metadata('design:type', Number)
|
281 | ], MdCheckbox.prototype, "tabindex", void 0);
|
282 | __decorate([
|
283 | Input(),
|
284 | __metadata('design:type', String)
|
285 | ], MdCheckbox.prototype, "name", void 0);
|
286 | __decorate([
|
287 | Output(),
|
288 | __metadata('design:type', EventEmitter)
|
289 | ], MdCheckbox.prototype, "change", void 0);
|
290 | __decorate([
|
291 | Input(),
|
292 | __metadata('design:type', Object)
|
293 | ], MdCheckbox.prototype, "checked", null);
|
294 | __decorate([
|
295 | Input(),
|
296 | __metadata('design:type', Object)
|
297 | ], MdCheckbox.prototype, "indeterminate", null);
|
298 | MdCheckbox = __decorate([
|
299 | Component({selector: 'md-checkbox',
|
300 | template: "<label class=\"md-checkbox-layout\"> <div class=\"md-checkbox-inner-container\"> <input class=\"md-checkbox-input\" type=\"checkbox\" [id]=\"inputId\" [checked]=\"checked\" [disabled]=\"disabled\" [name]=\"name\" [tabIndex]=\"tabindex\" [indeterminate]=\"indeterminate\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledby\" (focus)=\"_onInputFocus()\" (blur)=\"_onInputBlur()\" (change)=\"_onInteractionEvent($event)\" (click)=\"_onInputClick($event)\"> <div class=\"md-ink-ripple\"></div> <div class=\"md-checkbox-frame\"></div> <div class=\"md-checkbox-background\"> <svg version=\"1.1\" class=\"md-checkbox-checkmark\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" xml:space=\"preserve\"> <path class=\"md-checkbox-checkmark-path\" fill=\"none\" stroke=\"white\" d=\"M4.1,12.7 9,17.6 20.3,6.3\"/> </svg> <!-- Element for rendering the indeterminate state checkbox. --> <div class=\"md-checkbox-mixedmark\"></div> </div> </div> <span class=\"md-checkbox-label\"> <ng-content></ng-content> </span> </label> ",
|
301 | styles: ["/** * Mixin that creates a new stacking context. * see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context */ /** * This mixin hides an element visually. * That means it's still accessible for screen-readers but not visible in view. */ /** * Forces an element to grow to fit floated contents; used as as an alternative to * `overflow: hidden;` because it doesn't cut off contents. */ /** * A mixin, which generates temporary ink ripple on a given component. * When $bindToParent is set to true, it will check for the focused class on the same selector as you included * that mixin. * It is also possible to specify the color palette of the temporary ripple. By default it uses the * accent palette for its background. */ /** The width/height of the checkbox element. */ /** The width of the line used to draw the checkmark / mixedmark. */ /** The width of the checkbox border shown when the checkbox is unchecked. */ /** The color of the checkbox border. */ /** The color of the checkbox's checkmark / mixedmark. */ /** The color that is used as the checkbox background when it is checked. */ /** The base duration used for the majority of transitions for the checkbox. */ /** The amount of spacing between the checkbox and its label. */ /** * Fades in the background of the checkbox when it goes from unchecked -> {checked,indeterminate}. */ @keyframes md-checkbox-fade-in-background { 0% { opacity: 0; } 50% { opacity: 1; } } /** * Fades out the background of the checkbox when it goes from {checked,indeterminate} -> unchecked. */ @keyframes md-checkbox-fade-out-background { 0%, 50% { opacity: 1; } 100% { opacity: 0; } } /** * \"Draws\" in the checkmark when the checkbox goes from unchecked -> checked. */ @keyframes md-checkbox-unchecked-checked-checkmark-path { 0%, 50% { stroke-dashoffset: 22.91026; } 50% { animation-timing-function: cubic-bezier(0, 0, 0.2, 0.1); } 100% { stroke-dashoffset: 0; } } /** * Horizontally expands the mixedmark when the checkbox goes from unchecked -> indeterminate. */ @keyframes md-checkbox-unchecked-indeterminate-mixedmark { 0%, 68.2% { transform: scaleX(0); } 68.2% { animation-timing-function: cubic-bezier(0, 0, 0, 1); } 100% { transform: scaleX(1); } } /** * \"Erases\" the checkmark when the checkbox goes from checked -> unchecked. */ @keyframes md-checkbox-checked-unchecked-checkmark-path { from { animation-timing-function: cubic-bezier(0.4, 0, 1, 1); stroke-dashoffset: 0; } to { stroke-dashoffset: -22.91026; } } /** * Rotates and fades out the checkmark when the checkbox goes from checked -> indeterminate. This * animation helps provide the illusion of the checkmark \"morphing\" into the mixedmark. */ @keyframes md-checkbox-checked-indeterminate-checkmark { from { animation-timing-function: cubic-bezier(0, 0, 0.2, 0.1); opacity: 1; transform: rotate(0deg); } to { opacity: 0; transform: rotate(45deg); } } /** * Rotates and fades the checkmark back into position when the checkbox goes from indeterminate -> * checked. This animation helps provide the illusion that the mixedmark is \"morphing\" into the * checkmark. */ @keyframes md-checkbox-indeterminate-checked-checkmark { from { animation-timing-function: cubic-bezier(0.14, 0, 0, 1); opacity: 0; transform: rotate(45deg); } to { opacity: 1; transform: rotate(360deg); } } /** * Rotates and fades in the mixedmark when the checkbox goes from checked -> indeterminate. This * animation, similar to md-checkbox-checked-indeterminate-checkmark, helps provide an illusion * of \"morphing\" from checkmark -> mixedmark. */ @keyframes md-checkbox-checked-indeterminate-mixedmark { from { animation-timing-function: cubic-bezier(0, 0, 0.2, 0.1); opacity: 0; transform: rotate(-45deg); } to { opacity: 1; transform: rotate(0deg); } } /** * Rotates and fades out the mixedmark when the checkbox goes from indeterminate -> checked. This * animation, similar to md-checkbox-indeterminate-checked-checkmark, helps provide an illusion * of \"morphing\" from mixedmark -> checkmark. */ @keyframes md-checkbox-indeterminate-checked-mixedmark { from { animation-timing-function: cubic-bezier(0.14, 0, 0, 1); opacity: 1; transform: rotate(0deg); } to { opacity: 0; transform: rotate(315deg); } } /** * Horizontally collapses and fades out the mixedmark when the checkbox goes from indeterminate -> * unchecked. */ @keyframes md-checkbox-indeterminate-unchecked-mixedmark { 0% { animation-timing-function: linear; opacity: 1; transform: scaleX(1); } 32.8%, 100% { opacity: 0; transform: scaleX(0); } } /** * Applied to elements that cover the checkbox's entire inner container. */ .md-checkbox-frame, .md-checkbox-background, .md-checkbox-checkmark { bottom: 0; left: 0; position: absolute; right: 0; top: 0; } /** * Applied to elements that are considered \"marks\" within the checkbox, e.g. the checkmark and * the mixedmark. */ .md-checkbox-checkmark, .md-checkbox-mixedmark { width: calc(100% - 4px); } /** * Applied to elements that appear to make up the outer box of the checkmark, such as the frame * that contains the border and the actual background element that contains the marks. */ .md-checkbox-frame, .md-checkbox-background { border-radius: 2px; box-sizing: border-box; pointer-events: none; } md-checkbox { cursor: pointer; } .md-checkbox-layout { cursor: inherit; align-items: baseline; display: inline-flex; } .md-checkbox-inner-container { display: inline-block; height: 20px; line-height: 0; margin: auto; margin-right: 8px; order: 0; position: relative; vertical-align: middle; white-space: nowrap; width: 20px; } [dir='rtl'] .md-checkbox-inner-container { margin-left: 8px; margin-right: auto; } .md-checkbox-layout .md-checkbox-label { line-height: 24px; } .md-checkbox-frame { background-color: transparent; border: 2px solid rgba(0, 0, 0, 0.54); transition: border-color 90ms cubic-bezier(0, 0, 0.2, 0.1); will-change: border-color; } .md-checkbox-background { align-items: center; display: inline-flex; justify-content: center; transition: background-color 90ms cubic-bezier(0, 0, 0.2, 0.1), opacity 90ms cubic-bezier(0, 0, 0.2, 0.1); will-change: background-color, opacity; } .md-checkbox-checkmark { fill: #fafafa; width: 100%; } .md-checkbox-checkmark-path { stroke: #fafafa !important; stroke-dashoffset: 22.91026; stroke-dasharray: 22.91026; stroke-width: 2.66667px; } .md-checkbox-mixedmark { background-color: #fafafa; height: 2px; opacity: 0; transform: scaleX(0) rotate(0deg); } .md-checkbox-align-end .md-checkbox-inner-container { order: 1; margin-left: 8px; margin-right: auto; } [dir='rtl'] .md-checkbox-align-end .md-checkbox-inner-container { margin-left: auto; margin-right: 8px; } .md-checkbox-checked .md-checkbox-checkmark { opacity: 1; } .md-checkbox-checked .md-checkbox-checkmark-path { stroke-dashoffset: 0; } .md-checkbox-checked .md-checkbox-mixedmark { transform: scaleX(1) rotate(-45deg); } .md-checkbox-checked .md-checkbox-background { background-color: #9c27b0; } .md-checkbox-indeterminate .md-checkbox-background { background-color: #9c27b0; } .md-checkbox-indeterminate .md-checkbox-checkmark { opacity: 0; transform: rotate(45deg); } .md-checkbox-indeterminate .md-checkbox-checkmark-path { stroke-dashoffset: 0; } .md-checkbox-indeterminate .md-checkbox-mixedmark { opacity: 1; transform: scaleX(1) rotate(0deg); } .md-checkbox-unchecked .md-checkbox-background { background-color: transparent; } .md-checkbox-disabled { cursor: default; } .md-checkbox-disabled.md-checkbox-checked .md-checkbox-background, .md-checkbox-disabled.md-checkbox-indeterminate .md-checkbox-background { background-color: #b0b0b0; } .md-checkbox-disabled:not(.md-checkbox-checked) .md-checkbox-frame { border-color: #b0b0b0; } .md-checkbox-anim-unchecked-checked .md-checkbox-background { animation: 180ms linear 0ms md-checkbox-fade-in-background; } .md-checkbox-anim-unchecked-checked .md-checkbox-checkmark-path { animation: 180ms linear 0ms md-checkbox-unchecked-checked-checkmark-path; } .md-checkbox-anim-unchecked-indeterminate .md-checkbox-background { animation: 180ms linear 0ms md-checkbox-fade-in-background; } .md-checkbox-anim-unchecked-indeterminate .md-checkbox-mixedmark { animation: 90ms linear 0ms md-checkbox-unchecked-indeterminate-mixedmark; } .md-checkbox-anim-checked-unchecked .md-checkbox-background { animation: 180ms linear 0ms md-checkbox-fade-out-background; } .md-checkbox-anim-checked-unchecked .md-checkbox-checkmark-path { animation: 90ms linear 0ms md-checkbox-checked-unchecked-checkmark-path; } .md-checkbox-anim-checked-indeterminate .md-checkbox-checkmark { animation: 90ms linear 0ms md-checkbox-checked-indeterminate-checkmark; } .md-checkbox-anim-checked-indeterminate .md-checkbox-mixedmark { animation: 90ms linear 0ms md-checkbox-checked-indeterminate-mixedmark; } .md-checkbox-anim-indeterminate-checked .md-checkbox-checkmark { animation: 500ms linear 0ms md-checkbox-indeterminate-checked-checkmark; } .md-checkbox-anim-indeterminate-checked .md-checkbox-mixedmark { animation: 500ms linear 0ms md-checkbox-indeterminate-checked-mixedmark; } .md-checkbox-anim-indeterminate-unchecked .md-checkbox-background { animation: 180ms linear 0ms md-checkbox-fade-out-background; } .md-checkbox-anim-indeterminate-unchecked .md-checkbox-mixedmark { animation: 300ms linear 0ms md-checkbox-indeterminate-unchecked-mixedmark; } .md-checkbox-input { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; text-transform: none; width: 1px; } .md-ink-ripple { border-radius: 50%; opacity: 0; height: 48px; left: 50%; overflow: hidden; pointer-events: none; position: absolute; top: 50%; transform: translate(-50%, -50%); transition: opacity ease 280ms, background-color ease 280ms; width: 48px; } .md-checkbox-focused .md-ink-ripple { opacity: 1; background-color: rgba(156, 39, 176, 0.26); } .md-checkbox-disabled .md-ink-ripple { background-color: #000; } /*# sourceMappingURL=checkbox.css.map */ "],
|
302 | host: {
|
303 | '[class.md-checkbox-indeterminate]': 'indeterminate',
|
304 | '[class.md-checkbox-checked]': 'checked',
|
305 | '[class.md-checkbox-disabled]': 'disabled',
|
306 | '[class.md-checkbox-align-end]': 'align == "end"',
|
307 | '[class.md-checkbox-focused]': 'hasFocus',
|
308 | },
|
309 | providers: [MD_CHECKBOX_CONTROL_VALUE_ACCESSOR],
|
310 | encapsulation: ViewEncapsulation.None,
|
311 | changeDetection: ChangeDetectionStrategy.OnPush
|
312 | }),
|
313 | __metadata('design:paramtypes', [Renderer, ElementRef])
|
314 | ], MdCheckbox);
|
315 | return MdCheckbox;
|
316 | }());
|
317 | export var MdCheckboxModule = (function () {
|
318 | function MdCheckboxModule() {
|
319 | }
|
320 | MdCheckboxModule.forRoot = function () {
|
321 | return {
|
322 | ngModule: MdCheckboxModule,
|
323 | providers: []
|
324 | };
|
325 | };
|
326 | MdCheckboxModule = __decorate([
|
327 | NgModule({
|
328 | exports: [MdCheckbox],
|
329 | declarations: [MdCheckbox],
|
330 | }),
|
331 | __metadata('design:paramtypes', [])
|
332 | ], MdCheckboxModule);
|
333 | return MdCheckboxModule;
|
334 | }());
|
335 |
|
336 |
|