Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ink-select-input

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ink-select-input

Select input component for Ink

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
205K
decreased by-0.27%
Maintainers
2
Weekly downloads
 
Created

What is ink-select-input?

The ink-select-input package is a React component for Ink, a React renderer for the terminal. It allows developers to create interactive command-line interfaces with selectable input options.

What are ink-select-input's main functionalities?

Basic Select Input

This feature allows you to create a basic select input component where users can navigate through options using arrow keys and select an option by pressing Enter.

const { h, render, Component } = require('ink');
const SelectInput = require('ink-select-input').default;

class App extends Component {
  handleSelect = item => {
    console.log(item.label);
  };

  render() {
    const items = [
      { label: 'Option 1', value: 'option1' },
      { label: 'Option 2', value: 'option2' },
      { label: 'Option 3', value: 'option3' }
    ];

    return <SelectInput items={items} onSelect={this.handleSelect} />;
  }
}

render(<App />);

Customizing Item Rendering

This feature allows you to customize how each item in the select input is rendered. In this example, a custom render function is used to add a '>' symbol next to the selected item.

const { h, render, Component } = require('ink');
const SelectInput = require('ink-select-input').default;

class App extends Component {
  handleSelect = item => {
    console.log(item.label);
  };

  renderItem = (item, { isSelected }) => (
    <div>
      {isSelected ? '>' : ' '} {item.label}
    </div>
  );

  render() {
    const items = [
      { label: 'Option 1', value: 'option1' },
      { label: 'Option 2', value: 'option2' },
      { label: 'Option 3', value: 'option3' }
    ];

    return <SelectInput items={items} onSelect={this.handleSelect} itemComponent={this.renderItem} />;
  }
}

render(<App />);

Handling Input Change

This feature allows you to handle changes in the highlighted item. The onHighlight prop is used to execute a function whenever the highlighted item changes.

const { h, render, Component } = require('ink');
const SelectInput = require('ink-select-input').default;

class App extends Component {
  handleSelect = item => {
    console.log(item.label);
  };

  handleChange = item => {
    console.log('Changed to:', item.label);
  };

  render() {
    const items = [
      { label: 'Option 1', value: 'option1' },
      { label: 'Option 2', value: 'option2' },
      { label: 'Option 3', value: 'option3' }
    ];

    return <SelectInput items={items} onSelect={this.handleSelect} onHighlight={this.handleChange} />;
  }
}

render(<App />);

Other packages similar to ink-select-input

Keywords

FAQs

Package last updated on 22 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc