# # Customize Thumbnail

This part will show the UI structure,layout, label of the thumbnail panel,etc. Fragment related details are as following UI fragments. Much more API details are as following API Reference
(opens new window) document.

## # Thumbnail Panel Structure Details

Before customizing the thumbnail UI, we need to know the following details:

1. Thumbnail Addon
2. Thumbnail Panel
3. Thumbnail List

### # Thumbnail Addon

Before using the thumbnail component, please make sure that `thumbnail` Addon is loaded correctly (refer to here). About how to load Addon, please refer to here.

### # Thumbnail Panel

In the built-in layout template,`<thumbnail-sidebar-panel></thumbnail-sidebar-panel>` is the left sidebar thumbnail panel. And it is actually as the following template:

    <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
        <thumbnail:toolbar></thumbnail:toolbar>
        <thumbnail:complete-thumbnail-list></thumbnail:complete-thumbnail-list>
    </thumbnail:sidebar-panel>

It includes `<thumbnail:toolbar>` and `<thumbnail:complete-thumbnail-list>`, if you want to exchange the structure, you can refer to the following template:

    <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
        <thumbnail:complete-thumbnail-list></thumbnail:complete-thumbnail-list>
        <thumbnail:toolbar></thumbnail:toolbar>
    </thumbnail:sidebar-panel>

Next, by fragments, you can exchange the built-in `sidebar-thumbnail-panel`:

    <script>
        const libPath = window.top.location.origin + '/lib';
        const FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION;
        const pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: libPath,
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: document.body,
            appearance: UIExtension.appearances.adaptive.extend({
                getDefaultFragments() {
                    return [{
                        target: 'sidebar-thumbnail-panel',
                        action: FRAGMENT_ACTION.REPLACE,
                        template: `
                            <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
                                <thumbnail:complete-thumbnail-list></thumbnail:complete-thumbnail-list>
                                <thumbnail:toolbar></thumbnail:toolbar>
                            </thumbnail:sidebar-panel>
                        `
                    }]
                }
            }),
            addons: libPath + '/uix-addons/allInOne.js'
        });
    </script>

    {
        "iframeOptions": {
            "style": "height: 500px"
        }
    }

### # Thumbnail List

`<thumbnail:complete-thumbnail-list>` includes all the features of the thumbnail list as follows:

    <thumbnail:thumbnail-list
        @thumbnail:centered
        @thumbnail:rearrange-pages
        @thumbnail:drop-to-merge-doc
        @aria:label="thumbnail:title"
    >
        <thumbnail:thumbnail-item
            @foreach="thumbnail in thumbnail_list.thumbnails track by id"
            @setter.thumbnail_id="thumbnail.id"
            @lazy-content="visible"
        >
            <div class="fv__ui-thumbnail-viewer-container">
                <thumbnail:thumbnail-viewer @setter.thumbnail="thumbnail" @thumbnail:visible-rect-control></thumbnail:thumbnail-viewer>
            </div>
            <div class="fv__ui-thumbnail-item-label">@{thumbnail.pageIndex+1}</div>
        </thumbnail:thumbnail-item>
    </thumbnail:thumbnail-list>

Structure details as following:

Node | Structure | Type | isRequired | Details
--- | --- | --- | --- | ---
`<thumbnail:thumbnail-list>` | `@thumbnail:centered` | Instruct | N | When dragging the sidebar panel to change the width of the panel, thumbnail list will automatically insert a line feed and be shown in the middle.
`<thumbnail:thumbnail-list>` | `@thumbnail:rearrange-pages` | Instruct | N | Drag the thumbnail to adjust the PDF pages' orders.
`<thumbnail:thumbnail-list>` | `@thumbnail:drop-to-merge-doc` | Instruct | N | Insert the PDF dragged to the thumbnail list to the specified position.
`<thumbnail:thumbnail-list>` | `@aria:label="thumbnail:title"` | Instruct | N | Accessibility attribute
`<thumbnail:thumbnail-item>` | `@foreach="thumbnail in thumbnail_list.thumbnails track by id"` | Instruct | Y | It is to create the thumbnail list, and cannot be modified.
`<thumbnail:thumbnail-item>` | `@setter.thumbnail_id="thumbnail.id"` | Instruct | Y | It is mandatory, and to set thumbnail ID.
`<thumbnail:thumbnail-item>` | `@lazy-content="active"` | Instruct | N | To improve the performance of loading the thumbnail.
`div.fv__ui-thumbnail-viewer-container` | - | HTML Element | Y | It is thumbnail-viewer container without any adjustment.
`<thumbnail:thumbnail-viewer>` | `@thumbnail:visible-rect-control` | Instruct | N | Mark and control the PDF visible area.
`div.fv__ui-thumbnail-item-label` | - | HTML Element | N | It is a container to show the current page's abbreviated information. After modifying the container, much more information will be shown.

When you need to customize the thumbnail list, you should exchange `<thumbnail:complete-thumbnail-list>` to the above template as following:

    <script>
        const libPath = window.top.location.origin + '/lib';
        const FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION;
        const pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: libPath,
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: document.body,
            appearance: UIExtension.appearances.adaptive.extend({
                getDefaultFragments() {
                    return [{
                        target: 'sidebar-thumbnail-panel',
                        action: FRAGMENT_ACTION.REPLACE,
                        template: `
                            <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
                                <thumbnail:toolbar></thumbnail:toolbar>
                                <thumbnail:thumbnail-list
                                    @thumbnail:centered
                                    @thumbnail:rearrange-pages
                                    @thumbnail:drop-to-merge-doc
                                    @aria:label="thumbnail:title"
                                >
                                    <thumbnail:thumbnail-item
                                        @foreach="thumbnail in thumbnail_list.thumbnails track by id"
                                        @setter.thumbnail_id="thumbnail.id"
                                        @lazy-content="visible"
                                    >
                                        <div class="fv__ui-thumbnail-viewer-container">
                                            <thumbnail:thumbnail-viewer @setter.thumbnail="thumbnail" @thumbnail:visible-rect-control></thumbnail:thumbnail-viewer>
                                        </div>
                                        <div class="fv__ui-thumbnail-item-label">@{thumbnail.pageIndex+1}</div>
                                    </thumbnail:thumbnail-item>
                                </thumbnail:thumbnail-list>
                            </thumbnail:sidebar-panel>
                        `
                    }]
                }
            }),
            addons: libPath + '/uix-addons/allInOne.js'
        });
    </script>

    {
        "iframeOptions": {
            "style": "height: 500px"
        }
    }

Run the above example, the result is same with the built-in result.

## # Start to Customize Thumbnail

### # Customize Thumbnail Elements

After changing `<div class="fv__ui-thumbnail-item-label">@{thumbnail.pageIndex+1}</div>` to `<div class="fv__ui-thumbnail-item-label">Page: @{thumbnail.pageIndex+1}</div>`，the result is as following:

    <script>
        const libPath = window.top.location.origin + '/lib';
        const FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION;
        const pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: libPath,
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: document.body,
            appearance: UIExtension.appearances.adaptive.extend({
                getDefaultFragments() {
                    return [{
                        target: 'sidebar-thumbnail-panel',
                        action: FRAGMENT_ACTION.REPLACE,
                        template: `
                            <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
                                <thumbnail:toolbar></thumbnail:toolbar>
                                <thumbnail:thumbnail-list
                                    @thumbnail:centered
                                    @thumbnail:rearrange-pages
                                    @thumbnail:drop-to-merge-doc
                                    @aria:label="thumbnail:title"
                                >
                                    <thumbnail:thumbnail-item
                                        @foreach="thumbnail in thumbnail_list.thumbnails track by id"
                                        @setter.thumbnail_id="thumbnail.id"
                                        @lazy-content="visible"
                                    >
                                        <div class="fv__ui-thumbnail-viewer-container">
                                            <thumbnail:thumbnail-viewer @setter.thumbnail="thumbnail" @thumbnail:visible-rect-control></thumbnail:thumbnail-viewer>
                                        </div>
                                        <div class="fv__ui-thumbnail-item-label">Page: @{thumbnail.pageIndex+1}</div>
                                    </thumbnail:thumbnail-item>
                                </thumbnail:thumbnail-list>
                            </thumbnail:sidebar-panel>
                        `
                    }]
                }
            }),
            addons: libPath + '/uix-addons/allInOne.js'
        });
    </script>

    {
        "iframeOptions": {
            "style": "height: 500px"
        }
    }

You can adjust the thumbnail structure and insert much more components:

    <script>
        const libPath = window.top.location.origin + '/lib';
        const FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION;
        const pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: libPath,
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: document.body,
            appearance: UIExtension.appearances.adaptive.extend({
                getDefaultFragments() {
                    return [{
                        target: 'sidebar-thumbnail-panel',
                        action: FRAGMENT_ACTION.REPLACE,
                        template: `
                            <thumbnail:sidebar-panel name="sidebar-thumbnail-panel" @lazy-content="active">
                                <thumbnail:toolbar></thumbnail:toolbar>
                                <thumbnail:thumbnail-list
                                    @thumbnail:centered
                                    @thumbnail:rearrange-pages
                                    @thumbnail:drop-to-merge-doc
                                    @aria:label="thumbnail:title"
                                >
                                    <thumbnail:thumbnail-item
                                        @foreach="thumbnail in thumbnail_list.thumbnails track by id"
                                        @setter.thumbnail_id="thumbnail.id"
                                        @lazy-content="visible"
                                    >
                                        <div class="my-thumbnail-item-toolbox">
                                            <button @controller="thumbnail:DeletePageController">delete</button>
                                            <button @controller="thumbnail:RotateRightController">rotate right</button>
                                            <button @controller="thumbnail:RotateLeftController">rotate left</button>
                                        </div>
                                        <div class="fv__ui-thumbnail-viewer-container">
                                            <thumbnail:thumbnail-viewer @setter.thumbnail="thumbnail" @thumbnail:visible-rect-control></thumbnail:thumbnail-viewer>
                                        </div>
                                    </thumbnail:thumbnail-item>
                                </thumbnail:thumbnail-list>
                            </thumbnail:sidebar-panel>
                        `
                    }]
                }
            }),
            addons: libPath + '/uix-addons/allInOne.js'
        });
    </script>
    <style>
        .my-thumbnail-item-toolbox {
            display: flex;
            padding: 0.2em 0;
            flex-direction: row;
        }
        .my-thumbnail-item-toolbox button{
            height: 2em;
            line-height: 1;
            font-size: 12px;
        }
    </style>

    {
        "iframeOptions": {
            "style": "height: 500px"
        }
    }

### # Customize Thumbnail Right Click Menu

The following is the template of the thumbnail right click menu:

    <contextmenu name="fv--thumbnail-contextmenu" @thumbnail:permission>
        <contextmenu-item feature="rotate" name="contextmenu-item-thumbnail-rotate-left" @controller="thumbnail:RotateLeftController">thumbnail:contextmenu.rotateLeft</contextmenu-item>
        <contextmenu-item feature="rotate" name="contextmenu-item-thumbnail-rotate-right" @controller="thumbnail:RotateRightController">thumbnail:contextmenu.rotateRight</contextmenu-item>
        <contextmenu-separator></contextmenu-separator>
        <contextmenu-item feature="insert" name="contextmenu-item-thumbnail-add-blank-page" @controller="thumbnail:InsertBlankPageController">thumbnail:contextmenu.addBlankPage</contextmenu-item>
        <contextmenu-separator></contextmenu-separator>
        <thumbnail:delete-page-contextmenu-item name="contextmenu-item-thumbnail-delete"></thumbnail:delete-page-contextmenu-item>
    </contextmenu>

We can configure the fragments to delete or add the menu item:

    <script>
        var libPath = window.top.location.origin + '/lib';
        var FRAGMENT_ACTION = UIExtension.UIConsts.FRAGMENT_ACTION;
        var customModule = UIExtension.modular.module('custom', []);

        customModule.registerController(UIExtension.Controller.extend({
            mounted: function() {
                pdfui.callAddonAPI('Thumbnail','onSelectThumbnail', [function(currentSelectedPageIndexes) {
                    console.log(currentSelectedPageIndexes);
                }]).then(removeListener => {
                    this.addDestroyHook(removeListener);
                })
            }
        }, {
            getName: function() {
                return 'CustomThumbnailItemOperationController';
            }
        }));

        var pdfui = new UIExtension.PDFUI({
            viewerOptions: {
                libPath: libPath,
                jr: {
                    licenseSN: licenseSN,
                    licenseKey: licenseKey
                }
            },
            renderTo: document.body,
            appearance: UIExtension.appearances.adaptive.extend({
                getDefaultFragments() {
                    return [{
                        target: 'contextmenu-item-thumbnail-delete',
                        action: FRAGMENT_ACTION.REMOVE
                    }, {
                        target: 'fv--thumbnail-contextmenu',
                        action: FRAGMENT_ACTION.APPEND,
                        template:`<contextmenu-item @controller="thumbnail:DeletePageController">Custom delete page menu</contextmenu-item>`
                    }, {
                        target: 'fv--thumbnail-contextmenu',
                        action: FRAGMENT_ACTION.APPEND,
                        template: `<contextmenu-item @controller="custom:CustomThumbnailItemOperationController">Custom Action</contextmenu-item>`
                    }]
                }
            }),
            addons: libPath + '/uix-addons/allInOne.js'
        });
    </script>

    {
        "iframeOptions": {
            "style": "height: 500px"
        }
    }