Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Refactor] TabsComponent to CodeComponent custom element #969

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

Merged
merged 5 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,890 changes: 893 additions & 1,997 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@angular/common": "9.1.2",
"@angular/compiler": "9.1.2",
"@angular/core": "9.1.2",
"@angular/elements": "9.1.2",
"@angular/flex-layout": "8.0.0-beta.27",
"@angular/forms": "9.1.2",
"@angular/http": "7.2.16",
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {
Expand Down Expand Up @@ -35,20 +35,23 @@ import { BasePageComponent } from './homepage/pages/page/page.component';
import { PipesComponent } from './homepage/pages/pipes/pipes.component';
import { SupportComponent } from './homepage/pages/support/support.component';
import { SharedModule } from './shared/shared.module';
import { CustomElementsModule } from './custom-elements/custom-elements.module';

const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
suppressScrollX: true,
wheelPropagation: true,
};

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
HttpClientModule,
PerfectScrollbarModule,
SharedModule,
CustomElementsModule,
],
declarations: [
AppComponent,
Expand Down
26 changes: 26 additions & 0 deletions src/app/custom-elements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Custom Elements

## <code-element>

### Attributes

| Attribute | Type |
|-----------|---------|
| filename | string |

### Usage

```html
<code-element filename="cat.service">
<pre slot="ts" class="language-typescript">
<code class="language-typescript">
console.log("Hello");
</code>
</pre>
<pre slot="js" class="language-javascript">
<code class="language-javascript">
console.log("Hello");
</code>
</pre>
</code-element>
```
19 changes: 19 additions & 0 deletions src/app/custom-elements/code/code.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="code-wrapper" [ngClass]="{ 'has-switcher': hasSwitcher }">
<div class="filename" *ngIf="hasSwitcher">
<span> {{ filename }}{{ isJsActive ? '.js' : '.ts' }} </span>
<div class="tabs-wrapper">
<span class="tab" [class.active]="isJsActive" (click)="isJsActive = true">
JS
</span>
<span
class="tab active"
[class.active]="!isJsActive"
(click)="isJsActive = false"
>
TS
</span>
</div>
</div>
<slot name="ts" *ngIf="!isJsActive"></slot>
<slot name="js" *ngIf="isJsActive"></slot>
</div>
45 changes: 45 additions & 0 deletions src/app/custom-elements/code/code.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@import './../../../scss/utils.scss';

.tabs-wrapper {
position: absolute;
right: 0;
top: 0;
bottom: 0;
}

.tab {
color: #dfdfdf;
cursor: pointer;
margin: 0;
float: right;
font-weight: 600;
height: 100%;
padding: 12px 20px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
&:hover:not(.active) {
color: #efefef;
}
&.active {
display: none;
}
}

.filename {
background: #151515;
color: #fff;
padding: 12px 30px;
margin: 35px 0 -35px;
display: block;
min-height: 25px;
position: relative;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
overflow: hidden;
font-size: 15px;
}

:host .has-switcher ::slotted(pre) {
border-top-left-radius: 0 !important;
border-top-right-radius: 0 !important;
}
26 changes: 26 additions & 0 deletions src/app/custom-elements/code/code.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Component,
Input,
ViewEncapsulation,
AfterViewInit,
ElementRef,
} from '@angular/core';

@Component({
selector: 'app-code',
templateUrl: './code.component.html',
styleUrls: ['./code.component.scss'],
encapsulation: ViewEncapsulation.ShadowDom,
})
export class CodeComponent implements AfterViewInit {
constructor(public element: ElementRef) {}

public isJsActive = false;
public hasSwitcher: boolean;

@Input() public filename: string;

ngAfterViewInit() {
this.hasSwitcher = this.element.nativeElement.children.length > 1;
}
}
18 changes: 18 additions & 0 deletions src/app/custom-elements/custom-elements.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule, Injector, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CodeComponent } from './code/code.component';
import { createCustomElement } from '@angular/elements';

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [CodeComponent],
imports: [CommonModule],
entryComponents: [CodeComponent],
exports: [CodeComponent],
})
export class CustomElementsModule {
constructor(injector: Injector) {
const CodeElement = createCustomElement(CodeComponent, { injector });
customElements.define('code-element', CodeElement);
}
}
3 changes: 2 additions & 1 deletion src/app/homepage/pages/cli/cli.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from './../../../shared/shared.module';
import { CliLibrariesComponent } from './libraries/libaries.component';
Expand Down Expand Up @@ -51,6 +51,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
CliOverviewComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/faq/faq.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { GlobalPrefixComponent } from './global-prefix/global-prefix.component';
Expand Down Expand Up @@ -37,6 +37,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
GlobalPrefixComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/fundamentals/fundamentals.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { AsyncComponentsComponent } from './async-components/async-components.component';
Expand Down Expand Up @@ -83,6 +83,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
AsyncComponentsComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/graphql/graphql.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { CliPluginComponent } from './cli-plugin/cli-plugin.component';
Expand Down Expand Up @@ -105,6 +105,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
QuickStartComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CustomTransportComponent } from './custom-transport.component';
import { TabsComponent } from '../../../../shared/components/tabs/tabs.component';
import { ExtensionPipe } from '../../../../shared/pipes/extension.pipe';

describe('CustomTransportComponent', () => {
beforeEach(async(() => {
return TestBed.configureTestingModule({
declarations: [
TabsComponent,
ExtensionPipe,
CustomTransportComponent
]
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/microservices/microservices.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { BasicsComponent } from './basics/basics.component';
Expand Down Expand Up @@ -79,6 +79,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
BasicsComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/recipes/recipes.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { CqrsComponent } from './cqrs/cqrs.component';
Expand Down Expand Up @@ -76,6 +76,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
SqlTypeormComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/techniques/techniques.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { AuthenticationComponent } from './authentication/authentication.component';
Expand Down Expand Up @@ -111,6 +111,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
SqlComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/homepage/pages/websockets/websockets.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SharedModule } from '../../../shared/shared.module';
import { AdapterComponent } from './adapter/adapter.component';
Expand Down Expand Up @@ -43,6 +43,7 @@ const routes: Routes = [
];

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
GatewaysComponent,
Expand Down
8 changes: 0 additions & 8 deletions src/app/shared/components/tabs/tabs.component.html

This file was deleted.

41 changes: 0 additions & 41 deletions src/app/shared/components/tabs/tabs.component.scss

This file was deleted.

24 changes: 0 additions & 24 deletions src/app/shared/components/tabs/tabs.component.spec.ts

This file was deleted.

Loading