Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit d60da1b

Browse files
committed
refactor(operators): remove clipboard dependency and add confirmation
1 parent 408b3b6 commit d60da1b

File tree

7 files changed

+61
-59
lines changed

7 files changed

+61
-59
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"@types/hammerjs": "2.0.35",
4343
"core-js": "2.4.1",
4444
"hammerjs": "2.0.8",
45-
"ngx-clipboard": "8.1.0",
4645
"rxjs": "5.5.2",
4746
"ts-loader": "3.1.1",
4847
"zone.js": "0.8.14"

src/app/material/material.module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
MatCardModule,
1212
MatInputModule,
1313
MatMenuModule,
14-
MatTooltipModule
14+
MatTooltipModule,
15+
MatSnackBarModule
1516
} from '@angular/material';
1617

1718
@NgModule({
@@ -26,7 +27,8 @@ import {
2627
MatCardModule,
2728
MatInputModule,
2829
MatMenuModule,
29-
MatTooltipModule
30+
MatTooltipModule,
31+
MatSnackBarModule
3032
],
3133
exports: [
3234
MatToolbarModule,
@@ -38,7 +40,8 @@ import {
3840
MatCardModule,
3941
MatInputModule,
4042
MatMenuModule,
41-
MatTooltipModule
43+
MatTooltipModule,
44+
MatSnackBarModule
4245
]
4346
})
4447
export class MaterialModule {}

src/app/operators/components/operator-examples/operator-examples.component.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<h2> Examples </h2>
2-
<div
3-
class="code-example"
4-
*ngFor="let example of operatorExamples"
5-
appHighlightJs>
2+
<div class="code-example"
3+
*ngFor="let example of operatorExamples"
4+
appHighlightJs>
65
<div class="code-block mat-elevation-z2">
76
<div class="example-header">
8-
<div class="header-title" [innerHTML]="example.name"></div>
9-
<button
10-
mat-icon-button
11-
ngxClipboard
12-
[cbContent]="example.code"
13-
matTooltip="Copy">
7+
<div class="header-title"
8+
[innerHTML]="example.name"></div>
9+
<button mat-icon-button
10+
(click)="copyToClipboard.emit(example.code)"
11+
matTooltip="Copy">
1412
<mat-icon>content_copy</mat-icon>
1513
</button>
1614
</div>

src/app/operators/components/operator-examples/operator-examples.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, EventEmitter, Output, Input } from '@angular/core';
22
import { OperatorExample } from '../../../../operator-docs';
33

44
@Component({
@@ -8,4 +8,5 @@ import { OperatorExample } from '../../../../operator-docs';
88
})
99
export class OperatorExamplesComponent {
1010
@Input() operatorExamples: OperatorExample[];
11+
@Output() copyToClipboard = new EventEmitter<string>();
1112
}
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
<app-operator-header
2-
[operatorName]="operatorName"
3-
[operatorSignature]="signature"
4-
[id]="operatorName"
5-
class="operator-header">
1+
<app-operator-header [operatorName]="operatorName"
2+
[operatorSignature]="signature"
3+
[id]="operatorName"
4+
class="operator-header">
65
</app-operator-header>
76
<section class="main-operator-container mat-typography">
8-
<h3 class="short-description" [innerHTML]="shortDescription"></h3>
9-
<app-operator-extras
10-
class="margin-bottom-16"
11-
*ngIf="shortDescriptionExtras"
12-
[operatorExtras]="shortDescriptionExtras">
7+
<h3 class="short-description"
8+
[innerHTML]="shortDescription">
9+
</h3>
10+
<app-operator-extras class="margin-bottom-16"
11+
*ngIf="shortDescriptionExtras"
12+
[operatorExtras]="shortDescriptionExtras">
1313
</app-operator-extras>
14-
<app-marble-diagram
15-
class="margin-bottom-32"
16-
[operatorName]="operatorName"
17-
[useInteractiveMarbles]="useInteractiveMarbles"
18-
[url]="marbleUrl">
14+
<app-marble-diagram class="margin-bottom-32"
15+
[operatorName]="operatorName"
16+
[useInteractiveMarbles]="useInteractiveMarbles"
17+
[url]="marbleUrl">
1918
</app-marble-diagram>
20-
<app-operator-examples
21-
[operatorExamples]="examples" class="margin-bottom-16">
19+
<app-operator-examples [operatorExamples]="examples"
20+
(copyToClipboard)="copyToClipboard($event)"
21+
class="margin-bottom-16">
2222
</app-operator-examples>
23-
<app-operator-parameters
24-
[operatorParameters]="parameters"
25-
*ngIf="parameters?.length">
23+
<app-operator-parameters [operatorParameters]="parameters"
24+
*ngIf="parameters?.length">
2625
</app-operator-parameters>
27-
<app-operator-walkthrough
28-
class="margin-bottom-16"
29-
[operatorWalkthrough]="walkthrough" >
26+
<app-operator-walkthrough class="margin-bottom-16"
27+
[operatorWalkthrough]="walkthrough">
3028
</app-operator-walkthrough>
31-
<app-operator-extras
32-
class="margin-bottom-16"
33-
*ngIf="walkthroughExtras"
34-
[operatorExtras]="walkthroughExtras">
29+
<app-operator-extras class="margin-bottom-16"
30+
*ngIf="walkthroughExtras"
31+
[operatorExtras]="walkthroughExtras">
3532
</app-operator-extras>
36-
<app-related-operators
37-
[relatedOperators]="relatedOperators">
33+
<app-related-operators [relatedOperators]="relatedOperators">
3834
</app-related-operators>
39-
<app-additional-resources
40-
[additionalResources]="additionalResources"
41-
[sourceUrl]="sourceUrl"
42-
[specsUrl]="specsUrl">
35+
<app-additional-resources [additionalResources]="additionalResources"
36+
[sourceUrl]="sourceUrl"
37+
[specsUrl]="specsUrl">
4338
</app-additional-resources>
4439
</section>

src/app/operators/components/operator/operator.component.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {
77
InjectionToken
88
} from '@angular/core';
99
import { Router, ActivatedRoute } from '@angular/router';
10+
import { MatSnackBar } from '@angular/material';
11+
import { pluck } from 'rxjs/operators';
12+
import { CopierService } from '../../../core/services/copier.service';
1013
import { SeoService } from '../../../core/services/seo.service';
1114
import { OperatorDoc } from '../../../../operator-docs/operator.model';
12-
import { pluck } from 'rxjs/operators';
1315

1416
export const OPERATOR_TOKEN = new InjectionToken<string>('operators');
1517

@@ -28,8 +30,10 @@ export class OperatorComponent implements OnInit {
2830
constructor(
2931
private _router: Router,
3032
private _activatedRoute: ActivatedRoute,
31-
@Inject(OPERATOR_TOKEN) public operators: OperatorDoc[],
32-
private _seo: SeoService
33+
private _seo: SeoService,
34+
private _copierService: CopierService,
35+
private _snackBar: MatSnackBar,
36+
@Inject(OPERATOR_TOKEN) public operators: OperatorDoc[]
3337
) {}
3438

3539
ngOnInit() {
@@ -63,6 +67,15 @@ export class OperatorComponent implements OnInit {
6367
}
6468
}
6569

70+
copyToClipboard(code: string) {
71+
this._copierService.copyText(code);
72+
this._snackBar.open(
73+
'The example has been copied to your clipboard!',
74+
null,
75+
{ duration: 3000 }
76+
);
77+
}
78+
6679
get operatorName() {
6780
return this.operator.name;
6881
}

src/app/operators/operators.module.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from '@angular/core';
66
import { CommonModule } from '@angular/common';
77
import { LayoutModule } from '@angular/cdk/layout';
8-
import { ClipboardModule } from 'ngx-clipboard';
98

109
import { ALL_OPERATORS, OperatorDoc } from '../../operator-docs';
1110
import { OperatorsRoutingModule } from './operators-routing.module';
@@ -41,13 +40,7 @@ import { MaterialModule } from '../material/material.module';
4140
HighlightJsDirective,
4241
SafeUrlPipe
4342
],
44-
imports: [
45-
CommonModule,
46-
MaterialModule,
47-
OperatorsRoutingModule,
48-
ClipboardModule,
49-
LayoutModule
50-
],
43+
imports: [CommonModule, MaterialModule, OperatorsRoutingModule, LayoutModule],
5144
providers: [
5245
{ provide: OPERATORS_TOKEN, useValue: ALL_OPERATORS },
5346
{ provide: OPERATOR_TOKEN, useValue: ALL_OPERATORS }

0 commit comments

Comments
 (0)