(config: BadgeIndicatorConfig)
| 45 | * Returns the element, or null if visible is false. |
| 46 | */ |
| 47 | export function createBadgeIndicator(config: BadgeIndicatorConfig): HTMLElement | null { |
| 48 | const { container, className, icon, tooltip, ariaLabel, onClick, visible = true } = config; |
| 49 | |
| 50 | if (!visible) return null; |
| 51 | |
| 52 | const indicator = container.createEl("div", { |
| 53 | cls: className, |
| 54 | attr: { "aria-label": ariaLabel || tooltip }, |
| 55 | }); |
| 56 | |
| 57 | setIcon(indicator, icon); |
| 58 | setTooltip(indicator, tooltip, { placement: "top" }); |
| 59 | |
| 60 | if (onClick) { |
| 61 | prepareInteractiveControl(indicator); |
| 62 | indicator.addEventListener("click", (e) => { |
| 63 | e.stopPropagation(); |
| 64 | onClick(e); |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | return indicator; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Updates or creates a badge indicator, returning the element. |
no test coverage detected