Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 37b8a88

Browse files
seanforyou23dlabrecq
authored andcommitted
feat(copy-updates): align copy component impl with latest designs (#444)
improve tests fix tooltip flutter add tooltip for copy buttons use input element for copy value container remove redundant triggers clean up view templates use obj for storing common values in copyBase add project flag to tslint script to avoid "rule requires type information" warning use readonly input instead of span so copy value is scrollable use tooltipText input prop instead of tooltip to avoid namespace collision both focus and hover can launch a tooltip specify body for container attribute to fix tooltip styling issues avoid breaking changes by setting buttonAriaLabel to buttonLabel value when passed in update tests to use new property name
1 parent 4bada91 commit 37b8a88

19 files changed

+154
-43
lines changed

src/app/copy/block-copy/block-copy.component.html

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<div class="pfng-block-copy">
1+
<div class="pfng-block-copy" [ngStyle]="{'width': width}">
22
<label
33
*ngIf="label"
44
class="pfng-block-copy-label"
55
[attr.for]="buttonId">{{label}}</label>
66
<div class="pfng-block-copy-inner-container">
77
<div class="pfng-block-copy-preview" [ngClass]="{'pf-is-open': expanded}">
88
<button
9+
type="button"
910
[attr.aria-label]="expandToggleAriaLabel"
1011
[attr.aria-expanded]="expanded"
11-
class="pfng-block-copy-preview-btn"
12+
class="btn btn-default pfng-block-copy-preview-btn"
1213
(click)="togglePanel()">
1314
<i
1415
aria-hidden="true"
@@ -17,20 +18,32 @@
1718
</button>
1819
<div
1920
class="pfng-block-copy-preview-txt-cont"
20-
placement="{{tooltipPlacement ? tooltipPlacement : null}}"
21-
tooltip="{{tooltip ? tooltip : null}}">
22-
<span class="pfng-block-copy-preview-txt">{{value}}</span>
21+
[placement]="tooltipPlacement"
22+
[tooltip]="tooltipText"
23+
container="body">
24+
<input
25+
type="text"
26+
tabindex="-1"
27+
[value]="value"
28+
class="pfng-block-copy-preview-txt"
29+
readonly="readonly">
2330
</div>
2431
<button
32+
type="button"
2533
[attr.id]="buttonId"
26-
class="btn btn-lg btn-default pfng-block-copy-btn"
34+
class="btn btn-default pfng-block-copy-btn"
2735
[attr.aria-label]="buttonAriaLabel"
36+
[tooltip]="copyBtnTooltipText"
37+
[placement]="copyBtnTooltipPlacement"
38+
triggers="hover"
39+
container="body"
2840
(click)="copy()">
2941
<span>
30-
<ng-container *ngIf="!recentlyCopied">{{buttonLabel}}</ng-container>
42+
<ng-container *ngIf="!recentlyCopied">
43+
<i class="fa fa-clipboard" aria-hidden="true"></i>
44+
</ng-container>
3145
<ng-container *ngIf="recentlyCopied">
3246
<i class="fa fa-check" aria-hidden="true"></i>
33-
Copied
3447
</ng-container>
3548
</span>
3649
</button>

src/app/copy/block-copy/block-copy.component.less

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
.pfng-block-copy {
2+
max-width: 100%;
23
&-inner-container {
4+
background: #fff;
35
border: 1px solid #bbb;
46
}
57
&-preview {
68
display: flex;
79
&.pf-is-open {
810
border-bottom: 1px solid #bbb;
9-
background: #ddd;
1011
}
1112
&-btn {
12-
background: none;
1313
border: none;
1414
border-right: 1px solid #bbb;
1515
padding: 0;
1616
}
1717
&-icon {
1818
cursor: pointer;
19-
padding: 0 1em;
19+
padding: 0 .679em;
2020
&.fa-angle-right {
21-
padding: 0 1.15em;
21+
padding: 0 .822em;
2222
}
2323
}
2424
&-txt-cont {
@@ -33,6 +33,8 @@
3333
text-overflow: ellipsis;
3434
margin-right: 1em;
3535
margin-left: .75em;
36+
border: none;
37+
width: 100%;
3638
}
3739
}
3840
&-btn {

src/app/copy/block-copy/block-copy.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Block Copy component', () => {
3232
componentConfig = {
3333
label: 'Block-level Foobar',
3434
expandToggleAriaLabel: 'Expand Block-level Foobar',
35-
tooltip: 'Block Copy Tooltip',
35+
tooltipText: 'Block Copy Tooltip',
3636
value: 'Token'
3737
};
3838
})

src/app/copy/block-copy/block-copy.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Component,
33
Input,
4+
OnInit,
45
ViewEncapsulation
56
} from '@angular/core';
67

@@ -35,7 +36,7 @@ import { CopyService } from '../copy-service/copy.service';
3536
selector: 'pfng-block-copy',
3637
templateUrl: './block-copy.component.html'
3738
})
38-
export class BlockCopyComponent extends CopyBase {
39+
export class BlockCopyComponent extends CopyBase implements OnInit {
3940
/**
4041
* Label output above the block copy component
4142
*/
@@ -68,6 +69,12 @@ export class BlockCopyComponent extends CopyBase {
6869
super(copyService);
6970
}
7071

72+
ngOnInit() {
73+
if (!this.buttonAriaLabel && this.buttonLabel) {
74+
this.buttonAriaLabel = this.buttonLabel;
75+
}
76+
}
77+
7178
/**
7279
* Generates a unique ID for the button
7380
*/

src/app/copy/block-copy/example/block-copy-basic-example.component.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
<div class="col-sm-8 padding-bottom-15">
44
<p>This basic example illustrates how you can control various bits of text within the component. Block copy is not intended for use with small strings of text.</p>
55
<pfng-block-copy
6-
[buttonAriaLabel]="basicEx01.buttonAriaLabel"
7-
[buttonLabel]="basicEx01.buttonLabel"
6+
[buttonAriaLabel]="basicEx01.buttonAriaLabel"
87
[expandToggleAriaLabel]="basicEx01.expandToggleAriaLabel"
98
[label]="basicEx01.label"
10-
[tooltip]="basicEx01.tooltip"
9+
[tooltipText]="basicEx01.tooltip"
1110
[value]="basicEx01.value"
1211
(onCopy)="handleCopy($event)"></pfng-block-copy>
1312
</div>
1413
</div>
1514
<div class="row padding-top-10">
1615
<div class="col-sm-12">
1716
<h4 class="actions-label">Actions</h4>
18-
<hr/>
17+
<hr>
1918
</div>
2019
</div>
2120
<div class="row">

src/app/copy/block-copy/example/block-copy-basic-example.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
OnInit,
44
ViewEncapsulation
55
} from '@angular/core';
6-
import {CopyEvent} from '../../copy-event';
7-
import {NotificationType} from '../../../notification/notification-type';
6+
import { CopyEvent } from '../../copy-event';
87

98
@Component({
109
encapsulation: ViewEncapsulation.None,
@@ -14,7 +13,6 @@ import {NotificationType} from '../../../notification/notification-type';
1413
export class BlockCopyBasicExampleComponent implements OnInit {
1514
actionsText: string = '';
1615
basicEx01 = {
17-
buttonLabel: 'Copy JSON',
1816
buttonAriaLabel: 'Copy Swagger JSON',
1917
expandToggleAriaLabel: 'Toggle Swagger JSON',
2018
label: 'Swagger JSON',

src/app/copy/block-copy/example/block-copy-expanded-example.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
[expanded]="expandedEx01.expanded"
1010
[label]="expandedEx01.label"
1111
[value]="expandedEx01.value"
12+
[width]="expandedEx01.width"
1213
(onCopy)="handleCopy($event)"></pfng-block-copy>
1314
</div>
1415
</div>
1516
<div class="row padding-top-10">
1617
<div class="col-sm-12">
1718
<h4 class="actions-label">Actions</h4>
18-
<hr/>
19+
<hr>
1920
</div>
2021
</div>
2122
<div class="row">

src/app/copy/block-copy/example/block-copy-expanded-example.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class BlockCopyExpandedExampleComponent {
1717
expandToggleAriaLabel: 'Toggle GraphQL Query',
1818
expanded: true,
1919
label: 'GraphQL Query',
20-
value: 'query HeroNameAndFriends($episode: Episode) {hero(episode: $episode) {name friends {name}}}'
20+
value: 'query HeroNameAndFriends($episode: Episode) {hero(episode: $episode) {name friends {name}}}',
21+
width: '605px'
2122
};
2223

2324
constructor() {}

src/app/copy/block-copy/example/block-copy-notification-example.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[buttonLabel]="cbExConfig.buttonLabel"
99
[expandToggleAriaLabel]="cbExConfig.expandToggleAriaLabel"
1010
[label]="cbExConfig.label"
11-
[tooltip]="cbExConfig.tooltip"
11+
[tooltipText]="cbExConfig.tooltip"
1212
[value]="cbExConfig.value"
1313
(onCopy)="handleCopy($event, {
1414
name: cbExConfig.buttonAriaLabel,
@@ -19,7 +19,7 @@
1919
<div class="row padding-top-10">
2020
<div class="col-sm-12">
2121
<h4 class="actions-label">Actions</h4>
22-
<hr/>
22+
<hr>
2323
</div>
2424
</div>
2525
<div class="row">

src/app/copy/copy-base.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { CopyService } from './copy-service/copy.service';
1111
* A config containing properties for copy components
1212
*/
1313
export abstract class CopyBase {
14+
protected _copyDefaults = {
15+
copyBtnTooltipText: 'Copy to Clipboard',
16+
tooltipCopiedText: 'Copied'
17+
};
18+
1419
/**
1520
* Copy button aria label (announced to screen readers)
1621
*/
@@ -19,18 +24,38 @@ export abstract class CopyBase {
1924
/**
2025
* A tooltip that describes the value to be copied
2126
*/
22-
@Input('tooltip') tooltip: string;
27+
@Input('tooltipText') tooltipText: string;
2328

2429
/**
2530
* Placement for the tooltip
2631
*/
2732
@Input('tooltipPlacement') tooltipPlacement: string = 'top';
2833

34+
/**
35+
* A tooltip that describes what the copy button does
36+
*/
37+
@Input('copyBtnTooltipText') copyBtnTooltipText: string = this._copyDefaults.copyBtnTooltipText;
38+
39+
/**
40+
* A tooltip that informs user that copy action recently occurred
41+
*/
42+
@Input('tooltipCopiedText') tooltipCopiedText: string = this._copyDefaults.tooltipCopiedText;
43+
44+
/**
45+
* Placement for the copy button tooltip
46+
*/
47+
@Input('copyBtnTooltipPlacement') copyBtnTooltipPlacement: string = 'top';
48+
2949
/**
3050
* The value to be copied to the clipboard
3151
*/
3252
@Input('value') value: string;
3353

54+
/**
55+
* A width to set on the copy container
56+
*/
57+
@Input('width') width: string;
58+
3459
/**
3560
* Event emitted when values are copied to the clipboard
3661
*/
@@ -56,14 +81,17 @@ export abstract class CopyBase {
5681
* Copy given value to the clipboard
5782
*/
5883
copy(): void {
59-
let result = this.copyService.copy(this.value);
84+
const result = this.copyService.copy(this.value),
85+
originalCopyBtnTooltipText = this.copyBtnTooltipText;
6086
if (result) {
6187
this.onCopy.emit({
6288
value: this.value
6389
} as CopyEvent);
6490
this._recentlyCopied = true;
91+
this.copyBtnTooltipText = this.tooltipCopiedText || this._copyDefaults.tooltipCopiedText;
6592
setTimeout(() => {
6693
this._recentlyCopied = false;
94+
this.copyBtnTooltipText = originalCopyBtnTooltipText || this._copyDefaults.copyBtnTooltipText;
6795
}, 3000);
6896
}
6997
}

0 commit comments

Comments
 (0)