New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ink-select-input

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ink-select-input - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

35

dist/index.js

@@ -7,2 +7,3 @@ 'use strict';

const figures = require('figures');
const arrRotate = require('arr-rotate');

@@ -43,2 +44,3 @@ const noop = () => {};

this.state = {
rotateIndex: 0,
selectedIndex: 0

@@ -50,4 +52,6 @@ };

render({ items, indicatorComponent, itemComponent }, { selectedIndex }) {
return items.map((item, index) => {
render({ items, indicatorComponent, itemComponent, limit }, { rotateIndex, selectedIndex }) {
const slicedItems = typeof limit === 'number' ? arrRotate(items, rotateIndex).slice(0, limit) : items;
return slicedItems.map((item, index) => {
const isSelected = index === selectedIndex;

@@ -75,2 +79,3 @@

this.setState({
rotateIndex: 0,
selectedIndex: 0

@@ -82,4 +87,5 @@ });

handleKeyPress(ch, key) {
const { items, focus, onSelect } = this.props;
const { selectedIndex } = this.state;
const { items, focus, limit, onSelect } = this.props;
const { rotateIndex, selectedIndex } = this.state;
const hasLimit = typeof limit === 'number';

@@ -90,16 +96,20 @@ if (focus === false) {

if (key.name === 'up') {
const lastIndex = items.length - 1;
if (key.name === 'up' || key.name === 'k') {
const lastIndex = (hasLimit ? limit : items.length) - 1;
const atFirstIndex = selectedIndex === 0;
const nextIndex = hasLimit ? selectedIndex : lastIndex;
this.setState({
selectedIndex: atFirstIndex ? lastIndex : selectedIndex - 1
rotateIndex: atFirstIndex ? rotateIndex + 1 : rotateIndex,
selectedIndex: atFirstIndex ? nextIndex : selectedIndex - 1
});
}
if (key.name === 'down') {
const atLastIndex = selectedIndex === items.length - 1;
if (key.name === 'down' || key.name === 'j') {
const atLastIndex = selectedIndex === (hasLimit ? limit : items.length) - 1;
const nextIndex = hasLimit ? selectedIndex : 0;
this.setState({
selectedIndex: atLastIndex ? 0 : selectedIndex + 1
rotateIndex: atLastIndex ? rotateIndex - 1 : rotateIndex,
selectedIndex: atLastIndex ? nextIndex : selectedIndex + 1
});

@@ -109,3 +119,4 @@ }

if (key.name === 'return') {
onSelect(items[selectedIndex]);
const slicedItems = hasLimit ? arrRotate(items, rotateIndex).slice(0, limit) : items;
onSelect(slicedItems[selectedIndex]);
}

@@ -120,2 +131,3 @@ }

itemComponent: PropTypes.func,
limit: PropTypes.number,
onSelect: PropTypes.func

@@ -129,2 +141,3 @@ };

itemComponent: Item,
limit: null,
onSelect: noop

@@ -131,0 +144,0 @@ };

{
"name": "ink-select-input",
"version": "1.0.0",
"version": "1.1.0",
"description": "Select input component for Ink",

@@ -30,2 +30,3 @@ "license": "MIT",

"dependencies": {
"arr-rotate": "^1.0.0",
"figures": "^2.0.0",

@@ -36,11 +37,11 @@ "lodash.isequal": "^4.5.0",

"devDependencies": {
"ava": "^0.20.0",
"ava": "^0.25.0",
"babel-cli": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"eslint-config-xo-react": "^0.13.0",
"eslint-config-xo-react": "^0.16.0",
"eslint-plugin-react": "^7.1.0",
"ink": "^0.3.1",
"sinon": "^3.1.0",
"xo": "^0.18.2"
"ink": "^0.4.1",
"sinon": "^4.4.9",
"xo": "^0.20.3"
},

@@ -47,0 +48,0 @@ "babel": {

@@ -78,5 +78,11 @@ # ink-select-input [![Build Status](https://travis-ci.org/vadimdemedes/ink-select-input.svg?branch=master)](https://travis-ci.org/vadimdemedes/ink-select-input)

### limit
Type: `number`
Number of items to display.
## License
MIT © [Vadim Demedes](http://github.com/vadimdemedes)
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