Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit b188d4f

Browse files
bogusredlynnmercier
authored andcommitted
feat(menu): annotate mdc-menu for closure compiler
Resolves #339 Added new annotations to mdc-menu. Corrected a couple of annotations in base.
1 parent 94d62ad commit b188d4f

File tree

7 files changed

+356
-62
lines changed

7 files changed

+356
-62
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
},
159159
"closureWhitelist": [
160160
"mdc-animation",
161-
"mdc-base"
161+
"mdc-base",
162+
"mdc-menu"
162163
]
163164
}

packages/mdc-base/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class MDCComponent {
3939
* @param {...?} args
4040
*/
4141
constructor(root, foundation = undefined, ...args) {
42-
/** @private {!Element} */
42+
/** @protected {!Element} */
4343
this.root_ = root;
4444
this.initialize(...args);
4545
// Note that we initialize foundation here and not within the constructor's default param so that
@@ -104,7 +104,7 @@ export default class MDCComponent {
104104
* with the given data.
105105
* @param {string} evtType
106106
* @param {!Object} evtData
107-
* @param {boolean} shouldBubble
107+
* @param {boolean=} shouldBubble
108108
*/
109109
emit(evtType, evtData, shouldBubble = false) {
110110
let evt;
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* eslint no-unused-vars: [2, {"args": "none"}] */
18+
19+
/**
20+
* Adapter for MDC Simple Menu. Provides an interface for managing
21+
* - classes
22+
* - dom
23+
* - focus
24+
* - position
25+
* - dimensions
26+
* - event handlers
27+
*
28+
* Additionally, provides type information for the adapter to the Closure
29+
* compiler.
30+
*
31+
* Implement this adapter for your framework of choice to delegate updates to
32+
* the component in your framework of choice. See architecture documentation
33+
* for more details.
34+
* https://github.com/material-components/material-components-web/blob/master/docs/architecture.md
35+
*
36+
* @record
37+
*/
38+
export default class MDCSimpleMenuAdapter {
39+
/** @param {string} className */
40+
addClass(className) {}
41+
42+
/** @param {string} className */
43+
removeClass(className) {}
44+
45+
/**
46+
* @param {string} className
47+
* @return {boolean}
48+
*/
49+
hasClass(className) {}
50+
51+
/** @return {boolean} */
52+
hasNecessaryDom() {}
53+
54+
/**
55+
* @param {EventTarget} target
56+
* @param {string} attributeName
57+
* @return {string}
58+
*/
59+
getAttributeForEventTarget(target, attributeName) {}
60+
61+
/** @return {{ width: number, height: number }} */
62+
getInnerDimensions() {}
63+
64+
/** @return {boolean} */
65+
hasAnchor() {}
66+
67+
/** @return {{width: number, height: number, top: number, right: number, bottom: number, left: number}} */
68+
getAnchorDimensions() {}
69+
70+
/** @return {{ width: number, height: number }} */
71+
getWindowDimensions() {}
72+
73+
/**
74+
* @param {number} x
75+
* @param {number} y
76+
*/
77+
setScale(x, y) {}
78+
79+
/**
80+
* @param {number} x
81+
* @param {number} y
82+
*/
83+
setInnerScale(x, y) {}
84+
85+
/** @return {number} */
86+
getNumberOfItems() {}
87+
88+
/**
89+
* @param {string} type
90+
* @param {function(!Event)} handler
91+
*/
92+
registerInteractionHandler(type, handler) {}
93+
94+
/**
95+
* @param {string} type
96+
* @param {function(!Event)} handler
97+
*/
98+
deregisterInteractionHandler(type, handler) {}
99+
100+
/** @param {function(!Event)} handler */
101+
registerBodyClickHandler(handler) {}
102+
103+
/** @param {function(!Event)} handler */
104+
deregisterBodyClickHandler(handler) {}
105+
106+
/**
107+
* @param {number} index
108+
* @return {{top: number, height: number}}
109+
*/
110+
getYParamsForItemAtIndex(index) {}
111+
112+
/**
113+
* @param {number} index
114+
* @param {string|null} value
115+
*/
116+
setTransitionDelayForItemAtIndex(index, value) {}
117+
118+
/**
119+
* @param {EventTarget} target
120+
* @return {number}
121+
*/
122+
getIndexForEventTarget(target) {}
123+
124+
/** @param {{index: number}} evtData */
125+
notifySelected(evtData) {}
126+
127+
notifyCancel() {}
128+
129+
saveFocus() {}
130+
131+
restoreFocus() {}
132+
133+
/** @return {boolean} */
134+
isFocused() {}
135+
136+
focus() {}
137+
138+
/** @return {number} */
139+
getFocusedItemIndex() /* number */ {}
140+
141+
/** @param {number} index */
142+
focusItemAtIndex(index) {}
143+
144+
/** @return {boolean} */
145+
isRtl() {}
146+
147+
/** @param {string} origin */
148+
setTransformOrigin(origin) {}
149+
150+
/** @param {{
151+
* top: (string|undefined),
152+
* right: (string|undefined),
153+
* bottom: (string|undefined),
154+
* left: (string|undefined)
155+
* }} position */
156+
setPosition(position) {}
157+
158+
/** @return {number} */
159+
getAccurateTime() {}
160+
}

packages/mdc-menu/simple/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/** @enum {string} */
1618
export const cssClasses = {
1719
ROOT: 'mdc-simple-menu',
1820
OPEN: 'mdc-simple-menu--open',
@@ -22,13 +24,15 @@ export const cssClasses = {
2224
BOTTOM_RIGHT: 'mdc-simple-menu--open-from-bottom-right',
2325
};
2426

27+
/** @enum {string} */
2528
export const strings = {
2629
ITEMS_SELECTOR: '.mdc-simple-menu__items',
2730
SELECTED_EVENT: 'MDCSimpleMenu:selected',
2831
CANCEL_EVENT: 'MDCSimpleMenu:cancel',
2932
ARIA_DISABLED_ATTR: 'aria-disabled',
3033
};
3134

35+
/** @enum {number} */
3236
export const numbers = {
3337
// Amount of time to wait before triggering a selected event on the menu. Note that this time
3438
// will most likely be bumped up once interactive lists are supported to allow for the ripple to

0 commit comments

Comments
 (0)