1

It is possible to replace a panel tool by an awesome font icon.

I made several attempts with CSS but it does not work.

Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2a0i

jose
  • 1,490
  • 3
  • 30
  • 65
  • Do you want to replace Panel heading with an icon? or do you want to replace field label with icon? – Ibrahim Nov 22 '17 at 18:04
  • I want to create a custom panel tool with awesome font icon. It seems to work on some versions of extjs 6, but I'm not getting it in version 5 – jose Nov 22 '17 at 18:09
  • it is working now? I can see print icon – Ibrahim Nov 22 '17 at 18:26
  • @Ibrahim I added the tool print just for illustration. The desired icon is to the left of the tool print if you hover the mouse cursor and click – jose Nov 22 '17 at 18:29
  • I guess ExtJS 5 does not support font awesome, you migh use background-image: url(".....") instead – Ibrahim Nov 22 '17 at 18:58
  • @Ibrahim While ExtJS 5 does not support FontAwesome out of the box, you can always add it somehow. – Alexander Nov 22 '17 at 19:13

2 Answers2

2

You are on the right track, but the issue is that ExtJS 5 uses the img tag for tool elements, and there's a "minor" issue with :before pseudo elements for img tags. You will have to work around that by appending the original Ext.panel.Tool to use a span instead whenever you need that:

Ext.define('',{
    override: 'Ext.panel.Tool',
    renderTpl: [
        '<tpl if="ui==\'glyph\'">',
            '<span id="{id}-toolEl" data-ref="toolEl" src="{blank}" class="{baseCls}-img {baseCls}-{type}' +
                '{childElCls}" role="presentation"/>',
        '<tpl else>',
            '<img id="{id}-toolEl" data-ref="toolEl" src="{blank}" class="{baseCls}-img {baseCls}-{type}' +
                '{childElCls}" role="presentation"/>',
        '</tpl>'
    ]
});

Then you can tell some tools to use ui:"glyph", which is used in the override to detect that a div should be used, thus allowing :before pseudo elements and, therefore, a FontAwesome icon:

tools: [{
    type: 'edit',
    ui:"glyph",
    cls:'component-tool-edit',
    callback: function() {
        alert();
    }

and then the icon is technically displayed:

you only have to add FontAwesome to the project and amend your stylesheet:

@font-face {
    font-family: 'FontAwesome';
    src: url('font-awesome/fonts/fontawesome-webfont.eot?v=4.7.0');
    src: url('font-awesome/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('font-awesome/fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('font-awesome/fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('font-awesome/fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('font-awesome/fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
    font-weight: normal;
    font-style: normal;
}
Alexander
  • 19,906
  • 19
  • 75
  • 162
  • Thanks Alexander. I still have not figured out how to handle the class with renderTpl. This class is an override and should go to the overrides folder? Ext.define ('overrides.panel.GlyphTools') {} – jose Nov 22 '17 at 20:12
  • Ok. Work's great. Thanks again Alexander. – jose Nov 22 '17 at 20:30
  • Alexander, when I use in a grid panel, with a single icon the grid has a blue frame around the columns and with more than one icon the columns and rows of the grid disappear and the inside turns blue – jose Nov 22 '17 at 21:18
  • Even in a simple panel it generates a bug. Its the renderTpl? Deconfigures the header and the rest of the panel. Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2a0s – jose Nov 22 '17 at 21:39
  • @josei Sorry, overlooked that. For some reason, a div is not working - can you try to use a `span` instead? – Alexander Nov 23 '17 at 03:35
  • Alexander thanks again. Works's great with a span. I edited the fiddle in my previous comment with span – jose Nov 23 '17 at 10:38
1

Override .x-panel-header-title-default .x-panel-header-default css class and add a background "awesome icon" image.


Edit:

It is difficult to visualize what you want but this should get you started.

.x-panel-header-default
{
    /*this should remove the gradient from the panel header try using a icon instead*/
    background-image: none !important; 
}
  • @pryadarshi Can clarify a little more from my fiddle, please. I'm trying to implement your suggestion but I still did not succeed. – jose Nov 22 '17 at 18:32
  • @pryadarshi thanks. Not quite what I mean. the icon has to have the behavior of a tool and trigger events. – jose Nov 22 '17 at 19:11
  • @josei Ok I got it ... you want a custom icon that can be clicked..... right. Check this link https://stackoverflow.com/questions/36057624/how-to-attach-an-on-click-event-for-icon-in-ext-js – priyadarshi swain Nov 22 '17 at 19:34
  • @pryadarshi thanks I'm considering using buttons - just icon - instead of tools. It's simpler to implement with awesome fonts in version 5.. – jose Nov 22 '17 at 19:41