# Usage
## Create toolbar with default config
```html
```
This is how the default toolbar looks like:

## Customize
Foxit WebPDF SDK allows developers to customize their toolbar's configuration. The toolbar's configuration is divided into two parts: `top` and `bottom`. This is how the toolbar elements look in your application:

And their configuration structure should be:
```js
window.toolbarConfig = {
top: {...},
bottom: {...}
}
```
If you only need to customize the top toolbar, you can use the code below:
```js
var docViewerId = 'docViewer';
WebPDF.ready(/*parameters*/).then(function(){
window.toolbarConfig.top = {
type: 'panel',
name: 'toolbar',
layout: 'flow',
gap: 'md',
sub: [{
extend: 'hand'
},{
extend: 'save'
}, {
extend: 'distance'
}, {
extend: 'screen'
}]
};
new WebPDF.Toolbar(window.toolbarConfig, docViewerId).initialize();
});
```
And the output will be:

WebPDF SDK provides many default component configurations, you can extend them by name and overwrite some properties if you wish to. To see all the internal default configurations names, please refer to the end of this article. [default configurations table](#default\ configurations)
### Components and relative configurations
#### Common structure
All component types support the `type` and `name` properties:
```js
{
type: 'the type of component',
name: 'an identifier of this component, it must be globally unique'
}
```
#### Container components
Container is a specialized component type that acts as a way to organize and hold components. Its layout provides a way to organize and display subcomponents.
##### Layout
WEBDPF SDK supports 3 types of layout, they are `flow`, `grid` and `no`.
By default, the container's layout value is `no`.
1. `flow` layout
```js
{
type: 'container component type',
layout: 'flow',
orientation: 'horizontal|vertical', // default `horizontal`
gap: 'sm|md|lg', // sm -> small gap, md -> medium gap, lg -> large gap, by default no gap
}
```
1. `grid` layout
```js
{
type: 'container component type',
layout: 'grid',
cols: 3, // columns count
width: 100, // width of container in px
height: 100 // height of container in px
}
```
1. `no` layout
```js
{
type: 'container component type',
layout: 'no' // or this property not be declared
}
```
##### supported container components
Currently, WebPDF SDK provides 4 container components: `panel`, `tab`, `groups`, `group`
1. panel
```js
{
type: 'panel',
layout: 'flow', // or 'grid' or 'no'
sub: [/*sub components or widgets*/]
}
```
1. tab
```js
{
type: 'tab',
events: {
tabactive: function(currentTab, lastTab) {
// Triggered after tab switched
}
},
tabs: [{
name: 'tab name',
body: {
type: 'panel|groups'
}
}]
}
```
1. groups and group
`group` can't exist independently of other components, it must be configured as the subcomponent of `groups`. The `layout` property is not supported for `groups`, only for the `group` component.
```js
{
type: 'groups',
groups: [{
sub: [],
layout: 'flow',
gap: 'md'
}, {
sub: [],
layout: 'grid',
cols: 3,
width: 100,
height: 100
}]
}
```
#### Widgets
Widgets are components that allows user to click, select files and then trigger handle event to controller. Foxit WebPDF SDK supports 3 types of widgets: `button`, `fileSelector`, `dropdown`.
1. This is the configuration structure of `button` and `fileSelector`:
```js
{
type: 'button|fileSelector',
tip: 'The title of the tooltip',
tipdesc: 'text of the tooltip',
text: 'text of button',
cls: 'the class of button',
iconCls: 'the class of button\'s icon',
handler: 'click event handler',
events: {
before: function(component, config, data){}, // Call before click event handle
after: function(component, config, data){} // Call after click event handler
},
params: {
// parameters
},
permissions: [
// list of required permissions
]
}
```
1. Configuration structure of `dropdown`:
```js
{
type: 'dropdown',
inline: true, // false
tip: 'The title of the tooltip',
tipdesc: 'text of the tooltip',
text: 'text of dropdown button',
cls: 'class of dropdown button',
iconCls: 'icon class of dropdown button',
handler: 'click event handler name',
buttons: [{
type: 'dropdownItem', // optional, fixed value.
tip: 'The title of the tooltip',
tipdesc: 'text of the tooltip',
text: 'text of dropdown item',
iconCls: 'icon class of dropdown item',
showtip: true, // whether or not show tooltip on mouse over.
isAdditive: true,// Whether or not can be selected, if not, once user select this item, dropdown button will switch to this item, the otherwise not.
isFileSelector: true, // whether or not a file selector. if true, it allows user to select local file.
accept: '.fdf,.xfdf', // accept file formats of file selector.
handler: 'name of click event handler'
}]
}
```
## Toolbar extension
Components, layouts and controllers customized by developers must be registered to `WebPDF.Toolbar.getRegistry()` with a globally unique name.
### Customize Component example
```js
WebPDF.Toolbar.getRegistry().registerComponent('custom_button', {
'constructor': function(options){
this.superclass.call(this, options);
this.text = options.text;
},
methods: {
doActive: function() {
this.$element.css('background', '#d7bae7');
},
doDeactive: function() {
this.$element.css('background', 'transparent');
},
mounted: function() {
var self = this;
this.$element.click(function(){
self.trigger('handle');
});
},
render: function(){
return $('