Skip to content

Commit

Permalink
feat(menu): annotate mdc-menu for closure compiler
Browse files Browse the repository at this point in the history
Resolves #339 Added new annotations to mdc-menu. Corrected a couple of annotations in base.
  • Loading branch information
bogusred authored and lynnmercier committed Jun 22, 2017
1 parent 94d62ad commit b188d4f
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 62 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
},
"closureWhitelist": [
"mdc-animation",
"mdc-base"
"mdc-base",
"mdc-menu"
]
}
4 changes: 2 additions & 2 deletions packages/mdc-base/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class MDCComponent {
* @param {...?} args
*/
constructor(root, foundation = undefined, ...args) {
/** @private {!Element} */
/** @protected {!Element} */
this.root_ = root;
this.initialize(...args);
// Note that we initialize foundation here and not within the constructor's default param so that
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class MDCComponent {
* with the given data.
* @param {string} evtType
* @param {!Object} evtData
* @param {boolean} shouldBubble
* @param {boolean=} shouldBubble
*/
emit(evtType, evtData, shouldBubble = false) {
let evt;
Expand Down
160 changes: 160 additions & 0 deletions packages/mdc-menu/simple/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint no-unused-vars: [2, {"args": "none"}] */

/**
* Adapter for MDC Simple Menu. Provides an interface for managing
* - classes
* - dom
* - focus
* - position
* - dimensions
* - event handlers
*
* Additionally, provides type information for the adapter to the Closure
* compiler.
*
* Implement this adapter for your framework of choice to delegate updates to
* the component in your framework of choice. See architecture documentation
* for more details.
* https://github.com/material-components/material-components-web/blob/master/docs/architecture.md
*
* @record
*/
export default class MDCSimpleMenuAdapter {
/** @param {string} className */
addClass(className) {}

/** @param {string} className */
removeClass(className) {}

/**
* @param {string} className
* @return {boolean}
*/
hasClass(className) {}

/** @return {boolean} */
hasNecessaryDom() {}

/**
* @param {EventTarget} target
* @param {string} attributeName
* @return {string}
*/
getAttributeForEventTarget(target, attributeName) {}

/** @return {{ width: number, height: number }} */
getInnerDimensions() {}

/** @return {boolean} */
hasAnchor() {}

/** @return {{width: number, height: number, top: number, right: number, bottom: number, left: number}} */
getAnchorDimensions() {}

/** @return {{ width: number, height: number }} */
getWindowDimensions() {}

/**
* @param {number} x
* @param {number} y
*/
setScale(x, y) {}

/**
* @param {number} x
* @param {number} y
*/
setInnerScale(x, y) {}

/** @return {number} */
getNumberOfItems() {}

/**
* @param {string} type
* @param {function(!Event)} handler
*/
registerInteractionHandler(type, handler) {}

/**
* @param {string} type
* @param {function(!Event)} handler
*/
deregisterInteractionHandler(type, handler) {}

/** @param {function(!Event)} handler */
registerBodyClickHandler(handler) {}

/** @param {function(!Event)} handler */
deregisterBodyClickHandler(handler) {}

/**
* @param {number} index
* @return {{top: number, height: number}}
*/
getYParamsForItemAtIndex(index) {}

/**
* @param {number} index
* @param {string|null} value
*/
setTransitionDelayForItemAtIndex(index, value) {}

/**
* @param {EventTarget} target
* @return {number}
*/
getIndexForEventTarget(target) {}

/** @param {{index: number}} evtData */
notifySelected(evtData) {}

notifyCancel() {}

saveFocus() {}

restoreFocus() {}

/** @return {boolean} */
isFocused() {}

focus() {}

/** @return {number} */
getFocusedItemIndex() /* number */ {}

/** @param {number} index */
focusItemAtIndex(index) {}

/** @return {boolean} */
isRtl() {}

/** @param {string} origin */
setTransformOrigin(origin) {}

/** @param {{
* top: (string|undefined),
* right: (string|undefined),
* bottom: (string|undefined),
* left: (string|undefined)
* }} position */
setPosition(position) {}

/** @return {number} */
getAccurateTime() {}
}
4 changes: 4 additions & 0 deletions packages/mdc-menu/simple/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @enum {string} */
export const cssClasses = {
ROOT: 'mdc-simple-menu',
OPEN: 'mdc-simple-menu--open',
Expand All @@ -22,13 +24,15 @@ export const cssClasses = {
BOTTOM_RIGHT: 'mdc-simple-menu--open-from-bottom-right',
};

/** @enum {string} */
export const strings = {
ITEMS_SELECTOR: '.mdc-simple-menu__items',
SELECTED_EVENT: 'MDCSimpleMenu:selected',
CANCEL_EVENT: 'MDCSimpleMenu:cancel',
ARIA_DISABLED_ATTR: 'aria-disabled',
};

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

0 comments on commit b188d4f

Please sign in to comment.