Repository: hxf31891/react-gradient-color-picker
Branch: main
Commit: e97eba085d67
Files: 42
Total size: 149.8 KB
Directory structure:
gitextract__r_hbhn9/
├── .github/
│ └── workflows/
│ ├── pull-request.yml
│ └── release-package.yml
├── .gitignore
├── .npmignore
├── .nvmrc
├── .prettierrc
├── LICENSE
├── README.md
├── biome.json
├── package.json
├── src/
│ ├── components/
│ │ ├── AdvancedControls.tsx
│ │ ├── ComparibleColors.tsx
│ │ ├── Controls.tsx
│ │ ├── EyeDropper.tsx
│ │ ├── GradientBar.tsx
│ │ ├── GradientControls.tsx
│ │ ├── Hue.tsx
│ │ ├── Inputs.tsx
│ │ ├── Opacity.tsx
│ │ ├── Picker.tsx
│ │ ├── Portal.tsx
│ │ ├── Presets.tsx
│ │ ├── Square.tsx
│ │ ├── icon.tsx
│ │ └── index.tsx
│ ├── constants.ts
│ ├── context.tsx
│ ├── hooks/
│ │ ├── useColorPicker.ts
│ │ ├── usePaintHue.ts
│ │ └── usePaintSquare.ts
│ ├── index.ts
│ ├── shared/
│ │ └── types.ts
│ ├── styles/
│ │ ├── darkStyles.ts
│ │ └── styles.ts
│ └── utils/
│ ├── converters.ts
│ ├── formatters.ts
│ ├── gradientParser.ts
│ └── utils.ts
├── test/
│ ├── gradientParser.spec.js
│ └── utils.spec.js
├── tsconfig.build.json
└── tsconfig.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/pull-request.yml
================================================
name: Run tests
on: pull_request
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm i -g npm@latest
- run: npm ci
- run: npm test
run-eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm i -g npm@latest
- run: npm ci
- run: npm run eslint
================================================
FILE: .github/workflows/release-package.yml
================================================
name: Release Package
on:
release:
types: [created]
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm i -g npm@latest
- run: npm ci
- run: npm test
run-eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm i -g npm@latest
- run: npm ci
- run: npm run eslint
publish-gpr:
needs:
- run-tests
- run-eslint
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm i -g npm@latest
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
================================================
FILE: .gitignore
================================================
# OS
.DS_Store
# Cache
.cache
.playwright
.tmp
*.tsbuildinfo
.eslintcache
# Yarn
.pnp.*
**/.yarn/*
!**/.yarn/patches
!**/.yarn/plugins
!**/.yarn/releases
!**/.yarn/sdks
!**/.yarn/versions
# Project-generated directories and files
coverage
dist
node_modules
playwright-report
test-results
package.tgz
# Logs
npm-debug.log
yarn-error.log
# .env files
**/.env
**/.env.*
!**/.env.example
================================================
FILE: .npmignore
================================================
/*.log
/*.DS_Store
/.idea
/.gitignore
/node_modules/
/.github/
/src/
/babel.config.js
**/*.spec.js
/.eslintignore
/.prettierrc
/.eslintrc.js
================================================
FILE: .nvmrc
================================================
v16
================================================
FILE: .prettierrc
================================================
{
"endOfLine": "lf",
"semi": false,
"singleQuote": true,
"useTabs": false,
"trailingComma": "es5"
}
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2022 Harry Fox
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
[![Npm Version][npm-version-image]][npm-version-url]
[![Downloads][downloads-image]][downloads-url]
[![License][license-image]][license-url]
# react-best-gradient-color-picker
- Customizable, easy to use color and gradient picker for React.js
- Simply pass in an rgba or css gradient string as value and an onChange handler
- Variety of optional tools like eye dropper, advanced color settings, and color guide
- use the useColorPicker hook for complete control over of the picker
- You can completly customize the UI by hiding the included elements and using the hook to build your own
- You can also customize preset options by passing in an array of rgba colors (see custom presets below)
## Install
```
npm install react-best-gradient-color-picker
```
```
yarn add react-best-gradient-color-picker
```
## Demo
See the picker in action [here](https://gradient-package-demo.web.app/)
**Table of Contents**
- [Basic Example](#item-three)
- [Props](#item-four)
- [API](#item-five)
- [useColorPicker Hook](#item-six)
- [Hook Basic Example](#item-seven)
- [Hook Functions](#item-eight)
- [Hook State](#item-nine)
- [More Hook Examples](#item-ten)
- [Styling](#item-fifteen)
- [Legacy Options](#item-eleven)
- [Roadmap](#item-twelve)
- [License](#item-thirteen)
- [Acknowledgments](#item-fourteen)
## Basic Example
```js
import React from 'react'
import ColorPicker from 'react-best-gradient-color-picker'
function MyApp() {
const [color, setColor] = useState('rgba(255,255,255,1)');
return
### Props
| Name | Type | Default | Description |
|---------------------|--------------| ----------------------- |---------------------------------------------------------------------------|
| value | `string` | 'rgba(175, 51, 242, 1)' | The starting color |
| width | `int` | 294 | (optional) The width of the picker |
| height | `int` | 294 | (optional) The height of the picker |
| hideInputs | `boolean` | `false` | (optional) hide the hex and rgba inputs |
| hideOpacity | `boolean` | `false` | (optional) hide the opacity bar |
| hideHue | `boolean` | `false` | (optional) hide the hue bar |
| hideControls | `boolean` | `false` | (optional) hide the entire top row of various control btns |
| hideColorTypeBtns | `boolean` | `false` | (optional) hide the solid/gradient buttons |
| hidePresets | `boolean` | `false` | (optional) hide the preset color options |
| hideEyeDrop | `boolean` | `false` | (optional) hide (and disable the eye dropper tool |
| hideAdvancedSliders | `boolean` | `false` | (optional) hide the additional sliders (saturation, luminence, brightness |
| hideColorGuide | `boolean` | `false` | (optional) hide the color guide, a tool that shows color pairings |
| hideInputType | `boolean` | `false` | (optional) hide the input type selector, looking the type |
| hideGradientType | `boolean` | `false` | (optional) hide the linear/circular gradient type toggle (only relevant in gradient mode)|
| hideGradientAngle | `boolean` | `false` | (optional) hide the gradient angle input (only relevant in gradient mode with a linear gradient)|
| hideGradientStop | `boolean` | `false` | (optional) hide the gradient point stop input (only relevant in gradient mode)|
| hideGradientControls| `boolean` | `false` | (optional) hide the all gradient controls (the bar that appears below top controls when in gradient mode)|
| hidePickerSquare | `boolean` | `false` | (optional) hide the main picker color swatch (the square that appears at the top)|
| showHexAlpha | `boolean` | `false` | (optional) add alpha (AA) channel to hex value which represents the opacity of the color|
| presets | `array` | ['rgba(0,0,0,1)', ...] | (optional) pass in custom preset options ['rgba()', 'rgba()', ..] |
| locales | `object` | { CONTROLS: { SOLID: 'Solid', GRADIENT: 'Gradient' }} | (optional) pass in custom locales |
| disableDarkMode | `boolean` | false | (optional) disable automatic dark mode style adjustments |
| disableLightMode | `boolean` | false | (optional) force the component to only use the dark mode styles |
| className | `string` | '' | (optional) a CSS class for the picker parent (see styling for more options)|
| idSuffix | `string` | '' | (optional) Adds a suffix to all the ids of the picker elements, useful when using multiple pickers on the same page|
### API
| Name | Description |
| ---------------- | ---------------------------------------------------------------- |
| onChange | A function to update color value |
# useColorPicker
- Take complete control of the picker
- Get current state
- Convert between color types
## Basic Example
- Initialize the hook by passing in the same color value and onChange handler
```js
import React from 'react'
import ColorPicker, { useColorPicker } from 'react-best-gradient-color-picker'
function MyApp() {
const [color, setColor] = useState('linear-gradient(90deg, rgba(96,93,93,1) 0%, rgba(255,255,255,1) 100%)');
const { setSolid, setGradient } = useColorPicker(color, setColor);
return(