├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── npm-publish.yml ├── .gitignore ├── .mergify.yml ├── .npmignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── jest.setup.js ├── package.json ├── src └── Crisp.jsx ├── tests └── Crisp.test.jsx ├── webpack.config.js └── yarn.lock /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | time: "09:00" 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run eslint for the package 2 | 3 | name: CI 4 | 5 | on: 6 | push: 7 | branches: [ master ] 8 | pull_request: 9 | branches: [ master ] 10 | 11 | jobs: 12 | eslint: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 14 19 | - run: yarn install 20 | - run: yarn run eslint 21 | tests: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v2 25 | - uses: actions/setup-node@v1 26 | with: 27 | node-version: 14 28 | - run: yarn install 29 | - run: yarn test 30 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This package will publish the package on NPM 2 | name: Publish Package 3 | 4 | on: 5 | release: 6 | types: [released] 7 | 8 | # Allow to run it manually 9 | workflow_dispatch: 10 | 11 | jobs: 12 | publish-npm: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 14 19 | registry-url: https://registry.npmjs.org/ 20 | - name: Install dependencies 21 | run: yarn install 22 | - name: Build the package 23 | run: yarn build 24 | - name: Publish the package on NPM 25 | run: yarn publish 26 | env: 27 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /dist 13 | 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: automatic merge 3 | conditions: 4 | - base=master 5 | - "#approved-reviews-by>=1" 6 | - "check-success=eslint" 7 | - "check-success=tests" 8 | actions: 9 | merge: 10 | strict: "smart" 11 | method: squash 12 | - name: warn on conflicts 13 | conditions: 14 | - conflict 15 | actions: 16 | comment: 17 | message: This pull request is now in conflict 😕 18 | label: 19 | add: 20 | - conflict 21 | - name: remove conflict label if not needed 22 | conditions: 23 | - -conflict 24 | actions: 25 | label: 26 | remove: 27 | - conflict 28 | - name: dismiss reviews 29 | conditions: 30 | - author!=@react-crisp 31 | actions: 32 | dismiss_reviews: {} 33 | - name: dismiss reviews for core devs 34 | conditions: 35 | - author=@react-crisp 36 | actions: 37 | dismiss_reviews: 38 | # Do not remove approval for core devs 39 | approved: false 40 | - name: request review 41 | conditions: 42 | - -merged 43 | - -closed 44 | - "#approved-reviews-by=0" 45 | - "#changes-requested-reviews-by=0" 46 | - "check-success=eslint" 47 | - "check-success=tests" 48 | actions: 49 | request_reviews: 50 | teams: 51 | - react-crisp 52 | - name: Merge Dependabot's pull requests 53 | conditions: 54 | - author=dependabot[bot] 55 | - "check-success=eslint" 56 | - "check-success=tests" 57 | actions: 58 | merge: 59 | strict: "smart" 60 | method: rebase 61 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .mergify.yml 2 | .github/ 3 | src/ 4 | webpack.config.js 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [opensource@mergify.io](opensource@mergify.io). 59 | All complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to react-crisp 2 | 3 | First off, thanks for taking the time to contribute! 4 | 5 | The following is a set of guidelines for contributing to react-crisp. 6 | These are mostly guidelines, not rules. Use your best judgment, and feel free 7 | to propose changes to this document in a pull request. 8 | 9 | ## Code of Conduct 10 | 11 | This project and everyone participating in it is governed by the 12 | [react-crisp Code of Conduct](CODE_OF_CONDUCT.md). By participating, you 13 | are expected to uphold this code. Please report unacceptable behavior to 14 | [opensource@mergify.io](mailto:opensource@mergify.io). 15 | 16 | ## How Can I Contribute? 17 | 18 | ### Reporting Bugs 19 | 20 | This section guides you through submitting a bug report for react-crisp. 21 | Following these guidelines helps maintainers and the community 22 | understand your report, reproduce the behavior, and find related reports. 23 | 24 | Before creating bug reports, please perform a [cursory 25 | search](https://github.com/Mergifyio/react-crisp/issues?q=is%3Aissue%20is%3Aopen%20) 26 | to see if the problem has already been reported. If it has and the issue is 27 | still open, add a comment to the existing issue instead of opening a new one. 28 | When you are creating a bug report, please [include as many details as 29 | possbile](#how-do-i-submit-a-good-bug-report). 30 | 31 | > **Note:** If you find a **Closed** issue that seems like it is the same thing 32 | > that you're experiencing, open a new issue and include a link to the original 33 | > issue in the body of your new one. 34 | 35 | #### How Do I Submit A (Good) Bug Report? 36 | 37 | Bugs are tracked as [GitHub 38 | issues](https://guides.github.com/features/issues/). 39 | 40 | Explain the problem and include additional details to help maintainers 41 | reproduce the problem: 42 | 43 | * **Use a clear and descriptive title** for the issue to identify the problem. 44 | 45 | * **Describe the exact steps which reproduce the problem** in as many details 46 | as possible. For example, start by explaining how you use the 47 | react-crisp package, e.g. which code you write and the error you get. 48 | When listing steps, **don't just say what you did, but explain how you did it**. 49 | 50 | * **Provide specific examples to demonstrate the steps**. Include links to 51 | files or GitHub projects, or copy/pasteable snippets, which you use in those 52 | examples. If you're providing snippets in the issue, use [Markdown code 53 | blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). 54 | 55 | * **Describe the behavior you observed after following the steps** and point 56 | out what exactly is the problem with that behavior. 57 | 58 | * **Explain which behavior you expected to see instead and why.** 59 | 60 | 61 | Provide more context by answering these questions: 62 | 63 | * **Did the problem start happening recently** (e.g. after updating to a new 64 | version of react-crisp) or was this always a problem? 65 | 66 | * If the problem started happening recently, **can you reproduce the problem in 67 | an older version of react-crisp?** What's the most recent version in 68 | which the problem doesn't happen? You can install older versions of 69 | react-crisp from [the npm registery](https://www.npmjs.com/package/react-crisp). 70 | 71 | * **Can you reliably reproduce the issue?** If not, provide details about how 72 | often the problem happens and under which conditions it normally happens. 73 | 74 | 75 | Include details about your configuration and environment: 76 | 77 | * **Which version of react-crisp are you using?** You can get the exact 78 | version by running `yarn list | grep "react-crisp"` in your terminal. 79 | 80 | * **What's the name and version of the OS you're using**? 81 | 82 | * **What's the version of React you're using**? 83 | 84 | ### Suggesting Enhancements 85 | 86 | This section guides you through submitting an enhancement suggestion for 87 | react-crisp, including completely new features and minor improvements to 88 | existing functionality. Following these guidelines helps maintainers and the 89 | community understand your suggestion and find related suggestions. 90 | 91 | When you are creating an enhancement suggestion, please [include as many 92 | details as possible](#how-do-i-submit-a-good-enhancement-suggestion) and 93 | including the steps that you imagine you would take if the feature you're 94 | requesting existed. 95 | 96 | #### How Do I Submit A (Good) Enhancement Suggestion? 97 | 98 | Enhancement suggestions are tracked as [GitHub 99 | issues](https://guides.github.com/features/issues/). 100 | 101 | Provide the following information: 102 | 103 | * **Use a clear and descriptive title** for the issue to identify the 104 | suggestion. 105 | 106 | * **Provide a step-by-step description of the suggested enhancement** in as 107 | many details as possible. 108 | 109 | * **Provide specific examples to demonstrate the steps**. Include 110 | copy/pasteable snippets which you use in those examples, as [Markdown code 111 | blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). 112 | 113 | * **Describe the current behavior** and **explain which behavior you expected 114 | to see instead** and why. 115 | 116 | * **Include screenshots and animated GIFs** which help you demonstrate the 117 | steps or point out the part of react-crisp which the suggestion is 118 | related to. You can use [this tool](https://www.cockos.com/licecap/) to 119 | record GIFs on macOS and Windows, and [this 120 | tool](https://github.com/colinkeenan/silentcast) or [this 121 | tool](https://github.com/GNOME/byzanz) on Linux. 122 | 123 | * **Explain why this enhancement would be useful** to most react-crisp 124 | users. 125 | 126 | * **List some other tools or applications where this enhancement exists.** 127 | 128 | * **Specify which version of react-crisp you're using.** You can get the 129 | exact version by running `yarn list| grep "react-crisp"` in your 130 | terminal. 131 | 132 | * **Specify the name and version of the OS you're using.** 133 | 134 | * **Specify the version of React you're using** 135 | 136 | ## Code Contribution 137 | 138 | ### Hacking on react-crisp 139 | 140 | If you're hitting a bug in react-crisp or just want to experiment with 141 | adding a feature, follow these steps. 142 | 143 | #### Prerequisites 144 | 145 | - React >= 16.0 146 | 147 | #### Cloning 148 | 149 | ``` command-line 150 | $ git clone https://github.com/Mergifyio/react-crisp 151 | ``` 152 | 153 | #### Setup your environment 154 | 155 | From there, you can navigate into the directory where you've cloned the 156 | react-crisp source code and install all the required dependencies: 157 | 158 | ``` command-line 159 | $ cd react-crisp 160 | $ yarn install 161 | ``` 162 | 163 | #### Make your changes 164 | 165 | ``` command-line 166 | $ git checkout -b somefeature 167 | 168 | $ git commit -am 'I did some changes' 169 | $ git pull-request 170 | Forked repository: https://github.com/Mergifyio/react-crisp 171 | Force-pushing branch `somefeature' to remote `github' 172 | Counting objects: 5, done. 173 | Delta compression using up to 4 threads. 174 | Compressing objects: 100% (4/4), done. 175 | Writing objects: 100% (5/5), 562 bytes | 0 bytes/s, done. 176 | Total 5 (delta 3), reused 0 (delta 0) 177 | remote: Resolving deltas: 100% (3/3), completed with 3 local objects. 178 | To https://github.com/Mergifyio/react-crisp.git 179 | + 73a733f7...1be2bf29 somefeature -> somefeature (forced update) 180 | Pull-request created: https://github.com/react-crispxyz/react-crisp/pull/42 181 | ``` 182 | 183 | ### Pull Requests 184 | 185 | * Squash your commits. 186 | * Include examples, outputs, etc... whenever possible. 187 | * Include screenshots and animated GIFs in your pull request whenever possible. 188 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 Mergifyio 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Mergify Status][mergify-status]][mergify] 2 | 3 | [mergify]: https://mergify.io 4 | [mergify-status]: https://img.shields.io/endpoint.svg?url=https://gh.mergify.io/badges/Mergifyio/react-crisp&style=flat 5 | 6 | # ⚠️ Repository Status ⚠️ 7 | 8 | This repository is not maintained anymore. 9 | 10 | # React-Crisp 11 | 12 | React implementation for the messaging application [Crisp](https://crisp.chat/) 13 | 14 | # Install 15 | 16 | ```shell 17 | npm add react-crisp 18 | or 19 | yarn add react-crisp 20 | ``` 21 | 22 | # Usage 23 | 24 | ```javascript 25 | /* Import the component */ 26 | import Crisp from 'react-crisp'; 27 | 28 | /* Insert the componenent */ 29 | 30 | ``` 31 | 32 | # Identify the user and assign attributes 33 | 34 | ```javascript 35 | 43 | ``` 44 | 45 | For a complete list of attributes please see the [Crisp's Docs](https://help.crisp.chat/en/article/how-to-use-dollarcrisp-javascript-sdk-10ud15y/#2-set-a-value). 46 | 47 | # Configuration 48 | 49 | ```javascript 50 | 57 | ``` 58 | For a complete list of parameters please see the [Crisp's Docs](https://help.crisp.chat/en/article/how-to-use-dollarcrisp-javascript-sdk-10ud15y/#2-changes-runtime-configuration). 59 | 60 | # Safe mode 61 | 62 | To prevent Crisp to emit errors when an exception occurs, you may enable the Safe Mode (see [Crisp's Docs](https://help.crisp.chat/en/article/how-to-use-dollarcrisp-javascript-sdk-10ud15y/#1-disable-warnings-amp-errors). With `react-crisp` it's done like this: 63 | ```javascript 64 | 68 | ``` 69 | 70 | # Set `CRISP_RUNTIME_CONFIG` 71 | 72 | ```javascript 73 | 79 | ``` 80 | 81 | For more details about the variable `CRISP_RUNTIME_CONFIG` see [Crisp's Docs](https://help.crisp.chat/en/). 82 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-env', '@babel/preset-react'], 3 | plugins: ['@babel/plugin-transform-runtime'], 4 | }; 5 | -------------------------------------------------------------------------------- /jest.setup.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Reset the DOM between tests is not automatic... 3 | * https://github.com/facebook/jest/issues/1224#issuecomment-716075260 4 | */ 5 | const sideEffects = { 6 | document: { 7 | addEventListener: { 8 | fn: document.addEventListener, 9 | refs: [], 10 | }, 11 | keys: Object.keys(document), 12 | }, 13 | window: { 14 | addEventListener: { 15 | fn: window.addEventListener, 16 | refs: [], 17 | }, 18 | keys: Object.keys(window), 19 | }, 20 | }; 21 | 22 | // Lifecycle Hooks 23 | // ----------------------------------------------------------------------------- 24 | beforeAll(async () => { 25 | // Spy addEventListener 26 | ['document', 'window'].forEach((obj) => { 27 | const { fn } = sideEffects[obj].addEventListener; 28 | const { refs } = sideEffects[obj].addEventListener; 29 | 30 | function addEventListenerSpy(type, listener, options) { 31 | // Store listener reference so it can be removed during reset 32 | refs.push({ type, listener, options }); 33 | // Call original window.addEventListener 34 | fn(type, listener, options); 35 | } 36 | 37 | // Add to default key array to prevent removal during reset 38 | sideEffects[obj].keys.push('addEventListener'); 39 | 40 | // Replace addEventListener with mock 41 | global[obj].addEventListener = addEventListenerSpy; 42 | }); 43 | }); 44 | 45 | // Reset JSDOM. This attempts to remove side effects from tests, however it does 46 | // not reset all changes made to globals like the window and document 47 | // objects. Tests requiring a full JSDOM reset should be stored in separate 48 | // files, which is only way to do a complete JSDOM reset with Jest. 49 | beforeEach(async () => { 50 | const rootElm = document.documentElement; 51 | 52 | // Remove attributes on root element 53 | [...rootElm.attributes].forEach((attr) => rootElm.removeAttribute(attr.name)); 54 | 55 | // Remove elements (faster than setting innerHTML) 56 | while (rootElm.firstChild) { 57 | rootElm.removeChild(rootElm.firstChild); 58 | } 59 | 60 | // Remove global listeners and keys 61 | ['document', 'window'].forEach((obj) => { 62 | const { refs } = sideEffects[obj].addEventListener; 63 | 64 | // Listeners 65 | while (refs.length) { 66 | const { type, listener, options } = refs.pop(); 67 | global[obj].removeEventListener(type, listener, options); 68 | } 69 | 70 | // Keys 71 | Object.keys(global[obj]) 72 | .filter((key) => !sideEffects[obj].keys.includes(key)) 73 | .forEach((key) => { 74 | delete global[obj][key]; 75 | }); 76 | }); 77 | 78 | // Restore base elements 79 | rootElm.innerHTML = ''; 80 | }); 81 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-crisp", 3 | "version": "0.1.4", 4 | "license": "Apache-2.0", 5 | "description": "React component implementation of Crisp the messaging app", 6 | "homepage": "https://github.com/Mergifyio/react-crisp", 7 | "main": "./dist/crisp.js", 8 | "keywords": [ 9 | "React", 10 | "Crisp", 11 | "npm" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/Mergifyio/react-crisp" 16 | }, 17 | "jest": { 18 | "setupFilesAfterEnv": [ 19 | "./jest.setup.js" 20 | ] 21 | }, 22 | "eslintConfig": { 23 | "env": { 24 | "browser": true 25 | }, 26 | "extends": [ 27 | "airbnb", 28 | "plugin:import/errors", 29 | "plugin:import/warnings", 30 | "plugin:jest/recommended" 31 | ] 32 | }, 33 | "dependencies": { 34 | "prop-types": ">=15.0.0", 35 | "react": ">=16.8.0", 36 | "react-dom": ">=16.8.0" 37 | }, 38 | "devDependencies": { 39 | "@babel/core": "^7.12.3", 40 | "@babel/plugin-transform-runtime": "^7.12.1", 41 | "@babel/preset-env": "^7.12.1", 42 | "@babel/preset-react": "^7.12.5", 43 | "@testing-library/react": "^12.0.0", 44 | "babel-jest": "^27.0.0", 45 | "babel-loader": "^8.2.0", 46 | "eslint": "^7.11.0", 47 | "eslint-config-airbnb": "^18.2.0", 48 | "eslint-module-utils": "^2.6.0", 49 | "eslint-plugin-flowtype": "^6.0.1", 50 | "eslint-plugin-import": "^2.22.1", 51 | "eslint-plugin-import-order-alphabetical": "^1.0.1", 52 | "eslint-plugin-jest": "^24.1.3", 53 | "eslint-plugin-jsx-a11y": "^6.3.1", 54 | "eslint-plugin-react": "^7.21.5", 55 | "eslint-plugin-react-hooks": "^4.2.0", 56 | "jest": "^26.6.3", 57 | "webpack-cli": "^4.2.0", 58 | "webpack-module": "^0.1.0" 59 | }, 60 | "scripts": { 61 | "eslint": "eslint --ext .js --ext .jsx ./src", 62 | "build": "webpack", 63 | "test": "jest" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Crisp.jsx: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | import React, { useRef, useEffect } from 'react'; 3 | 4 | function usePrevious(value) { 5 | const ref = useRef(); 6 | useEffect(() => { 7 | ref.current = value; 8 | }); 9 | return ref.current; 10 | } 11 | 12 | function pushCrisp(method, parameters) { 13 | if (Object.keys(parameters).length > 0) { 14 | const items = Object.entries(parameters); 15 | items.map((item) => { 16 | const [key, value] = item; 17 | return global.$crisp.push([method, key, value]); 18 | }); 19 | } 20 | } 21 | 22 | function Crisp(props) { 23 | const { 24 | crispWebsiteId, 25 | crispTokenId, 26 | crispRuntimeConfig, 27 | safeMode, 28 | configuration, 29 | attributes, 30 | } = props; 31 | 32 | const previousCrispWebsiteId = usePrevious(crispWebsiteId); 33 | if (previousCrispWebsiteId && previousCrispWebsiteId !== crispWebsiteId) { 34 | throw Error("crispWebsiteId can't be changed"); 35 | } 36 | const previousCrispTokenId = usePrevious(crispTokenId); 37 | if (previousCrispTokenId && previousCrispTokenId !== crispTokenId) { 38 | throw Error("crispTokenId can't be changed"); 39 | } 40 | 41 | const previousCrispRuntimeConfig = usePrevious(crispRuntimeConfig); 42 | if (previousCrispRuntimeConfig && previousCrispRuntimeConfig !== crispRuntimeConfig) { 43 | throw Error("crispRuntimeConfig can't be changed"); 44 | } 45 | 46 | const previousSafeMode = usePrevious(safeMode); 47 | if (previousSafeMode && previousSafeMode !== safeMode) { 48 | throw Error("safeMode can't be changed"); 49 | } 50 | 51 | if (global.$crisp === undefined) { 52 | // Must be call before any other $crisp method 53 | // https://help.crisp.chat/en/article/how-to-use-dollarcrisp-javascript-sdk-10ud15y/#1-disable-warnings-amp-errors 54 | global.$crisp = [['safe', safeMode]]; 55 | } 56 | 57 | // Custom configuration 58 | pushCrisp('set', attributes); 59 | pushCrisp('config', configuration); 60 | 61 | const scriptUrl = 'https://client.crisp.chat/l.js'; 62 | const scripts = document.querySelector(`script[src='${scriptUrl}']`); 63 | if (scripts === null) { 64 | // CRISP_WEBSITE_ID, CRISP_TOKEN_ID and CRISP_RUNTIME_CONFIG 65 | // must be declared before inserting the script 66 | // https://help.crisp.chat/en/article/how-to-restore-chat-sessions-with-a-token-c32v4t/ 67 | // https://help.crisp.chat/en/article/how-to-use-crisp-with-reactjs-fe0eyz/ 68 | 69 | global.CRISP_WEBSITE_ID = crispWebsiteId; 70 | global.CRISP_TOKEN_ID = crispTokenId; 71 | global.CRISP_RUNTIME_CONFIG = crispRuntimeConfig; 72 | 73 | // We are good start Crisp 74 | const script = document.createElement('script'); 75 | script.src = scriptUrl; 76 | script.async = 1; 77 | document.head.appendChild(script); 78 | } 79 | 80 | return <>; 81 | } 82 | 83 | Crisp.propTypes = { 84 | crispWebsiteId: PropTypes.string.isRequired, 85 | crispTokenId: PropTypes.string, 86 | crispRuntimeConfig: PropTypes.objectOf(PropTypes.oneOfType([ 87 | PropTypes.string, 88 | PropTypes.number, 89 | PropTypes.bool, 90 | PropTypes.array, 91 | ])), 92 | attributes: PropTypes.objectOf(PropTypes.array), 93 | configuration: PropTypes.objectOf(PropTypes.array), 94 | safeMode: PropTypes.bool, 95 | }; 96 | Crisp.defaultProps = { 97 | crispTokenId: '', 98 | crispRuntimeConfig: {}, 99 | attributes: {}, 100 | configuration: {}, 101 | safeMode: false, 102 | }; 103 | 104 | export default Crisp; 105 | -------------------------------------------------------------------------------- /tests/Crisp.test.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | render, waitFor, 4 | } from '@testing-library/react'; 5 | 6 | import Crisp from '../src/Crisp'; 7 | 8 | test('Crisp load', async () => { 9 | await render(); 10 | 11 | await waitFor(() => expect(global.$crisp).toBeDefined()); 12 | await waitFor(() => expect(document.querySelector('.crisp-client')).toBeDefined()); 13 | await waitFor(() => expect(global.CRISP_WEBSITE_ID).toMatch(/foo-website-id-load/)); 14 | }); 15 | 16 | test('Crisp with a token ID', async () => { 17 | const tokenId = 'foo-token-id'; 18 | await render( 19 | , 23 | ); 24 | 25 | await waitFor(() => expect(global.CRISP_TOKEN_ID).toMatch(/foo-token-id/)); 26 | }); 27 | 28 | test('Crisp with a Runtime Config', async () => { 29 | const runtimeConfig = { session_merge: true }; 30 | 31 | await render( 32 | , 36 | ); 37 | 38 | await waitFor(() => expect(global.$crisp).toBeDefined()); 39 | await waitFor(() => expect(global.CRISP_RUNTIME_CONFIG.session_merge).toBeTruthy()); 40 | await waitFor(() => expect(document.querySelector('.crisp-client')).toBeDefined()); 41 | }); 42 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: './src/Crisp.jsx', 5 | output: { 6 | path: path.resolve('dist'), 7 | filename: 'crisp.js', 8 | libraryTarget: 'commonjs2', 9 | }, 10 | module: { 11 | rules: [ 12 | { 13 | test: /\.jsx?$/, 14 | exclude: /(node_modules)/, 15 | use: 'babel-loader', 16 | }, 17 | ], 18 | }, 19 | }; 20 | --------------------------------------------------------------------------------