1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __assign, __extends } from "tslib";
|
24 | import { MDCComponent } from '@material/base/component';
|
25 | import { MDCRipple } from '@material/ripple/component';
|
26 | import { MDCRippleFoundation } from '@material/ripple/foundation';
|
27 | import { MDCChipTrailingAction } from '../trailingaction/component';
|
28 | import { strings as trailingActionStrings } from '../trailingaction/constants';
|
29 | import { strings } from './constants';
|
30 | import { MDCChipFoundation } from './foundation';
|
31 | var MDCChip = (function (_super) {
|
32 | __extends(MDCChip, _super);
|
33 | function MDCChip() {
|
34 | return _super !== null && _super.apply(this, arguments) || this;
|
35 | }
|
36 | Object.defineProperty(MDCChip.prototype, "selected", {
|
37 | |
38 |
|
39 |
|
40 | get: function () {
|
41 | return this.foundation.isSelected();
|
42 | },
|
43 | |
44 |
|
45 |
|
46 | set: function (selected) {
|
47 | this.foundation.setSelected(selected);
|
48 | },
|
49 | enumerable: false,
|
50 | configurable: true
|
51 | });
|
52 | Object.defineProperty(MDCChip.prototype, "shouldRemoveOnTrailingIconClick", {
|
53 | |
54 |
|
55 |
|
56 | get: function () {
|
57 | return this.foundation.getShouldRemoveOnTrailingIconClick();
|
58 | },
|
59 | |
60 |
|
61 |
|
62 | set: function (shouldRemove) {
|
63 | this.foundation.setShouldRemoveOnTrailingIconClick(shouldRemove);
|
64 | },
|
65 | enumerable: false,
|
66 | configurable: true
|
67 | });
|
68 | Object.defineProperty(MDCChip.prototype, "setShouldFocusPrimaryActionOnClick", {
|
69 | |
70 |
|
71 |
|
72 | set: function (shouldFocus) {
|
73 | this.foundation.setShouldFocusPrimaryActionOnClick(shouldFocus);
|
74 | },
|
75 | enumerable: false,
|
76 | configurable: true
|
77 | });
|
78 | Object.defineProperty(MDCChip.prototype, "ripple", {
|
79 | get: function () {
|
80 | return this.rippleSurface;
|
81 | },
|
82 | enumerable: false,
|
83 | configurable: true
|
84 | });
|
85 | Object.defineProperty(MDCChip.prototype, "id", {
|
86 | get: function () {
|
87 | return this.root.id;
|
88 | },
|
89 | enumerable: false,
|
90 | configurable: true
|
91 | });
|
92 | MDCChip.attachTo = function (root) {
|
93 | return new MDCChip(root);
|
94 | };
|
95 | MDCChip.prototype.initialize = function (rippleFactory, trailingActionFactory) {
|
96 | var _this = this;
|
97 | if (rippleFactory === void 0) { rippleFactory = function (el, foundation) { return new MDCRipple(el, foundation); }; }
|
98 | if (trailingActionFactory === void 0) { trailingActionFactory = function (el) { return new MDCChipTrailingAction(el); }; }
|
99 | this.leadingIcon = this.root.querySelector(strings.LEADING_ICON_SELECTOR);
|
100 | this.checkmark = this.root.querySelector(strings.CHECKMARK_SELECTOR);
|
101 | this.primaryAction =
|
102 | this.root.querySelector(strings.PRIMARY_ACTION_SELECTOR);
|
103 | var trailingActionEl = this.root.querySelector(strings.TRAILING_ACTION_SELECTOR);
|
104 | if (trailingActionEl) {
|
105 | this.trailingAction = trailingActionFactory(trailingActionEl);
|
106 | }
|
107 |
|
108 |
|
109 | var rippleAdapter = __assign(__assign({}, MDCRipple.createAdapter(this)), { computeBoundingRect: function () { return _this.foundation.getDimensions(); } });
|
110 | this.rippleSurface =
|
111 | rippleFactory(this.root, new MDCRippleFoundation(rippleAdapter));
|
112 | };
|
113 | MDCChip.prototype.initialSyncWithDOM = function () {
|
114 | var _this = this;
|
115 |
|
116 | this.handleTrailingActionInteraction = function () {
|
117 | _this.foundation.handleTrailingActionInteraction();
|
118 | };
|
119 | this.handleTrailingActionNavigation =
|
120 | function (evt) {
|
121 | _this.foundation.handleTrailingActionNavigation(evt);
|
122 | };
|
123 |
|
124 | this.handleClick = function () {
|
125 | _this.foundation.handleClick();
|
126 | };
|
127 | this.handleKeydown = function (evt) {
|
128 | _this.foundation.handleKeydown(evt);
|
129 | };
|
130 | this.handleTransitionEnd = function (evt) {
|
131 | _this.foundation.handleTransitionEnd(evt);
|
132 | };
|
133 | this.handleFocusIn = function (evt) {
|
134 | _this.foundation.handleFocusIn(evt);
|
135 | };
|
136 | this.handleFocusOut = function (evt) {
|
137 | _this.foundation.handleFocusOut(evt);
|
138 | };
|
139 | this.listen('transitionend', this.handleTransitionEnd);
|
140 | this.listen('click', this.handleClick);
|
141 | this.listen('keydown', this.handleKeydown);
|
142 | this.listen('focusin', this.handleFocusIn);
|
143 | this.listen('focusout', this.handleFocusOut);
|
144 | if (this.trailingAction) {
|
145 | this.listen(trailingActionStrings.INTERACTION_EVENT, this.handleTrailingActionInteraction);
|
146 | this.listen(trailingActionStrings.NAVIGATION_EVENT, this.handleTrailingActionNavigation);
|
147 | }
|
148 | };
|
149 | MDCChip.prototype.destroy = function () {
|
150 | this.rippleSurface.destroy();
|
151 | this.unlisten('transitionend', this.handleTransitionEnd);
|
152 | this.unlisten('keydown', this.handleKeydown);
|
153 | this.unlisten('click', this.handleClick);
|
154 | this.unlisten('focusin', this.handleFocusIn);
|
155 | this.unlisten('focusout', this.handleFocusOut);
|
156 | if (this.trailingAction) {
|
157 | this.unlisten(trailingActionStrings.INTERACTION_EVENT, this.handleTrailingActionInteraction);
|
158 | this.unlisten(trailingActionStrings.NAVIGATION_EVENT, this.handleTrailingActionNavigation);
|
159 | }
|
160 | _super.prototype.destroy.call(this);
|
161 | };
|
162 | |
163 |
|
164 |
|
165 | MDCChip.prototype.beginExit = function () {
|
166 | this.foundation.beginExit();
|
167 | };
|
168 | MDCChip.prototype.getDefaultFoundation = function () {
|
169 | var _this = this;
|
170 |
|
171 |
|
172 | var adapter = {
|
173 | addClass: function (className) { return _this.root.classList.add(className); },
|
174 | addClassToLeadingIcon: function (className) {
|
175 | if (_this.leadingIcon) {
|
176 | _this.leadingIcon.classList.add(className);
|
177 | }
|
178 | },
|
179 | eventTargetHasClass: function (target, className) {
|
180 | return target ? target.classList.contains(className) : false;
|
181 | },
|
182 | focusPrimaryAction: function () {
|
183 | if (_this.primaryAction) {
|
184 | _this.primaryAction.focus();
|
185 | }
|
186 | },
|
187 | focusTrailingAction: function () {
|
188 | if (_this.trailingAction) {
|
189 | _this.trailingAction.focus();
|
190 | }
|
191 | },
|
192 | getAttribute: function (attr) { return _this.root.getAttribute(attr); },
|
193 | getCheckmarkBoundingClientRect: function () {
|
194 | return _this.checkmark ? _this.checkmark.getBoundingClientRect() : null;
|
195 | },
|
196 | getComputedStyleValue: function (propertyName) {
|
197 | return window.getComputedStyle(_this.root).getPropertyValue(propertyName);
|
198 | },
|
199 | getRootBoundingClientRect: function () { return _this.root.getBoundingClientRect(); },
|
200 | hasClass: function (className) { return _this.root.classList.contains(className); },
|
201 | hasLeadingIcon: function () { return !!_this.leadingIcon; },
|
202 | isRTL: function () { return window.getComputedStyle(_this.root).getPropertyValue('direction') === 'rtl'; },
|
203 | isTrailingActionNavigable: function () {
|
204 | if (_this.trailingAction) {
|
205 | return _this.trailingAction.isNavigable();
|
206 | }
|
207 | return false;
|
208 | },
|
209 | notifyInteraction: function () { return _this.emit(strings.INTERACTION_EVENT, { chipId: _this.id }, true ); },
|
210 | notifyNavigation: function (key, source) {
|
211 | return _this.emit(strings.NAVIGATION_EVENT, { chipId: _this.id, key: key, source: source }, true );
|
212 | },
|
213 | notifyRemoval: function (removedAnnouncement) {
|
214 | _this.emit(strings.REMOVAL_EVENT, { chipId: _this.id, removedAnnouncement: removedAnnouncement }, true );
|
215 | },
|
216 | notifySelection: function (selected, shouldIgnore) {
|
217 | return _this.emit(strings.SELECTION_EVENT, { chipId: _this.id, selected: selected, shouldIgnore: shouldIgnore }, true );
|
218 | },
|
219 | notifyTrailingIconInteraction: function () {
|
220 | return _this.emit(strings.TRAILING_ICON_INTERACTION_EVENT, { chipId: _this.id }, true );
|
221 | },
|
222 | notifyEditStart: function () { },
|
223 | notifyEditFinish: function () { },
|
224 | removeClass: function (className) { return _this.root.classList.remove(className); },
|
225 | removeClassFromLeadingIcon: function (className) {
|
226 | if (_this.leadingIcon) {
|
227 | _this.leadingIcon.classList.remove(className);
|
228 | }
|
229 | },
|
230 | removeTrailingActionFocus: function () {
|
231 | if (_this.trailingAction) {
|
232 | _this.trailingAction.removeFocus();
|
233 | }
|
234 | },
|
235 | setPrimaryActionAttr: function (attr, value) {
|
236 | if (_this.primaryAction) {
|
237 | _this.primaryAction.setAttribute(attr, value);
|
238 | }
|
239 | },
|
240 | setStyleProperty: function (propertyName, value) {
|
241 | return _this.root.style.setProperty(propertyName, value);
|
242 | },
|
243 | };
|
244 | return new MDCChipFoundation(adapter);
|
245 | };
|
246 | MDCChip.prototype.setSelectedFromChipSet = function (selected, shouldNotifyClients) {
|
247 | this.foundation.setSelectedFromChipSet(selected, shouldNotifyClients);
|
248 | };
|
249 | MDCChip.prototype.focusPrimaryAction = function () {
|
250 | this.foundation.focusPrimaryAction();
|
251 | };
|
252 | MDCChip.prototype.focusTrailingAction = function () {
|
253 | this.foundation.focusTrailingAction();
|
254 | };
|
255 | MDCChip.prototype.removeFocus = function () {
|
256 | this.foundation.removeFocus();
|
257 | };
|
258 | MDCChip.prototype.remove = function () {
|
259 | var parent = this.root.parentNode;
|
260 | if (parent !== null) {
|
261 | parent.removeChild(this.root);
|
262 | }
|
263 | };
|
264 | return MDCChip;
|
265 | }(MDCComponent));
|
266 | export { MDCChip };
|
267 |
|
\ | No newline at end of file |