Skip to content

Commit

Permalink
[issue-433] address PR feedback
Browse files Browse the repository at this point in the history
ensure copy btn tooltip is restored to original value
allow users to pass in text used for "copied" tooltip
  • Loading branch information
seanforyou23 committed Aug 9, 2018
1 parent 0eded5b commit e0642b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/app/copy/copy-base.ts
Expand Up @@ -12,10 +12,8 @@ import { CopyService } from './copy-service/copy.service';
*/
export abstract class CopyBase {
protected _copyDefaults = {
tooltipPlacement: 'top',
copyBtnTooltipPlacement: 'top',
copyBtnTooltipText: 'Copy to Clipboard',
copiedTooltipText: 'Copied'
tooltipCopiedText: 'Copied'
};

/**
Expand All @@ -31,17 +29,22 @@ export abstract class CopyBase {
/**
* Placement for the tooltip
*/
@Input('tooltipPlacement') tooltipPlacement: string = this._copyDefaults.tooltipPlacement;
@Input('tooltipPlacement') tooltipPlacement: string = 'top';

/**
* A tooltip that describes what the copy button does
*/
@Input('copyBtnTooltipText') copyBtnTooltipText: string = this._copyDefaults.copyBtnTooltipText;

/**
* A tooltip that informs user that copy action recently occurred
*/
@Input('tooltipCopiedText') tooltipCopiedText: string = this._copyDefaults.tooltipCopiedText;

/**
* Placement for the copy button tooltip
*/
@Input('copyBtnTooltipPlacement') copyBtnTooltipPlacement: string = this._copyDefaults.copyBtnTooltipPlacement;
@Input('copyBtnTooltipPlacement') copyBtnTooltipPlacement: string = 'top';

/**
* The value to be copied to the clipboard
Expand Down Expand Up @@ -78,16 +81,17 @@ export abstract class CopyBase {
* Copy given value to the clipboard
*/
copy(): void {
let result = this.copyService.copy(this.value);
const result = this.copyService.copy(this.value),
originalCopyBtnTooltipText = this.copyBtnTooltipText;
if (result) {
this.onCopy.emit({
value: this.value
} as CopyEvent);
this._recentlyCopied = true;
this.copyBtnTooltipText = this._copyDefaults.copiedTooltipText;
this.copyBtnTooltipText = this.tooltipCopiedText || this._copyDefaults.tooltipCopiedText;
setTimeout(() => {
this._recentlyCopied = false;
this.copyBtnTooltipText = this._copyDefaults.copyBtnTooltipText;
this.copyBtnTooltipText = originalCopyBtnTooltipText || this._copyDefaults.copyBtnTooltipText;
}, 3000);
}
}
Expand Down
Expand Up @@ -12,6 +12,8 @@
[tooltipText]="basicExConfig.tooltip"
[value]="basicExConfig.value"
[width]="basicExConfig.width"
[copyBtnTooltipText]="basicExConfig.copyBtnTooltip"
[tooltipCopiedText]="basicExConfig.copiedTxt"
(onCopy)="handleCopy($event)"></pfng-inline-copy>
It is recommended to not repeat the copyValue text for the tooltip as this would be redundant.
Just as with BlockCopy, you have full and independent control over tooltips, aria labels, button labels, and every other piece of text that's displayed as part of this component.
Expand Down
Expand Up @@ -16,7 +16,9 @@ export class InlineCopyBasicExampleComponent implements OnInit {
buttonAriaLabel: 'Copy WAI-ARIA URL',
tooltip: 'ARIA W3C Recommendation',
value: 'https://www.w3.org/TR/wai-aria-1.1/',
width: '200px'
width: '200px',
copyBtnTooltip: 'Copy WAI-ARIA URL',
copiedTxt: 'Copied WAI-ARIA URL to clipboard'
};

constructor() {}
Expand Down

0 comments on commit e0642b1

Please sign in to comment.