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-blessed-contrib

v0.2.1

Published

A wrapper for blessed-contrib widgets to be rendered with react-blessed.

Downloads

25

Readme

react-blessed-contrib

A wrapper for blessed-contrib widgets to be rendered with react-blessed.

Installation

You can install react-blessed-contrib through npm:

npm install react blessed react-blessed
npm install react-blessed-contrib

Demo

For a quick demo you can clone this repository and check some of the examples:

git clone https://github.com/dundalek/react-blessed-contrib
cd react-blessed-contrib
npm install

# Some examples (code is in `examples/`)
npm run dashboard
npm run charts
npm run basic

# Run any example with babel-node
./node_modules/.bin/babel-node examples/charts.js

Usage

Using components

Import components and render with React. You can mix them with native react-blessed components. Most components can be used directly as shown in the example. Refer to following sections to see how to use layout components like Grid and Carousel.

import React, { Component } from 'react';
import blessed from 'blessed';
import { render } from 'react-blessed';
import { Bar } from 'react-blessed-contrib';

// Rendering a simple centered box with a bar chart
class App extends Component {
  render() {
    return (
      <box top="center"
           left="center"
           width="80%"
           height="80%"
           border={{type: 'line'}}
           style={{border: {fg: 'blue'}}}>
        <Bar
          label="Server Utilization (%)"
          barWidth={4}
          barSpacing={6}
          xOffset={0}
          maxHeight={9}
          data={{
            titles: ['bar1', 'bar2'],
            data: [5, 10]
          }}
        />
      </box>
    );
  }
}

// Creating our screen
const screen = blessed.screen();

// Rendering the React app using our screen
const component = render(<App />, screen);

Grid

Pass in children components to use a grid layout:

import { Grid, Map } from 'react-blessed-contrib';

<Grid rows={12} cols={12}>
  <Map row={0} col={0} rowSpan={4} colSpan={4} label="World Map" />
  <box row={4} col={4} rowSpan={4} colSpan={4}>My Box</box>
</Grid>

If you don't specify rowSpan or colSpan then 1 is used as a default:

import { Grid, Map } from 'react-blessed-contrib';

<Grid rows={1} cols={2}>
  <Map col={0} label="World Map" />
  <box col={1}>My Box</box>
</Grid>

In case there would be name conflicts with props (row, col, rowSpan, colSpan), you can use alternative notation:

import { Grid, GridItem, Map } from 'react-blessed-contrib';

<Grid rows={12} cols={12}>
  <GridItem row={0} col={0} rowSpan={4} colSpan={4} component={Map} options={{label: 'World Map'}} />
  <GridItem row={4} col={4} rowSpan={4} colSpan={4} component={'box'} options={{content: 'My Box'}} />
</Grid>

Carousel

Pass in subcomponents as children. Refer to examples/carousel.js for full example.

import { Carousel } from 'react-blessed-contrib';

<Carousel interval={3000} controlKeys={true} screen={screen}>
  <Page1 />
  <Page2 />
</Carousel>

Wrapping a custom blessed widget

Say you have a custom blessed widget:

const widget = myBlessedWidget();
screen.append(widget);

You can wrap it in a component and use like:

import React from 'react';
import { render } from 'react-blessed';
import { createBlessedComponent } = 'react-blessed-contrib';

const MyBlessedWidget = createBlessedComponent(myBlessedWidget);

render(<MyBlessedWidget />, screen);

License

MIT

Resources

Useful resources for learning more about React internals:

  • https://facebook.github.io/react/blog/2015/12/18/react-components-elements-and-instances.html
  • http://goshakkk.name/react-custom-renderers/