Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tooltip support for icons #7608

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion core/icons/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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);
}

Expand All @@ -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 {}
Expand Down
Loading