mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
feat: add tooltip support for icons (#7608)
This commit is contained in:
@@ -15,6 +15,7 @@ import {Size} from '../utils/size.js';
|
||||
import {Svg} from '../utils/svg.js';
|
||||
import type {IconType} from './icon_types.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as tooltip from '../tooltip.js';
|
||||
|
||||
/**
|
||||
* The abstract icon class. Icons are visual elements that live in the top-start
|
||||
@@ -35,7 +36,12 @@ export abstract class Icon implements IIcon {
|
||||
/** The root svg element visually representing this icon. */
|
||||
protected svgRoot: SVGGElement | null = null;
|
||||
|
||||
constructor(protected sourceBlock: Block) {}
|
||||
/** The tooltip for this icon. */
|
||||
protected tooltip: tooltip.TipInfo;
|
||||
|
||||
constructor(protected sourceBlock: Block) {
|
||||
this.tooltip = sourceBlock;
|
||||
}
|
||||
|
||||
getType(): IconType<IIcon> {
|
||||
throw new Error('Icons must implement getType');
|
||||
@@ -54,9 +60,12 @@ export abstract class Icon implements IIcon {
|
||||
this,
|
||||
pointerdownListener,
|
||||
);
|
||||
(this.svgRoot as any).tooltip = this;
|
||||
tooltip.bindMouseEvents(this.svgRoot);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
tooltip.unbindMouseEvents(this.svgRoot);
|
||||
dom.removeNode(this.svgRoot);
|
||||
}
|
||||
|
||||
@@ -68,6 +77,19 @@ export abstract class Icon implements IIcon {
|
||||
return new Size(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tooltip for this icon to the given value. Null to show the
|
||||
* tooltip of the block.
|
||||
*/
|
||||
setTooltip(tip: tooltip.TipInfo | null) {
|
||||
this.tooltip = tip ?? this.sourceBlock;
|
||||
}
|
||||
|
||||
/** Returns the tooltip for this icon. */
|
||||
getTooltip(): tooltip.TipInfo {
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
applyColour(): void {}
|
||||
|
||||
updateEditable(): void {}
|
||||
|
||||
Reference in New Issue
Block a user