-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathBaseLabel.ts
53 lines (43 loc) · 1.43 KB
/
BaseLabel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { LitElement, html } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js';
import styles from './BaseLabel.css';
/**
* Base label class
*/
export abstract class BaseLabel extends LitElement {
static readonly styles = [styles];
abstract variant?: string;
abstract color?: string;
abstract icon?: string;
/** Represents the state of the anonymous and icon slots */
protected slots = new SlotController(this, null, 'icon');
override render() {
const { variant, color, icon } = this;
const hasIcon = !!icon || this.slots.hasSlotted('icon');
return html`
<span id="container"
class=${classMap({ hasIcon, [variant ?? '']: !!variant, [color ?? '']: !!color })}>
<slot name="icon" part="icon">${this.renderDefaultIcon?.()}</slot>
<slot id="text"></slot>
${this.renderSuffix?.() ?? ''}
</span>
`;
}
/**
* Fallback content for the icon slot. When the `icon` attribute is set, it
* should render an icon corresponding to the value.
*
* @example ```html
* <pf-icon icon=${this.icon}></pf-icon>
* ```
*/
protected abstract renderDefaultIcon?(): unknown;
/**
* Optional override to render content after the anonymous slot.
* @example ```html
* <button id="close-button">X</button>
* ```
*/
protected abstract renderSuffix?(): unknown;
}