-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EC-457] Component library icon buttons (#3372)
* [EC-457] feat: initial version of icon button * [EC-457] feat: modify template and start adding inputs * [EC-457] feat: implement all styles * [EC-457] chore: cleanup * [EC-457] feat: fix hover styles after discussions * [EC-457] feat: add focus ring workaround * [EC-457] chore: refactor stories a bit * [EC-457] fix: button style attr name reserved word collision * [EC-356] feat: match padding with figma * [EC-457] feat: use icon button in banner * [EC-457] chore: cleanup css classes * [EC-457] feat: improve aria * [EC-457] feat: use icon button in dialog * [EC-457] fix: make focus and hover styles independent * [EC-457] fix: remove primary 500 border * [EC-457] chore: cleanup * [EC-457] chore: move css class to common list * [EC-457] fix: use focus-visible * [EC-457] chore: expand on workaround fix * [EC-457] fix: default sizing * [EC-457] fix: align trash icon right * [EC-457] fix: add missing aria labels * [EC-457] fix: add i18n service to banner tests * [EC-457] chore: rename size `default` to `button` * [EC-457] feat: double padding * [EC-457] feat: simplify sizes - update default * [EC-457] fix: revert selector fix - gonna create separate pr * [EC-457] chore: remove superfluous dependencies * [EC-457] fix: remove non-working onClose handler Removing this storybook action because we already test it as part of the dialog service stories. It requries mocking the dialogRef to capture the close function which makes this story more complex but adds very little value as we already test it elsewhere.
- Loading branch information
Showing
16 changed files
with
292 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
libs/components/src/icon-button/icon-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { Component, HostBinding, Input } from "@angular/core"; | ||
|
||
export type IconButtonStyle = "contrast" | "main" | "muted" | "primary" | "secondary" | "danger"; | ||
|
||
const styles: Record<IconButtonStyle, string[]> = { | ||
contrast: [ | ||
"tw-bg-transparent", | ||
"!tw-text-contrast", | ||
"tw-border-transparent", | ||
"hover:tw-bg-transparent-hover", | ||
"hover:tw-border-text-contrast", | ||
"focus-visible:before:tw-ring-text-contrast", | ||
"disabled:hover:tw-bg-transparent", | ||
], | ||
main: [ | ||
"tw-bg-transparent", | ||
"!tw-text-main", | ||
"tw-border-transparent", | ||
"hover:tw-bg-transparent-hover", | ||
"hover:tw-border-text-main", | ||
"focus-visible:before:tw-ring-text-main", | ||
"disabled:hover:tw-bg-transparent", | ||
], | ||
muted: [ | ||
"tw-bg-transparent", | ||
"!tw-text-muted", | ||
"tw-border-transparent", | ||
"hover:tw-bg-transparent-hover", | ||
"hover:tw-border-primary-700", | ||
"focus-visible:before:tw-ring-primary-700", | ||
"disabled:hover:tw-bg-transparent", | ||
], | ||
primary: [ | ||
"tw-bg-primary-500", | ||
"!tw-text-contrast", | ||
"tw-border-primary-500", | ||
"hover:tw-bg-primary-700", | ||
"hover:tw-border-primary-700", | ||
"focus-visible:before:tw-ring-primary-700", | ||
"disabled:hover:tw-bg-primary-500", | ||
], | ||
secondary: [ | ||
"tw-bg-transparent", | ||
"!tw-text-muted", | ||
"tw-border-text-muted", | ||
"hover:!tw-text-contrast", | ||
"hover:tw-bg-text-muted", | ||
"focus-visible:before:tw-ring-primary-700", | ||
"disabled:hover:tw-bg-transparent", | ||
"disabled:hover:!tw-text-muted", | ||
"disabled:hover:tw-border-text-muted", | ||
], | ||
danger: [ | ||
"tw-bg-transparent", | ||
"!tw-text-danger", | ||
"tw-border-danger-500", | ||
"hover:!tw-text-contrast", | ||
"hover:tw-bg-danger-500", | ||
"focus-visible:before:tw-ring-primary-700", | ||
"disabled:hover:tw-bg-transparent", | ||
"disabled:hover:!tw-text-danger", | ||
"disabled:hover:tw-border-danger-500", | ||
], | ||
}; | ||
|
||
export type IconButtonSize = "default" | "small"; | ||
|
||
const sizes: Record<IconButtonSize, string[]> = { | ||
default: ["tw-px-2.5", "tw-py-1.5"], | ||
small: ["tw-leading-none", "tw-text-base", "tw-p-1"], | ||
}; | ||
|
||
@Component({ | ||
selector: "button[bitIconButton]", | ||
template: `<i class="bwi" [ngClass]="icon" aria-hidden="true"></i>`, | ||
}) | ||
export class BitIconButtonComponent { | ||
@Input("bitIconButton") icon: string; | ||
|
||
@Input() buttonType: IconButtonStyle = "main"; | ||
|
||
@Input() size: IconButtonSize = "default"; | ||
|
||
@HostBinding("class") get classList() { | ||
return [ | ||
"tw-font-semibold", | ||
"tw-border", | ||
"tw-border-solid", | ||
"tw-rounded", | ||
"tw-transition", | ||
"hover:tw-no-underline", | ||
"disabled:tw-opacity-60", | ||
"disabled:hover:tw-border-transparent", | ||
"focus:tw-outline-none", | ||
|
||
// Workaround for box-shadow with transparent offset issue: | ||
// https://github.com/tailwindlabs/tailwindcss/issues/3595 | ||
// Remove `before:` and use regular `tw-ring` when browser no longer has bug, or better: | ||
// switch to `outline` with `outline-offset` when Safari supports border radius on outline. | ||
// Using `box-shadow` to create outlines is a hack and as such `outline` should be preferred. | ||
"tw-relative", | ||
"before:tw-content-['']", | ||
"before:tw-block", | ||
"before:tw-absolute", | ||
"before:-tw-inset-[3px]", | ||
"before:tw-rounded-md", | ||
"before:tw-transition", | ||
"before:tw-ring", | ||
"focus-visible:before:tw-ring-text-contrast", | ||
"focus-visible:tw-z-10", | ||
] | ||
.concat(styles[this.buttonType]) | ||
.concat(sizes[this.size]); | ||
} | ||
} |
Oops, something went wrong.