npm package: @mclck/cloudsigns
Description: Widget initialization class.
Author: "Dmitriy Konovalov
Latest version: 0.0.1

# cloudsigns_widget

## Install

```bash
$ yarn install
```

```bash
$ npm run dev
$ npm run build
```

## How to use
**Build first.**

Execute the file `build/cloudsigns.min.js` in browser.

Create the instance, like:

```javascript
const csw = new CloudsignsWidget();
```

Initialize widget call:

```javascript
csw.startSign(
	{
		"clientKey": "some-client-key",
		"templateKey": "some-template-key"
	}
);
```

And then click on selected button;

## Examples

### HTML
```html
<form id="form-id">
	<input type="text" data-cs="birth" />
	<input type="text" data-cs="name" />
	<input type="text" data-cs="snils" />
</form>
<button id="button">
	Start sign
</button>
```

### Vanilla
```javascript
const widget = new CloudsignsWidget("form-id");
const element = document.getElementById("button");

element.addEventListener("click", () => {
	widget.startSign({
		clientKey: "some-client-key",
		templateKey: "some-template-key",
		snils: "some-snils",
		onStart: () => {
			console.info("Request success!");
		},
		onError: (error) => {
			console.error("Request error", error);
		},
		onSignSuccess: (data) => {
			console.info("Sign success!", data);
		},
		onSignError: (error) => {
			console.error("Sign error", error);
		}
	});
});
```

### jQuery

```javascript
const widget = new CloudsignsWidget("form-id");
const element = $("button");

element.on("click", () => {
	widget.startSign({
		clientKey: "some-client-key",
		templateKey: "some-template-key",
		snils: "some-snils",
		onStart: () => {
			console.info("Request success!");
		},
		onError: (error) => {
			console.error("Request error", error);
		},
		onSignSuccess: (data) => {
			console.info("Sign success!", data);
		},
		onSignError: (error) => {
			console.error("Sign error", error);
		}
	});
});
```


### NPM Module (React)
```jsx
import CloudsignsWidget from "cloud-signs";

export const SignComponent = () => {
	const handleStartSign = () => {
		const widget = new CloudsignsWidget("form-id");

		widget.startSign({
			clientKey: "some-client-key",
			templateKey: "some-template-key",
			snils: "some-snils",
			onStart: () => {
				console.info("Request success!");
			},
			onError: (error) => {
				console.error("Request error", error);
			},
			onSignSuccess: (data) => {
				console.info("Sign success!", data);
			},
			onSignError: (error) => {
				console.error("Sign error", error);
			}
		});
	}

	return (
		<div>
			<form id="form-id">
				<input type="text" data-cs="birth" />
				<input type="text" data-cs="name" />
				<input type="text" data-cs="snils" />
			</form>
			<button onClick={handleStartSign}>
				Start sign
			</button>
		</div>
	)
}
```

## Options

```typescript
type ObjectRecord = Record<string, ObjectRecord>

type WidgetOptions = {
	url: string,
	clientKey: string,
	templateKey: string,
	documentParams: ObjectRecord,
	snils: string,
	onStart?(result: any): void,
	onSignSuccess?(result: any): void,
	onError?(error: jqXHR): void
	onSignError?(error: ay): void
};
interface IWidget {
	startSign(options: WidgetOptions): void
	destroy(): void
};
```

## LICENSE

MIT