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 { MDCFoundation } from '@material/base/foundation';
|
25 | import { cssClasses, strings } from './constants';
|
26 | var MDCIconButtonToggleFoundation = (function (_super) {
|
27 | __extends(MDCIconButtonToggleFoundation, _super);
|
28 | function MDCIconButtonToggleFoundation(adapter) {
|
29 | var _this = _super.call(this, __assign(__assign({}, MDCIconButtonToggleFoundation.defaultAdapter), adapter)) || this;
|
30 | |
31 |
|
32 |
|
33 |
|
34 | _this.hasToggledAriaLabel = false;
|
35 | return _this;
|
36 | }
|
37 | Object.defineProperty(MDCIconButtonToggleFoundation, "cssClasses", {
|
38 | get: function () {
|
39 | return cssClasses;
|
40 | },
|
41 | enumerable: false,
|
42 | configurable: true
|
43 | });
|
44 | Object.defineProperty(MDCIconButtonToggleFoundation, "strings", {
|
45 | get: function () {
|
46 | return strings;
|
47 | },
|
48 | enumerable: false,
|
49 | configurable: true
|
50 | });
|
51 | Object.defineProperty(MDCIconButtonToggleFoundation, "defaultAdapter", {
|
52 | get: function () {
|
53 | return {
|
54 | addClass: function () { return undefined; },
|
55 | hasClass: function () { return false; },
|
56 | notifyChange: function () { return undefined; },
|
57 | removeClass: function () { return undefined; },
|
58 | getAttr: function () { return null; },
|
59 | setAttr: function () { return undefined; },
|
60 | };
|
61 | },
|
62 | enumerable: false,
|
63 | configurable: true
|
64 | });
|
65 | MDCIconButtonToggleFoundation.prototype.init = function () {
|
66 | var ariaLabelOn = this.adapter.getAttr(strings.DATA_ARIA_LABEL_ON);
|
67 | var ariaLabelOff = this.adapter.getAttr(strings.DATA_ARIA_LABEL_OFF);
|
68 | if (ariaLabelOn && ariaLabelOff) {
|
69 | if (this.adapter.getAttr(strings.ARIA_PRESSED) !== null) {
|
70 | throw new Error('MDCIconButtonToggleFoundation: Button should not set ' +
|
71 | '`aria-pressed` if it has a toggled aria label.');
|
72 | }
|
73 | this.hasToggledAriaLabel = true;
|
74 | }
|
75 | else {
|
76 | this.adapter.setAttr(strings.ARIA_PRESSED, String(this.isOn()));
|
77 | }
|
78 | };
|
79 | MDCIconButtonToggleFoundation.prototype.handleClick = function () {
|
80 | this.toggle();
|
81 | this.adapter.notifyChange({ isOn: this.isOn() });
|
82 | };
|
83 | MDCIconButtonToggleFoundation.prototype.isOn = function () {
|
84 | return this.adapter.hasClass(cssClasses.ICON_BUTTON_ON);
|
85 | };
|
86 | MDCIconButtonToggleFoundation.prototype.toggle = function (isOn) {
|
87 | if (isOn === void 0) { isOn = !this.isOn(); }
|
88 |
|
89 | if (isOn) {
|
90 | this.adapter.addClass(cssClasses.ICON_BUTTON_ON);
|
91 | }
|
92 | else {
|
93 | this.adapter.removeClass(cssClasses.ICON_BUTTON_ON);
|
94 | }
|
95 |
|
96 | if (this.hasToggledAriaLabel) {
|
97 | var ariaLabel = isOn ?
|
98 | this.adapter.getAttr(strings.DATA_ARIA_LABEL_ON) :
|
99 | this.adapter.getAttr(strings.DATA_ARIA_LABEL_OFF);
|
100 | this.adapter.setAttr(strings.ARIA_LABEL, ariaLabel || '');
|
101 | }
|
102 | else {
|
103 | this.adapter.setAttr(strings.ARIA_PRESSED, "" + isOn);
|
104 | }
|
105 | };
|
106 | return MDCIconButtonToggleFoundation;
|
107 | }(MDCFoundation));
|
108 | export { MDCIconButtonToggleFoundation };
|
109 |
|
110 | export default MDCIconButtonToggleFoundation;
|
111 |
|
\ | No newline at end of file |