Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(menu-surface): Convert JS to TypeScript #4273

Merged
merged 52 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6324518
chore(menu-surface): Convert JS to TypeScript
acdvorak Jan 19, 2019
6b9bdf0
Merge branch 'feat/typescript' into feat/typescript--menu-surface
acdvorak Jan 23, 2019
f8a687a
WIP: Remove `MDCMenuSurface` prefix from type names; remove `readonly…
acdvorak Jan 23, 2019
07fff99
WIP: Simplify types; replace string props with number for top/bottom/…
acdvorak Jan 23, 2019
a0843b1
WIP: Replace indexable types on `MenuPosition` with `keyof`
acdvorak Jan 23, 2019
7e3e6fe
WIP: Consolidate width/height properties into `MenuSize` objects
acdvorak Jan 23, 2019
1538325
WIP: Rename `MenuSize` to `MenuDimensions`
acdvorak Jan 23, 2019
913f607
WIP: Remove obsolete TODOs
acdvorak Jan 23, 2019
947b90a
WIP: Remove unnecessary JSDoc annotation
acdvorak Jan 23, 2019
6f3045d
WIP: Relocate type annotation
acdvorak Jan 23, 2019
f55703f
WIP: Remove stray empty comment
acdvorak Jan 23, 2019
ee56995
WIP: Move `MenuPosition` and `MenuDimensions` defs from `adapter.ts` …
acdvorak Jan 23, 2019
ec3b469
fix(infrastructure): add strict: true to tsconfig
Jan 23, 2019
96c0514
fix: add strict: true to tsconfi
Jan 23, 2019
e3c3d50
WIP: Fix linter error
acdvorak Jan 24, 2019
b95fcfa
WIP: Update focusable element types to `HTMLElement | SVGElement`
acdvorak Jan 24, 2019
5bf6e27
WIP: Strong typing for `getTransformPropertyName()` return value
acdvorak Jan 24, 2019
0f0525d
WIP: Style
acdvorak Jan 24, 2019
83429aa
Merge branch 'feat/typescript--menu-surface' of github.com:material-c…
acdvorak Jan 24, 2019
e704163
fix: add tsconfig and update packages
Jan 24, 2019
09aae61
Update foundation.ts
Jan 24, 2019
fda0f28
Update foundation.ts
Jan 24, 2019
5075a05
fix: update closest from HTMLElement to Element
Jan 24, 2019
1811646
WIP: Fix tslint errors
acdvorak Jan 24, 2019
06bb41a
fix: remove dups of strict=true
Jan 24, 2019
b8ec011
Merge remote-tracking branch 'origin/fix/tsconfigupdate' into feat/ty…
acdvorak Jan 24, 2019
82eb81e
WIP: Fix strict mode errors
acdvorak Jan 24, 2019
54a86ae
WIP: Replace most `HTMLElement` types with `Element`
acdvorak Jan 24, 2019
583b87d
WIP: Add `MenuDistance` type with all properties required
acdvorak Jan 31, 2019
f71d734
WIP: Replace `Array.forEach()` with `for...of`
acdvorak Jan 31, 2019
920470d
WIP: Use `Partial<MenuDistance>` instead of `MenuPosition`
acdvorak Jan 31, 2019
0d9b8a8
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Jan 31, 2019
5288593
Merge remote-tracking branch 'origin/feat/typescript' into feat/types…
acdvorak Jan 31, 2019
ab6d979
WIP: Remove file-level `tslint:disable` comments
acdvorak Jan 31, 2019
7f043d5
WIP: Use `SpecificEventListener`
acdvorak Feb 1, 2019
964932d
WIP: Fix JSDoc syntax for `@see`
acdvorak Feb 1, 2019
69d1c19
WIP: Initialize member variables with inline values
acdvorak Feb 1, 2019
6d54f74
WIP: Add comments to members with definite assignment operators (`!`)
acdvorak Feb 1, 2019
f976600
WIP: Revert removal of `/index` from JS import paths
acdvorak Feb 1, 2019
ec8d68c
WIP: Fix comments in foundation and test
acdvorak Feb 1, 2019
c2db556
WIP: Increase foundation test coverage from 91% to 99%
acdvorak Feb 1, 2019
9452569
WIP: Improve component test coverage
acdvorak Feb 1, 2019
63845ba
WIP: Increase component test coverage to 100%
acdvorak Feb 1, 2019
16eb9a7
WIP: Clean up debugging code
acdvorak Feb 1, 2019
e264819
WIP: Dummy commit
acdvorak Feb 1, 2019
f00a4aa
Revert "WIP: Dummy commit"
acdvorak Feb 1, 2019
56b75ac
WIP: Rename `.js` to `.ts` in README
acdvorak Feb 1, 2019
d45afea
WIP: Move `Menu*` interface defs from `constants.ts` to new `types.ts…
acdvorak Feb 4, 2019
9c76326
WIP: Update `Menu*` interfaces to point to `types.ts` in README
acdvorak Feb 4, 2019
b964b75
WIP: Change `MenuPosition` to `Partial<MenuDistance>` in MDCMenu's RE…
acdvorak Feb 4, 2019
3fee18d
WIP: Fix typo
acdvorak Feb 5, 2019
86cfdad
WIP: Change `null` to empty string to be consistent with PR #4351
acdvorak Feb 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/material-components-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import * as linearProgress from '@material/linear-progress/index';
import * as lineRipple from '@material/line-ripple/index';
import * as list from '@material/list/index';
import * as menu from '@material/menu/index';
import * as menuSurface from '@material/menu-surface/index';
import * as menuSurface from '@material/menu-surface/index.ts';
import * as notchedOutline from '@material/notched-outline/index';
import * as radio from '@material/radio/index';
import * as ripple from '@material/ripple/index';
Expand Down
6 changes: 3 additions & 3 deletions packages/mdc-menu-surface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Mixin | Description

Constant Name | Description
--- | ---
`Corner` | Enum for representing an element corner for positioning the menu-surface. See [constants.js](./constants.js).
`AnchorMargin` | Margin values representing the distance from anchor point that the menu surface should be shown. See [foundation.js](./foundation.js).
`Corner` | Enum for representing an element corner for positioning the menu-surface. See [constants.js](constants.ts).
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
`AnchorMargin` | Margin values representing the distance from anchor point that the menu surface should be shown. See [foundation.js](foundation.ts).

## `MDCMenuSurface` Properties and Methods

Expand Down Expand Up @@ -216,7 +216,7 @@ Method Signature | Description

Method Signature | Description
--- | ---
`setAnchorCorner(corner: Corner) => void` | Sets the corner that the menu surface will be anchored to. See [constants.js](./constants.js)
`setAnchorCorner(corner: Corner) => void` | Sets the corner that the menu surface will be anchored to. See [constants.js](constants.ts)
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
`setAnchorMargin(margin: AnchorMargin) => void` | Sets the distance from the anchor point that the menu surface should be shown.
`setIsHoisted(isHoisted: boolean) => void` | Sets whether the menu surface has been hoisted to the body so that the offsets are calculated relative to the page and not the anchor.
`setFixedPosition(isFixed: boolean) => void` | Sets whether the menu surface is using fixed positioning.
Expand Down
127 changes: 0 additions & 127 deletions packages/mdc-menu-surface/adapter.js

This file was deleted.

131 changes: 131 additions & 0 deletions packages/mdc-menu-surface/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* Adapter for MDCMenuSurface. Provides an interface for managing
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
* - 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/code/architecture.md
*/
interface MDCMenuSurfaceAdapter {
addClass(className: string): void;
removeClass(className: string): void;
hasClass(className: string): boolean;
hasAnchor(): boolean;

isElementInContainer(el: Element): boolean;
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
isFocused(): boolean;
isFirstElementFocused(): boolean;
isLastElementFocused(): boolean;
isRtl(): boolean;

getInnerDimensions(): MDCMenuSurfaceSize;
getAnchorDimensions(): MDCMenuSurfaceRect;
getWindowDimensions(): MDCMenuSurfaceSize;
getBodyDimensions(): MDCMenuSurfaceSize;
getWindowScroll(): MDCMenuSurfacePoint;
setPosition(position: MDCMenuSurfacePositionInput): void;
setMaxHeight(height: string): void;
setTransformOrigin(origin: string): void;

/** Saves the element that was focused before the menu surface was opened. */
saveFocus(): void;

/** Restores focus to the element that was focused before the menu surface was opened. */
restoreFocus(): void;

/** Focuses the first focusable element in the menu-surface. */
focusFirstElement(): void;

/** Focuses the first focusable element in the menu-surface. */
focusLastElement(): void;

/** Emits an event when the menu surface is closed. */
notifyClose(): void;

/** Emits an event when the menu surface is opened. */
notifyOpen(): void;
}

// TODO(acdvorak): Should properties be readonly?
acdvorak marked this conversation as resolved.
Show resolved Hide resolved

interface MDCMenuSurfacePositionInput {
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
/*readonly*/ top?: number | string;
/*readonly*/ right?: number | string;
/*readonly*/ bottom?: number | string;
/*readonly*/ left?: number | string;

// TODO(acdvorak): Remove this and find a better way than for...in with hasOwnProperty().
[key: string]: number | string;
acdvorak marked this conversation as resolved.
Show resolved Hide resolved
}

interface MDCMenuSurfacePositionOutput {
/*readonly*/ top: number;
/*readonly*/ right: number;
/*readonly*/ bottom: number;
/*readonly*/ left: number;

// TODO(acdvorak): Remove this and find a better way than for...in with hasOwnProperty().
[key: string]: number;
}

interface MDCMenuSurfaceRect {
/*readonly*/ top: number;
/*readonly*/ right: number;
/*readonly*/ bottom: number;
/*readonly*/ left: number;
/*readonly*/ width: number;
/*readonly*/ height: number;
/*readonly*/ x?: number;
/*readonly*/ y?: number;
}

interface MDCMenuSurfaceSize {
/*readonly*/ width: number;
/*readonly*/ height: number;
}

interface MDCMenuSurfacePoint {
/*readonly*/ x: number;
/*readonly*/ y: number;
}

// TODO(acdvorak): Export with {} syntax in other component PRs
export {
MDCMenuSurfaceAdapter,
MDCMenuSurfacePoint,
MDCMenuSurfacePositionInput,
MDCMenuSurfacePositionOutput,
MDCMenuSurfaceSize,
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* THE SOFTWARE.
*/

/** @enum {string} */
// tslint:disable:object-literal-sort-keys no-bitwise
acdvorak marked this conversation as resolved.
Show resolved Hide resolved

const cssClasses = {
ANCHOR: 'mdc-menu-surface--anchor',
ANIMATING_CLOSED: 'mdc-menu-surface--animating-closed',
Expand All @@ -31,55 +32,55 @@ const cssClasses = {
ROOT: 'mdc-menu-surface',
};

/** @enum {string} */
const strings = {
CLOSED_EVENT: 'MDCMenuSurface:closed',
OPENED_EVENT: 'MDCMenuSurface:opened',
FOCUSABLE_ELEMENTS: 'button:not(:disabled), [href]:not([aria-disabled="true"]), input:not(:disabled), ' +
'select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"]):not([aria-disabled="true"])',
CLOSED_EVENT: 'MDCMenuSurface:closed',
FOCUSABLE_ELEMENTS: [
'button:not(:disabled)', '[href]:not([aria-disabled="true"])', 'input:not(:disabled)',
'select:not(:disabled)', 'textarea:not(:disabled)', '[tabindex]:not([tabindex="-1"]):not([aria-disabled="true"])',
].join(', '),
};

/** @enum {number} */
const numbers = {
// Total duration of menu-surface open animation.
/** Total duration of menu-surface open animation. */
TRANSITION_OPEN_DURATION: 120,
// Total duration of menu-surface close animation.

/** Total duration of menu-surface close animation. */
TRANSITION_CLOSE_DURATION: 75,
// Margin left to the edge of the viewport when menu-surface is at maximum possible height.

/** Margin left to the edge of the viewport when menu-surface is at maximum possible height. */
MARGIN_TO_EDGE: 32,
// Ratio of anchor width to menu-surface width for switching from corner positioning to center positioning.

/** Ratio of anchor width to menu-surface width for switching from corner positioning to center positioning. */
ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO: 0.67,
};

/**
* Enum for bits in the {@see Corner) bitmap.
* @enum {number}
*/
const CornerBit = {
BOTTOM: 1,
CENTER: 2,
RIGHT: 4,
FLIP_RTL: 8,
};
enum CornerBit {
BOTTOM = 1,
CENTER = 2,
RIGHT = 4,
FLIP_RTL = 8,
}

/**
* Enum for representing an element corner for positioning the menu-surface.
*
* The START constants map to LEFT if element directionality is left
* to right and RIGHT if the directionality is right to left.
* Likewise END maps to RIGHT or LEFT depending on the directionality.
*
* @enum {number}
*/
const Corner = {
TOP_LEFT: 0,
TOP_RIGHT: CornerBit.RIGHT,
BOTTOM_LEFT: CornerBit.BOTTOM,
BOTTOM_RIGHT: CornerBit.BOTTOM | CornerBit.RIGHT,
TOP_START: CornerBit.FLIP_RTL,
TOP_END: CornerBit.FLIP_RTL | CornerBit.RIGHT,
BOTTOM_START: CornerBit.BOTTOM | CornerBit.FLIP_RTL,
BOTTOM_END: CornerBit.BOTTOM | CornerBit.RIGHT | CornerBit.FLIP_RTL,
};
enum Corner {
TOP_LEFT = 0,
TOP_RIGHT = CornerBit.RIGHT,
BOTTOM_LEFT = CornerBit.BOTTOM,
BOTTOM_RIGHT = CornerBit.BOTTOM | CornerBit.RIGHT,
TOP_START = CornerBit.FLIP_RTL,
TOP_END = CornerBit.FLIP_RTL | CornerBit.RIGHT,
BOTTOM_START = CornerBit.BOTTOM | CornerBit.FLIP_RTL,
BOTTOM_END = CornerBit.BOTTOM | CornerBit.RIGHT | CornerBit.FLIP_RTL,
}

export {cssClasses, strings, numbers, CornerBit, Corner};
Loading