🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

ink-gradient

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ink-gradient - npm Package Compare versions

Comparing version
2.0.0
to
3.0.0
+35
dist/index.d.ts
import { type FC as ReactFC, type ReactNode } from 'react';
export type GradientName = 'cristal' | 'teen' | 'mind' | 'morning' | 'vice' | 'passion' | 'fruit' | 'instagram' | 'atlas' | 'retro' | 'summer' | 'pastel' | 'rainbow';
export type GradientColors = Array<string | Record<string, unknown>>;
export type Props = {
readonly children: ReactNode;
/**
The name of a [built-in gradient](https://github.com/bokub/gradient-string#available-built-in-gradients).
Mutually exclusive with `colors`.
*/
readonly name?: GradientName;
/**
[Colors to use to make the gradient.](https://github.com/bokub/gradient-string#initialize-a-gradient)
Mutually exclusive with `name`.
*/
readonly colors?: GradientColors;
};
/**
@example
```
import React from 'react';
import {render} from 'ink';
import Gradient from 'ink-gradient';
import BigText from 'ink-big-text';
render(
<Gradient name="rainbow">
<BigText text="unicorns"/>
</Gradient>
);
```
*/
declare const Gradient: ReactFC<Props>;
export default Gradient;
import React from 'react';
import { Transform } from 'ink';
import PropTypes from 'prop-types';
import gradientString from 'gradient-string';
import stripAnsi from 'strip-ansi';
/**
@example
```
import React from 'react';
import {render} from 'ink';
import Gradient from 'ink-gradient';
import BigText from 'ink-big-text';
render(
<Gradient name="rainbow">
<BigText text="unicorns"/>
</Gradient>
);
```
*/
const Gradient = props => {
if (props.name && props.colors) {
throw new Error('The `name` and `colors` props are mutually exclusive');
}
let gradient;
if (props.name) {
gradient = gradientString[props.name];
}
else if (props.colors) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
gradient = gradientString(props.colors); // TODO: Make stronger type.
}
else {
throw new Error('Either `name` or `colors` prop must be provided');
}
const applyGradient = (text) => gradient.multiline(stripAnsi(text));
return React.createElement(Transform, { transform: applyGradient }, props.children);
};
Gradient.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,
name: PropTypes.oneOf([
'cristal',
'teen',
'mind',
'morning',
'vice',
'passion',
'fruit',
'instagram',
'atlas',
'retro',
'summer',
'pastel',
'rainbow',
]),
colors: PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
])),
};
export default Gradient;
+38
-36
{
"name": "ink-gradient",
"version": "2.0.0",
"version": "3.0.0",
"description": "Gradient color component for Ink",

@@ -13,14 +13,18 @@ "license": "MIT",

},
"main": "dist.js",
"type": "module",
"exports": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"engines": {
"node": ">=10"
"node": ">=16"
},
"scripts": {
"build": "babel index.js --out-file=dist.js",
"pretest": "npm run build",
"prepublish": "npm run build",
"pretest": "npm run build",
"test": "xo && ava"
"test": "xo && ava",
"build": "tsc"
},
"files": [
"dist.js"
"dist"
],

@@ -46,32 +50,33 @@ "keywords": [

"dependencies": {
"gradient-string": "^1.2.0",
"prop-types": "^15.7.2",
"strip-ansi": "^6.0.0"
"@types/gradient-string": "^1.1.2",
"gradient-string": "^2.0.2",
"prop-types": "^15.8.1",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.3",
"@babel/preset-react": "^7.0.0",
"ava": "^2.4.0",
"clear-module": "^4.1.1",
"eslint-config-xo-react": "^0.23.0",
"eslint-plugin-react": "^7.7.0",
"eslint-plugin-react-hooks": "^4.0.8",
"ink": "^3.0.3",
"ink-testing-library": "^2.0.1",
"react": "^16.8.2",
"xo": "^0.33.0"
},
"peerDependencies": {
"ink": ">=3.0.0",
"react": ">=16.8.0"
"ink": ">=4"
},
"babel": {
"presets": [
"@ava/stage-4",
"@babel/preset-react"
]
"devDependencies": {
"@sindresorhus/tsconfig": "^3.0.1",
"@types/react": "^18.2.10",
"ava": "^5.3.0",
"eslint-config-xo-react": "^0.27.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"ink": "^4.2.0",
"ink-testing-library": "^3.0.0",
"react": "^18.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3",
"xo": "^0.54.2"
},
"ava": {
"color": true
"color": true,
"extensions": {
"ts": "module",
"tsx": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
]
},

@@ -81,7 +86,4 @@ "xo": {

"xo-react"
],
"rules": {
"react/require-default-props": "off"
}
]
}
}

@@ -1,2 +0,2 @@

# ink-gradient [![Build Status](https://travis-ci.com/sindresorhus/ink-gradient.svg?branch=master)](https://travis-ci.com/github/sindresorhus/ink-gradient)
# ink-gradient

@@ -7,9 +7,7 @@ > Gradient color component for [Ink](https://github.com/vadimdemedes/ink)

Looking for a version compatible with Ink 2.x? Check out [this release](https://github.com/sindresorhus/ink-gradient/tree/v1.0.0).
## Install
```sh
npm install ink-gradient
```
$ npm install ink-gradient
```

@@ -35,3 +33,3 @@ ## Usage

It accepts a string or Ink component as `children`, for example, [`ink-box`](https://github.com/sindresorhus/ink-box).
It accepts a string or Ink component as `children`. For example, [`<Box/>`](https://github.com/vadimdemedes/ink#box).

@@ -44,4 +42,6 @@ #### Props

Name of a [built-in gradient](https://github.com/bokub/gradient-string#available-built-in-gradients).
The name of a [built-in gradient](https://github.com/bokub/gradient-string#available-built-in-gradients).
Mutually exclusive with `colors`.
##### colors

@@ -53,6 +53,7 @@

Mutually exclusive with `name`.
## Related
- [ink-box](https://github.com/sindresorhus/ink-box) - Box component for Ink
- [ink-big-text](https://github.com/sindresorhus/ink-big-text) - Awesome text component for Ink
- [ink-link](https://github.com/sindresorhus/ink-link) - Link component for Ink
"use strict";
var _react = _interopRequireDefault(require("react"));
var _ink = require("ink");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _gradientString = _interopRequireDefault(require("gradient-string"));
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const Gradient = props => {
if (props.name && props.colors) {
throw new Error('The `name` and `colors` props are mutually exclusive');
}
const gradient = props.name ? _gradientString.default[props.name] : (0, _gradientString.default)(props.colors);
const applyGradient = text => gradient.multiline((0, _stripAnsi.default)(text));
return /*#__PURE__*/_react.default.createElement(_ink.Transform, {
transform: applyGradient
}, props.children);
};
Gradient.propTypes = {
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]).isRequired,
name: _propTypes.default.oneOf(['cristal', 'teen', 'mind', 'morning', 'vice', 'passion', 'fruit', 'instagram', 'atlas', 'retro', 'summer', 'pastel', 'rainbow']),
colors: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]))
};
module.exports = Gradient;