360dialog-connect-button
Advanced tools
Comparing version 0.2.2 to 0.3.0
{ | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
197
README.md
@@ -1,160 +0,105 @@ | ||
# TSDX React User Guide | ||
# 360dialog Partner Integrated Onboarding | ||
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it. | ||
This package provides a button component to quickly integrate the 360dialog Partner Integrated Onboarding process into your existing React.js application. To learn more about this process and how to participate in this as a 360dialog Partner, please visit [our documentation](https://docs.360dialog.com/) or contact your account manager. If you want to become a 360dialog Partner in order to enable your clients to use the WhatsApp Business API, please [get in touch with us](https://www.360dialog.com/contact). | ||
> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`. | ||
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/) | ||
## Commands | ||
<br/> | ||
<br/> | ||
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`. | ||
# Prerequisites | ||
In order to access the 360dialog Partner Integrated Onboarding process you need to set your `partner_redirect_url` via the Partner API. This will be used to redirect the client after the onboarding process is finished. **Important:** To use the `ConnectButton` component the redirect URL needs to match the route, that has the button integrated. | ||
The recommended workflow is to run TSDX in one terminal: | ||
<br/> | ||
<br/> | ||
```bash | ||
npm start # or yarn start | ||
``` | ||
# Installation | ||
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`. | ||
Then run the example inside another: | ||
```bash | ||
cd example | ||
npm i # or yarn to install dependencies | ||
npm start # or yarn start | ||
## With yarn | ||
``` | ||
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases). | ||
To do a one-off build, use `npm run build` or `yarn build`. | ||
To run tests, use `npm test` or `yarn test`. | ||
## Configuration | ||
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly. | ||
### Jest | ||
Jest tests are set up to run with `npm test` or `yarn test`. | ||
### Bundle analysis | ||
Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. | ||
#### Setup Files | ||
This is the folder structure we set up for you: | ||
```txt | ||
/example | ||
index.html | ||
index.tsx # test your component here in a demo app | ||
package.json | ||
tsconfig.json | ||
/src | ||
index.tsx # EDIT THIS | ||
/test | ||
blah.test.tsx # EDIT THIS | ||
.gitignore | ||
package.json | ||
README.md # EDIT THIS | ||
tsconfig.json | ||
yarn add 360dialog-connect-button | ||
``` | ||
#### React Testing Library | ||
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this. | ||
### Rollup | ||
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details. | ||
### TypeScript | ||
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs. | ||
## Continuous Integration | ||
### GitHub Actions | ||
Two actions are added by default: | ||
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix | ||
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit) | ||
## Optimizations | ||
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations: | ||
```js | ||
// ./types/index.d.ts | ||
declare var __DEV__: boolean; | ||
// inside your code... | ||
if (__DEV__) { | ||
console.log('foo'); | ||
} | ||
## With NPM | ||
``` | ||
npm install 360dialog-connect-button | ||
``` | ||
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions. | ||
## Module Formats | ||
<br/> | ||
<br/> | ||
CJS, ESModules, and UMD module formats are supported. | ||
# Getting started | ||
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found. | ||
Add the connect button to your app: | ||
```jsx | ||
import { ConnectButton } from "360dialog-connect-button"; | ||
## Deploying the Example Playground | ||
const App = () => { | ||
The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`): | ||
const handleCallback = (callbackObject) => { | ||
/* The callback function returns the client ID as well as all channel IDs, for which you're enabled to fetch the API key via the Partner API */ | ||
```bash | ||
cd example # if not already in the example folder | ||
npm run build # builds to dist | ||
netlify deploy # deploy the dist folder | ||
``` | ||
console.log("client ID: "+callbackObject.client) | ||
console.log("channel IDs: " + callbackObject.channels); | ||
} | ||
Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify: | ||
```bash | ||
netlify init | ||
# build command: yarn build && cd example && yarn && yarn build | ||
# directory to deploy: example/dist | ||
# pick yes for netlify.toml | ||
return ( | ||
<div> | ||
<ConnectButton | ||
partnerId={'your-partner-id'} | ||
callback={handleCallback} | ||
/> | ||
</div> | ||
); | ||
}; | ||
``` | ||
## Named Exports | ||
<br/> | ||
<br/> | ||
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library. | ||
# Properties | ||
## Including Styles | ||
Following properties are supported by the button component: | ||
| Property name | Type | Description | Required | | ||
| ----------- | ----------- | ----------- | ----------- | | ||
| partnerId | string | Your 360dialog Partner ID | ✅ | | ||
| callback | (callbackObject: {client: string, channels: string}) => void | Callback function, that receives the returned client ID as well as channel IDs | ✅ | | ||
| requestedNumber | string | Optional parameter to request acces for a specific phone number | | | ||
| label | string | Optional parameter to provide a custom button label | | | ||
| env | string | BETA ONLY: Provide a environment to test in | | | ||
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like. | ||
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader. | ||
<br/> | ||
<br/> | ||
## Publishing to NPM | ||
# Styling | ||
We recommend using [np](https://github.com/sindresorhus/np). | ||
The `ConnectButton` component is an unstyled `<button />` component. You can use any styling method, e.g. CSS-in-JS libraries such as `styled-components`. | ||
## Usage with Lerna | ||
```jsx | ||
import { ConnectButton } from "360dialog-connect-button"; | ||
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_. | ||
const App = () => { | ||
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project. | ||
const StyledConnectButton = styled(ConnectButton)` | ||
outline: none; | ||
background: #ff4369; | ||
color: white; | ||
padding: 8px 16px; | ||
border-radius: 3px; | ||
margin-top: 32px; | ||
border: none; | ||
`; | ||
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below. | ||
```diff | ||
"alias": { | ||
- "react": "../node_modules/react", | ||
- "react-dom": "../node_modules/react-dom" | ||
+ "react": "../../../node_modules/react", | ||
+ "react-dom": "../../../node_modules/react-dom" | ||
}, | ||
return ( | ||
<div> | ||
<StyledConnectButton | ||
partnerId={'your-partner-id'} | ||
callback={handleCallback} | ||
/> | ||
</div> | ||
); | ||
}; | ||
``` | ||
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43562
106