0.0.109 • Published 2 years ago

envoy-toolkit-react v0.0.109

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Installation

You can install envoy js toolkit with NPM, Yarn, or a good ol' via unpkg.com.

NPM

$ npm i @envoy/envoy-toolkit-react
## or
$ yarn add @envoy/envoy-toolkit-react

CDN

If you're not using a module bundler or package manager we also have a global ("UMD") build hosted on the unpkg.com CDN. Simply add the following tag to the bottom of your HTML file:

<link rel="stylesheet" href="https://unpkg.com/envoy-toolkit-core@latest/dist/index.css" />
<script src="https://unpkg.com/envoy-toolkit-react@latest/dist/index.umd.js"></script>

Quick start

1. Import toolkit components

import 'envoy-toolkit-core/dist/index.css'
import { EnvoyToolKit } from '@envoy/envoy-toolkit-react'

2. Initialize a toolkit

const apiKey = '<Api-Key>' // you cand find it in Account -> Security -> Api key

EnvoyToolKit.init({
  apiKey,
  sandbox: true // if you need to use sandbox envinronment
})

3. Use in JSX

Usage examples:

const ShareIcon = () => (
  <svg
    className='env-inline-block'
    width={24}
    height={24}
    viewBox='0 0 24 24'
    preserveAspectRatio='none'
    fill='none'
    xmlns='http://www.w3.org/2000/svg'
  >
    <g opacity='0.5'>
      <path
        d='M10 5H6C5.44772 5 5 5.44772 5 6V18C5 18.5523 5.44772 19 6 19H18C18.5523 19 19 18.5523 19 18V14'
        stroke='rgb(16, 185, 129)'
        strokeWidth={2}
        strokeLinecap='round'
        strokeLinejoin='round'
      />
      <path d='M20 9L20 4H15' stroke='rgb(16, 185, 129)' strokeWidth={2} strokeLinecap='round' strokeLinejoin='round' />
      <path d='M13 11L20 4' stroke='rgb(16, 185, 129)' strokeWidth={2} strokeLinecap='round' strokeLinejoin='round' />
    </g>
  </svg>
)

const CustomShareComponent: FC<EnvoyShareComponentChildInjectedProps> = ({ onClick, isLoading }) => {
  return isLoading ? (
    <div>Loading</div>
  ) : (
    <a href='/#' onClick={onClick}>
      Gift button
    </a>
  )
}

const App = () => {
  return (
    <div>
      <div>
        {/* VARIANT 1 */}
        <EnvoyShareComponent
          config={{
            userId: 'some-user-id',
            contentConfig: {
              contentType: ContentType.Video,
              contentId: 'some-content-id',
              contentName: 'content name',
              contentDescription: 'contentDescription'
            }
          }}
        >
          {(shareProps) =>
            shareProps.isLoading ? (
              <span>Loading</span>
            ) : (
              <a onClick={shareProps.onClick as any} className='envoy-shareLink' href='/#'>
                <ShareIcon />
                Gift button provided by User
              </a>
            )
          }
        </EnvoyShareComponent>
      </div>
      {/* VARIANT 2 */}
      <div>
        <EnvoyShareComponent
          config={{
            userId: 'some-user-id',
            contentConfig: {
              contentType: ContentType.Video,
              contentId: 'some-content-id',
              contentName: 'content name',
              contentDescription: 'contentDescription'
            }
          }}
        />
      </div>
      {/* VARIANT 3 */}
      <div>
        <EnvoyShareComponent
          config={{
            userId: 'some-user-id',
            contentConfig: {
              contentType: ContentType.Video,
              contentId: 'some-content-id',
              contentName: 'content name',
              contentDescription: 'contentDescription'
            }
          }}
        >
          <CustomShareComponent />
        </EnvoyShareComponent>
      </div>

      <div style={{ height: '10000px' }} />
    </div>
  )
}

Vanilla js usage example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="https://unpkg.com/envoy-toolkit-core@latest/dist/index.css" />
</head>
<body>

<div id="envoy-gift-button"></div>

<!--<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>-->
<!--<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>-->
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
<script src="https://unpkg.com/envoy-toolkit-core@latest/dist/index.umd.js"></script>
<script src="https://unpkg.com/envoy-toolkit-react@latest/dist/index.umd.js"></script>
<script>
  const apiKey =
    "eyJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTQwODc5NzksImlzcyI6IkVudm95IFBsYXRmb3JtIiwianRpIjoiY2YwMmEyZmYtNjExOC00YWFmLWEzMzAtNzM2MjlhOTc4YjU2IiwibGlua19xdW90YSI6MTAwLCJvcmdfbmFtZSI6ImxpdHZhbiIsInNhbmRib3hfbGlua19xdW90YSI6MTAwfQ.-i4hman1hsOR2ybBXViZNb4pwnGZ3tE1u4b60keYHKUj4WA6Nmn23l4toTHbr9mNW4fR1FTYbffBuvvWFMbgwQ";
  const { EnvoyToolkitCore, ContentType, EnvoyShareComponent } = envoyToolkitReact;
  EnvoyToolkitCore.init({
    apiKey,
    sandbox: true
  });

  const container = document.getElementById("envoy-gift-button");
  const root = ReactDOM.createRoot(container);
  root.render(React.createElement(EnvoyShareComponent, {
    config: {
      userId: "some-user-id",
      contentConfig: {
        contentType: ContentType.Video,
        contentId: "some-content-id",
        contentName: "content name",
        contentDescription: "contentDescription"
      }
    }
  }));

</script>

</body>
</html>
0.0.88

2 years ago

0.0.89

2 years ago

0.0.106

2 years ago

0.0.105

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.107

2 years ago

0.0.91

2 years ago

0.0.101

2 years ago

0.0.92

2 years ago

0.0.94

2 years ago

0.0.87

2 years ago

0.0.86

2 years ago

0.0.85

2 years ago

0.0.84

2 years ago

0.0.83

2 years ago

0.0.82

2 years ago

0.0.80

2 years ago

0.0.77

2 years ago

0.0.74

2 years ago

0.0.62

2 years ago

0.0.61

2 years ago

0.0.51

2 years ago

0.0.40

2 years ago

0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago

1.0.0

2 years ago