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

[CL-54] Add support for button block without argument + submit button #3498

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions libs/components/src/button/button.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ export class ButtonDirective {
"focus:tw-ring-primary-700",
"focus:tw-z-10",
]
.concat(this.block ? ["tw-w-full", "tw-block"] : ["tw-inline-block"])
.concat(
this.block == null || this.block === false ? ["tw-inline-block"] : ["tw-w-full", "tw-block"]
)
.concat(buttonStyles[this.buttonType ?? "secondary"]);
}

@Input()
buttonType: ButtonTypes = null;

@Input()
block = false;
@Input() buttonType: ButtonTypes = null;
@Input() block?: boolean;
}
18 changes: 18 additions & 0 deletions libs/components/src/button/button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ export const Disabled = DisabledTemplate.bind({});
Disabled.args = {
size: "small",
};

const BlockTemplate: Story<ButtonDirective> = (args: ButtonDirective) => ({
props: args,
template: `
<span class="tw-flex">
<button bitButton [buttonType]="buttonType" [block]="block">[block]="true" Button</button>
<a bitButton [buttonType]="buttonType" [block]="block" href="#" class="tw-ml-2">[block]="true" Link</a>

<button bitButton [buttonType]="buttonType" block class="tw-ml-2">block Button</button>
<a bitButton [buttonType]="buttonType" block href="#" class="tw-ml-2">block Link</a>
</span>
`,
});

export const Block = BlockTemplate.bind({});
Block.args = {
block: true,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<button bitButton type="submit" [buttonType]="buttonType" [disabled]="loading || disabled">
<button
bitButton
type="submit"
[block]="block"
[buttonType]="buttonType"
[disabled]="loading || disabled"
>
<span class="tw-relative">
<span [ngClass]="{ 'tw-invisible': loading }">
<ng-content></ng-content>
Expand Down
8 changes: 7 additions & 1 deletion libs/components/src/submit-button/submit-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from "@angular/core";
import { Component, HostBinding, Input } from "@angular/core";

import { ButtonTypes } from "../button";

Expand All @@ -10,4 +10,10 @@ export class SubmitButtonComponent {
@Input() buttonType: ButtonTypes = "primary";
@Input() disabled = false;
@Input() loading: boolean;

@Input() block?: boolean;

@HostBinding("class") get classList() {
return this.block == null || this.block === false ? [] : ["tw-w-full", "tw-block"];
}
}
3 changes: 2 additions & 1 deletion libs/components/src/submit-button/submit-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
args: {
buttonType: "primary",
loading: false,
block: false,
},
parameters: {
design: {
Expand All @@ -25,7 +26,7 @@ export default {

const Template: Story<SubmitButtonComponent> = (args: SubmitButtonComponent) => ({
props: args,
template: `<bit-submit-button [buttonType]="buttonType" [loading]="loading" [disabled]="disabled">
template: `<bit-submit-button [buttonType]="buttonType" [loading]="loading" [disabled]="disabled" [block]="block">
Submit
</bit-submit-button>`,
});
Expand Down