Skip to content

Icon Pack Mixin

IconPackMixin

The IconPackMixin class provides basic functionality for letting plugins expose custom icon packs that are available in the InvenTree UI. This is especially useful to provide a custom crafted icon pack with icons for different location types, e.g. different sizes and styles of drawers, bags, ESD bags, ... which are not available in the standard tabler icons library.

Sample Plugin

The following example demonstrates how to use the IconPackMixin class to add a custom icon pack:

Example plugin to add custom icons.

Source code in src/backend/InvenTree/plugin/samples/icons/icon_sample.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class SampleIconPlugin(IconPackMixin, InvenTreePlugin):
    """Example plugin to add custom icons."""

    NAME = 'SampleIconPackPlugin'
    SLUG = 'sampleicons'
    TITLE = 'My sample icon pack plugin'

    VERSION = '0.0.1'

    def icon_packs(self):
        """Return a list of custom icon packs."""
        return [
            IconPack(
                name='My Custom Icons',
                prefix='my',
                fonts={
                    'woff2': static('fontawesome/webfonts/fa-regular-400.woff2'),
                    'woff': static('fontawesome/webfonts/fa-regular-400.woff'),
                    'truetype': static('fontawesome/webfonts/fa-regular-400.ttf'),
                },
                icons={
                    'my-icon': {
                        'name': 'My Icon',
                        'category': '',
                        'tags': ['my', 'icon'],
                        'variants': {'filled': 'f0a5', 'cool': 'f073'},
                    }
                },
            )
        ]