npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-linear-gradient-picker

v3.0.1

Published

React linear gradient picker

Downloads

8,797

Readme

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

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

| Name | Type | Default Value | Required? | Description |-|-|-|-|- | palette | PaletteColor[] | undefined | Yes | The gradient pickers color palette, Each palette color struct is described below | onPaletteChange | Function | undefined | Yes | The function to trigger upon palette change (Can be either from stop drag or color select). | paletteHeight | Number | 32 | No | The stops palette display area height | width | Number | 400 | No | Determines the width of the gradient picker | stopRemovalDrop | Number | 50 | No | Sets the Y stop drop removal offset, If the user will drag the color stop further than specified, Color will be removed | maxStops | Number | 5 | No | The max gradient picker palette length can have | minStops | Number | 2 | No | The min gradient picker palette length can have

|> Palette Color | Name | Type | Default Value | Required? | Description |-|-|-|-|- | color | String | | Yes | The stop color, can be either hex of rgb format. | `offset`| `Number` | | Yes | The stop color offset in percent. | opacity| Number | 1 | No | The stop color opacity. | active| Boolean | `` | No | Rather the current color is active (selected) or not.

Gradient Picker Popover Usage

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

| Name | Type | Default Value | Required? | Description |-|-|-|-|- | trigger | React Component | defaultTrigger | No | The popover trigger component, Will use default implementation if empty. | open | Boolean | false | Yes | Controls the popover open state | setOpen | Function | undefined | Yes | The setOpen method to be called upon open changes | showGradientTypePicker | Boolean | true | No | Rather to show the gradientType picker control. | showAnglePicker | Boolean | true | No | Rather to show the anglePicker picker control. | angle | Number | undefined | No | The angle picker angle value | setAngle | Function | undefined | No | Then angle picker setAngle method to be called upon angle changes

  • This component accepts all of <GradientPicker/> pros.

Angle Picker Usage

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

| Name | Type | Default Value | Required? | Description |-|-|-|-|- | angle | Number | undefined | Yes | The controlled angle. | setAngle | Function | undefined | Yes | The set angle method to be trigger after an angle was changes. | size | Number | 48 | No | Determines the size of the angle picker | snap | Number | 5 | No | Determines the angle change snapping, Can be removed with setting as 0