2020-07-15 21:30:37 +00:00
|
|
|
import { Component, Event, EventEmitter, Prop, h } from '@stencil/core';
|
|
|
|
|
|
|
|
/**
|
2020-07-17 10:09:10 +00:00
|
|
|
* @since 2.0
|
2020-07-15 21:30:37 +00:00
|
|
|
* @status stable
|
|
|
|
*
|
|
|
|
* @slot - The tag's content.
|
|
|
|
*
|
|
|
|
* @part base - The component's base wrapper.
|
|
|
|
* @part content - The tag content.
|
|
|
|
* @part clear-button - The clear button.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
tag: 'sl-tag',
|
|
|
|
styleUrl: 'tag.scss',
|
|
|
|
shadow: true
|
|
|
|
})
|
|
|
|
export class Tag {
|
|
|
|
tag: HTMLElement;
|
|
|
|
|
|
|
|
/** The tag's type. */
|
2020-08-16 15:27:18 +00:00
|
|
|
@Prop({ reflect: true }) type: 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'text' = 'primary';
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** The tag's size. */
|
2020-08-16 15:27:18 +00:00
|
|
|
@Prop({ reflect: true }) size: 'small' | 'medium' | 'large' = 'medium';
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** Set to true to draw a pill-style tag with rounded edges. */
|
2020-08-16 15:27:18 +00:00
|
|
|
@Prop({ reflect: true }) pill = false;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** Set to true to make the tag clearable. */
|
2020-08-16 15:27:18 +00:00
|
|
|
@Prop({ reflect: true }) clearable = false;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** Emitted when the clear button is activated. */
|
2020-10-09 21:45:16 +00:00
|
|
|
@Event({ eventName: 'sl-clear' }) slClear: EventEmitter;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
2020-07-21 19:18:58 +00:00
|
|
|
connectedCallback() {
|
|
|
|
this.handleClearClick = this.handleClearClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
handleClearClick() {
|
|
|
|
this.slClear.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
ref={el => (this.tag = el)}
|
|
|
|
part="base"
|
|
|
|
class={{
|
|
|
|
tag: true,
|
|
|
|
|
|
|
|
// Types
|
|
|
|
'tag--primary': this.type === 'primary',
|
|
|
|
'tag--success': this.type === 'success',
|
|
|
|
'tag--info': this.type === 'info',
|
|
|
|
'tag--warning': this.type === 'warning',
|
|
|
|
'tag--danger': this.type === 'danger',
|
|
|
|
'tag--text': this.type === 'text',
|
|
|
|
|
|
|
|
// Sizes
|
|
|
|
'tag--small': this.size === 'small',
|
|
|
|
'tag--medium': this.size === 'medium',
|
|
|
|
'tag--large': this.size === 'large',
|
|
|
|
|
|
|
|
// Modifers
|
|
|
|
'tag--pill': this.pill,
|
|
|
|
'tag--clearable': this.clearable
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span part="content" class="tag__content">
|
|
|
|
<slot />
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{this.clearable && (
|
2020-07-24 20:57:38 +00:00
|
|
|
<sl-icon-button part="clear-button" name="x" class="tag__clear" onClick={this.handleClearClick} />
|
2020-07-15 21:30:37 +00:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|