diff --git a/packages/ui-library/src/components/actions/buttons/text-button/index.css.ts b/packages/ui-library/src/components/actions/buttons/text-button/index.css.ts index fa395bf11..5065a54a5 100644 --- a/packages/ui-library/src/components/actions/buttons/text-button/index.css.ts +++ b/packages/ui-library/src/components/actions/buttons/text-button/index.css.ts @@ -18,12 +18,11 @@ export const styleCustom = typeSafeNestedCss` .blr-text-button { align-items: center; justify-content: center; - display: inline-flex; + display: flex; cursor: pointer; position: relative; &.xs { - gap: ${TextButton.Container.ItemSpacing.XS}; padding: ${TextButton.Container.Padding.XS}; border-radius: ${TextButton.Container.BorderRadius.XS}; @@ -33,7 +32,6 @@ export const styleCustom = typeSafeNestedCss` } &.sm { - gap: ${TextButton.Container.ItemSpacing.SM}; padding: ${TextButton.Container.Padding.SM}; border-radius: ${TextButton.Container.BorderRadius.SM}; @@ -43,9 +41,9 @@ export const styleCustom = typeSafeNestedCss` } &.md { - gap: ${TextButton.Container.ItemSpacing.MD}; padding: ${TextButton.Container.Padding.MD}; border-radius: ${TextButton.Container.BorderRadius.MD}; + & > .focus-layer { border-radius: ${TextButton.Container.BorderRadius.MD}; @@ -53,7 +51,6 @@ export const styleCustom = typeSafeNestedCss` } &.lg { - gap: ${TextButton.Container.ItemSpacing.LG}; padding: ${TextButton.Container.Padding.LG}; border-radius: ${TextButton.Container.BorderRadius.LG}; @@ -63,7 +60,6 @@ export const styleCustom = typeSafeNestedCss` } &.xl { - gap: ${TextButton.Container.ItemSpacing.XL}; padding: ${TextButton.Container.Padding.XL}; border-radius: ${TextButton.Container.BorderRadius.XL}; @@ -75,9 +71,49 @@ export const styleCustom = typeSafeNestedCss` .loading { & > .icon, - & > .label { + & > .label, + & > .flex-container { visibility: hidden; } } + .block { + display: block; + } + + .inline-block { + display: inline-block; + } + + .flex-container { + display: flex; + justify-content: center; + align-items: center; + + &.xs { + gap: ${TextButton.Container.ItemSpacing.XS} + } + + &.sm { + gap: ${TextButton.Container.ItemSpacing.SM} + } + + &.md { + gap: ${TextButton.Container.ItemSpacing.MD} + } + + &.lg { + gap: ${TextButton.Container.ItemSpacing.LG} + } + + &.xl { + gap: ${TextButton.Container.ItemSpacing.XL} + } + } + + .trailing-icon-class, + .leading-icon-class { + display: flex; + align-items: center; + } `; diff --git a/packages/ui-library/src/components/actions/buttons/text-button/index.stories.ts b/packages/ui-library/src/components/actions/buttons/text-button/index.stories.ts index 4d2b86be2..e8de805f8 100644 --- a/packages/ui-library/src/components/actions/buttons/text-button/index.stories.ts +++ b/packages/ui-library/src/components/actions/buttons/text-button/index.stories.ts @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { BlrTextButtonType, BlrTextButtonRenderFunction } from './index'; import { PureIconKeys } from '@boiler/icons'; -import { ActionSizes, ActionVariants, IconPositionVariant } from '../../../../globals/constants'; +import { ActionSizes, ActionVariants, IconPositionVariant, ButtonDisplayOptions } from '../../../../globals/constants'; import { Themes } from '../../../../foundation/_tokens-generated/index.themes'; export default { @@ -21,6 +21,10 @@ export default { options: ActionSizes, control: { type: 'select' }, }, + buttonDisplay: { + options: ButtonDisplayOptions, + control: { type: 'select' }, + }, variant: { options: ActionVariants, control: { type: 'select' }, @@ -44,11 +48,11 @@ const args: BlrTextButtonType = { variant: 'cta', size: 'md', label: 'Button', - onClick: () => console.log('onClick'), - onBlur: () => console.log('onBlur'), hasIcon: true, iconPosition: 'leading', icon: 'blr360', + onClick: () => console.log('onClick'), + onBlur: () => console.log('onBlur'), loading: false, disabled: false, buttonId: 'button-id', diff --git a/packages/ui-library/src/components/actions/buttons/text-button/index.test.ts b/packages/ui-library/src/components/actions/buttons/text-button/index.test.ts index 449798d77..4cb477a59 100644 --- a/packages/ui-library/src/components/actions/buttons/text-button/index.test.ts +++ b/packages/ui-library/src/components/actions/buttons/text-button/index.test.ts @@ -14,6 +14,7 @@ const sampleParams: BlrTextButtonType = { variant: 'cta', loadingStatus: 'Loading', theme: 'Light', + buttonDisplay: 'inline-block', }; describe('blr-text-button', () => { @@ -157,4 +158,26 @@ describe('blr-text-button', () => { expect(leadingIcon).not.to.exist; expect(svg).not.to.exist; }); + + it('display the button as block when "buttonDisplay" is set as block', async () => { + const element = await fixture(BlrTextButtonRenderFunction({ ...sampleParams, buttonDisplay: 'block' })); + + const button = querySelectorDeep('span', element.getRootNode() as HTMLElement); + + if (button) { + const buttonCssDisplay = getComputedStyle(button)['display']; + expect(buttonCssDisplay).to.equal('block'); + } + }); + + it('displays the button as inline-block when "buttonDisplay" is set as inline-block', async () => { + const element = await fixture(BlrTextButtonRenderFunction({ ...sampleParams, buttonDisplay: 'inline-block' })); + + const button = querySelectorDeep('span', element.getRootNode() as HTMLElement); + + if (button) { + const buttonCssDisplay = getComputedStyle(button)['display']; + expect(buttonCssDisplay).to.equal('inline-block'); + } + }); }); diff --git a/packages/ui-library/src/components/actions/buttons/text-button/index.ts b/packages/ui-library/src/components/actions/buttons/text-button/index.ts index 9785be7c5..e21134100 100644 --- a/packages/ui-library/src/components/actions/buttons/text-button/index.ts +++ b/packages/ui-library/src/components/actions/buttons/text-button/index.ts @@ -11,6 +11,7 @@ import { SizesType, FormSizesType, IconPositionVariant, + ButtonDisplayType, } from '../../../../globals/types'; import { determineLoaderVariant } from '../../../../utils/determine-loader-variant'; import { BlrIconRenderFunction } from '../../../ui/icon'; @@ -29,17 +30,16 @@ export class BlrTextButton extends LitElement { @property() label = 'Button Label'; @property() onClick?: HTMLButtonElement['onclick']; @property() onBlur?: HTMLButtonElement['onblur']; - @property() leadingIcon?: SizelessIconType; - @property() trailingIcon?: SizelessIconType; @property() icon?: SizelessIconType; - @property() loading!: boolean; - @property() disabled!: boolean; + @property({ type: Boolean }) hasIcon?: boolean; + @property() iconPosition?: IconPositionVariant = 'leading'; + @property({ type: Boolean }) loading!: boolean; + @property({ type: Boolean }) disabled!: boolean; @property() buttonId?: string; @property() variant: ActionVariantType = 'primary'; @property() size?: ActionSizesType = 'md'; @property() loadingStatus!: string; - @property() hasIcon?: boolean; - @property() iconPosition?: IconPositionVariant = 'leading'; + @property() buttonDisplay?: ButtonDisplayType = 'inline-block'; @property() theme: ThemeType = 'Light'; @@ -56,7 +56,7 @@ export class BlrTextButton extends LitElement { }; protected render() { - if (this.size) { + if (this.size && this.buttonDisplay) { const dynamicStyles = this.theme === 'Light' ? [actionLight] : [actionDark]; const classes = classMap({ @@ -66,10 +66,18 @@ export class BlrTextButton extends LitElement { [`${this.size}`]: this.size, 'disabled': this.disabled, 'loading': this.loading, + [this.buttonDisplay]: this.buttonDisplay, }); const iconClasses = classMap({ - icon: true, + 'icon': true, + 'leading-icon-class': this.iconPosition === 'leading', + 'trailing-icon-class': this.iconPosition === 'trailing', + }); + + const flexContainerClasses = classMap({ + 'flex-container': true, + [`${this.size}`]: this.size, }); const loaderVariant = determineLoaderVariant(this.variant); @@ -89,7 +97,8 @@ export class BlrTextButton extends LitElement { 'Icon', ]).toLowerCase() as SizesType; - const labelAndIconGroup = html` ${this.hasIcon && this.iconPosition === 'leading' + const labelAndIconGroup = html`
+ ${this.hasIcon && this.iconPosition === 'leading' ? BlrIconRenderFunction({ icon: calculateIconName(this.icon, iconSizeVariant), size: iconSizeVariant, @@ -97,7 +106,7 @@ export class BlrTextButton extends LitElement { classMap: iconClasses, }) : nothing} - ${this.label} + ${this.label} ${this.hasIcon && this.iconPosition === 'trailing' ? BlrIconRenderFunction({ icon: calculateIconName(this.icon, iconSizeVariant), @@ -105,7 +114,8 @@ export class BlrTextButton extends LitElement { hideAria: true, classMap: iconClasses, }) - : nothing}`; + : nothing} +
`; return html`