Newer
Older
import {Component, h, Prop, Host} from '@stencil/core';
import {ButtonVariants} from '../../utils/utils';
import colors from '../../global/colors';
})
export class Button {
/**
* Button type. Defaults to submit.
*/
@Prop() buttonType: string = 'submit';
/**
* Custom classes added to button element.
*/
@Prop() buttonClasses: string = '';
/**
* Size (height) of the button. Normal: 44px, large: 48px
*/
/**
* Use this to programmatically disable the button, matches the native button functionality
*/
@Prop() disabled: boolean = false;
/**
* Set this on if an anchor tag is required instead of a button.
*/
/**
* Aria label for the element
*/
@Prop() ariaLabel?: string;
/**
* Use only with url property. Sets the
*/
@Prop() isExternal?: boolean = false;
/**
* Icon to use on the left side
*/
@Prop() iconRight?: string;
const classAttributes = ['hy-button', this.variant, this.state, 'size-' + this.size, this.buttonClasses];
const target = this.isExternal ? '_blank' : '_self';
return this.url ? (
<Host icon-right="hy-icon-arrow-right" aria-label={this.ariaLabel}>
<div style={{display: 'flex'}}>
<a class={classAttributes.join(' ')} href={this.url} target={target}>
<span class="hy-button__text">
<slot />
</span>
<span class="hy-button__icon">
<hy-icon icon="hy-icon-arrow-right" fill={iconFillColor} size={13} />
</span>
</a>
</div>
</Host>
) : (
<Host aria-label={this.ariaLabel}>
<button type={this.buttonType} class={classAttributes.join(' ')} disabled={this.disabled}>
<hy-icon icon={this.icon} fill={iconFillColor} size={13} />
</span>
)}
<slot />
</span>
{!!this.iconRight && (
<hy-icon icon={this.iconRight} fill={iconFillColor} size={13} />
</span>
)}
</button>
</Host>
);
}
}