From ba824e9718d7bc63a9ea7d67128c301db2fc250b Mon Sep 17 00:00:00 2001
From: Andreas Coroiu
Date: Thu, 15 Sep 2022 10:20:30 +0200
Subject: [PATCH 1/9] [EC-556] feat: convert button into component
---
.../{button.directive.spec.ts => button.component.spec.ts} | 0
.../button/{button.directive.ts => button.component.ts} | 7 ++++---
libs/components/src/button/button.module.ts | 6 +++---
libs/components/src/button/button.stories.ts | 6 +++---
libs/components/src/button/index.ts | 2 +-
5 files changed, 11 insertions(+), 10 deletions(-)
rename libs/components/src/button/{button.directive.spec.ts => button.component.spec.ts} (100%)
rename libs/components/src/button/{button.directive.ts => button.component.ts} (92%)
diff --git a/libs/components/src/button/button.directive.spec.ts b/libs/components/src/button/button.component.spec.ts
similarity index 100%
rename from libs/components/src/button/button.directive.spec.ts
rename to libs/components/src/button/button.component.spec.ts
diff --git a/libs/components/src/button/button.directive.ts b/libs/components/src/button/button.component.ts
similarity index 92%
rename from libs/components/src/button/button.directive.ts
rename to libs/components/src/button/button.component.ts
index 59e7b4269f77..cdf6c5afa5a8 100644
--- a/libs/components/src/button/button.directive.ts
+++ b/libs/components/src/button/button.component.ts
@@ -1,4 +1,4 @@
-import { Input, HostBinding, Directive } from "@angular/core";
+import { Input, HostBinding, Component } from "@angular/core";
export type ButtonTypes = "primary" | "secondary" | "danger";
@@ -38,10 +38,11 @@ const buttonStyles: Record = {
],
};
-@Directive({
+@Component({
selector: "button[bitButton], a[bitButton]",
+ template: "",
})
-export class ButtonDirective {
+export class ButtonComponent {
@HostBinding("class") get classList() {
return [
"tw-font-semibold",
diff --git a/libs/components/src/button/button.module.ts b/libs/components/src/button/button.module.ts
index c9c3822abfac..448e7c9dcf64 100644
--- a/libs/components/src/button/button.module.ts
+++ b/libs/components/src/button/button.module.ts
@@ -1,11 +1,11 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
-import { ButtonDirective } from "./button.directive";
+import { ButtonComponent } from "./button.component";
@NgModule({
imports: [CommonModule],
- exports: [ButtonDirective],
- declarations: [ButtonDirective],
+ exports: [ButtonComponent],
+ declarations: [ButtonComponent],
})
export class ButtonModule {}
diff --git a/libs/components/src/button/button.stories.ts b/libs/components/src/button/button.stories.ts
index 35a7dbfe8296..c32d3fd8a4b4 100644
--- a/libs/components/src/button/button.stories.ts
+++ b/libs/components/src/button/button.stories.ts
@@ -1,10 +1,10 @@
import { Meta, Story } from "@storybook/angular";
-import { ButtonDirective } from "./button.directive";
+import { ButtonComponent } from "./button.component";
export default {
title: "Component Library/Button",
- component: ButtonDirective,
+ component: ButtonComponent,
args: {
buttonType: "primary",
},
@@ -16,7 +16,7 @@ export default {
},
} as Meta;
-const Template: Story = (args: ButtonDirective) => ({
+const Template: Story = (args: ButtonComponent) => ({
props: args,
template: `
diff --git a/libs/components/src/button/index.ts b/libs/components/src/button/index.ts
index 1bdd62ddbcf6..ff86120cb113 100644
--- a/libs/components/src/button/index.ts
+++ b/libs/components/src/button/index.ts
@@ -1,2 +1,2 @@
-export * from "./button.directive";
+export * from "./button.component";
export * from "./button.module";
From b14b7d90a74b12c3d2f988f02fa036a0482509f2 Mon Sep 17 00:00:00 2001
From: Andreas Coroiu
Date: Thu, 15 Sep 2022 11:49:05 +0200
Subject: [PATCH 2/9] [EC-556] feat: implement loading state
---
.../src/button/button.component.html | 8 +++
.../src/button/button.component.spec.ts | 49 ++++++++++++++++++-
.../components/src/button/button.component.ts | 13 +++--
libs/components/src/button/button.stories.ts | 25 +++++++---
4 files changed, 80 insertions(+), 15 deletions(-)
create mode 100644 libs/components/src/button/button.component.html
diff --git a/libs/components/src/button/button.component.html b/libs/components/src/button/button.component.html
new file mode 100644
index 000000000000..4875c159e926
--- /dev/null
+++ b/libs/components/src/button/button.component.html
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/libs/components/src/button/button.component.spec.ts b/libs/components/src/button/button.component.spec.ts
index a7c3024e4801..46d9c48fab0c 100644
--- a/libs/components/src/button/button.component.spec.ts
+++ b/libs/components/src/button/button.component.spec.ts
@@ -60,16 +60,61 @@ describe("Button", () => {
expect(buttonDebugElement.nativeElement.classList.contains("tw-block")).toBe(false);
expect(linkDebugElement.nativeElement.classList.contains("tw-block")).toBe(false);
});
+
+ it("should not be disabled when loading and disabled are false", () => {
+ testAppComponent.loading = false;
+ testAppComponent.disabled = false;
+ fixture.detectChanges();
+
+ expect(buttonDebugElement.attributes["loading"]).toBeFalsy();
+ expect(linkDebugElement.attributes["loading"]).toBeFalsy();
+ expect(buttonDebugElement.nativeElement.disabled).toBeFalsy();
+ });
+
+ it("should be disabled when disabled is true", () => {
+ testAppComponent.disabled = true;
+ fixture.detectChanges();
+
+ expect(buttonDebugElement.nativeElement.disabled).toBeTruthy();
+ // Anchor tags cannot be disabled.
+ });
+
+ it("should be disabled when loading is true", () => {
+ testAppComponent.loading = true;
+ fixture.detectChanges();
+
+ expect(buttonDebugElement.nativeElement.disabled).toBeTruthy();
+ });
});
@Component({
selector: "test-app",
template: `
-
- Link
+
+
+ Link
+
`,
})
class TestApp {
buttonType: string;
block: boolean;
+ disabled: boolean;
+ loading: boolean;
}
diff --git a/libs/components/src/button/button.component.ts b/libs/components/src/button/button.component.ts
index cdf6c5afa5a8..b5f8ae74491e 100644
--- a/libs/components/src/button/button.component.ts
+++ b/libs/components/src/button/button.component.ts
@@ -40,7 +40,7 @@ const buttonStyles: Record = {
@Component({
selector: "button[bitButton], a[bitButton]",
- template: "",
+ templateUrl: "button.component.html",
})
export class ButtonComponent {
@HostBinding("class") get classList() {
@@ -64,9 +64,12 @@ export class ButtonComponent {
.concat(buttonStyles[this.buttonType ?? "secondary"]);
}
- @Input()
- buttonType: ButtonTypes = null;
+ @HostBinding("attr.disabled") get disabledAttr() {
+ return this.disabled || this.loading ? true : null;
+ }
- @Input()
- block = false;
+ @Input() buttonType: ButtonTypes = null;
+ @Input() block = false;
+ @Input() loading = false;
+ @Input() disabled = false;
}
diff --git a/libs/components/src/button/button.stories.ts b/libs/components/src/button/button.stories.ts
index c32d3fd8a4b4..33f964d678d3 100644
--- a/libs/components/src/button/button.stories.ts
+++ b/libs/components/src/button/button.stories.ts
@@ -7,6 +7,8 @@ export default {
component: ButtonComponent,
args: {
buttonType: "primary",
+ disabled: false,
+ loading: false,
},
parameters: {
design: {
@@ -19,8 +21,8 @@ export default {
const Template: Story = (args: ButtonComponent) => ({
props: args,
template: `
-
- Link
+
+ Link
`,
});
@@ -39,16 +41,23 @@ Danger.args = {
buttonType: "danger",
};
-const DisabledTemplate: Story = (args) => ({
+const AllStylesTemplate: Story = (args) => ({
props: args,
template: `
-
-
-
+
+
+
`,
});
-export const Disabled = DisabledTemplate.bind({});
+export const Disabled = AllStylesTemplate.bind({});
Disabled.args = {
- size: "small",
+ disabled: true,
+ loading: false,
+};
+
+export const Loading = AllStylesTemplate.bind({});
+Loading.args = {
+ disabled: false,
+ loading: true,
};
From de182ce0985fad98e492613f5677ec5b9d49db20 Mon Sep 17 00:00:00 2001
From: Andreas Coroiu
Date: Thu, 15 Sep 2022 11:50:31 +0200
Subject: [PATCH 3/9] [EC-556] feat: remove loading from submit button
---
.../src/submit-button/submit-button.component.html | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/libs/components/src/submit-button/submit-button.component.html b/libs/components/src/submit-button/submit-button.component.html
index f3c097b2f342..efb78074cdf6 100644
--- a/libs/components/src/submit-button/submit-button.component.html
+++ b/libs/components/src/submit-button/submit-button.component.html
@@ -1,10 +1,3 @@
-
-
+
{{ "checkBreaches" | i18n }}
-
+
{{ "reportError" | i18n }}...
diff --git a/apps/web/src/app/reports/pages/exposed-passwords-report.component.html b/apps/web/src/app/reports/pages/exposed-passwords-report.component.html
index 2c5547efc7cf..928549b436c1 100644
--- a/apps/web/src/app/reports/pages/exposed-passwords-report.component.html
+++ b/apps/web/src/app/reports/pages/exposed-passwords-report.component.html
@@ -2,9 +2,9 @@
{{ "exposedPasswordsReport" | i18n }}
{{ "exposedPasswordsReportDesc" | i18n }}
-
+
{{ "checkExposedPasswords" | i18n }}
-
+
{{ "noExposedPasswords" | i18n }}
diff --git a/apps/web/src/app/settings/change-kdf.component.html b/apps/web/src/app/settings/change-kdf.component.html
index b06cf01d060c..18d668cfbb83 100644
--- a/apps/web/src/app/settings/change-kdf.component.html
+++ b/apps/web/src/app/settings/change-kdf.component.html
@@ -71,7 +71,7 @@ {{ "encKeySettings" | i18n }}
-
+
{{ "changeKdf" | i18n }}
-
+
diff --git a/apps/web/src/app/settings/change-password.component.html b/apps/web/src/app/settings/change-password.component.html
index 6f36236a7ae5..b4c5013fad6a 100644
--- a/apps/web/src/app/settings/change-password.component.html
+++ b/apps/web/src/app/settings/change-password.component.html
@@ -100,7 +100,7 @@ {{ "changeMasterPassword" | i18n }}
-
+
{{ "changeMasterPassword" | i18n }}
-
+
diff --git a/apps/web/src/app/settings/emergency-access-add-edit.component.html b/apps/web/src/app/settings/emergency-access-add-edit.component.html
index e7198e190304..fceb94915827 100644
--- a/apps/web/src/app/settings/emergency-access-add-edit.component.html
+++ b/apps/web/src/app/settings/emergency-access-add-edit.component.html
@@ -100,9 +100,9 @@
- {{
- "submit" | i18n
- }}
+
+ {{ "submit" | i18n }}
+
{{ "cancel" | i18n }}
diff --git a/apps/web/src/app/settings/premium.component.html b/apps/web/src/app/settings/premium.component.html
index 63995b457acd..3a2ea45a79db 100644
--- a/apps/web/src/app/settings/premium.component.html
+++ b/apps/web/src/app/settings/premium.component.html
@@ -68,9 +68,9 @@
{{ "goPremium" | i18n }}
"licenseFileDesc" | i18n: "bitwarden_premium_license.json"
}}
-
+
{{ "submit" | i18n }}
-
+
{{ "paymentChargedAnnually" | i18n }}
-
+
{{ "submit" | i18n }}
-
+
diff --git a/apps/web/src/app/settings/two-factor-setup.component.html b/apps/web/src/app/settings/two-factor-setup.component.html
index 698e7fd9c07d..b21fca894555 100644
--- a/apps/web/src/app/settings/two-factor-setup.component.html
+++ b/apps/web/src/app/settings/two-factor-setup.component.html
@@ -77,9 +77,14 @@