react-codejar
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

react-codejar

NPM React wrapper around the CodeJar library

Install

npm install --save react-codejar

Features

You can customize codejar by passing the options prop, it also have a lineNumbers prop that will use codejar's withLineNumbers for you.

Usage

import React, { Component, useState } from "react";

// You can choose to use the component or the hook
import { ReactCodeJar, useCodeJar } from "react-codejar";

const highlight = editor => {
  let code = editor.textContent;
  code = code.replace(/\((\w+?)(\b)/g, '(<font color="#8a2be2">$1</font>$2');
  editor.innerHTML = code;
};

const ComponentExample = () => {
  const [code, setCode] = useState('(format t "lisp example")');

  return (
    <ReactCodeJar
      code={code} // Initial code value
      onUpdate={setCode} // Update the text
      highlight={highlight} // Highlight function, receive the editor
      lineNumbers={true} // Show line numbers
    />
  );
};

const HookExample = () => {
  const [code, setCode] = useState('(format t "lisp example")');

  const editorRef = useCodeJar({
    code, // Initial code value
    onUpdate: setCode, // Update the text
    highlight, // Highlight function, receive the editor
    lineNumbers: true // Show line numbers
  });

  return <div ref={editorRef}></div>;
};

License

GPL3 © guilhermelimak

Readme

Keywords

none

Package Sidebar

Install

npm i react-codejar

Weekly Downloads

213

Version

1.1.2

License

GPL3

Unpacked Size

32.3 kB

Total Files

9

Last publish

Collaborators

  • guilhermelimak