Skip to content

Commit

Permalink
fix: handle scrolling correctly (#168)
Browse files Browse the repository at this point in the history
Closes #161
  • Loading branch information
kyubisation authored Sep 16, 2019
1 parent 2e85d3d commit c9fa496
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 64 deletions.
1 change: 0 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
],
"styles": [
"projects/angular-showcase/src/styles.scss",
"node_modules/perfect-scrollbar/css/perfect-scrollbar.css",
"node_modules/highlight.js/styles/github.css"
],
"scripts": [],
Expand Down
68 changes: 35 additions & 33 deletions projects/angular-showcase/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<nav class="menu" [class.menu-open]="showMenu" perfectScrollbar>
<ul>
<li>
<a routerLink="/" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }"
>Introduction</a
>
</li>
<li class="title">Libraries</li>
<li>
<a routerLink="/public" routerLinkActive="active">@sbb-esta/angular-public</a>
</li>
<li>
<a routerLink="/business" routerLinkActive="active">@sbb-esta/angular-business</a>
</li>
<li>
<a routerLink="/core" routerLinkActive="active">@sbb-esta/angular-core</a>
</li>
<li>
<a routerLink="/icons" routerLinkActive="active">@sbb-esta/angular-icons</a>
</li>
<li>
<a routerLink="/keycloak" routerLinkActive="active">@sbb-esta/angular-keycloak</a>
</li>
<li class="title">About</li>
<li>
<a href="https://angular.io/">Angular {{ angularVersion }}</a>
</li>
<li>
<a routerLink="/">Showcase {{ showcaseVersion }}</a>
</li>
</ul>
<nav class="menu" [class.menu-open]="showMenu">
<perfect-scrollbar>
<ul>
<li>
<a routerLink="/" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }"
>Introduction</a
>
</li>
<li class="title">Libraries</li>
<li>
<a routerLink="/public" routerLinkActive="active">@sbb-esta/angular-public</a>
</li>
<li>
<a routerLink="/business" routerLinkActive="active">@sbb-esta/angular-business</a>
</li>
<li>
<a routerLink="/core" routerLinkActive="active">@sbb-esta/angular-core</a>
</li>
<li>
<a routerLink="/icons" routerLinkActive="active">@sbb-esta/angular-icons</a>
</li>
<li>
<a routerLink="/keycloak" routerLinkActive="active">@sbb-esta/angular-keycloak</a>
</li>
<li class="title">About</li>
<li>
<a href="https://angular.io/">Angular {{ angularVersion }}</a>
</li>
<li>
<a routerLink="/">Showcase {{ showcaseVersion }}</a>
</li>
</ul>
</perfect-scrollbar>
</nav>

<div class="container">
Expand All @@ -52,7 +54,7 @@
</svg>
</a>
</div>
<div class="content" perfectScrollbar>
<perfect-scrollbar class="content">
<router-outlet></router-outlet>
</div>
</perfect-scrollbar>
</div>
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { ICON_COMPONENT_LIST, IconCollectionModule } from '@sbb-esta/angular-icons';
import { MonacoEditorModule } from 'ngx-monaco-editor';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -24,7 +24,7 @@ import { PublicModule } from './public/public.module';
MonacoEditorModule.forRoot({ baseUrl: './assets' }),
IconCollectionModule,
ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
PerfectScrollbarModule,
ScrollingModule,
HttpClientModule,
BrowserAnimationsModule,
PublicModule,
Expand Down
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/business/business.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { TabsModule } from '@sbb-esta/angular-public/tabs';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { SharedModule } from '../shared/shared.module';

Expand All @@ -15,7 +15,7 @@ import { ComponentViewerComponent } from './component-viewer/component-viewer.co
declarations: [BusinessComponent, ComponentViewerComponent],
imports: [
CommonModule,
PerfectScrollbarModule,
ScrollingModule,
PortalModule,
BusinessExamplesModule,
SharedModule,
Expand Down
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { TabsModule } from '@sbb-esta/angular-public/tabs';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { SharedModule } from '../shared/shared.module';

Expand All @@ -15,7 +15,7 @@ import { ExamplesModule } from './examples/examples.module';
declarations: [CoreComponent, ComponentViewerComponent],
imports: [
CommonModule,
PerfectScrollbarModule,
ScrollingModule,
PortalModule,
ExamplesModule,
SharedModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { ExampleProvider } from '../../shared/example-provider';
export class CoreComponent implements ExampleProvider {
modules = {
breakpoints: 'Breakpoints',
datetime: 'Datetime'
datetime: 'Datetime',
scrolling: 'Scrolling'
};
private _examples: { [component: string]: { [name: string]: ComponentPortal<any> } } = {};

Expand Down
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/icons/icons.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { ICON_COMPONENT_LIST } from '@sbb-esta/angular-icons';
import { SearchModule } from '@sbb-esta/angular-public/search';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { SharedModule } from '../shared/shared.module';

Expand All @@ -21,7 +21,7 @@ import { IconsComponent } from './icons/icons.component';
CommonModule,
ReactiveFormsModule,
PortalModule,
PerfectScrollbarModule,
ScrollingModule,
SearchModule,
SharedModule,
IconsRoutingModule
Expand Down
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/public/public.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { TabsModule } from '@sbb-esta/angular-public/tabs';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { SharedModule } from '../shared/shared.module';

Expand All @@ -15,8 +15,8 @@ import { PublicComponent } from './public/public.component';
declarations: [PublicComponent, ComponentViewerComponent],
imports: [
CommonModule,
PerfectScrollbarModule,
PortalModule,
ScrollingModule,
PublicExamplesModule,
SharedModule,
TabsModule,
Expand Down
4 changes: 2 additions & 2 deletions projects/angular-showcase/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';
import { TabsModule } from '@sbb-esta/angular-public/tabs';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';

import { ApiViewerComponent } from './api-viewer/api-viewer.component';
import { ExampleViewerComponent } from './example-viewer/example-viewer.component';
Expand All @@ -16,7 +16,7 @@ import { SubmenuComponent } from './submenu/submenu.component';
ExampleViewerComponent,
ApiViewerComponent
],
imports: [CommonModule, PerfectScrollbarModule, PortalModule, TabsModule],
imports: [CommonModule, ScrollingModule, PortalModule, TabsModule],
exports: [SubmenuComponent, MarkdownViewerComponent, ExampleViewerComponent, ApiViewerComponent]
})
export class SharedModule {}
1 change: 1 addition & 0 deletions projects/sbb-esta/angular-core/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/sbb-esta/angular-core",
"whitelistedNonPeerDependencies": ["tslib", "ngx-perfect-scrollbar"],
"lib": {
"entryFile": "public-api.ts"
}
Expand Down
3 changes: 3 additions & 0 deletions projects/sbb-esta/angular-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"@angular/cdk": "^8.0.0",
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0"
},
"dependencies": {
"ngx-perfect-scrollbar": "^8.0.0"
}
}
1 change: 1 addition & 0 deletions projects/sbb-esta/angular-core/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from '@sbb-esta/angular-core/common-behaviors';
export * from '@sbb-esta/angular-core/datetime';
export * from '@sbb-esta/angular-core/error';
export * from '@sbb-esta/angular-core/models';
export * from '@sbb-esta/angular-core/scrolling';
1 change: 1 addition & 0 deletions projects/sbb-esta/angular-core/scrolling/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/public_api';
19 changes: 19 additions & 0 deletions projects/sbb-esta/angular-core/scrolling/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"ngPackage": {
"lib": {
"umdModuleIds": {
"@sbb-esta/angular-core": "sbbAngularCore",
"@sbb-esta/angular-core/base": "sbbAngularCoreBase",
"@sbb-esta/angular-core/breakpoints": "sbbAngularCoreBreakpoints",
"@sbb-esta/angular-core/common-behaviors": "sbbAngularCoreCommonBehaviors",
"@sbb-esta/angular-core/datetime": "sbbAngularCoreDatetime",
"@sbb-esta/angular-core/error": "sbbAngularCoreError",
"@sbb-esta/angular-core/forms": "sbbAngularCoreForms",
"@sbb-esta/angular-core/icon-directive": "sbbAngularCoreIconDirective",
"@sbb-esta/angular-core/models": "sbbAngularCoreModels",
"@sbb-esta/angular-icons": "sbbAngularIcons",
"ngx-perfect-scrollbar": "ngxPerfectScrollbar"
}
}
}
}
28 changes: 28 additions & 0 deletions projects/sbb-esta/angular-core/scrolling/scrolling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The `scrolling` module wraps the [ngx-perfect-scrollbar](https://www.npmjs.com/package/ngx-perfect-scrollbar)
package. The wrapper fixes an issue with the [CDK Overlay](https://material.angular.io/cdk/overlay/overview)
integration.

### Usage

See the documentation for [ngx-perfect-scrollbar](https://www.npmjs.com/package/ngx-perfect-scrollbar)
on how to use the `perfect-scrollbar`.

```ts
import { ScrollingModule } from '@sbb-esta/angular-core/scrolling';

@NgModule({
...
imports: [
...
ScrollingModule,
...
]
})
export class AppModule {}
```

```html
<perfect-scrollbar style="max-width: 600px; max-height: 400px;" [config]="config">
<div>Scrollable content</div>
</perfect-scrollbar>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ElementRef } from '@angular/core';
import { Subject } from 'rxjs';

import { PsComponentScrollable, PsDirectiveScrollable } from './ps-scrollable.directive';

describe('PsDirectiveScrollable', () => {
const perfectScrollbarMock = {
psScrollY: new Subject(),
psScrollX: new Subject()
};
const scrollDispatcherMock = {
register(): void {},
deregister(): void {}
};

it('should emit on inner scroll', () => {
const directive = new PsDirectiveScrollable(
perfectScrollbarMock as any,
new ElementRef(null),
scrollDispatcherMock as any,
null,
null
);
let counter = 0;
directive.elementScrolled().subscribe(() => ++counter);
perfectScrollbarMock.psScrollX.next();
expect(counter).toBe(1);
perfectScrollbarMock.psScrollY.next();
expect(counter).toBe(2);
});
});

describe('PsComponentScrollable', () => {
const perfectScrollbarMock = {
psScrollY: new Subject(),
psScrollX: new Subject()
};
const scrollDispatcherMock = {
register(): void {},
deregister(): void {}
};

it('should emit on inner scroll', () => {
const directive = new PsComponentScrollable(
perfectScrollbarMock as any,
new ElementRef(null),
scrollDispatcherMock as any,
null,
null
);
let counter = 0;
directive.elementScrolled().subscribe(() => ++counter);
perfectScrollbarMock.psScrollX.next();
expect(counter).toBe(1);
perfectScrollbarMock.psScrollY.next();
expect(counter).toBe(2);
});
});
Loading

0 comments on commit c9fa496

Please sign in to comment.