Skip to content

Commit

Permalink
docs: Update basic docs (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1guelpf authored Dec 15, 2022
1 parent 2a4d989 commit 108a82b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,47 @@ Getting started with the Javascript package is really easy. Just follow the step
If your app is built on React, using the React widget is by far the easiest approach.

```jsx
import "@worldcoin/idkit/build/index.css";
import { IDKitWidget } from "@worldcoin/idkit";

<IDKitWidget />;
<IDKitWidget actionId="get_this_from_the_dev_portal" onSuccess={handleProof}>
{({ open }) => (
{/* You can render whatever you want here, and call open() to open the widget */}
<button onClick={open}>Click me</button>
)}
</IDKitWidget>
```

Alternatively, you can render the component without children (on your layout, for exampld) and use the `useIDKit` hook to open it programmatically.

```jsx
import { useIDKit } from "@worldcoin/idkit";

const { open, setOpen } = useIDKit({
actionId: "get_this_from_the_dev_portal",
onSuccess: handleProof,
});
```

### Generic JS apps

If your app doesn't have a framework or doesn't use React, continue here.

1. Add a `<div>` in your HTML where you'd like to include IDKit.
1. Initialize IDKit (please refer to the docs for further customization details).

```html
<div id="idkit-js"></div>
```js
IDKit.init({
actionId: "get_this_from_the_dev_portal",
});
```

2. Initialize IDKit (please refer to the docs for further customization details).
2. Then, open the widget and await the proof (you can do this in response to a button click, for example).

```js
IDKit.init("idkit-js");
button.addEventListener("click", async () => {
const proof = await IDKit.open();

console.log(proof);
});
```

## 🧑‍💻 Development & testing
Expand Down
6 changes: 3 additions & 3 deletions idkit/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# IDKit JS Widget

This folder (`/idkit`) contains the main code for the JS widget. For instructions on **how to use the widget**, please refer to the repository's main [README](/README.md).
This folder (`/idkit`) contains the main code for the widget. For instructions on **how to use the widget**, please refer to the repository's main [README](/README.md).

## ℹ️ About the codebase

- The widget is made to work mainly with vanilla JS code (no framework required). The starting point can be found in `vanilla.tsx`.
- The React wrapper is found on `index.ts` (and is exported as `IDKitWidget`).
- The widget is made to work mainly with vanilla JS code (no framework required). The starting point can be found in `src/vanilla.tsx`.
- The React wrapper is found on `src/components/IDKitWidget/index.ts`.

## 🧑‍💻 Development & testing

Expand Down
10 changes: 5 additions & 5 deletions idkit/src/types/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export type Config = {
actionId: string
autoClose?: boolean
onSuccess?: CallbackFn
copy: {
title: string
heading: string
subheading: string
success: string
copy?: {
title?: string
heading?: string
subheading?: string
success?: string
}
}

0 comments on commit 108a82b

Please sign in to comment.