diff --git a/projects/angular-showcase/src/app/app.component.html b/projects/angular-showcase/src/app/app.component.html index 1f83315dc5..2a24eea617 100644 --- a/projects/angular-showcase/src/app/app.component.html +++ b/projects/angular-showcase/src/app/app.component.html @@ -1,36 +1,34 @@
@@ -54,7 +52,7 @@
- +
- +
diff --git a/projects/angular-showcase/src/app/business/business-routing.module.ts b/projects/angular-showcase/src/app/business/business-routing.module.ts index 0975834c77..e159dd5838 100644 --- a/projects/angular-showcase/src/app/business/business-routing.module.ts +++ b/projects/angular-showcase/src/app/business/business-routing.module.ts @@ -1,10 +1,11 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { PublicComponentViewerModule } from '../features/public-component-viewer/public-component-viewer.module'; +import { PublicComponentViewerComponent } from '../features/public-component-viewer/public-component-viewer/public-component-viewer.component'; import { MarkdownViewerComponent } from '../shared/markdown-viewer/markdown-viewer.component'; import { BusinessComponent } from './business/business.component'; -import { ComponentViewerComponent } from './component-viewer/component-viewer.component'; const routes: Routes = [ { @@ -24,12 +25,12 @@ const routes: Routes = [ }, { path: 'components/:id', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-business' } }, { path: 'components/:id/:section', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-business' } } ] @@ -37,7 +38,7 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forChild(routes)], + imports: [RouterModule.forChild(routes), PublicComponentViewerModule], exports: [RouterModule] }) export class BusinessRoutingModule {} diff --git a/projects/angular-showcase/src/app/business/business.module.ts b/projects/angular-showcase/src/app/business/business.module.ts index 7f9f085c0c..e338358f0f 100644 --- a/projects/angular-showcase/src/app/business/business.module.ts +++ b/projects/angular-showcase/src/app/business/business.module.ts @@ -9,10 +9,9 @@ import { SharedModule } from '../shared/shared.module'; import { BusinessExamplesModule } from './business-examples/business-examples.module'; import { BusinessRoutingModule } from './business-routing.module'; import { BusinessComponent } from './business/business.component'; -import { ComponentViewerComponent } from './component-viewer/component-viewer.component'; @NgModule({ - declarations: [BusinessComponent, ComponentViewerComponent], + declarations: [BusinessComponent], imports: [ CommonModule, ScrollingModule, diff --git a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.scss b/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.scss deleted file mode 100644 index 17f4130db9..0000000000 --- a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.scss +++ /dev/null @@ -1,10 +0,0 @@ -:host { - display: block; - height: calc(100vh - 48px); - overflow-y: hidden; - margin-left: 300px; -} - -article { - padding: 3rem; -} diff --git a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.ts b/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.ts deleted file mode 100644 index be3a9cb39f..0000000000 --- a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Component, Renderer2 } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; - -import { ComponentViewerBase } from '../../shared/component-viewer-base'; -import { ExampleProvider } from '../../shared/example-provider'; -import { HtmlLoader } from '../../shared/html-loader.service'; - -@Component({ - selector: 'sbb-component-viewer', - templateUrl: './component-viewer.component.html', - styleUrls: ['./component-viewer.component.scss'] -}) -export class ComponentViewerComponent extends ComponentViewerBase { - constructor( - htmlLoader: HtmlLoader, - exampleProvider: ExampleProvider, - route: ActivatedRoute, - renderer: Renderer2 - ) { - super(htmlLoader, exampleProvider, route, renderer); - } -} diff --git a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.html b/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.html deleted file mode 100644 index 1b5ad6ac9c..0000000000 --- a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.html +++ /dev/null @@ -1,15 +0,0 @@ - -
- - -
-
- -
-
- - - -
-
-
diff --git a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.ts b/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.ts deleted file mode 100644 index be3a9cb39f..0000000000 --- a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Component, Renderer2 } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; - -import { ComponentViewerBase } from '../../shared/component-viewer-base'; -import { ExampleProvider } from '../../shared/example-provider'; -import { HtmlLoader } from '../../shared/html-loader.service'; - -@Component({ - selector: 'sbb-component-viewer', - templateUrl: './component-viewer.component.html', - styleUrls: ['./component-viewer.component.scss'] -}) -export class ComponentViewerComponent extends ComponentViewerBase { - constructor( - htmlLoader: HtmlLoader, - exampleProvider: ExampleProvider, - route: ActivatedRoute, - renderer: Renderer2 - ) { - super(htmlLoader, exampleProvider, route, renderer); - } -} diff --git a/projects/angular-showcase/src/app/core/core-routing.module.ts b/projects/angular-showcase/src/app/core/core-routing.module.ts index 8926d15fe8..ede96dacf9 100644 --- a/projects/angular-showcase/src/app/core/core-routing.module.ts +++ b/projects/angular-showcase/src/app/core/core-routing.module.ts @@ -1,7 +1,8 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { ComponentViewerComponent } from '../business/component-viewer/component-viewer.component'; +import { PublicComponentViewerModule } from '../features/public-component-viewer/public-component-viewer.module'; +import { PublicComponentViewerComponent } from '../features/public-component-viewer/public-component-viewer/public-component-viewer.component'; import { ApiViewerComponent } from '../shared/api-viewer/api-viewer.component'; import { MarkdownViewerComponent } from '../shared/markdown-viewer/markdown-viewer.component'; @@ -25,12 +26,12 @@ const routes: Routes = [ }, { path: 'components/:id', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-core' } }, { path: 'components/:id/:section', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-core' } }, { @@ -43,7 +44,7 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forChild(routes)], + imports: [RouterModule.forChild(routes), PublicComponentViewerModule], exports: [RouterModule] }) export class CoreRoutingModule {} diff --git a/projects/angular-showcase/src/app/core/core.module.ts b/projects/angular-showcase/src/app/core/core.module.ts index f784efea62..d1c144fa35 100644 --- a/projects/angular-showcase/src/app/core/core.module.ts +++ b/projects/angular-showcase/src/app/core/core.module.ts @@ -6,12 +6,11 @@ import { TabsModule } from '@sbb-esta/angular-public/tabs'; import { SharedModule } from '../shared/shared.module'; -import { ComponentViewerComponent } from './component-viewer/component-viewer.component'; import { CoreRoutingModule } from './core-routing.module'; import { CoreComponent } from './core/core.component'; @NgModule({ - declarations: [CoreComponent, ComponentViewerComponent], + declarations: [CoreComponent], imports: [ CommonModule, ScrollingModule, diff --git a/projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.html b/projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.html similarity index 100% rename from projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.html rename to projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.html diff --git a/projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.scss b/projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.scss similarity index 74% rename from projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.scss rename to projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.scss index 51829f97c2..123f059409 100644 --- a/projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.scss +++ b/projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.scss @@ -1,5 +1,5 @@ -@import '../../../../../sbb-esta/angular-core/styles/common/button'; -@import '../../../../../sbb-esta/angular-core/styles/common/colors'; +@import '../../../../../../sbb-esta/angular-core/styles/common/button'; +@import '../../../../../../sbb-esta/angular-core/styles/common/colors'; :host { display: block; diff --git a/projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.ts b/projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.ts similarity index 85% rename from projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.ts rename to projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.ts index 264a028a33..ab8903f9d6 100644 --- a/projects/angular-showcase/src/app/shared/example-viewer/example-viewer.component.ts +++ b/projects/angular-showcase/src/app/features/public-component-viewer/example-viewer/public-example-viewer.component.ts @@ -13,14 +13,14 @@ import { ActivatedRoute } from '@angular/router'; import { combineLatest, Observable, Subject } from 'rxjs'; import { map } from 'rxjs/operators'; -import { HtmlLoader } from '../html-loader.service'; +import { HtmlLoader } from '../../../shared/html-loader.service'; @Component({ - selector: 'sbb-example-viewer', - templateUrl: './example-viewer.component.html', - styleUrls: ['./example-viewer.component.scss'] + selector: 'sbb-public-example-viewer', + templateUrl: './public-example-viewer.component.html', + styleUrls: ['./public-example-viewer.component.scss'] }) -export class ExampleViewerComponent implements OnInit, AfterViewInit, OnDestroy { +export class PublicExampleViewerComponent implements OnInit, AfterViewInit, OnDestroy { @Input() example: ComponentPortal; @Input() name: string; @ViewChild('html', { static: false }) html: ElementRef; diff --git a/projects/angular-showcase/src/app/features/public-component-viewer/ps-chrome-patch.directive.ts b/projects/angular-showcase/src/app/features/public-component-viewer/ps-chrome-patch.directive.ts new file mode 100644 index 0000000000..b78079de0a --- /dev/null +++ b/projects/angular-showcase/src/app/features/public-component-viewer/ps-chrome-patch.directive.ts @@ -0,0 +1,20 @@ +import { Directive, ElementRef, Self } from '@angular/core'; +import { PerfectScrollbarComponent } from 'ngx-perfect-scrollbar'; + +@Directive({ + // tslint:disable-next-line: directive-selector + selector: 'perfect-scrollbar' +}) +export class PsChromePatchDirective { + constructor(elementRef: ElementRef, @Self() perfectScrollbar: PerfectScrollbarComponent) { + const element: HTMLElement = elementRef.nativeElement; + perfectScrollbar.psXReachEnd.subscribe(() => { + if ( + perfectScrollbar.directiveRef.elementRef.nativeElement.getBoundingClientRect().top < 0 && + element.scrollTo + ) { + element.scrollTo(0, 0); + } + }); + } +} diff --git a/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer.module.ts b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer.module.ts new file mode 100644 index 0000000000..9e2086d2fd --- /dev/null +++ b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer.module.ts @@ -0,0 +1,19 @@ +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 { PublicExampleViewerComponent } from './example-viewer/public-example-viewer.component'; +import { PsChromePatchDirective } from './ps-chrome-patch.directive'; +import { PublicComponentViewerComponent } from './public-component-viewer/public-component-viewer.component'; + +@NgModule({ + declarations: [ + PublicExampleViewerComponent, + PublicComponentViewerComponent, + PsChromePatchDirective + ], + imports: [CommonModule, PortalModule, ScrollingModule, TabsModule] +}) +export class PublicComponentViewerModule {} diff --git a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.html b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.html similarity index 86% rename from projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.html rename to projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.html index e3a04c9dae..e0a7c2f8b4 100644 --- a/projects/angular-showcase/src/app/business/component-viewer/component-viewer.component.html +++ b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.html @@ -8,11 +8,11 @@
- + > diff --git a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.scss b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.scss similarity index 82% rename from projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.scss rename to projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.scss index 17f4130db9..b066b4fa6f 100644 --- a/projects/angular-showcase/src/app/core/component-viewer/component-viewer.component.scss +++ b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.scss @@ -1,10 +1,12 @@ :host { display: block; - height: calc(100vh - 48px); - overflow-y: hidden; margin-left: 300px; } +perfect-scrollbar { + height: calc(100vh - 48px); +} + article { padding: 3rem; } diff --git a/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.ts b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.ts new file mode 100644 index 0000000000..e805c8ae1c --- /dev/null +++ b/projects/angular-showcase/src/app/features/public-component-viewer/public-component-viewer/public-component-viewer.component.ts @@ -0,0 +1,22 @@ +import { Component, Renderer2 } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; + +import { ComponentViewerBase } from '../../../shared/component-viewer-base'; +import { ExampleProvider } from '../../../shared/example-provider'; +import { HtmlLoader } from '../../../shared/html-loader.service'; + +@Component({ + selector: 'sbb-public-component-viewer', + templateUrl: './public-component-viewer.component.html', + styleUrls: ['./public-component-viewer.component.scss'] +}) +export class PublicComponentViewerComponent extends ComponentViewerBase { + constructor( + htmlLoader: HtmlLoader, + exampleProvider: ExampleProvider, + route: ActivatedRoute, + renderer: Renderer2 + ) { + super(htmlLoader, exampleProvider, route, renderer); + } +} diff --git a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.html b/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.html deleted file mode 100644 index e3a04c9dae..0000000000 --- a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.html +++ /dev/null @@ -1,19 +0,0 @@ - -
- - -
-
- -
-
- - - -
-
-
diff --git a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.scss b/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.scss deleted file mode 100644 index 17f4130db9..0000000000 --- a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.scss +++ /dev/null @@ -1,10 +0,0 @@ -:host { - display: block; - height: calc(100vh - 48px); - overflow-y: hidden; - margin-left: 300px; -} - -article { - padding: 3rem; -} diff --git a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.ts b/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.ts deleted file mode 100644 index be3a9cb39f..0000000000 --- a/projects/angular-showcase/src/app/public/component-viewer/component-viewer.component.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Component, Renderer2 } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; - -import { ComponentViewerBase } from '../../shared/component-viewer-base'; -import { ExampleProvider } from '../../shared/example-provider'; -import { HtmlLoader } from '../../shared/html-loader.service'; - -@Component({ - selector: 'sbb-component-viewer', - templateUrl: './component-viewer.component.html', - styleUrls: ['./component-viewer.component.scss'] -}) -export class ComponentViewerComponent extends ComponentViewerBase { - constructor( - htmlLoader: HtmlLoader, - exampleProvider: ExampleProvider, - route: ActivatedRoute, - renderer: Renderer2 - ) { - super(htmlLoader, exampleProvider, route, renderer); - } -} diff --git a/projects/angular-showcase/src/app/public/public-routing.module.ts b/projects/angular-showcase/src/app/public/public-routing.module.ts index bb248bf0fe..fec44cdac4 100644 --- a/projects/angular-showcase/src/app/public/public-routing.module.ts +++ b/projects/angular-showcase/src/app/public/public-routing.module.ts @@ -1,9 +1,10 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { PublicComponentViewerModule } from '../features/public-component-viewer/public-component-viewer.module'; +import { PublicComponentViewerComponent } from '../features/public-component-viewer/public-component-viewer/public-component-viewer.component'; import { MarkdownViewerComponent } from '../shared/markdown-viewer/markdown-viewer.component'; -import { ComponentViewerComponent } from './component-viewer/component-viewer.component'; import { PublicComponent } from './public/public.component'; const routes: Routes = [ @@ -24,12 +25,12 @@ const routes: Routes = [ }, { path: 'components/:id', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-public' } }, { path: 'components/:id/:section', - component: ComponentViewerComponent, + component: PublicComponentViewerComponent, data: { library: 'angular-public' } } ] @@ -37,7 +38,7 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forChild(routes)], + imports: [RouterModule.forChild(routes), PublicComponentViewerModule], exports: [RouterModule] }) export class PublicRoutingModule {} diff --git a/projects/angular-showcase/src/app/public/public.module.ts b/projects/angular-showcase/src/app/public/public.module.ts index 631693073f..9eefa3817d 100644 --- a/projects/angular-showcase/src/app/public/public.module.ts +++ b/projects/angular-showcase/src/app/public/public.module.ts @@ -6,13 +6,12 @@ import { TabsModule } from '@sbb-esta/angular-public/tabs'; import { SharedModule } from '../shared/shared.module'; -import { ComponentViewerComponent } from './component-viewer/component-viewer.component'; import { PublicExamplesModule } from './public-examples/public-examples.module'; import { PublicRoutingModule } from './public-routing.module'; import { PublicComponent } from './public/public.component'; @NgModule({ - declarations: [PublicComponent, ComponentViewerComponent], + declarations: [PublicComponent], imports: [ CommonModule, PortalModule, diff --git a/projects/angular-showcase/src/app/shared/shared.module.ts b/projects/angular-showcase/src/app/shared/shared.module.ts index 38fdc9134b..b230a34a0b 100644 --- a/projects/angular-showcase/src/app/shared/shared.module.ts +++ b/projects/angular-showcase/src/app/shared/shared.module.ts @@ -5,18 +5,12 @@ import { ScrollingModule } from '@sbb-esta/angular-core/scrolling'; import { TabsModule } from '@sbb-esta/angular-public/tabs'; import { ApiViewerComponent } from './api-viewer/api-viewer.component'; -import { ExampleViewerComponent } from './example-viewer/example-viewer.component'; import { MarkdownViewerComponent } from './markdown-viewer/markdown-viewer.component'; import { SubmenuComponent } from './submenu/submenu.component'; @NgModule({ - declarations: [ - SubmenuComponent, - MarkdownViewerComponent, - ExampleViewerComponent, - ApiViewerComponent - ], + declarations: [SubmenuComponent, MarkdownViewerComponent, ApiViewerComponent], imports: [CommonModule, ScrollingModule, PortalModule, TabsModule], - exports: [SubmenuComponent, MarkdownViewerComponent, ExampleViewerComponent, ApiViewerComponent] + exports: [SubmenuComponent, MarkdownViewerComponent, ApiViewerComponent] }) export class SharedModule {} diff --git a/projects/sbb-esta/angular-core/scrolling/src/ps-scrollable.directive.ts b/projects/sbb-esta/angular-core/scrolling/src/ps-scrollable.directive.ts index 112c75cc56..5104e2a5e7 100644 --- a/projects/sbb-esta/angular-core/scrolling/src/ps-scrollable.directive.ts +++ b/projects/sbb-esta/angular-core/scrolling/src/ps-scrollable.directive.ts @@ -1,6 +1,6 @@ import { Directionality } from '@angular/cdk/bidi'; import { CdkScrollable, ScrollDispatcher } from '@angular/cdk/overlay'; -import { Directive, ElementRef, NgZone, OnDestroy, Optional } from '@angular/core'; +import { Directive, ElementRef, NgZone, OnDestroy, Optional, Self } from '@angular/core'; import { PerfectScrollbarComponent, PerfectScrollbarDirective } from 'ngx-perfect-scrollbar'; import { merge, Observable } from 'rxjs'; @@ -16,7 +16,7 @@ import { merge, Observable } from 'rxjs'; // tslint:disable-next-line: directive-class-suffix export class PsDirectiveScrollable extends CdkScrollable implements OnDestroy { constructor( - private _scrollbar: PerfectScrollbarDirective, + @Self() private _scrollbar: PerfectScrollbarDirective, elementRef: ElementRef, scrollDispatcher: ScrollDispatcher, ngZone: NgZone, @@ -43,7 +43,7 @@ export class PsDirectiveScrollable extends CdkScrollable implements OnDestroy { // tslint:disable-next-line: directive-class-suffix export class PsComponentScrollable extends CdkScrollable { constructor( - private _scrollbar: PerfectScrollbarComponent, + @Self() private _scrollbar: PerfectScrollbarComponent, elementRef: ElementRef, scrollDispatcher: ScrollDispatcher, ngZone: NgZone, diff --git a/projects/sbb-esta/angular-public/table/src/_table.scss b/projects/sbb-esta/angular-public/table/src/_table.scss deleted file mode 100644 index d23ec6fb5c..0000000000 --- a/projects/sbb-esta/angular-public/table/src/_table.scss +++ /dev/null @@ -1,78 +0,0 @@ -@import '../../../angular-core/styles/common/variables'; -@import '../../../angular-core/styles/common/colors'; -@import '../../../angular-core/styles/common/functions'; -@import '../../../angular-core/styles/common/mediaqueries'; - -$tableBg: $sbbColorWhite; -$tableBorderColor: $sbbColorCloud; -$tableTheadBgColor: $sbbColorCloud; -$tableTbodyStripesBgColor: $sbbColorMilk; -$tableCaptionColor: $sbbColorGrey; - -@mixin tableCaption() { - font-size: pxToEm(13); - color: $tableCaptionColor; -} - -@mixin tableWrapper() { - max-width: 100%; - overflow: auto; - border: pxToEm(1) solid $tableBorderColor; -} - -@mixin tableScrollingPinModeEnabled() { - .sbb-table { - thead { - > tr { - th, - td { - &:first-child { - background-color: $tableTheadBgColor; - } - } - } - } - - tbody, - tfoot { - > tr { - th, - td { - &:first-child { - background-color: $tableBg; - } - } - - &:nth-child(even) { - th, - td { - &:first-child { - background-color: $tableTbodyStripesBgColor; - } - } - } - } - } - - thead, - tbody, - tfoot { - > tr { - th, - td { - &:first-child { - left: 0; - position: sticky; - z-index: 1; - - &::after { - border-left: pxToEm(1) solid $sbbColorPlatinum; - background-image: linear-gradient(-270deg, rgba(0, 0, 0, 0.2) 0%, transparent 100%); - opacity: 1; - } - } - } - } - } - } -} diff --git a/projects/sbb-esta/angular-public/table/src/table.module.ts b/projects/sbb-esta/angular-public/table/src/table.module.ts index 71cdd31b84..5ad096a608 100644 --- a/projects/sbb-esta/angular-public/table/src/table.module.ts +++ b/projects/sbb-esta/angular-public/table/src/table.module.ts @@ -1,11 +1,12 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; +import { ScrollingModule } from '@sbb-esta/angular-core/scrolling'; import { ScrollAreaDirective } from './table/table-scroll-area.directive'; import { TableComponent } from './table/table.component'; @NgModule({ - imports: [CommonModule], + imports: [CommonModule, ScrollingModule], declarations: [TableComponent, ScrollAreaDirective], exports: [TableComponent, ScrollAreaDirective] }) diff --git a/projects/sbb-esta/angular-public/table/src/table/table-scroll-area.directive.ts b/projects/sbb-esta/angular-public/table/src/table/table-scroll-area.directive.ts index 89cfb855f5..060c5b010c 100644 --- a/projects/sbb-esta/angular-public/table/src/table/table-scroll-area.directive.ts +++ b/projects/sbb-esta/angular-public/table/src/table/table-scroll-area.directive.ts @@ -1,4 +1,15 @@ -import { Directive, HostBinding, HostListener, Input } from '@angular/core'; +import { + Directive, + HostBinding, + Input, + OnChanges, + OnDestroy, + Self, + SimpleChanges +} from '@angular/core'; +import { PerfectScrollbarComponent } from 'ngx-perfect-scrollbar'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; const stickySupported = typeof CSS !== 'undefined' && @@ -9,11 +20,11 @@ const stickySupported = @Directive({ selector: '[sbbTableScrollArea]' }) -export class ScrollAreaDirective { +export class ScrollAreaDirective implements OnChanges, OnDestroy { + private _scrollListener = new Subject(); + /** Types of pin mode. */ - // tslint:disable-next-line:no-input-rename - @Input('sbbTableScrollArea') - pinMode: 'off' | 'on'; + @Input() pinMode: 'off' | 'on'; /** * Wrapper class of the table. */ @@ -29,14 +40,33 @@ export class ScrollAreaDirective { return this._isScrolling; } - @HostListener('scroll', ['$event.target']) - scrollTable(scrollTarget: any) { - if (stickySupported && this.pinMode === 'on') { - if (scrollTarget.scrollLeft > 0) { - this._isScrolling = true; - } else { - this._isScrolling = false; - } + constructor(@Self() private _perfectScrollbar: PerfectScrollbarComponent) {} + + ngOnChanges(changes: SimpleChanges): void { + if (!stickySupported) { + return; + } else if ( + changes.pinMode.currentValue === 'on' && + (changes.pinMode.firstChange || + changes.pinMode.previousValue !== changes.pinMode.currentValue) + ) { + this._perfectScrollbar.psXReachStart + .pipe(takeUntil(this._scrollListener)) + .subscribe(() => (this._isScrolling = false)); + this._perfectScrollbar.psScrollRight + .pipe(takeUntil(this._scrollListener)) + .subscribe(() => (this._isScrolling = true)); + } else if ( + changes.pinMode.currentValue === 'off' && + changes.pinMode.previousValue !== changes.pinMode.currentValue + ) { + this._scrollListener.next(); + this._isScrolling = false; } } + + ngOnDestroy(): void { + this._scrollListener.next(); + this._scrollListener.complete(); + } } diff --git a/projects/sbb-esta/angular-public/table/src/table/table.component.html b/projects/sbb-esta/angular-public/table/src/table/table.component.html index 1ef3efb2de..b9602472b2 100644 --- a/projects/sbb-esta/angular-public/table/src/table/table.component.html +++ b/projects/sbb-esta/angular-public/table/src/table/table.component.html @@ -1,9 +1,9 @@
-
+
-
+
diff --git a/projects/sbb-esta/angular-public/table/src/table/table.component.scss b/projects/sbb-esta/angular-public/table/src/table/table.component.scss index de2d69c90a..776a965fa4 100644 --- a/projects/sbb-esta/angular-public/table/src/table/table.component.scss +++ b/projects/sbb-esta/angular-public/table/src/table/table.component.scss @@ -1,17 +1,91 @@ -@import '../table'; +@import '../../../../angular-core/styles/common/variables'; +@import '../../../../angular-core/styles/common/colors'; +@import '../../../../angular-core/styles/common/functions'; +@import '../../../../angular-core/styles/common/mediaqueries'; -.sbb-table-container { - .sbb-table-wrapper { - @include tableWrapper(); +$tableBg: $sbbColorWhite; +$tableBorderColor: $sbbColorCloud; +$tableTheadBgColor: $sbbColorCloud; +$tableTbodyStripesBgColor: $sbbColorMilk; +$tableCaptionColor: $sbbColorGrey; - &.sbb-table-is-scrolling { - @include tableScrollingPinModeEnabled(); +sbb-table { + .sbb-table-container { + .sbb-table-wrapper .sbb-table { + border: pxToEm(1) solid $tableBorderColor; + } + + .sbb-table-caption { + > * { + font-size: pxToEm(13); + color: $tableCaptionColor; + } + } + } + + &.sbb-table-is-pinned .sbb-table-container .sbb-table-wrapper .sbb-table { + thead { + > tr { + th, + td { + &:first-child { + background-color: $tableTheadBgColor; + } + } + } + } + + tbody, + tfoot { + > tr { + th, + td { + &:first-child { + background-color: $tableBg; + } + } + + &:nth-child(even) { + th, + td { + &:first-child { + background-color: $tableTbodyStripesBgColor; + } + } + } + } + } + + thead, + tbody, + tfoot { + > tr { + th, + td { + &:first-child { + left: 0; + position: sticky; + z-index: 1; + } + } + } } } - .sbb-table-caption { - > * { - @include tableCaption(); + &.sbb-table-is-pinned.sbb-table-is-scrolling { + thead, + tbody, + tfoot { + > tr { + th, + td { + &:first-child::after { + border-left: pxToEm(1) solid $sbbColorPlatinum; + background-image: linear-gradient(-270deg, rgba(0, 0, 0, 0.2) 0%, transparent 100%); + opacity: 1; + } + } + } } } } diff --git a/projects/sbb-esta/angular-public/table/src/table/table.component.ts b/projects/sbb-esta/angular-public/table/src/table/table.component.ts index 674bceb9d7..9e0a1b8c56 100644 --- a/projects/sbb-esta/angular-public/table/src/table/table.component.ts +++ b/projects/sbb-esta/angular-public/table/src/table/table.component.ts @@ -1,4 +1,24 @@ -import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + HostBinding, + Input, + NgZone, + OnChanges, + OnDestroy, + SimpleChanges, + ViewChild, + ViewEncapsulation +} from '@angular/core'; +import { PerfectScrollbarComponent } from 'ngx-perfect-scrollbar'; +import { merge, Subject } from 'rxjs'; +import { distinctUntilChanged, mapTo, takeUntil } from 'rxjs/operators'; + +const stickySupported = + typeof CSS !== 'undefined' && + CSS.supports( + ['', '-o-', '-webkit-', '-moz-', '-ms-'].map(p => `(position: ${p}sticky)`).join(' or ') + ); @Component({ selector: 'sbb-table', @@ -7,7 +27,7 @@ import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@a changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) -export class TableComponent { +export class TableComponent implements OnChanges, OnDestroy { /** Table identifier. */ @Input() tableId: string; /** The labelledBy of the table component.*/ @@ -16,8 +36,6 @@ export class TableComponent { @Input() tableAlignment: 'none' | 'left' | 'center' | 'right'; /** Types of pin mode. */ @Input() pinMode: 'off' | 'on' = 'off'; - - private _tableClass: string; /** Class value of the table. */ @Input() set tableClass(classVal: string) { @@ -36,4 +54,51 @@ export class TableComponent { return classList; } + private _tableClass: string; + + /** @docs-private */ + @ViewChild(PerfectScrollbarComponent, { static: true }) + _perfectScrollbar: PerfectScrollbarComponent; + + /** @docs-private */ + @HostBinding('class.sbb-table-is-scrolling') _scrolling = false; + /** @docs-private */ + @HostBinding('class.sbb-table-is-pinned') get _pinned() { + return this.pinMode === 'on'; + } + + private _scrollListener = new Subject(); + + constructor(private _zone: NgZone) {} + + ngOnChanges(changes: SimpleChanges): void { + if (!stickySupported) { + return; + } else if ( + changes.pinMode.currentValue === 'on' && + (changes.pinMode.firstChange || + changes.pinMode.previousValue !== changes.pinMode.currentValue) + ) { + merge( + this._perfectScrollbar.psXReachStart.pipe(mapTo(false)), + this._perfectScrollbar.psScrollRight.pipe(mapTo(true)) + ) + .pipe( + takeUntil(this._scrollListener), + distinctUntilChanged() + ) + .subscribe(v => this._zone.run(() => (this._scrolling = v))); + } else if ( + changes.pinMode.currentValue === 'off' && + changes.pinMode.previousValue !== changes.pinMode.currentValue + ) { + this._scrollListener.next(); + this._scrolling = false; + } + } + + ngOnDestroy(): void { + this._scrollListener.next(); + this._scrollListener.complete(); + } } diff --git a/scripts/memory.ps1 b/scripts/memory.ps1 new file mode 100644 index 0000000000..5bb2349d1f --- /dev/null +++ b/scripts/memory.ps1 @@ -0,0 +1 @@ +$env:NODE_OPTIONS="--max_old_space_size=7168" \ No newline at end of file