npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-cmirror

v1.4.2

Published

Codemirror Component for React.js, all Codemirror options and event are supported.

Downloads

49

Readme

react-cmirror

Codemirror Component for React.js, all Codemirror options and events are supported.

中文|English

npm npm

1. Installation

npm install --save react-cmirror

2. Demo & Examples

To build the examples locally, run:

npm install
npm run start

3. Usage

Minimal usage:

import ReactCodeMirror from 'react-cmirror';
<ReactCodeMirror value={text} />

4. Properties

  • value: the editor value
  • options: options for CodeMirror, see the CodeMirror Configuration for available options.
  • width: set width the editor, width and height can be either numbers (interpreted as pixels) or CSS units ("100%", for example). You can pass null for either of them to indicate that that dimension should not be changed.
  • height: set height the editor, same as width

Note: width and height overriding the css style of CodeMirror, if you want to change the style of CodeMirror, refer to CodeMirror Customized Styling for detail.

5. Events

CodeMirror support kinds of Events, to use these events, you need to follow the rules:

  • Uppercase the first letter of event name, and add on at the beginning, as the property of editor.
  • Event handle function recieve arguments as CodeMirror defined.

For example, to deal with scroll event, you need set property onScroll, and handeScroll will recieve instance argument :

handleScroll = (instance /*CodeMirror instance*/) => {
  console.log(instance);
}

<ReactCodeMirror onScroll={this.handleScroll} />

6. Access to CodeMirror

You can get CodeMirror instance from editor and CodeMirror object from codemirror by using ref.

getInstance = (instance) => {
  this.codemirror = instance.codemirror;
  this.editor = instance.editor;
}
<ReactCodeMirror ref={this.getInstance}/>

7. Language modes&Themes

Language modes CodeMirror support syntax highlighting by setting language mode. These Language Modes are available. By default, no modes is included, to enable this:

  • import language mode from mode directory of codemirror
  • set mode option in options property

Themes To change the color schemes of highlighting, theme option is supplied, these Themes are avalible, to use like this:

  • import theme from theme directory of codemirror
  • set theme in options property
import ReactCodeMirror from 'react-cmirror';
import 'codemirror/mode/markdown/markdown';
import 'codemirror/theme/monokai.css';

<ReactCodeMirror options={{mode: 'markdown', theme: 'monokai'}} />

8. Addon

Addons are used to implement extra editor functionality, import addon after react-cmirror, and set options follow the instruction.

import ReactCodeMirror from 'react-cmirror';
import 'codemirror/addon/display/fullscreen';
import 'codemirror/addon/display/fullscreen.css';
<ReactCodeMirror options={{fullScreen: true}} />

9. Async loading

Asynchronous loading page may cause unexpected rendering, use addon autorefresh to resolve it. Or you can call refresh function of CodeMirror manually after the page loaded.

License

Copyright (c) 2017 ZiQiangWang MIT Licensed.