Skip to content

Commit

Permalink
feat(module:menu dropdown): refactor menu dropdown & add test & add d…
Browse files Browse the repository at this point in the history
…oc (#990)

feat(module:menu dropdown): refactor menu dropdown & add test & add doc
  • Loading branch information
vthinkxie authored Feb 4, 2018
1 parent 6480d49 commit ca1d4e2
Show file tree
Hide file tree
Showing 63 changed files with 2,126 additions and 507 deletions.
5 changes: 4 additions & 1 deletion .angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
},
"codeCoverage": {
"exclude": [
"./site/**"
"./site/**",
"./components/test.ts",
"./components/core/**",
"./components/**/demo/**"
]
}
},
Expand Down
12 changes: 6 additions & 6 deletions PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
## 组件
| 组件 | 文档 | 测试 | 功能 | 负责 | 重构 |
| --- | --- | --- | --- | --- | --- |
| button || 100% | 100% | vthinkxie | x |
| icon || - | 100% | vthinkxie | x |
| grid || 100% | 100% | vthinkxie | x |
| layout || 100% | 100% | vthinkxie | x |
| button || 100% | 100% | vthinkxie | - |
| icon || - | 100% | vthinkxie | - |
| grid || 100% | 100% | vthinkxie | - |
| layout || 100% | 100% | vthinkxie | - |
| breadcrumb || 100% | 100% | vthinkxie | - |
| dropdown | x | x | x | vthinkxie | - |
| menu | x | x | x | vthinkxie | - |
| dropdown | | 100% | 100% | vthinkxie | - |
| menu | | 100% | 100% | vthinkxie | |
| pagination | x | x | x | vthinkxie | - |
| steps | x | x | x | vthinkxie | - |
| checkbox | x | x | x | vthinkxie | - |
Expand Down
12 changes: 6 additions & 6 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</a>
</p>

# NG ZORRO
[![Travis branch](https://img.shields.io/travis/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)]()
[![Coveralls github](https://img.shields.io/coveralls/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)]()
# NG-ZORRO
[![Travis branch](https://img.shields.io/travis/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)](https://travis-ci.org/NG-ZORRO/ng-zorro-antd)
[![Coveralls github](https://img.shields.io/coveralls/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)](https://coveralls.io/github/NG-ZORRO/ng-zorro-antd)
[![Gemnasium](https://img.shields.io/gemnasium/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://gemnasium.com/github.com/NG-ZORRO/ng-zorro-antd)
[![npm package](https://img.shields.io/npm/v/ng-zorro-antd.svg?style=flat-square)](https://www.npmjs.org/package/ng-zorro-antd)

[![GitHub Release Date](https://img.shields.io/github/release-date/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://github.com/NG-ZORRO/ng-zorro-antd/releases)
[![Issue Stats](https://img.shields.io/issuestats/i/github/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://github.com/NG-ZORRO/ng-zorro-antd/issues)
[![NPM downloads](http://img.shields.io/npm/dm/ng-zorro-antd.svg?style=flat-square)](https://npmjs.org/package/ng-zorro-antd)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/NG-ZORRO/ng-zorro-antd.svg)](http://isitmaintained.com/project/NG-ZORRO/ng-zorro-antd "Average time to resolve an issue")
[![Gitter](https://img.shields.io/gitter/room/ng-zorro/ng-zorro-antd.svg?style=flat-square)](https://gitter.im/ng-zorro/ng-zorro-antd)

这里是 Ant Design 的 Angular 5.0 实现,开发和服务于企业级后台产品。
Expand All @@ -26,7 +26,7 @@

## 支持环境

* 现代浏览器和 IE9 以上(需要 [polyfills](https://angular.io/guide/browser-support)
* 现代浏览器和 IE9 以上(需要 [polyfills](https://angular.io/guide/browser-support))

## 兼容版本

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</a>
</p>

# NG ZORRO
[![Travis branch](https://img.shields.io/travis/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)]()
[![Coveralls github](https://img.shields.io/coveralls/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)]()
# NG-ZORRO
[![Travis branch](https://img.shields.io/travis/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)](https://travis-ci.org/NG-ZORRO/ng-zorro-antd)
[![Coveralls github](https://img.shields.io/coveralls/NG-ZORRO/ng-zorro-antd/0.7.0.svg?style=flat-square)](https://coveralls.io/github/NG-ZORRO/ng-zorro-antd)
[![Gemnasium](https://img.shields.io/gemnasium/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://gemnasium.com/github.com/NG-ZORRO/ng-zorro-antd)
[![npm package](https://img.shields.io/npm/v/ng-zorro-antd.svg?style=flat-square)](https://www.npmjs.org/package/ng-zorro-antd)

[![GitHub Release Date](https://img.shields.io/github/release-date/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://github.com/NG-ZORRO/ng-zorro-antd/releases)
[![Issue Stats](https://img.shields.io/issuestats/i/github/NG-ZORRO/ng-zorro-antd.svg?style=flat-square)](https://github.com/NG-ZORRO/ng-zorro-antd/issues)
[![NPM downloads](http://img.shields.io/npm/dm/ng-zorro-antd.svg?style=flat-square)](https://npmjs.org/package/ng-zorro-antd)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/NG-ZORRO/ng-zorro-antd.svg)](http://isitmaintained.com/project/NG-ZORRO/ng-zorro-antd "Average time to resolve an issue")
[![Gitter](https://img.shields.io/gitter/room/ng-zorro/ng-zorro-antd.svg?style=flat-square)](https://gitter.im/ng-zorro/ng-zorro-antd)

An enterprise-class UI components based on Ant Design and Angular.
Expand All @@ -27,7 +27,7 @@ An enterprise-class UI components based on Ant Design and Angular.

## Environment Support

* Modern browsers and Internet Explorer 9+with [polyfills](https://angular.io/guide/browser-support))。
* Modern browsers and Internet Explorer 9+ (with [polyfills](https://angular.io/guide/browser-support)).

## Angular Version Support

Expand Down
16 changes: 8 additions & 8 deletions components/button/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { Component, ViewEncapsulation } from '@angular/core';
<span>Danger</span>
</button>`,
styles : [
`
[nz-button] {
margin-right: 8px;
margin-bottom: 12px;
}
`
[id^=components-button-demo-] [nz-button] {
margin-right: 8px;
margin-bottom: 12px;
}
nz-button-group [nz-button] {
margin-right: 0;
}
[id^=components-button-demo-] nz-button-group [nz-button] {
margin-right: 0;
}
`
]
})
Expand Down
1 change: 1 addition & 0 deletions components/button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
3 changes: 3 additions & 0 deletions components/button/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './nz-button.component';
export * from './nz-button-group.component';
export * from './nz-button.module';
42 changes: 42 additions & 0 deletions components/core/testing/dispatch-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {
createFakeEvent,
createKeyboardEvent,
createMouseEvent,
createTouchEvent
} from './event-objects';

/** Utility to dispatch any event on a Node. */
export function dispatchEvent(node: Node | Window, event: Event): Event {
node.dispatchEvent(event);
return event;
}

/** Shorthand to dispatch a fake event on a specified node. */
export function dispatchFakeEvent(node: Node | Window, type: string, canBubble?: boolean): Event {
return dispatchEvent(node, createFakeEvent(type, canBubble));
}

/** Shorthand to dispatch a keyboard event with a specified key code. */
export function dispatchKeyboardEvent(node: Node, type: string, keyCode: number, target?: Element):
KeyboardEvent {
return dispatchEvent(node, createKeyboardEvent(type, keyCode, target)) as KeyboardEvent;
}

/** Shorthand to dispatch a mouse event on the specified coordinates. */
export function dispatchMouseEvent(node: Node, type: string, x = 0, y = 0,
event = createMouseEvent(type, x, y)): MouseEvent {
return dispatchEvent(node, event) as MouseEvent;
}

/** Shorthand to dispatch a touch event on the specified coordinates. */
export function dispatchTouchEvent(node: Node, type: string, x = 0, y = 0) {
return dispatchEvent(node, createTouchEvent(type, x, y));
}
81 changes: 81 additions & 0 deletions components/core/testing/event-objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/** Creates a browser MouseEvent with the specified options. */
export function createMouseEvent(type: string, x = 0, y = 0) {
const event = document.createEvent('MouseEvent');

event.initMouseEvent(type,
false, /* canBubble */
false, /* cancelable */
window, /* view */
0, /* detail */
x, /* screenX */
y, /* screenY */
x, /* clientX */
y, /* clientY */
false, /* ctrlKey */
false, /* altKey */
false, /* shiftKey */
false, /* metaKey */
0, /* button */
null /* relatedTarget */);

return event;
}

/** Creates a browser TouchEvent with the specified pointer coordinates. */
export function createTouchEvent(type: string, pageX = 0, pageY = 0) {
// In favor of creating events that work for most of the browsers, the event is created
// as a basic UI Event. The necessary details for the event will be set manually.
const event = document.createEvent('UIEvent');
const touchDetails = {pageX, pageY};

event.initUIEvent(type, true, true, window, 0);

// Most of the browsers don't have a "initTouchEvent" method that can be used to define
// the touch details.
Object.defineProperties(event, {
touches: {value: [touchDetails]}
});

return event;
}

/** Dispatches a keydown event from an element. */
export function createKeyboardEvent(type: string, keyCode: number, target?: Element, key?: string) {
let event = document.createEvent('KeyboardEvent') as any;
// Firefox does not support `initKeyboardEvent`, but supports `initKeyEvent`.
let initEventFn = (event.initKeyEvent || event.initKeyboardEvent).bind(event);
let originalPreventDefault = event.preventDefault;

initEventFn(type, true, true, window, 0, 0, 0, 0, 0, keyCode);

// Webkit Browsers don't set the keyCode when calling the init function.
// See related bug https://bugs.webkit.org/show_bug.cgi?id=16735
Object.defineProperties(event, {
keyCode: { get: () => keyCode },
key: { get: () => key },
target: { get: () => target }
});

// IE won't set `defaultPrevented` on synthetic events so we need to do it manually.
event.preventDefault = function() {
Object.defineProperty(event, 'defaultPrevented', { get: () => true });
return originalPreventDefault.apply(this, arguments);
};

return event;
}

/** Creates a fake event object with any desired event type. */
export function createFakeEvent(type: string, canBubble = true, cancelable = true) {
const event = document.createEvent('Event');
event.initEvent(type, canBubble, cancelable);
return event;
}
24 changes: 24 additions & 0 deletions components/core/testing/fake-viewport-ruler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/** @docs-private */
export class FakeViewportRuler {
getViewportRect() {
return {
left: 0, top: 0, width: 1014, height: 686, bottom: 686, right: 1014
};
}

getViewportSize() {
return {width: 1014, height: 686};
}

getViewportScrollPosition() {
return {top: 0, left: 0};
}
}
11 changes: 11 additions & 0 deletions components/core/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/



export * from './public-api';
38 changes: 38 additions & 0 deletions components/core/testing/mock-ng-zone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {EventEmitter, Injectable, NgZone} from '@angular/core';


/**
* Mock synchronous NgZone implementation that can be used
* to flush out `onStable` subscriptions in tests.
*
* via: https://github.com/angular/angular/blob/master/packages/core/testing/src/ng_zone_mock.ts
* @docs-private
*/
@Injectable()
export class MockNgZone extends NgZone {
onStable: EventEmitter<any> = new EventEmitter(false);

constructor() {
super({enableLongStackTrace: false});
}

run(fn: Function): any {
return fn();
}

runOutsideAngular(fn: Function): any {
return fn();
}

simulateZoneExit(): void {
this.onStable.emit(null);
}
}
14 changes: 14 additions & 0 deletions components/core/testing/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

export * from './dispatch-events';
export * from './event-objects';
export * from './type-in-element';
export * from './wrapped-error-message';
export * from './fake-viewport-ruler';
export * from './mock-ng-zone';
21 changes: 21 additions & 0 deletions components/core/testing/type-in-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {dispatchFakeEvent} from './dispatch-events';

/**
* Focuses an input, sets its value and dispatches
* the `input` event, simulating the user typing.
* @param value Value to be set on the input.
* @param element Element onto which to set the value.
*/
export function typeInElement(value: string, element: HTMLInputElement) {
element.focus();
element.value = value;
dispatchFakeEvent(element, 'input');
}
16 changes: 16 additions & 0 deletions components/core/testing/wrapped-error-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* Gets a RegExp used to detect an angular wrapped error message.
* See https://github.com/angular/angular/issues/8348
*/
export function wrappedErrorMessage(e: Error) {
const escapedMessage = e.message.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
return new RegExp(escapedMessage);
}
8 changes: 4 additions & 4 deletions components/core/util/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coerci
export function toBoolean(value: boolean | string): boolean {
return coerceBooleanProperty(value);
}
//
// export function toNumber(value: number | string): number {
// return coerceNumberProperty(value);
// }

export function toNumber(value: number | string): number {
return coerceNumberProperty(value);
}
Loading

0 comments on commit ca1d4e2

Please sign in to comment.