mirror of
https://github.com/bitwarden/browser
synced 2026-02-16 16:59:30 +00:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { Directive, HostListener, Input } from "@angular/core";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
import { ToastService } from "@bitwarden/components";
|
|
import { ToastVariant } from "@bitwarden/components/src/toast/toast.component";
|
|
|
|
@Directive({
|
|
selector: "[appCopyClick]",
|
|
})
|
|
export class CopyClickDirective {
|
|
private _showToast = false;
|
|
private toastVariant: ToastVariant = "success";
|
|
|
|
constructor(
|
|
private platformUtilsService: PlatformUtilsService,
|
|
private toastService: ToastService,
|
|
private i18nService: I18nService,
|
|
) {}
|
|
|
|
@Input("appCopyClick") valueToCopy = "";
|
|
|
|
/**
|
|
* When set, the toast displayed will show `<valueLabel> copied`
|
|
* instead of the default messaging.
|
|
*/
|
|
@Input() valueLabel: string;
|
|
|
|
/**
|
|
* When set without a value, a success toast will be shown when the value is copied
|
|
* @example
|
|
* ```html
|
|
* <app-component [appCopyClick]="value to copy" showToast/></app-component>
|
|
* ```
|
|
* When set with a value, a toast with the specified variant will be shown when the value is copied
|
|
*
|
|
* @example
|
|
* ```html
|
|
* <app-component [appCopyClick]="value to copy" showToast="info"/></app-component>
|
|
* ```
|
|
*/
|
|
@Input() set showToast(value: ToastVariant | "") {
|
|
// When the `showToast` is set without a value, an empty string will be passed
|
|
if (value === "") {
|
|
this._showToast = true;
|
|
} else {
|
|
this._showToast = true;
|
|
this.toastVariant = value;
|
|
}
|
|
}
|
|
|
|
@HostListener("click") onClick() {
|
|
this.platformUtilsService.copyToClipboard(this.valueToCopy);
|
|
|
|
if (this._showToast) {
|
|
const message = this.valueLabel
|
|
? this.i18nService.t("valueCopied", this.valueLabel)
|
|
: this.i18nService.t("copySuccessful");
|
|
|
|
this.toastService.showToast({
|
|
variant: this.toastVariant,
|
|
title: null,
|
|
message,
|
|
});
|
|
}
|
|
}
|
|
}
|