Skip to content

build: add clipboard to dev app #18715

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 1 commit into from
Mar 5, 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
/src/dev-app/card/** @jelbourn
/src/dev-app/checkbox/** @jelbourn @devversion
/src/dev-app/chips/** @jelbourn
/src/dev-app/clipboard/** @jelbourn @xkxx
/src/dev-app/column-resize/** @kseamon @andrewseguin
/src/dev-app/connected-overlay/** @jelbourn @crisbeto
/src/dev-app/dataset/** @andrewseguin
Expand Down
1 change: 1 addition & 0 deletions src/dev-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ng_module(
"//src/dev-app/card",
"//src/dev-app/checkbox",
"//src/dev-app/chips",
"//src/dev-app/clipboard",
"//src/dev-app/column-resize",
"//src/dev-app/connected-overlay",
"//src/dev-app/datepicker",
Expand Down
22 changes: 22 additions & 0 deletions src/dev-app/clipboard/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ng_module", "sass_binary")

ng_module(
name = "clipboard",
srcs = glob(["**/*.ts"]),
assets = [
":clipboard_demo_scss",
"clipboard-demo.html",
],
deps = [
"//src/cdk/clipboard",
"@npm//@angular/forms",
"@npm//@angular/router",
],
)

sass_binary(
name = "clipboard_demo_scss",
src = "clipboard-demo.scss",
)
24 changes: 24 additions & 0 deletions src/dev-app/clipboard/clipboard-demo-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {ClipboardModule} from '@angular/cdk/clipboard';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {ClipboardDemo} from './clipboard-demo';

@NgModule({
imports: [
ClipboardModule,
FormsModule,
RouterModule.forChild([{path: '', component: ClipboardDemo}]),
],
declarations: [ClipboardDemo],
})
export class ClipboardDemoModule {
}
14 changes: 14 additions & 0 deletions src/dev-app/clipboard/clipboard-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<section>
<label for="example-textarea">Text to be copied</label>
<textarea id="example-textarea" cols="30" rows="10" [(ngModel)]="value"></textarea>
</section>

<section>
<label for="example-attempts-input">Copy attempts</label>
<input id="example-attempts-input" type="number" [(ngModel)]="attempts"/>
</section>

<button (click)="copyViaService()">Copy to clipboard via service</button>
<button
[cdkCopyToClipboard]="value"
[cdkCopyToClipboardAttempts]="attempts">Copy to clipboard via directive</button>
8 changes: 8 additions & 0 deletions src/dev-app/clipboard/clipboard-demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
label {
display: block;
}

section {
margin: 8px 0;
}

36 changes: 36 additions & 0 deletions src/dev-app/clipboard/clipboard-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Component} from '@angular/core';
import {Clipboard} from '@angular/cdk/clipboard';


@Component({
selector: 'clipboard-demo',
styleUrls: ['clipboard-demo.css'],
templateUrl: 'clipboard-demo.html',
})
export class ClipboardDemo {
attempts = 3;

value = `Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. It's not ` +
`a story the Jedi would tell you. It's a Sith legend. Darth Plagueis was a Dark Lord ` +
`of the Sith, so powerful and so wise he could use the Force to influence the ` +
`midichlorians to create life… He had such a knowledge of the dark side that he could ` +
`even keep the ones he cared about from dying. The dark side of the Force is a pathway ` +
`to many abilities some consider to be unnatural. He became so powerful… the only ` +
`thing he was afraid of was losing his power, which eventually, of course, he did. ` +
`Unfortunately, he taught his apprentice everything he knew, then his apprentice ` +
`killed him in his sleep. Ironic. He could save others from death, but not himself.`;

constructor(private _clipboard: Clipboard) {}

copyViaService() {
this._clipboard.copy(this.value);
}
}
1 change: 1 addition & 0 deletions src/dev-app/dev-app/dev-app-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DevAppLayout {
{name: 'Card', route: '/card'},
{name: 'Checkbox', route: '/checkbox'},
{name: 'Chips', route: '/chips'},
{name: 'Clipboard', route: '/clipboard'},
{name: 'Column Resize', route: 'column-resize'},
{name: 'Connected Overlay', route: '/connected-overlay'},
{name: 'Datepicker', route: '/datepicker'},
Expand Down
1 change: 1 addition & 0 deletions src/dev-app/dev-app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const DEV_APP_ROUTES: Routes = [
{path: 'card', loadChildren: 'card/card-demo-module#CardDemoModule'},
{path: 'checkbox', loadChildren: 'checkbox/checkbox-demo-module#CheckboxDemoModule'},
{path: 'chips', loadChildren: 'chips/chips-demo-module#ChipsDemoModule'},
{path: 'clipboard', loadChildren: 'clipboard/clipboard-demo-module#ClipboardDemoModule'},
{
path: 'column-resize',
loadChildren: 'column-resize/column-resize-demo-module#ColumnResizeDemoModule'
Expand Down