@bajayk/html-editor

1.0.0 • Public • Published

HTML Editor

Demo Link

Installation

npm install @bajayk/html-editor

How to use in Vanila JS.

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="script.js" type="module"></script>
</head>

<body>
    <html-editor id="html-editor"></html-editor>
    <br />
    <button id="btn-output">Editor Output</button>
    <br/>
    <textarea id="output">

    </textarea>
</body>

</html>

script.js

import HTMLEditor from "./html-editor/html-editor.js";

const htmlEditor = document.querySelector("#html-editor");
htmlEditor.html = `<h1>Hello World</h1>`;

const btnOutput = document.querySelector("#btn-output");
btnOutput.addEventListener("click", showOutput);

function showOutput(){
    console.log("showOutput");
    console.log(htmlEditor.html);
    const output = document.querySelector("#output");
    const html = htmlEditor.html;
    output.innerHTML = html;
}

How to use in React

import { useEffect, useRef, useState } from 'react'
import HTMLEditor from '@bajayk/html-editor';


function App() {
  const htmlRef = useRef();

  const [html, setHtml] = useState('<h1>Hello World</h1>')

  useEffect(() => {
    htmlRef.current.html = html;
  },[html])

  return (
    <>
      <h1>HTML Editor Demo</h1>
      <html-editor ref={htmlRef}></html-editor>
      <br/>
      <button onClick={() => {
        setHtml(htmlRef.current.html)
      }}>Get HTML</button>
      <br/>
      <br/>
      <textarea value={html} style={{width:'100%', height:100}}></textarea>
    </>
  )
}

export default App;

Readme

Keywords

Package Sidebar

Install

npm i @bajayk/html-editor

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

18.2 kB

Total Files

3

Last publish

Collaborators

  • bajayk