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

@haensl/react-component-console

v2.0.14

Published

A console emulator component for React.

Downloads

9

Readme

react-component-console CircleCI

A console emulator component for React.

NPM

npm version

Features

  • Highly customizable console emulator
  • Callbacks

Quick start

  1. Install the react-component-console dependency
npm i -S @haensl/react-component-console

or

yarn add @haensl/react-component-console
  1. Use it in your React app
import Console from '@haensl/react-component-console';
// ...

class MyComponent extends React.Component {
  // ...

  render() {
    return (
      <Console lines={[
        'Hi!',
        'How are you today?'
      ]} />
    );
  }
}

export default MyComponent;

Customize

The following properties let you customize component behaviour.

Lines lines

Specify the string or array of strings to write.

Example

<Console lines={[
  'Hi!',
  'How are you today?'
]} />

Callbacks

onFinishWritingLine

Provide a callback which is called for every line that was written. The callback receives the line as parameter.

Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  onFinishWritingLine={
    (line) => {
      console.info('Console has finished writing line', line);
    }
  }
/>

onFinishWritingLines

Provide a callback which is called when all lines have been written. The callback receives the lines as parameter.

Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  onFinishWritingLines={
    (lines) => {
      console.info('Console has finished writing all lines', line);
    }
  }
/>

Console console

The console property lets you customize console behaviour.

Appending console.append

Set this property to true to append lines instead of writing them one by one.

Typing console.typing

react-component-console features highly cusomizable human-like typing behaviour. The following options let you fine tune typing the way you want.

console.typing.char

This object lets you specify typing behaviour concerning a single character. For every character a new delay is calculated depending on the average character delay and a deviation. If you, e.g. specify an average delay of 100ms and a deviation of 0.2 (or 20%), you end up with character typing delays between 80ms and 120ms.

Signature
{
  avgMs: 150, // average milliseconds to type a character
  deviation: 0.3, // deviation to apply to avgMs
  minMs: 50, // minimum milliseconds to type a character
  maxMs: Number.MAX_SAFE_INTEGER // maximum milliseconds to type a character
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  console={{
    typing: {
      char: {
        avgMs: 100, // 100 ms average time to write a character
        deviation: 0.2, // deviate typing delay by 20 %
        minMs: 80 // take at least 80ms to write a character
      }
    }
  }}
/>

console.typing.line

This object lets you specify details concerning typing of a line. It works analogous to console.typing.char in the sense that you specify the average delay between lines (i.e. how long it takes to hit the return button) and a deviation from this average.

Signature
{
  delay: {
    avgMs: 1000, // average delay between lines in milliseconds, i.e. time to hit return
    deviation: 0.3, // deviation to apply to avgMs
    minMs: 50, // minimum delay between lines in milliseconds
    maxMs: Number.MAX_SAFE_INTEGER // maximum delay between lines in milliseconds
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  console={{
    typing: {
      line: {
        avgMs: 600, // 600 ms average delay between lines
        deviation: 0.2, // deviate line delay by 20 %
        minMs: 500 // delay at least by 500ms to between lines
      }
    }
  }}
/>

Styles/CSS-classes

The Console component uses standard CSS classes for styles. You can overwrite any styles in your own stylesheets and you can supply your own class names as well.

console.classes

Use this object to customize Console component class names.

Signature
{
  classes: {
    element: 'Console' // class name assigned to the wrapping element
  }
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  console={{
    classes: {
      element: 'My-Console' // use .My-Console instead of the default .Console class name
    }
  }}
/>

Line

The line property lets you customize the Line component used by Console to render lines.

Styles/CSS-classes

line.classes

Use this object to customize class names of the Line component. You can overwrite any styles in your own stylesheets and you can supply your own class names.

Signature
{
  classes: {
    element: 'Console-Line', // class name assigned to the Line element
    content: 'Console-Line-content' // class name assigned to the content, i.e. text, rendered in a line
  }
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  line={{
    classes: {
      element: 'My-Line' // use .My-Line instead of the default .Console-Line class name
    }
  }}
/>

PS1

The ps1 property lets you customize the PS1 component.

Styles/CSS classes

ps1.classes

Use this object to customize class names of the PS1 component. You can overwrite any styles in your own stylesheets and you can supply your own class names.

Signature
{
  classes: {
    element: 'Console-PS1', // class name assigned to the PS1 element
  }
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  ps1={{
    classes: {
      element: 'My-PS1' // use .My-PS1 instead of the default .Console-PS1 class name
    }
  }}
/>

Content

ps1.content

Use this property to customize the PS1 content rendered in the Console.

Signature
{
  content: '$' // display a dollar sign as PS1
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  ps1={{
    content: '~' // display a tilde instead of the default dollar sign
  }}
/>

Cursor

The cursor property lets you customize the Cursor component rendered in the Console.

Styles/CSS classes

cursor.classes

Use this object to supply your own class names for the Cursor component. You can overwrite any styles in your own stylesheets and you can supply your own class names.

Signature
{
  classes: {
    blink: 'Console-Cursor--blink', // class name to assign when the Cursor is blinking
    element: 'Console-Cursor', // class name to assign to the Cursor component
    write: 'Console-Cursor--write' // class name to assign when the Cursor is in writing state
  }
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  cursor={{
    classes: {
      blink: 'My-Console-Cursor--isBlinking', // use this instead of the default for blinking state
      element: 'My-Console-Cursor', // use this instead of the default for the Cursor component
      write: 'My-Console-Cursor--isWriting' // use this instead of the default for writing state
    }
  }}
/>

Blink interval

cursor.intervalMs

Use this property to specify how rapidly the Cursor should blink.

Signature
{
  intervalMs: 400 // blink for 400ms on and off
}
Example
<Console
  lines={[
    'Hi!',
    'How are you today?'
  ]}
  cursor={{
    intervalMs: 250 // blink faster then the default 400ms
  }}
/>

Changelog

License