Skip to content

Commit

Permalink
Merge branch 'master' into feature/toastr
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibing committed Sep 11, 2018
2 parents bbc73a4 + 2edd9b3 commit 216324b
Show file tree
Hide file tree
Showing 42 changed files with 1,307 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/articles/install-into-existing.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Same way you can enable Auth Module (more details under [Auth Module Concepts &
## Install Styles
Now, let's import Nebular styles
Include Bootstrap and default Nebular theme CSS files into your `.angular-cli.json` file:
Include Bootstrap and default Nebular theme CSS files into your `angular.json` file (or `.angular-cli.json` for Angular < 6.0):
```scss
"styles": [
Expand Down
File renamed without changes
10 changes: 10 additions & 0 deletions docs/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ export const structure = [
'NbContextMenuDirective',
],
},
{
type: 'tabs',
name: 'Dialog',
icon: 'dialog.svg',
source: [
'NbDialogService',
'NbDialogRef',
'NbDialogConfig',
],
},
{
type: 'tabs',
name: 'Toastr',
Expand Down
8 changes: 4 additions & 4 deletions e2e/popover.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ describe('nb-popover', () => {
element(placementRight).click();
const container = element(popover);
expect(container.isPresent()).toBeTruthy();
expect(container.getAttribute('class')).toEqual('right');
expect(container.getAttribute('class')).toEqual('nb-overlay-right');
});

it('render container in the bottom', () => {
element(placementBottom).click();
const container = element(popover);
expect(container.isPresent()).toBeTruthy();
expect(container.getAttribute('class')).toEqual('bottom');
expect(container.getAttribute('class')).toEqual('nb-overlay-bottom');
});

it('render container in the top', () => {
element(placementTop).click();
const container = element(popover);
expect(container.isPresent()).toBeTruthy();
expect(container.getAttribute('class')).toEqual('top');
expect(container.getAttribute('class')).toEqual('nb-overlay-top');
});

it('render container in the left', () => {
element(placementLeft).click();
const container = element(popover);
expect(container.isPresent()).toBeTruthy();
expect(container.getAttribute('class')).toEqual('left');
expect(container.getAttribute('class')).toEqual('nb-overlay-left');
});

it('open popover by host click', () => {
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions scripts/gulp/tasks/bundle/rollup-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ const ROLLUP_GLOBALS = {
'@angular/common/testing': 'ng.common.testing',
'@angular/common/http/testing': 'ng.common.http.testing',
'@angular/cdk/overlay': 'ng.cdk.overlay',
'@angular/cdk/portal': 'ng.cdk.overlay',
'@angular/cdk/platform': 'ng.cdk.overlay',
'@angular/cdk/platform': 'ng.cdk.platform',
'@angular/cdk/portal': 'ng.cdk.portal',
'@angular/cdk/a11y': 'ng.cdk.a11y',


// RxJS dependencies
Expand Down
12 changes: 12 additions & 0 deletions src/framework/theme/components/cdk/a11y/a11y.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';

import { NbFocusTrapFactoryService } from './focus-trap';


@NgModule({
providers: [
NbFocusTrapFactoryService,
],
})
export class NbA11yModule {
}
49 changes: 49 additions & 0 deletions src/framework/theme/components/cdk/a11y/focus-trap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Inject, Injectable, NgZone } from '@angular/core';
import { FocusTrap, FocusTrapFactory, InteractivityChecker } from '@angular/cdk/a11y';

import { NB_DOCUMENT } from '../../../theme.options';


/**
* Overrides angular cdk focus trap to keep restore functionality inside trap.
* */
export class NbFocusTrap extends FocusTrap {
protected previouslyFocusedElement: HTMLElement;

constructor(
protected element: HTMLElement,
protected checker: InteractivityChecker,
protected ngZone: NgZone,
protected document: Document,
deferAnchors) {
super(element, checker, ngZone, document, deferAnchors);
this.savePreviouslyFocusedElement();
}

restoreFocus() {
this.previouslyFocusedElement.focus();
this.destroy();
}

blurPreviouslyFocusedElement() {
this.previouslyFocusedElement.blur();
}

protected savePreviouslyFocusedElement() {
this.previouslyFocusedElement = this.document.activeElement as HTMLElement;
}
}

@Injectable()
export class NbFocusTrapFactoryService extends FocusTrapFactory {
constructor(
protected checker: InteractivityChecker,
protected ngZone: NgZone,
@Inject(NB_DOCUMENT) private document) {
super(checker, ngZone, document);
}

create(element: HTMLElement, deferCaptureElements?: boolean): NbFocusTrap {
return new NbFocusTrap(element, this.checker, this.ngZone, this.document, deferCaptureElements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import { NbViewportRulerAdapter } from './viewport-ruler-adapter';
{ provide: ScrollDispatcher, useClass: NbScrollDispatcherAdapter },
],
})
export class NbAdapterModule {
export class NbCdkAdapterModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { NbLayoutScrollService } from '../../../services/scroll.service';

@Injectable()
export class NbScrollDispatcherAdapter extends ScrollDispatcher {
constructor(_ngZone: NgZone, _platform: NbPlatform, protected scrollService: NbLayoutScrollService) {
super(_ngZone, _platform);
constructor(ngZone: NgZone, platform: NbPlatform, protected scrollService: NbLayoutScrollService) {
super(ngZone, platform);
}

scrolled(auditTimeInMs?: number): Observable<CdkScrollable | void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import { NbLayoutScrollService, NbScrollPosition } from '../../../services/scrol

@Injectable()
export class NbViewportRulerAdapter extends ViewportRuler {
constructor(_platform: NbPlatform, ngZone: NgZone,
constructor(platform: NbPlatform, ngZone: NgZone,
protected ruler: NbLayoutRulerService,
protected scroll: NbLayoutScrollService) {
super(_platform, ngZone);
super(platform, ngZone);
}

getViewportSize(): Readonly<{ width: number; height: number; }> {
let res;
/*
* getDimensions call is really synchronous operation.
* And we have to conform with the interface of the original service.
* */
this.ruler.getDimensions()
.pipe(map(dimensions => ({ width: dimensions.clientWidth, height: dimensions.clientHeight })))
.subscribe(rect => res = rect);
Expand All @@ -25,6 +29,10 @@ export class NbViewportRulerAdapter extends ViewportRuler {

getViewportScrollPosition(): { left: number; top: number } {
let res;
/*
* getPosition call is really synchronous operation.
* And we have to conform with the interface of the original service.
* */
this.scroll.getPosition()
.pipe(map((position: NbScrollPosition) => ({ top: position.y, left: position.x })))
.subscribe(position => res = position);
Expand Down
5 changes: 5 additions & 0 deletions src/framework/theme/components/cdk/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export * from './overlay';
export * from './a11y/a11y.module';
export * from './a11y/focus-trap';
export * from './adapter/overlay-container-adapter';
export * from './adapter/scroll-dispatcher-adapter';
export * from './adapter/viewport-ruler-adapter';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import '~@angular/cdk/overlay-prebuilt.css';

@mixin nb-overlay-theme {
.overlay-backdrop {
background: rgba(0, 0, 0, 0.288);
background: nb-theme(overlay-backdrop-bg);
}
}
22 changes: 20 additions & 2 deletions src/framework/theme/components/cdk/overlay/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Directive, Injectable, NgModule, TemplateRef, ViewContainerRef } from '@angular/core';
import { CdkPortal, ComponentPortal, Portal, PortalModule, TemplatePortal } from '@angular/cdk/portal';
import {
CdkPortal,
CdkPortalOutlet,
ComponentPortal,
Portal,
PortalInjector,
PortalModule,
TemplatePortal,
} from '@angular/cdk/portal';
import {
ComponentType,
ConnectedOverlayPositionChange,
Expand All @@ -13,6 +21,7 @@ import {
OverlayPositionBuilder,
OverlayRef,
PositionStrategy,
ScrollStrategy,
ScrollStrategyOptions,
} from '@angular/cdk/overlay';
import { Platform } from '@angular/cdk/platform';
Expand All @@ -22,6 +31,10 @@ import { Platform } from '@angular/cdk/platform';
export class NbPortalDirective extends CdkPortal {
}

@Directive({ selector: '[nbPortalOutlet]' })
export class NbPortalOutletDirective extends CdkPortalOutlet {
}

@Injectable()
export class NbOverlay extends Overlay {
}
Expand Down Expand Up @@ -49,6 +62,9 @@ export class NbOverlayContainer extends OverlayContainer {
export class NbFlexibleConnectedPositionStrategy extends FlexibleConnectedPositionStrategy {
}

export class NbPortalInjector extends PortalInjector {
}

export type NbPortal<T = any> = Portal<T>;
export type NbOverlayRef = OverlayRef;
export type NbComponentType<T = any> = ComponentType<T>;
Expand All @@ -58,6 +74,7 @@ export type NbConnectedOverlayPositionChange = ConnectedOverlayPositionChange;
export type NbConnectionPositionPair = ConnectionPositionPair;
export type NbOverlayConfig = OverlayConfig;
export type NbScrollStrategyOptions = ScrollStrategyOptions;
export type NbScrollStrategy = ScrollStrategy;

const CDK_MODULES = [OverlayModule, PortalModule];

Expand All @@ -76,8 +93,9 @@ const CDK_PROVIDERS = [
exports: [
...CDK_MODULES,
NbPortalDirective,
NbPortalOutletDirective,
],
declarations: [NbPortalDirective],
declarations: [NbPortalDirective, NbPortalOutletDirective],
providers: [...CDK_PROVIDERS],
})
export class NbCdkMappingModule {
Expand Down
10 changes: 5 additions & 5 deletions src/framework/theme/components/cdk/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { NbPosition } from './overlay-position';
export abstract class NbPositionedContainer {
@Input() position: NbPosition;

@HostBinding('class.top')
@HostBinding('class.nb-overlay-top')
get top(): boolean {
return this.position === NbPosition.TOP
}

@HostBinding('class.right')
@HostBinding('class.nb-overlay-right')
get right(): boolean {
return this.position === NbPosition.RIGHT
}

@HostBinding('class.bottom')
@HostBinding('class.nb-overlay-bottom')
get bottom(): boolean {
return this.position === NbPosition.BOTTOM
}

@HostBinding('class.left')
@HostBinding('class.nb-overlay-left')
get left(): boolean {
return this.position === NbPosition.LEFT
}
Expand Down Expand Up @@ -54,7 +54,7 @@ export class NbOverlayContainerComponent {
if (this.isComponent) {
Object.assign(el._componentRef.instance, this.context);
/**
* Change detection have to performed here, because another way applied context
* Change detection has to be performed here, because another way applied context
* will be rendered on the next change detection loop and
* we'll have incorrect positioning. Because rendered component may change its size
* based on the context.
Expand Down
6 changes: 4 additions & 2 deletions src/framework/theme/components/cdk/overlay/overlay.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { ModuleWithProviders, NgModule } from '@angular/core';

import { NbSharedModule } from '../../shared/shared.module';
import { NbCdkMappingModule } from './mapping';
import { NbAdapterModule } from '../adapter/adapter.module';
import { NbPositionBuilderService } from './overlay-position';
import { NbOverlayContainerComponent } from './overlay-container';
import { NbOverlayService } from './overlay';
import { NbCdkAdapterModule } from '../adapter/adapter.module';
import { NbPositionHelper } from './position-helper';


@NgModule({
imports: [
NbCdkMappingModule,
NbAdapterModule,
NbCdkAdapterModule,
NbSharedModule,
],
declarations: [NbOverlayContainerComponent],
Expand All @@ -27,6 +28,7 @@ export class NbOverlayModule {
providers: [
NbPositionBuilderService,
NbOverlayService,
NbPositionHelper,
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum NbGlobalPhysicalPosition {

export type NbGlobalPosition = NbGlobalPhysicalPosition | NbGlobalLogicalPosition;

@Injectable({ providedIn: 'root' })
@Injectable()
export class NbPositionHelper {
constructor(protected layoutDirection: NbLayoutDirectionService) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@
}
}

&.bottom .arrow {
&.nb-overlay-bottom .arrow {
top: calc(-#{$arrow-size} + 1px);
left: calc(50% - #{$arrow-size});
}

&.left .arrow {
&.nb-overlay-left .arrow {
right: round(-$arrow-size - $arrow-size / 2 + 2px);
top: calc(50% - #{$arrow-size / 2});
transform: rotate(90deg);
}

&.top .arrow {
&.nb-overlay-top .arrow {
bottom: calc(-#{$arrow-size} + 1px);
left: calc(50% - #{$arrow-size});
transform: rotate(180deg);
}

&.right .arrow {
&.nb-overlay-right .arrow {
left: round(-$arrow-size - $arrow-size / 2 + 2px);
top: calc(50% - #{$arrow-size / 2});
transform: rotate(270deg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class NbContextMenuDirective implements AfterViewInit, OnDestroy {
* Basic menu items, will be passed to the internal NbMenuComponent.
* */
@Input('nbContextMenu')
set _items(items: NbMenuItem[]) {
set setItems(items: NbMenuItem[]) {
this.validateItems(items);
this.items = items;
};
Expand Down
Loading

0 comments on commit 216324b

Please sign in to comment.