kopia lustrzana https://github.com/shoelace-style/shoelace
56 wiersze
1.6 KiB
TypeScript
56 wiersze
1.6 KiB
TypeScript
import { html } from 'lit';
|
|
import { customElement, property } from 'lit/decorators.js';
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
import ShoelaceElement from '../../internal/shoelace-element';
|
|
import styles from './badge.styles';
|
|
import type { CSSResultGroup } from 'lit';
|
|
|
|
/**
|
|
* @summary Badges are used to draw attention and display statuses or counts.
|
|
*
|
|
* @since 2.0
|
|
* @status stable
|
|
*
|
|
* @slot - The badge's content.
|
|
*
|
|
* @csspart base - The component's base wrapper.
|
|
*/
|
|
@customElement('sl-badge')
|
|
export default class SlBadge extends ShoelaceElement {
|
|
static styles: CSSResultGroup = styles;
|
|
|
|
/** The badge's theme variant. */
|
|
@property({ reflect: true }) variant: 'primary' | 'success' | 'neutral' | 'warning' | 'danger' = 'primary';
|
|
|
|
/** Draws a pill-style badge with rounded edges. */
|
|
@property({ type: Boolean, reflect: true }) pill = false;
|
|
|
|
/** Makes the badge pulsate to draw attention. */
|
|
@property({ type: Boolean, reflect: true }) pulse = false;
|
|
|
|
render() {
|
|
return html`
|
|
<slot
|
|
part="base"
|
|
class=${classMap({
|
|
badge: true,
|
|
'badge--primary': this.variant === 'primary',
|
|
'badge--success': this.variant === 'success',
|
|
'badge--neutral': this.variant === 'neutral',
|
|
'badge--warning': this.variant === 'warning',
|
|
'badge--danger': this.variant === 'danger',
|
|
'badge--pill': this.pill,
|
|
'badge--pulse': this.pulse
|
|
})}
|
|
role="status"
|
|
></slot>
|
|
`;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'sl-badge': SlBadge;
|
|
}
|
|
}
|