Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC-457] Component library icon buttons #3372

Merged
merged 31 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4732739
[EC-457] feat: initial version of icon button
coroiu Aug 24, 2022
9903492
[EC-457] feat: modify template and start adding inputs
coroiu Aug 24, 2022
34b409a
[EC-457] feat: implement all styles
coroiu Aug 24, 2022
af49ae0
[EC-457] chore: cleanup
coroiu Aug 24, 2022
756c85f
[EC-457] feat: fix hover styles after discussions
coroiu Aug 25, 2022
9b72b11
[EC-457] feat: add focus ring workaround
coroiu Aug 29, 2022
6a0142e
[EC-457] chore: refactor stories a bit
coroiu Aug 29, 2022
200bbe7
[EC-457] fix: button style attr name reserved word collision
coroiu Aug 29, 2022
9d71687
[EC-356] feat: match padding with figma
coroiu Aug 29, 2022
93a2b9b
[EC-457] feat: use icon button in banner
coroiu Aug 29, 2022
dd7e202
[EC-457] chore: cleanup css classes
coroiu Aug 29, 2022
f63b8ab
[EC-457] feat: improve aria
coroiu Aug 30, 2022
6adef29
[EC-457] feat: use icon button in dialog
coroiu Aug 30, 2022
8a11aa8
[EC-457] fix: make focus and hover styles independent
coroiu Aug 30, 2022
7a1e6c0
[EC-457] fix: remove primary 500 border
coroiu Aug 30, 2022
c55be5f
[EC-457] chore: cleanup
coroiu Aug 30, 2022
829987f
[EC-457] chore: move css class to common list
coroiu Aug 31, 2022
01f57ec
[EC-457] fix: use focus-visible
coroiu Aug 31, 2022
e85fef4
[EC-457] chore: expand on workaround fix
coroiu Aug 31, 2022
28fd130
[EC-457] fix: default sizing
coroiu Aug 31, 2022
05ad63b
[EC-457] fix: align trash icon right
coroiu Aug 31, 2022
fda8605
[EC-457] fix: add missing aria labels
coroiu Aug 31, 2022
e8ef7bb
[EC-457] fix: add i18n service to banner tests
coroiu Sep 1, 2022
45305aa
[EC-457] chore: rename size `default` to `button`
coroiu Sep 5, 2022
cfede15
[EC-457] feat: double padding
coroiu Sep 5, 2022
2704b80
[EC-457] feat: simplify sizes - update default
coroiu Sep 12, 2022
4c99611
Merge branch 'master' into EC-457-component-library-icon-buttons
coroiu Sep 13, 2022
d0d687c
[EC-457] fix: revert selector fix - gonna create separate pr
coroiu Sep 13, 2022
5962fe9
Merge remote-tracking branch 'origin/master' into EC-457-component-li…
coroiu Sep 13, 2022
e8a536b
[EC-457] chore: remove superfluous dependencies
coroiu Sep 14, 2022
cf5166d
[EC-457] fix: remove non-working onClose handler
coroiu Sep 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions libs/components/src/banner/banner.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div
class="tw-flex tw-items-center tw-gap-2 tw-py-2.5 tw-px-4 tw-text-contrast"
class="tw-flex tw-items-center tw-gap-2 tw-py-2.5 tw-px-4 tw-pr-2.5 tw-text-contrast"
[ngClass]="bannerClass"
[attr.role]="useAlertRole ? 'status' : null"
[attr.aria-live]="useAlertRole ? 'polite' : null"
Expand All @@ -8,7 +8,12 @@
<span class="tw-grow tw-text-base">
<ng-content></ng-content>
</span>
<button class="tw-border-0 tw-bg-transparent tw-p-0 tw-text-contrast" (click)="onClose.emit()">
<i class="bwi bwi-close tw-text-sm" *ngIf="icon" aria-hidden="true"></i>
</button>
<button
bitIconButton="bwi-close"
buttonType="contrast"
size="default"
(click)="onClose.emit()"
[attr.title]="'close' | i18n"
[attr.aria-label]="'close' | i18n"
></button>
</div>
15 changes: 15 additions & 0 deletions libs/components/src/banner/banner.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";

import { SharedModule } from "../shared/shared.module";
import { I18nMockService } from "../utils/i18n-mock.service";

import { BannerComponent } from "./banner.component";

describe("BannerComponent", () => {
Expand All @@ -8,7 +13,17 @@ describe("BannerComponent", () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SharedModule],
declarations: [BannerComponent],
providers: [
{
provide: I18nService,
useFactory: () =>
new I18nMockService({
close: "Close",
}),
},
],
}).compileComponents();

fixture = TestBed.createComponent(BannerComponent);
Expand Down
5 changes: 4 additions & 1 deletion libs/components/src/banner/banner.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";

import { IconButtonModule } from "../icon-button";
import { SharedModule } from "../shared/shared.module";

import { BannerComponent } from "./banner.component";

@NgModule({
imports: [CommonModule],
imports: [CommonModule, SharedModule, IconButtonModule],
exports: [BannerComponent],
declarations: [BannerComponent],
})
Expand Down
28 changes: 26 additions & 2 deletions libs/components/src/banner/banner.stories.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import { Meta, Story } from "@storybook/angular";
import { Meta, moduleMetadata, Story } from "@storybook/angular";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";

import { IconButtonModule } from "../icon-button";
import { SharedModule } from "../shared/shared.module";
import { I18nMockService } from "../utils/i18n-mock.service";

import { BannerComponent } from "./banner.component";

export default {
title: "Component Library/Banner",
component: BannerComponent,
decorators: [
moduleMetadata({
imports: [SharedModule, IconButtonModule],
providers: [
{
provide: I18nService,
useFactory: () => {
return new I18nMockService({
close: "Close",
});
},
},
],
}),
],
args: {
bannerType: "warning",
},
argTypes: {
onClose: { action: "onClose" },
},
} as Meta;

const Template: Story<BannerComponent> = (args: BannerComponent) => ({
props: args,
template: `
<bit-banner [bannerType]="bannerType">Content Really Long Text Lorem Ipsum Ipsum Ipsum <button>Button</button></bit-banner>
<bit-banner [bannerType]="bannerType" (onClose)="onClose($event)">Content Really Long Text Lorem Ipsum Ipsum Ipsum <button>Button</button></bit-banner>
`,
});

Expand Down
16 changes: 4 additions & 12 deletions libs/components/src/button/button.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const buttonStyles: Record<ButtonTypes, string[]> = {
"!tw-text-contrast",
"hover:tw-bg-primary-700",
"hover:tw-border-primary-700",
"focus:tw-bg-primary-700",
eliykat marked this conversation as resolved.
Show resolved Hide resolved
"focus:tw-border-primary-700",
],
secondary: [
"tw-bg-transparent",
Expand All @@ -19,9 +17,6 @@ const buttonStyles: Record<ButtonTypes, string[]> = {
"hover:tw-bg-secondary-500",
"hover:tw-border-secondary-500",
"hover:!tw-text-contrast",
"focus:tw-bg-secondary-500",
"focus:tw-border-secondary-500",
"focus:!tw-text-contrast",
],
danger: [
"tw-bg-transparent",
Expand All @@ -30,9 +25,6 @@ const buttonStyles: Record<ButtonTypes, string[]> = {
"hover:tw-bg-danger-500",
"hover:tw-border-danger-500",
"hover:!tw-text-contrast",
"focus:tw-bg-danger-500",
"focus:tw-border-danger-500",
"focus:!tw-text-contrast",
],
};

Expand All @@ -55,10 +47,10 @@ export class ButtonDirective {
"disabled:tw-border-secondary-100",
"disabled:!tw-text-main",
"focus:tw-outline-none",
"focus:tw-ring",
"focus:tw-ring-offset-2",
"focus:tw-ring-primary-700",
"focus:tw-z-10",
"focus-visible:tw-ring",
"focus-visible:tw-ring-offset-2",
"focus-visible:tw-ring-primary-700",
"focus-visible:tw-z-10",
]
.concat(this.block ? ["tw-w-full", "tw-block"] : ["tw-inline-block"])
.concat(buttonStyles[this.buttonType ?? "secondary"]);
Expand Down
5 changes: 3 additions & 2 deletions libs/components/src/dialog/dialog.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DialogModule as CdkDialogModule } from "@angular/cdk/dialog";
import { NgModule } from "@angular/core";

import { IconButtonModule } from "../icon-button";
import { SharedModule } from "../shared";

import { DialogService } from "./dialog.service";
Expand All @@ -10,11 +11,11 @@ import { DialogTitleContainerDirective } from "./directives/dialog-title-contain
import { SimpleDialogComponent } from "./simple-dialog/simple-dialog.component";

@NgModule({
imports: [SharedModule, CdkDialogModule],
imports: [SharedModule, IconButtonModule, CdkDialogModule],
declarations: [
DialogCloseDirective,
DialogComponent,
DialogTitleContainerDirective,
DialogComponent,
SimpleDialogComponent,
],
exports: [CdkDialogModule, DialogComponent, SimpleDialogComponent],
Expand Down
14 changes: 7 additions & 7 deletions libs/components/src/dialog/dialog/dialog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
class="tw-my-4 tw-flex tw-max-h-screen tw-flex-col tw-overflow-hidden tw-rounded tw-border tw-border-solid tw-border-secondary-300 tw-bg-text-contrast tw-text-main"
>
<div
class="tw-flex tw-gap-4 tw-border-0 tw-border-b tw-border-solid tw-border-secondary-300 tw-p-4"
class="tw-flex tw-items-center tw-gap-4 tw-border-0 tw-border-b tw-border-solid tw-border-secondary-300 tw-p-4"
>
<h1 bitDialogTitleContainer class="tw-mb-0 tw-grow tw-text-lg tw-uppercase">
<ng-content select="[bitDialogTitle]"></ng-content>
</h1>
<button
bitIconButton="bwi-close"
buttonType="main"
size="default"
bitDialogClose
class="tw-border-0 tw-bg-transparent tw-p-0"
title="{{ 'close' | i18n }}"
attr.aria-label="{{ 'close' | i18n }}"
>
<i class="bwi bwi-close tw-text-xs tw-font-bold tw-text-main" aria-hidden="true"></i>
</button>
[attr.title]="'close' | i18n"
[attr.aria-label]="'close' | i18n"
></button>
</div>

<div class="tw-overflow-y-auto tw-p-4 tw-pb-8">
Expand Down
15 changes: 13 additions & 2 deletions libs/components/src/dialog/dialog/dialog.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meta, moduleMetadata, Story } from "@storybook/angular";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";

import { ButtonModule } from "../../button";
import { IconButtonModule } from "../../icon-button";
import { SharedModule } from "../../shared";
import { I18nMockService } from "../../utils/i18n-mock.service";
import { DialogCloseDirective } from "../directives/dialog-close.directive";
Expand All @@ -15,7 +16,7 @@ export default {
component: DialogComponent,
decorators: [
moduleMetadata({
imports: [SharedModule, ButtonModule],
imports: [ButtonModule, SharedModule, IconButtonModule],
declarations: [DialogTitleContainerDirective, DialogCloseDirective],
providers: [
{
Expand All @@ -38,6 +39,9 @@ export default {
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library",
},
},
argTypes: {
onClose: { action: "onClose" },
},
eliykat marked this conversation as resolved.
Show resolved Hide resolved
} as Meta;

const Template: Story<DialogComponent> = (args: DialogComponent) => ({
Expand All @@ -46,9 +50,16 @@ const Template: Story<DialogComponent> = (args: DialogComponent) => ({
<bit-dialog [dialogSize]="dialogSize">
<span bitDialogTitle>{{title}}</span>
<span bitDialogContent>Dialog body text goes here.</span>
<div bitDialogFooter class="tw-flex tw-flex-row tw-gap-2">
<div bitDialogFooter class="tw-flex tw-items-center tw-flex-row tw-gap-2">
<button bitButton buttonType="primary">Save</button>
<button bitButton buttonType="secondary">Cancel</button>
<button
class="tw-ml-auto"
bitIconButton="bwi-trash"
buttonType="danger"
size="default"
title="Delete"
aria-label="Delete"></button>
eliykat marked this conversation as resolved.
Show resolved Hide resolved
</div>
</bit-dialog>
`,
Expand Down
25 changes: 21 additions & 4 deletions libs/components/src/dialog/simple-dialog.service.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import { DialogModule, DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
import { Component, Inject } from "@angular/core";
import { Meta, moduleMetadata, Story } from "@storybook/angular";

import { I18nService } from "@bitwarden/common/abstractions/i18n.service";

import { ButtonModule } from "../button";
import { IconButtonModule } from "../icon-button";
import { SharedModule } from "../shared/shared.module";
import { I18nMockService } from "../utils/i18n-mock.service";

import { DialogService } from "./dialog.service";
import { DialogComponent } from "./dialog/dialog.component";
import { DialogCloseDirective } from "./directives/dialog-close.directive";
import { DialogTitleContainerDirective } from "./directives/dialog-title-container.directive";
import { SimpleDialogComponent } from "./simple-dialog/simple-dialog.component";
Expand Down Expand Up @@ -60,13 +66,24 @@ export default {
decorators: [
moduleMetadata({
declarations: [
DialogComponent,
coroiu marked this conversation as resolved.
Show resolved Hide resolved
StoryDialogContentComponent,
DialogCloseDirective,
SimpleDialogComponent,
DialogTitleContainerDirective,
StoryDialogContentComponent,
SimpleDialogComponent,
],
imports: [SharedModule, IconButtonModule, ButtonModule, DialogModule],
providers: [
DialogService,
{
provide: I18nService,
useFactory: () => {
return new I18nMockService({
close: "Close",
});
},
},
],
imports: [ButtonModule, DialogModule],
providers: [DialogService],
}),
],
parameters: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meta, moduleMetadata, Story } from "@storybook/angular";

import { ButtonModule } from "../../button";
import { SharedModule } from "../../shared";
import { DialogTitleContainerDirective } from "../directives/dialog-title-container.directive";

import { IconDirective, SimpleDialogComponent } from "./simple-dialog.component";
Expand All @@ -10,7 +11,7 @@ export default {
component: SimpleDialogComponent,
decorators: [
moduleMetadata({
imports: [ButtonModule],
imports: [ButtonModule, SharedModule],
coroiu marked this conversation as resolved.
Show resolved Hide resolved
declarations: [IconDirective, DialogTitleContainerDirective],
}),
],
Expand Down
Loading