🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

reactjs-editor

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactjs-editor

A simple react library that lets you highlight text, make text bold, and add comment on any text as a sticky notes

6.6.4
Version published
Weekly downloads
99
-34.44%
Maintainers
1
Weekly downloads
 
Created


ReactjsEditor
ReactJSEditor

React package to highlight text,make text bold,add comment to text.View Demo.

screenshot

Get Started 👨🏻‍✈️

🛠️🛠️ Installation and Setup 🌱🌱


$ npm i reactjs-editor

⏭️ ⏭️ For javascript project. Your setup is successful

🦄✨🧙🏼‍♀️ Go see USAGE section directly


However in typescript you will probably get this error while trying to import package

⚠️⚠️⚠️ Could not find a declaration file for module 'reactjs-editor'. ⚠️⚠️⚠️


## So we have to setup type declaration support for Typescript and fix that error
⬇️ ⬇️ ⬇️ CLICK TO SETUP TYPE DECLARATION FOR TYPESCRIPT PROJECT
-----------------------------  FIRST STEP: -------------------------------


1. Go to your project root

2. Create a new [FILE_NAME].d.ts file 

3. Add this line below in the file  📝📝

declare module 'reactjs-editor';    //add this line and save


----------------------------- SECOND STEP: -------------------------------

1. Now open tsconfig.json file and just include path ➕➕➕

 "include": [
  "src",
  "./reacteditor.d.ts"  //Add this line and save
  ...
 ] 

👩🏿‍🔧👩🏿‍🔧 After this configuration setup, typescript won't show type error



🦄✨🧙🏼‍♀️ USAGE 🦄✨🧙🏼‍♀️

Import Package in your project

$ import { Editor } from 'reactjs-editor';

Use Editor component and insert any html content

   <Editor
        htmlContent={`<main> 
          <h1>Welcome to My Website</h1>
          <p>This is a paragraph of text in HTML. It's simple and easy to create.</p>
          <p>HTML stands for HyperText Markup Language. It's the standard markup language for  creating web pages.</p>
          <p>In HTML, you can create different types of elements such as headings, paragraphs, links, lists, and more to structure and format your content.</p>
         </main>`}
      />

🎉🎉🎉 Easy Peasy 🎉🎉🎉 Check it out



🚨🚨🚨 Note: ⚠️⚠️ Its important:

🚨🚨🚨 Make sure your htmlContent is wrapped inside main tag

✅✅✅

htmlContent={
<main>
{ *** all your html content here *** }
</main>
}

✅✅✅


🎉🎉🎉 That's it. 🎉🎉🎉



Additional Props for Customizations

Add your own colors

<Editor
      colors={["black","gold","red"]}
      ....
      />

Make sure to add your class in your css file

/* In your css file */

.black{
    background-color:#000,
    color:#fff,
},
.red{
    background-color:red,
    color:#fff,
}
.gold{
    background-color:gold,
    color:#fff,
}

//add as much as you like



Get Access to Changed HTML Element.

💾 Save user html changes and show them their changes on subsequent visit


import { Editor, useDomValue } from 'reactjs-editor';

...

 const { dom, setDom } = useDomValue();

  // eslint-disable-next-line react-hooks/exhaustive-deps
  const updatedDomValue  = {
    key: dom?.key,
    props: dom?.props,
    ref: dom?.ref,
    type: dom?.type,
  }


  console.log("%j", updatedDomValue );  
  
  // get your changed dom  like this and save it if you like to in your database or some place

Update dom using that " updatedDomValue " values you saved from above


useEffect(()=>{
  function updateDom(updatedDomValue:any){
   setDom(updatedDomValue); //set your dom like this
 
  }
  updateDom(updatedDomValue) // call this function where ever you like

},[])



If you want to customize designs of all other components such as floating button and modals

1. Inspect html element
2. Find className of specific elements
3. Override css present there from your own css files 

 In future update, I will create option to pass all components in a props

Support

Buy Me A Coffee

License

MIT

vivekneupane11@gmail.com  ·  GitHub @vivekneupane11  · 

FAQs

Package last updated on 05 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts