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

react-linear-gradient-picker

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-linear-gradient-picker

React linear gradient picker

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-14.56%
Maintainers
1
Weekly downloads
 
Created
Source

react-linear-gradient-picker

This package takes any color picker for you choice, And wraps it as a gradient picker. This plays well with the package angle picker, which allows your users to play with the gradient angle.

What you need to know before installing?

  • This package is using hooks, which means you need to use React 16.8 or higher.

Installation

npm i react-linear-gradient-picker

Gradient Picker Usage

gradient_preview

import React, { useState } from 'react';
import { Panel as ColorPicker } from 'rc-color-picker';
import { GradientPicker } from 'react-linear-gradient-picker';
import 'react-linear-gradient-picker/dist/index.css';

const WrappedColorPicker = ({ onSelect, ...rest }) => (
	<ColorPicker {...rest} onChange={c => {
		onSelect(c.color, c.alpha / 100);
	}}/>
);

const App = () => {
    const [palette, setPalette] = useState([
        { offset: '0.00', color: 'rgb(238, 241, 11)' },
        { offset: '0.49', color: 'rgb(215, 128, 37)' },
        { offset: '1.00', color: 'rgb(126, 32, 207)' }
    ]);

    return (
        <GradientPicker {...{
            width: 320,
            paletteHeight: 32,
            palette,
            onPaletteChange: setPalette
        }}>
            <WrappedColorPicker/>
        </GradientPicker>
    );
};

Accepted props

NameTypeDefault ValueRequired?Description
palettePaletteColor[]undefinedYesThe gradient pickers color palette, Each palette color struct is described below
onPaletteChangeFunctionundefinedYesThe function to trigger upon palette change (Can be either from stop drag or color select).
paletteHeightNumber32NoThe stops palette display area height
widthNumber400NoDetermines the width of the gradient picker
stopRemovalDropNumber50NoSets the Y stop drop removal offset, If the user will drag the color stop further than specified, Color will be removed
maxStopsNumber5NoThe max gradient picker palette length can have
minStopsNumber2NoThe min gradient picker palette length can have

|> Palette Color

NameTypeDefault ValueRequired?Description
colorString``YesThe stop color, can be either hex of rgb format.
offsetNumber``YesThe stop color offset in percent.
opacityNumber1NoThe stop color opacity.
activeBoolean``NoRather the current color is active (selected) or not.

Gradient Picker Popover Usage

gradient_popover_preview

import React, { useState } from 'react';
import { SketchPicker } from 'react-color';
import { GradientPickerPopover } from 'react-linear-gradient-picker';
import 'react-linear-gradient-picker/dist/index.css';

const rgbToRgba = (rgb, a = 1) => rgb
	.replace('rgb(', 'rgba(')
	.replace(')', `, ${a})`)

const WrapperPropTypes = {
	onSelect: PropTypes.func
};

const WrappedSketchPicker = ({ onSelect, ...rest }) => {
	return (
		<SketchPicker {...rest}
					  color={rgbToRgba(rest.color, rest.opacity)}
					  onChange={c => {
						  const { r, g, b, a } = c.rgb;
						  onSelect(`rgb(${r}, ${g}, ${b})`, a);
					  }}/>
	);
}

const initialPallet = [
	{ offset: '0.00', color: 'rgb(238, 241, 11)' },
	{ offset: '1.00', color: 'rgb(126, 32, 207)' }
];

const App = () => {
	const [open, setOpen] = useState(false);
	const [angle, setAngle] = useState(90);
	const [palette, setPalette] = useState(initialPallet);

	return (
		<GradientPickerPopover {...{
			open,
			setOpen,
			angle,
			setAngle,
			width: 220,
			maxStops: 3,
			paletteHeight: 32,
			palette,
			onPaletteChange: setPalette
		}}>
			<WrappedSketchPicker/>
		</GradientPickerPopover>
	);
};

export default App;

Accepted props

NameTypeDefault ValueRequired?Description
triggerReact ComponentdefaultTriggerNoThe popover trigger component, Will use default implementation if empty.
openBooleanfalseYesControls the popover open state
setOpenFunctionundefinedYesThe setOpen method to be called upon open changes
showGradientTypePickerBooleantrueNoRather to show the gradientType picker control.
showAnglePickerBooleantrueNoRather to show the anglePicker picker control.
angleNumberundefinedNoThe angle picker angle value
setAngleFunctionundefinedNoThen angle picker setAngle method to be called upon angle changes
  • This component accepts all of <GradientPicker/> pros.

Angle Picker Usage

gradient_preview

import React, { useState } from 'react';
import { AnglePicker } from 'react-linear-gradient-picker';
import 'react-linear-gradient-picker/dist/index.css';

const App = () => {
    const [angle, setAngle] = useState(25);

    return (
        <AnglePicker angle={angle} setAngle={setAngle}/>
    );
};

Accepted props

NameTypeDefault ValueRequired?Description
angleNumberundefinedYesThe controlled angle.
setAngleFunctionundefinedYesThe set angle method to be trigger after an angle was changes.
sizeNumber48NoDetermines the size of the angle picker
snapNumber5NoDetermines the angle change snapping, Can be removed with setting as 0

Keywords

FAQs

Package last updated on 23 Jul 2022

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