ink-spinner
Advanced tools
Comparing version 3.1.0 to 4.0.0-0
@@ -1,65 +0,26 @@ | ||
'use strict'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const { | ||
Box | ||
} = require('ink'); | ||
const spinners = require('cli-spinners'); | ||
class Spinner extends React.Component { | ||
constructor(...args) { | ||
super(...args); | ||
_defineProperty(this, "state", { | ||
frame: 0 | ||
}); | ||
_defineProperty(this, "switchFrame", () => { | ||
const { | ||
frame | ||
} = this.state; | ||
const spinner = this.getSpinner(); | ||
const isLastFrame = frame === spinner.frames.length - 1; | ||
const nextFrame = isLastFrame ? 0 : frame + 1; | ||
this.setState({ | ||
frame: nextFrame | ||
}); | ||
}); | ||
} | ||
render() { | ||
const spinner = this.getSpinner(); | ||
return /*#__PURE__*/React.createElement(Box, null, spinner.frames[this.state.frame]); | ||
} | ||
componentDidMount() { | ||
const spinner = this.getSpinner(); | ||
this.timer = setInterval(this.switchFrame, spinner.interval); | ||
} | ||
componentWillUnmount() { | ||
clearInterval(this.timer); | ||
} | ||
getSpinner() { | ||
return spinners[this.props.type] || spinners.dots; | ||
} | ||
} | ||
_defineProperty(Spinner, "propTypes", { | ||
type: PropTypes.string | ||
}); | ||
_defineProperty(Spinner, "defaultProps", { | ||
type: 'dots' | ||
}); | ||
module.exports = Spinner; | ||
module.exports.default = Spinner; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const React = require("react"); | ||
const react_1 = require("react"); | ||
const ink_1 = require("ink"); | ||
const cli_spinners_1 = require("cli-spinners"); | ||
/** | ||
* Spinner. | ||
*/ | ||
const Spinner = ({ type = 'dots' }) => { | ||
const [frame, setFrame] = react_1.useState(0); | ||
const spinner = cli_spinners_1.default[type]; | ||
react_1.useEffect(() => { | ||
const timer = setInterval(() => { | ||
setFrame(previousFrame => { | ||
const isLastFrame = previousFrame === spinner.frames.length - 1; | ||
return isLastFrame ? 0 : previousFrame + 1; | ||
}); | ||
}, spinner.interval); | ||
return () => { | ||
clearInterval(timer); | ||
}; | ||
}, [spinner]); | ||
return React.createElement(ink_1.Text, null, spinner.frames[frame]); | ||
}; | ||
exports.default = Spinner; |
{ | ||
"name": "ink-spinner", | ||
"version": "3.1.0", | ||
"version": "4.0.0-0", | ||
"description": "Spinner component for Ink", | ||
@@ -12,16 +12,13 @@ "license": "MIT", | ||
}, | ||
"main": "build/index.js", | ||
"types": "index.d.ts", | ||
"main": "build", | ||
"types": "build/index.d.ts", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"pretest": "npm run build", | ||
"test": "tsc --noEmit --jsx react --module commonjs index.test-d.tsx && xo && ava", | ||
"build": "babel src --out-dir=build", | ||
"prepare": "npm run build" | ||
"test": "tsc && xo && ava", | ||
"prepare": "tsc" | ||
}, | ||
"files": [ | ||
"build", | ||
"index.d.ts" | ||
"build" | ||
], | ||
@@ -39,14 +36,11 @@ "keywords": [ | ||
"dependencies": { | ||
"cli-spinners": "^1.0.0", | ||
"prop-types": "^15.5.10" | ||
"@types/react": "^16.9.38", | ||
"cli-spinners": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"@ava/babel": "^1.0.1", | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.3", | ||
"@babel/plugin-proposal-class-properties": "^7.3.3", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/register": "^7.10.3", | ||
"@babel/preset-react": "^7.10.1", | ||
"@sindresorhus/tsconfig": "^0.7.0", | ||
"@vdemedes/prettier-config": "^1.0.0", | ||
"ava": "^3.9.0", | ||
"babel-eslint": "^10.1.0", | ||
"delay": "^4.1.0", | ||
@@ -56,4 +50,7 @@ "eslint-config-xo-react": "^0.23.0", | ||
"eslint-plugin-react-hooks": "^4.0.4", | ||
"ink": "^2.0.0", | ||
"ink-testing-library": "^1.0.0", | ||
"husky": "^4.2.5", | ||
"ink": "^3.0.0-4", | ||
"ink-testing-library": "^2.0.0", | ||
"prettier": "^2.0.5", | ||
"pretty-quick": "^2.0.1", | ||
"react": "^16.8.2", | ||
@@ -65,28 +62,26 @@ "typescript": "^3.9.5", | ||
"react": "^16.8.2", | ||
"ink": "^2.0.0" | ||
"ink": "^3.0.0-4" | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
], | ||
"presets": [ | ||
"@babel/preset-react" | ||
] | ||
}, | ||
"ava": { | ||
"babel": true, | ||
"require": [ | ||
"@babel/register" | ||
] | ||
"babel": { | ||
"testOptions": { | ||
"presets": [ | ||
"@babel/preset-react" | ||
] | ||
} | ||
} | ||
}, | ||
"xo": { | ||
"parser": "babel-eslint", | ||
"extends": [ | ||
"xo-react" | ||
], | ||
"ignores": [ | ||
"index.d.ts", | ||
"index.test-d.tsx" | ||
] | ||
"extends": "xo-react", | ||
"prettier": true, | ||
"rules": { | ||
"react/prop-types": "off" | ||
} | ||
}, | ||
"prettier": "@vdemedes/prettier-config", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} |
@@ -1,5 +0,6 @@ | ||
# ink-spinner [![Build Status](https://travis-ci.org/vadimdemedes/ink-spinner.svg?branch=master)](https://travis-ci.org/vadimdemedes/ink-spinner) | ||
# ink-spinner ![test](https://github.com/vadimdemedes/ink-spinner/workflows/test/badge.svg) | ||
> Spinner component for [Ink](https://github.com/vadimdemedes/ink). Uses [cli-spinners](https://github.com/sindresorhus/cli-spinners) for the collection of spinners. | ||
Looking for a version compatible with Ink 2.x? Check out [previous release](https://github.com/vadimdemedes/ink-spinner/tree/v3.1.0). | ||
@@ -12,15 +13,16 @@ ## Install | ||
## Usage | ||
```js | ||
import React, {Fragment} from 'react'; | ||
import {render, Color} from 'ink'; | ||
```jsx | ||
import React from 'react'; | ||
import { render, Text } from 'ink'; | ||
import Spinner from 'ink-spinner'; | ||
render( | ||
<Fragment> | ||
<Color green><Spinner type="dots"/></Color> | ||
<Text> | ||
<Text color="green"> | ||
<Spinner type="dots" /> | ||
</Text> | ||
{' Loading'} | ||
</Fragment> | ||
</Text> | ||
); | ||
@@ -31,3 +33,2 @@ ``` | ||
## Props | ||
@@ -41,6 +42,1 @@ | ||
Type of a spinner. See [cli-spinners](https://github.com/sindresorhus/cli-spinners) for available spinners. | ||
## License | ||
MIT © [Vadim Demedes](https://github.com/vadimdemedes) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4777
42
2
40
+ Added@types/react@^16.9.38
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@16.14.62(transitive)
+ Added@types/scheduler@0.16.8(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcli-boxes@2.2.1(transitive)
+ Addedcli-spinners@2.9.2(transitive)
+ Addedcode-excerpt@3.0.0(transitive)
+ Addedconvert-to-spaces@1.0.2(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedescape-string-regexp@2.0.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedink@3.2.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedpatch-console@1.0.0(transitive)
+ Addedreact@17.0.2(transitive)
+ Addedreact-devtools-core@4.28.5(transitive)
+ Addedreact-reconciler@0.26.2(transitive)
+ Addedscheduler@0.20.2(transitive)
+ Addedshell-quote@1.8.1(transitive)
+ Addedstack-utils@2.0.6(transitive)
+ Addedtype-fest@0.12.0(transitive)
+ Addedws@7.5.10(transitive)
- Removedprop-types@^15.5.10
- Removedansi-escapes@3.2.0(transitive)
- Removedansi-regex@4.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedarrify@2.0.1(transitive)
- Removedastral-regex@1.0.0(transitive)
- Removedchalk@3.0.0(transitive)
- Removedcli-cursor@2.1.0(transitive)
- Removedcli-spinners@1.3.1(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedink@2.7.1(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedlodash.throttle@4.1.1(transitive)
- Removedlog-update@3.4.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedonetime@2.0.1(transitive)
- Removedreact-reconciler@0.24.0(transitive)
- Removedrestore-cursor@2.0.0(transitive)
- Removedscheduler@0.18.0(transitive)
- Removedstring-length@3.1.0(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedwrap-ansi@5.1.0(transitive)
Updatedcli-spinners@^2.3.0