A highly customizable, fully typed & tested color eye-dropper for your React project.
With flexibility in mind, let your users eye drop anything in your app within a minute.
React Component or React Hook, you have both at your disposal.
A example project is included for basic usage of both Component & Hook.
Yarn:
yarn add react-eyedrop
NPM:
npm install --save react-eyedrop
required
function
{ rgb: string, hex: string, customProps: object }
Example:
function onChange({ rgb, hex }) {
/* Do stuff */
}
<!-------->
<EyeDropper onChange={onChange} />
string
Example:
<EyeDropper wrapperClasses="my-css-class" />
/* or even */
<EyeDropper wrapperClasses={`my-css-class ${active ? 'my-active-css-class' : ''}`} />
string
Example:
<EyeDropper buttonClasses="my-css-class" />
/* or even */
<EyeDropper buttonClasses={`my-css-class ${active ? 'my-active-css-class' : ''}`} />
React Node
onClick
prop which gets passed down.Example:
const Button = ({ onClick }) =>
<button className="btn" onClick={onClick} >My custom button</button>
<!-------->
<EyeDropper customComponent={Button} />
object
Example:
const onChange = ({ rgb, hex, customProps }) => {
const { data1, data2, } = customProps
}
<!-------->
<Eyedropper customComponent={Button} customProps={{data1, data2, data3}} onChange={onChange}/>
string
Example:
const Button = ({ onClick, pixelColors }) =>
<button className="btn" onClick={onClick} style={{backgroundColor: pixelColors.hex}}>My custom button</button>
<!-------->
<EyeDropper customComponent={Button} colorsPassThrough='pixelColors' />
boolean
Example:
const Button = ({ onClick, disabled }) =>
<button className="btn" onClick={onClick} disabled={disabled} >My custom button</button>
boolean
true
false
-> true
during runtime)Example:
<EyeDropper once />
/* or */
<EyeDropper once={false} />
number
0-450
Example:
<EyeDropper pickRadius={1} />
string
copy
Example:
<EyeDropper cursorActive="cursor" />
string
auto
Example:
<EyeDropper cursorActive="auto" />
function
Example:
function getPeanut() {
console.log('Mmm... Definately overrated.')
}
<!-------->
<EyeDropper onInit={getPeanut} />
/* Will be called when component is mounted */
function
Example:
function getBananas() {
console.log('Ahhh... Much better.')
}
<!-------->
<EyeDropper onPickStart={getBananas} />
/* Will be called when starting to EyeDrop */
function
Example:
function buyBurritos() {
console.log('Yum!')
}
<!-------->
<EyeDropper onPickEnd={buyBurritos} />
/* Will be called when you finish EyeDropping */
colors
will contain whatever is clicked once pickColor
is called.
Call cancelPickColor
to stop picking colors. :zany_face:
Example:
import { useEyeDrop } from 'react-eyedrop'
const [colors, pickColor, cancelPickColor] = useEyeDrop({
once: boolean,
pickRadius: number,
cursorActive: CSS Cursors,
cursorInactive: CSS Cursors,
onPickStart?: () => void
onPickEnd?: () => void
onPickCancel?: () => void
})
Run the unit tests locally:
npm i
/* or */
yarn
/* and then */
npm run test
onPickEnd
propertyonPickEnd
since same functionality can be achieved with handleChangeimg
tags on the DOMpickRadius
feature to work with different units; radius & pixel.pickRadius
featurebuttonComponent
to customComponent
Manjodh "Mango" Singh – manjodheriksingh@gmail.com
Distributed under the MIT license. See license for more information.
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)