Skip to content

Commit b53eadd

Browse files
authored
fix: display icons in the toolbox for extension categories (#47)
1 parent 49663ed commit b53eadd

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

core/css.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,12 @@ const styles = `
12751275
.scratchCategoryMenuItem:hover {
12761276
color: $colour_toolboxHover !important;
12771277
}
1278+
1279+
.categoryIconBubble {
1280+
margin: 0 auto 0.125rem;
1281+
width: 1.25rem;
1282+
height: 1.25rem;
1283+
}
12781284
`;
12791285

12801286
Blockly.Css.register(styles);

src/scratch_continuous_category.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import {ContinuousCategory} from '@blockly/continuous-toolbox';
33

44
class ScratchContinuousCategory extends ContinuousCategory {
55
createIconDom_() {
6-
const icon = super.createIconDom_();
7-
icon.style.border = `1px solid ${this.toolboxItemDef_['secondaryColour']}`;
8-
return icon;
6+
if (this.toolboxItemDef_.iconURI) {
7+
const icon = document.createElement('img');
8+
icon.src = this.toolboxItemDef_.iconURI;
9+
icon.className = 'categoryIconBubble';
10+
return icon;
11+
} else {
12+
const icon = super.createIconDom_();
13+
icon.style.border = `1px solid ${this.toolboxItemDef_['secondaryColour']}`;
14+
return icon;
15+
}
916
}
10-
17+
1118
setSelected(isSelected) {
1219
super.setSelected(isSelected);
1320
// Prevent hardcoding the background color to grey.

0 commit comments

Comments
 (0)