Skip to content

Commit 473d4c6

Browse files
crisbetommalerba
authored andcommitted
feat: move clipboard module into cdk (#17272)
Moves the `clipboard` module into CDK stable, sets up the API goldens, adjusts some APIs to be more consistent and sets up a live example.
1 parent b228f07 commit 473d4c6

23 files changed

+137
-27
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
/src/cdk/a11y/** @jelbourn @devversion
6767
/src/cdk/accordion/** @jelbourn
6868
/src/cdk/bidi/** @jelbourn
69+
/src/cdk/clipboard/** @jelbourn @xkxx
6970
/src/cdk/coercion/** @jelbourn
7071
/src/cdk/collections/** @jelbourn @crisbeto @andrewseguin
7172
/src/cdk/drag-drop/** @crisbeto
@@ -114,7 +115,7 @@
114115
/src/material-experimental/select/** @crisbeto
115116

116117
# CDK experimental package
117-
/src/cdk-experimental/** @jelbourn
118+
/src/cdk-experimental/* @jelbourn
118119
/src/cdk-experimental/dialog/** @jelbourn @crisbeto
119120
/src/cdk-experimental/popover-edit/** @kseamon @andrewseguin
120121
/src/cdk-experimental/scrolling/** @mmalerba
@@ -243,6 +244,7 @@
243244
/tools/public_api_guard/cdk/accordion.d.ts @jelbourn
244245
/tools/public_api_guard/cdk/bidi.d.ts @jelbourn
245246
/tools/public_api_guard/cdk/cdk.d.ts @jelbourn
247+
/tools/public_api_guard/cdk/clipboard.d.ts @jelbourn @xkxx
246248
/tools/public_api_guard/cdk/coercion.d.ts @jelbourn
247249
/tools/public_api_guard/cdk/collections.d.ts @jelbourn @crisbeto @andrewseguin
248250
/tools/public_api_guard/cdk/drag-drop.d.ts @crisbeto

src/cdk-experimental/config.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# List of all entry-points of the Angular cdk-experimental package.
22
CDK_EXPERIMENTAL_ENTRYPOINTS = [
3-
"clipboard",
43
"dialog",
54
"popover-edit",
65
"scrolling",

src/cdk-experimental/clipboard/BUILD.bazel renamed to src/cdk/clipboard/BUILD.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
3+
load("//tools:defaults.bzl", "markdown_to_html", "ng_module", "ng_test_library", "ng_web_test_suite")
44

55
ng_module(
66
name = "clipboard",
@@ -9,7 +9,7 @@ ng_module(
99
exclude = ["**/*.spec.ts"],
1010
),
1111
assets = glob(["**/*.html"]),
12-
module_name = "@angular/cdk-experimental/clipboard",
12+
module_name = "@angular/cdk/clipboard",
1313
deps = [
1414
"@npm//@angular/common",
1515
"@npm//@angular/core",
@@ -35,3 +35,13 @@ ng_web_test_suite(
3535
name = "unit_tests",
3636
deps = [":unit_test_sources"],
3737
)
38+
39+
markdown_to_html(
40+
name = "overview",
41+
srcs = [":clipboard.md"],
42+
)
43+
44+
filegroup(
45+
name = "source-files",
46+
srcs = glob(["**/*.ts"]),
47+
)

src/cdk-experimental/clipboard/clipboard.md renamed to src/cdk/clipboard/clipboard.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
**Warning: this service is still experimental. It may have bugs and the API may change at any
2-
time**
3-
41
The clipboard package provides helpers for working with the system clipboard.
52

3+
## `cdkCopyToClipboard` directive
4+
5+
The `cdkCopyToClipboard` directive can be used to easily add copy-on-click
6+
functionality to an existing element. The directive selector doubles as an
7+
`@Input()` for the text to be copied.
8+
9+
```html
10+
<img src="avatar.jpg" alt="Hero avatar" [cdkCopyToClipboard]="getShortBio()">
11+
```
12+
13+
<!-- example(cdk-clipboard-overview) -->
14+
615
## `Clipboard` service
716

817
The `Clipboard` service copies text to the
@@ -50,13 +59,3 @@ class HeroProfile {
5059
}
5160
}
5261
```
53-
54-
## `cdkCopyToClipboard` directive
55-
56-
The `cdkCopyToClipboard` directive can be used to easily add copy-on-click
57-
functionality to an existing element. The directive selector doubles as an
58-
`@Input()` for the text to be copied.
59-
60-
```html
61-
<img src="avatar.jpg" alt="Hero avatar" [cdkCopyToClipboard]="getShortBio()">
62-
```

src/cdk-experimental/clipboard/copy-to-clipboard.ts renamed to src/cdk/clipboard/copy-to-clipboard.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ import {Clipboard} from './clipboard';
2121
@Directive({
2222
selector: '[cdkCopyToClipboard]',
2323
host: {
24-
'(click)': 'doCopy()',
24+
'(click)': 'copy()',
2525
}
2626
})
2727
export class CdkCopyToClipboard {
2828
/** Content to be copied. */
2929
@Input('cdkCopyToClipboard') text = '';
3030

31+
/**
32+
* Emits when some text is copied to the clipboard. The
33+
* emitted value indicates whether copying was successful.
34+
*/
3135
@Output() copied = new EventEmitter<boolean>();
3236

33-
constructor(private readonly clipboard: Clipboard) {}
37+
constructor(private readonly _clipboard: Clipboard) {}
3438

35-
doCopy() {
36-
this.copied.emit(this.clipboard.copy(this.text));
39+
/** Copies the current text to the clipboard. */
40+
copy() {
41+
this.copied.emit(this._clipboard.copy(this.text));
3742
}
3843
}
File renamed without changes.

0 commit comments

Comments
 (0)