# bone-cp

> Color picker for react native

Latest version **1.0.6** (published 2017-11-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install bone-cp
pnpm add bone-cp
yarn add bone-cp
bun add bone-cp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-11-16 |
| First published | 2017-04-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | instea.co |
| Maintainers | ilp64 |

## Links

- npm: https://www.npmjs.com/package/bone-cp
- Repository: https://github.com/ilp64/react-native-color-picker
- Homepage: https://github.com/instea/react-native-color-picker#readme
- Issues: https://github.com/ilp64/react-native-color-picker.git
- npm.io page: https://npm.io/package/bone-cp

## Dependencies (2)

- [tinycolor2](https://npm.io/package/tinycolor2.md) ^1.4.1
- [@ptomasroos/react-native-multi-slider](https://npm.io/package/@ptomasroos/react-native-multi-slider.md) 0.0.11

## Recent versions

- 1.0.6 (latest) — 2017-11-16
- 1.0.5 — 2017-11-15
- 1.0.4 — 2017-11-13
- 1.0.3 — 2017-10-20
- 1.0.2 — 2017-08-10
- 1.0.1 — 2017-04-12
- 1.0.0 — 2017-04-12

## README

# react-native-color-picker

React Native implementation of color picker for both Android and iOS.

![android preview](doc/preview_android.png)
![iphone preview](doc/preview_iphone.png)

* [x] works both in controlled and uncontrolled way
* [x] old color can be displayed for visual comparison
* [x] holo and triangle color pickers

## Getting started
Install the color picker
```
npm install react-native-color-picker --save
```
And use it in your application
```javascript
import { ColorPicker } from 'react-native-color-picker'

const Picker = () => (
  <ColorPicker
    onColorSelected={color => alert(`Color selected: ${color}`)}
    style={{flex: 1}}
  />
)
```
Color picker will use space you provide. Therefore it is necessary to provide styles that will determine picker's size.

## API

### Color picker type

We provide two types of color picker - holo (default) and triangle color picker. Both has the same API so that they are interchangable. Just import it and use it the same way:

```javascript
import { ColorPicker, TriangleColorPicker } from 'react-native-color-picker'
```

| ColorPicker | TriangleColorPicker |
| ----------- | ------------------- |
| ![](doc/holo.png) | ![](doc/triangle.png) |


### Props

Color pickers accepts properties below. Each property which define color is represented as a [color string](https://github.com/bgrins/TinyColor#accepted-string-input).

| Property | Type | Note |
|--------------------|------------|--------|
|`color`             |`String|HSV`|[Color string](https://github.com/bgrins/TinyColor#accepted-string-input) or HSV object (see below). Defines selected color in controlled component. |
|`defaultColor`      |`String`    |Defines initial selected color in uncontrolled component.|
|`oldColor`          |`String`    |Old color to be used for visual comparision. If it is not defined, whole circle is representing selected color.|
|`style`             |`Style`     |Styles passed to color picker container|
|`onColorSelected`   |`Function`  |Callback with color (HEX string) as argument called when user confirms color selection.|
|`onColorChange`     |`Function`  |Callback called each time when color is changed. Used in controlled component. Argument is color in HSV representation (see below)|
|`onOldColorSelected`|`Function`  |Callback with color (HEX string) as argument called when user selects old color.|

When using color picker as a controlled component you should always use HSV color representation to avoid conversion from/to HEX or RGB. HSV color representation is an object literal with properties:

```javascript
{
  h: number, // <0, 360>
  s: number, // <0, 1>
  v: number, // <0, 1>
}

```

### Helper functions

To utilize HSV -> HEX/RGB conversion we provide helper functions:

```javascript
import { toHsv, fromHsv } from 'react-native-color-picker'

toHsv('blue') // { h: 24, s: 1, v: 1 }

fromHsv({ h: 200, s: 0.4, v:0.4 }) // #3d5866

```

## Examples

* [Uncontrolled picker](examples/src/ExampleUncontrolledVertical.js)
* [Controlled picker](examples/src/ExampleControlledVertical.js)
* [Uncontrolled triangle picker](examples/src/ExampleUncontrolledTriangle.js)
* [Controlled triangle picker](examples/src/ExampleControlledTriangle.js)

## Limitations
* Does not work well within `ScrollView` due to touch event interference.

## Thanks
Our implementation was inspired by [Android Holo ColorPicker](https://github.com/LarsWerkman/HoloColorPicker)

---
_Source: https://npm.io/package/bone-cp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
