Skip to content

Commit

Permalink
fix: display icons in the toolbox for extension categories (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko authored Apr 26, 2024
1 parent 49663ed commit b53eadd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions core/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,12 @@ const styles = `
.scratchCategoryMenuItem:hover {
color: $colour_toolboxHover !important;
}
.categoryIconBubble {
margin: 0 auto 0.125rem;
width: 1.25rem;
height: 1.25rem;
}
`;

Blockly.Css.register(styles);
15 changes: 11 additions & 4 deletions src/scratch_continuous_category.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import {ContinuousCategory} from '@blockly/continuous-toolbox';

class ScratchContinuousCategory extends ContinuousCategory {
createIconDom_() {
const icon = super.createIconDom_();
icon.style.border = `1px solid ${this.toolboxItemDef_['secondaryColour']}`;
return icon;
if (this.toolboxItemDef_.iconURI) {
const icon = document.createElement('img');
icon.src = this.toolboxItemDef_.iconURI;
icon.className = 'categoryIconBubble';
return icon;
} else {
const icon = super.createIconDom_();
icon.style.border = `1px solid ${this.toolboxItemDef_['secondaryColour']}`;
return icon;
}
}

setSelected(isSelected) {
super.setSelected(isSelected);
// Prevent hardcoding the background color to grey.
Expand Down

0 comments on commit b53eadd

Please sign in to comment.