# DocVer-widget

### Install

``` 
yarn install @document-verification/docver-widget
 ```
or
 ``` 
npm i @document-verification/docver-widget
 ```

or add static js file

 ``` 
https://cdn.n37z.com/scripts/widget-latest.js
 ```
or use specific version
```
https://cdn.n37z.com/scripts/widget-{version}.js
```

Actual version you can find in https://www.npmjs.com/package/@document-verification/docver-widget

How to use:

``` 
import { DocsVerificationWidget } from '@document-verification/docver-widget';

const { root, destroy, updateStyles } = DocsVerificationWidget(props);

// update container className / style without remounting:
updateStyles({ className: 'my-widget', style: { maxWidth: 480 } });

// later, when tearing down the widget:
destroy();
 ```

Returns:

<table>
    <tr>
        <th>Property</th>
        <th>Type</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>root</td>
        <td>Root | null</td>
        <td>React root instance. <code>null</code> if the element with <code>elementId</code> was not found.</td>
    </tr>
    <tr>
        <td>destroy</td>
        <td>() => void</td>
        <td>Unmounts the widget and resets its internal Redux state. Call this when removing the widget from the page.</td>
    </tr>
    <tr>
        <td>updateStyles</td>
        <td>(options: { className?: string; style?: CSSProperties }) => void</td>
        <td>Updates the widget root container <code>className</code> and/or <code>style</code> without remounting. Only provided fields are changed.</td>
    </tr>
</table>

Available props:

<table>
    <tr>
        <th>Prop name</th>
        <th>Types</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>id</td>
        <td>string</td>
        <td>
        </td>
    </tr>
    <tr>
        <td>apiUrl</td>
        <td>string</td>
        <td></td>
    </tr>
    <tr>
        <td>elementId</td>
        <td>string</td>
        <td>Id of element when widget will be rendered</td>
    </tr>
    <tr>
        <td>onFinish</td>
        <td>() => Promise&lt;void&gt;</td>
        <td>Callback raised when user finish verification</td>
    </tr>
    <tr>
        <td>onInit</td>
        <td>(verificationStatus: 'completed' | 'expired' | 'active' | 'error', error?: unknown) => Promise&lt;void&gt;</td>
        <td>Callback raised before verification started</td>
    </tr>
    <tr>
        <td>theme</td>
        <td>Check theme section</td>
        <td>Custom styles</td>
    </tr>
    <tr>
        <td>defaultLanguage</td>
        <td>'en' | 'es' | 'pt' | 'ru' | 'de' | 'ar'</td>
        <td>Default Language</td>
    </tr>
    <tr>
        <td>logo</td>
        <td>string</td>
        <td>Optional logo URL shown in the widget header.</td>
    </tr>
    <tr>
        <td>className</td>
        <td>string</td>
        <td>Optional CSS class applied to the widget root container</td>
    </tr>
    <tr>
        <td>style</td>
        <td>CSSProperties</td>
        <td>Optional inline styles applied to the widget root container</td>
    </tr>
</table>

### Example:
 ```
import { DocsVerificationWidget } from '@document-verification/docver-widget';

export const renderWidget = async () => {
    const container = document.getElementById('root');

    if (container) {
        const { destroy } = DocsVerificationWidget({
            id: 'VF57124F182867E0',
            elementId: 'root',
            apiUrl: 'https://api.docs.com',
        });

        destroy(); // store destroy and call it when the widget should be removed
    }
};

renderWidget();
 ```

Or

```
<script type="module" defer src="https://cdn.n37z.com/scripts/widget-latest.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', () => {
        const renderWidget = async () => {
            const container = window.document.querySelector('#root');
            if (container) {
                const { destroy } = window.DocsVerificationWidget({
                    id: 'VF57124F182867E0',
                    elementId: 'root',
                    apiUrl: 'https://api.docs.com',
                });

                window.widgetDestroy = destroy;
            }
        };

        renderWidget();
    });
</script>
```
### Html:
```html
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
    </head>
    <body>
        <noscript>You need to enable JavaScript to run this app.</noscript>
        <div id="root"></div>
    </body>
</html>

```

### Theme:
In comment described default value:
```typescript
export type Theme = {
    palette?: Partial<{
        textMain: string; // #000000
        textLight: string; // #737390
        primaryA1: string; // #6664E8
        primaryA2: string; // #5A58DF
        primaryA3: string; // #D0D0FC
        primaryA4: string; // #E8E8FC
        primaryA5: string; // #E0E0FA
        primaryA6: string; // #E6EDFB
        primaryA7: string; // #FFFFFF
        secondaryA1: string; // #F6CDD9
        secondaryA2: string; // #F6F0C0
        secondaryA3: string; // #52C27F
        secondaryA4: string; // #FF5050
        secondaryA5: string; // #FFFCFD
        secondaryA6: string; // #FABC46
        secondaryA7: string; // #B25DF5
        secondaryA8: string; // #EDECFC
        secondaryA9: string; // #DEE1F2
        secondaryA10: string; // #F6F8FE
    }>;
    typography?: Partial<{
        fontFamily: string; // 'Funnel Display', Roboto, sans-serif
        body1: {
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
        };
        body2: {
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
        };
        caption: {
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
        };
        h1: Partial<{
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
            fontSize: string; // 50px
            fontWeight: string; // 500
            lineHeight: string; // 70px
            letterSpacing: string; // -0.01em
        }>;
        h2: Partial<{
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
            fontSize: string; // 28px
            fontWeight: string; // 500
            lineHeight: string; // 40px
            letterSpacing: string; // -0.01em
        }>;
        h3: Partial<{
            fontFamily: string; // 'Funnel Display', Roboto, sans-serif
            fontSize: string; // 20px
            fontWeight: string; // 500
            lineHeight: string; // 30px
            letterSpacing: string; // -0.01em
        }>;
        text: Partial<{
            fontSize: string; // 14px
            lineHeight: string; // 22px
            letterSpacing: string; // 0.002em
        }>;
        textBold: Partial<{
            fontSize: string; // 14px
            fontWeight: string; // 500
            lineHeight: string; // 22px
            letterSpacing: string; // 0.002em
        }>;
        smallText: Partial<{
            fontSize: string; // 12px
            lineHeight: string; // 18px
            letterSpacing: string; // 0.002em
        }>;
        smallTextBold: Partial<{
            fontSize: string; // 12px
            fontWeight: string; // 500
            lineHeight: string; // 18px
            letterSpacing: string; // 0.002em
        }>;
    }>;
};
```
