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

Commit

Permalink
feat(list): ts conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo committed Feb 1, 2019
1 parent 869e44c commit 6a66c5d
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 349 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"dist": "npm run build && npm run build:min",
"dev": "npm run clean && cross-env MDC_ENV=development webpack-dev-server --config=demos/webpack.config.js --progress --inline --hot --host 0.0.0.0",
"fix:js": "eslint --fix packages test webpack.config.js demos/webpack.config.js karma.conf.js",
"fix:ts": "tslint --fix \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"fix:ts": "tslint --exclude \"test/**/*.d.ts\" --fix \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"fix:css": "stylelint --fix \"packages/**/*.scss\"; stylelint --fix --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
"fix": "npm-run-all --parallel fix:*",
"lint:css": "stylelint \"packages/**/*.scss\"; stylelint --config=test/screenshot/.stylelintrc.yaml \"test/screenshot/**/*.scss\"",
"lint:js": "eslint packages test scripts webpack.config.js demos/webpack.config.js karma.conf.js",
"lint:ts": "tslint \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"lint:ts": "tslint --exclude \"test/**/*.d.ts\" \"packages/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\"",
"lint:html": "find test/screenshot/spec/ -name '*.html' | grep -v 'index.html$' | xargs htmllint",
"lint:imports": "node scripts/check-imports.js",
"lint": "npm-run-all --parallel lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-base/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MDCComponent<FoundationType extends MDCFoundation> {
* Fires a cross-browser-compatible custom event from the component root of the given type,
* with the given data.
*/
emit(evtType: string, evtData: object, shouldBubble = false) {
emit(evtType: string, evtData: number | object, shouldBubble = false) {
let evt;
if (typeof CustomEvent === 'function') {
evt = new CustomEvent(evtType, {
Expand Down
76 changes: 21 additions & 55 deletions packages/mdc-list/adapter.js → packages/mdc-list/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,102 +21,68 @@
* THE SOFTWARE.
*/

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

/**
* Adapter for MDC List. Provides an interface for managing focus.
*
* 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/code/architecture.md
*
* @record
*/
class MDCListAdapter {
/** @return {number} */
getListItemCount() {}

/**
* @return {number} */
getFocusedElementIndex() {}
interface MDCListAdapter {
getListItemCount(): number;

/**
* @param {number} index
* @param {string} attribute
* @param {string} value
*/
setAttributeForElementIndex(index, attribute, value) {}
getFocusedElementIndex(): number;

/**
* @param {number} index
* @param {string} attribute
*/
removeAttributeForElementIndex(index, attribute) {}
setAttributeForElementIndex(index: number, attribute: string, value: string): void;

/**
* @param {number} index
* @param {string} className
*/
addClassForElementIndex(index, className) {}
removeAttributeForElementIndex(index: number, attribute: string): void;

/**
* @param {number} index
* @param {string} className
*/
removeClassForElementIndex(index, className) {}
addClassForElementIndex(index: number, className: string): void;

removeClassForElementIndex(index: number, className: string): void;

/**
* Focuses list item at the index specified.
* @param {number} index
*/
focusItemAtIndex(index) {}
focusItemAtIndex(index: number): void;

/**
* Sets the tabindex to the value specified for all button/a element children of
* the list item at the index specified.
* @param {number} listItemIndex
* @param {number} tabIndexValue
*/
setTabIndexForListItemChildren(listItemIndex, tabIndexValue) {}
setTabIndexForListItemChildren(listItemIndex: number, tabIndexValue: string): void;

/**
* @param {number} index
* @return {boolean} Returns true if radio button is present at given list item index.
* @return Returns true if radio button is present at given list item index.
*/
hasRadioAtIndex(index) {}
hasRadioAtIndex(index: number): boolean

/**
* @param {number} index
* @return {boolean} Returns true if checkbox is present at given list item index.
* @return Returns true if checkbox is present at given list item index.
*/
hasCheckboxAtIndex(index) {}
hasCheckboxAtIndex(index: number): boolean;

/**
* @param {number} index
* @return {boolean} Returns true if checkbox inside a list item is checked.
* @return Returns true if checkbox inside a list item is checked.
*/
isCheckboxCheckedAtIndex(index) {}
isCheckboxCheckedAtIndex(index: number): boolean

/**
* Sets the checked status of checkbox or radio at given list item index.
* @param {number} index
* @param {boolean} isChecked
*/
setCheckedCheckboxOrRadioAtIndex(index, isChecked) {}
setCheckedCheckboxOrRadioAtIndex(index: number, isChecked: boolean): void

/**
* Notifies user action on list item.
*/
notifyAction(index) {}
notifyAction(index: number): void;

/**
* @return {boolean} Returns true when the current focused element is inside list root.
* @return Returns true when the current focused element is inside list root.
*/
isFocusInsideList() {}
isFocusInsideList(): boolean;
}

export default MDCListAdapter;
export {MDCListAdapter as default, MDCListAdapter};
27 changes: 12 additions & 15 deletions packages/mdc-list/constants.js → packages/mdc-list/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,33 @@
* THE SOFTWARE.
*/

/** @enum {string} */
const cssClasses = {
ROOT: 'mdc-list',
LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
LIST_ITEM_CLASS: 'mdc-list-item',
LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
ROOT: 'mdc-list',
};

/** @enum {string} */
const strings = {
ARIA_ORIENTATION: 'aria-orientation',
ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
ARIA_SELECTED: 'aria-selected',
ARIA_CHECKED: 'aria-checked',
ACTION_EVENT: 'MDCList:action',
ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
ARIA_CHECKED: 'aria-checked',
ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
ARIA_ORIENTATION: 'aria-orientation',
ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
RADIO_SELECTOR: 'input[type="radio"]:not(:disabled)',
CHECKBOX_SELECTOR: 'input[type="checkbox"]:not(:disabled)',
ARIA_SELECTED: 'aria-selected',
CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"]:not(:disabled), input[type="radio"]:not(:disabled)',
CHECKBOX_SELECTOR: 'input[type="checkbox"]:not(:disabled)',
CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: `.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} a`,
ENABLED_ITEMS_SELECTOR: '.mdc-list-item:not(.mdc-list-item--disabled)',
FOCUSABLE_CHILD_ELEMENTS: `.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled), .${cssClasses.LIST_ITEM_CLASS} a,
.${cssClasses.LIST_ITEM_CLASS} input[type="radio"]:not(:disabled),
.${cssClasses.LIST_ITEM_CLASS} input[type="checkbox"]:not(:disabled)`,
ENABLED_ITEMS_SELECTOR: '.mdc-list-item:not(.mdc-list-item--disabled)',
ACTION_EVENT: 'MDCList:action',
RADIO_SELECTOR: 'input[type="radio"]:not(:disabled)',
};

/** @typedef {number|!Array<number>} */
let Index;
type Index = number | number[];

export {strings, cssClasses, Index};
Loading

0 comments on commit 6a66c5d

Please sign in to comment.