JSPM

  • Created
  • Published
  • Downloads 23272
  • Score
    100M100P100Q151281F
  • License MIT

Pure JavaScript color picker for react-native

Package Exports

  • reanimated-color-picker
  • reanimated-color-picker/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (reanimated-color-picker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🔴 🟢 🔵

Reanimated Color Picker

npm GitHub GitHub issues Platform

- Pure JavaScript color picker for react-native.

- Highly customizable.

- Supports IOS, Android, Expo, and Web platforms.

- Supports right to left (RTL) layout.

⚠️ ⚠️ Warning ⚠️ ⚠️

  • This project is still in the beta stage.
  • Some properties may change.

Example_1 Example_2 Example_3 Example_4

🔹 Table of contents

🔹Prerequisites

🔹Installation

Note First we need to install react-native-gesture-handler(>=2.0.0) and react-native-reanimated(>=2.0.0),

  • Open a Terminal in the project root and run:
npm i reanimated-color-picker

🔹Usage

import React, { useState } from 'react';
import { Button, Modal, StyleSheet, View } from 'react-native';

import ColorPicker, { Panel1, Swatches, Preview, OpacitySlider, HueSlider } from 'reanimated-color-picker';

export default function App() {
  const [showModal, setShowModal] = useState(false);

  const onSelectColor = ({ hex }) => {
    // do something with the selected color.
    console.log(hex);
  };

  return (
    <View style={styles.container}>
      <Button title='Color Picker' onPress={() => setShowModal(true)} />

      <Modal visible={showModal} animationType='slide'>
        <ColorPicker style={{ width: '70%' }} value='red' onComplete={onSelectColor}>
          <Preview />
          <Panel1 />
          <HueSlider />
          <OpacitySlider />
          <Swatches />
        </ColorPicker>

        <Button title='Ok' onPress={() => setShowModal(false)} />
      </Modal>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
  },
});

🔹API

🔺ColorPicker Wrapper

  • The ColorPicker Wrapper is responsible for managing the built-in components.

  • It has the following props:

▫️value

  • The initial value of the color picker.
  • Accepts 'hex', 'rgb', 'rgba', 'hsl', 'hsla' and named color formats.
  • type: string
  • default: '#418181'

▫️sliderThickness

  • A global property to change the thickness of all descendant sliders components.
  • The thickness is the slider's width in case of vertical orientation and height in case of horizontal orientation.
  • type: number
  • default: 25

▫️thumbSize

  • A global property to change the thumb size of all descendant sliders components.
  • type: number
  • default: 35

▫️thumbShape

  • A global property to change the shape and appearance of the thumb of all descendant sliders components.
  • type: string
  • default: 'ring'
  • values: 'ring' | 'solid' | 'hollow' | 'line' | 'plus' | 'pill' | 'triangleUp' | 'triangleDown' | 'doubleTriangle' | 'rect' | 'circle'

▫️style

  • Color picker's container style.
  • If you want to change the width using the width property.
  • type: ViewStyle

Note some style properties will be overwritten.

▫️onChange

  • Called every time the color value changed.
  • The passed color object has the following properties: hex, rgb, rgba, hsl, and hsla
  • type: (color: object) => void
  • default: null

▫️onComplete

  • Called when the user releases the slider handle or when a swatch is clicked.
  • The passed color object has the following properties: hex, rgb, rgba, hsl, and hsla
  • type: (color: object) => void
  • default: null

🔺Built-in Components

🔸<Preview />

preview

  • The preview of the selected and the initial color.
Property Type Default Description
colorFormat string 'hex' preview color text format: 'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'hsv' or 'hsva'
hideInitialColor boolean false hide the initial color preview part
hideText boolean false hide preview color texts
style ViewStyle / preview container style
textStyle TextStyle / preview text style

Note some style properties will be overwritten.

🔸<PreviewText />

  • A React Native <Text> component that displays the preview color text.
Property Type Default Description
colorFormat string 'hex' preview color text format: 'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'hsv' or 'hsva'
style TextStyle / preview text style

🔸<Panel1 />

panel1

  • A square-shaped slider (adobe style) is used for changing the color's brightness and saturation.

Note you need to add <HueSlider /> alongside with it.

Property Type Default Description
thumbSize number 35 panel's handle (thumb) size (height*width)
thumbColor string interactive* change thumb's color
thumbShape string 'ring' change thumb's shape: 'ring', 'solid', 'hollow', 'line', 'plus', 'pill', 'triangleUp', 'triangleDown', 'doubleTriangle'
style ViewStyle / panel's container style

Note some style properties will be overwritten.

*️⃣ interactive: the thumb color will be changed depending on the contrast ratio if no color value is passed.

🔸<Panel2 />

panel2

  • A square-shaped slider (windows style) is used for changing the color's hue and saturation.

Note you need to add <BrightnessSlider /> alongside with it.

Property Type Default Description
thumbSize number 35 panel's handle (thumb) size (height*width)
thumbColor string interactive* change thumb's color
thumbShape string 'ring' change thumb's shape: 'ring', 'solid', 'hollow', 'line', 'plus', 'pill', 'triangleUp', 'triangleDown', 'doubleTriangle'
reverse boolean false reverse (flip) hue direction
style ViewStyle / panel's container style

Note some style properties will be overwritten.

*️⃣ interactive: the thumb color will be changed depending on the contrast ratio if no color value is passed.

🔸<Panel3 />

panel2

  • A circle-shaped slider is used for changing the color's hue and saturation.
  • Move the handle around the center to change the color's hue.
  • Move the handle away or toward the center to change the color's saturation.

Note you need to add <BrightnessSlider /> alongside with it.

Property Type Default Description
thumbSize number 35 panel's handle (thumb) size (height*width)
thumbColor string interactive* change thumb's color
thumbShape string 'ring' change thumb's shape: 'ring', 'solid', 'hollow', 'line', 'plus', 'pill', 'triangleUp', 'triangleDown', 'doubleTriangle'
style ViewStyle / panel's container style

Note some style properties will be overwritten.

*️⃣ interactive: the thumb color will be changed depending on the contrast ratio if no color value is passed.

🔸<HueSlider />

hue

  • A slider to change the color's hue.

  • Check out the Slider Props for more info.

🔸<SaturationSlider />

saturation

  • A slider to change the color's saturation.

  • Check out the Slider Props for more info.

🔸<BrightnessSlider />

brightness

  • A slider to change the color brightness.

  • Check out the Slider Props for more info.

🔸<OpacitySlider />

opacity

  • A slider to change the color's opacity.

  • Check out the Slider Props for more info.

🔸<Swatches />

swatches

  • A list of colored swatches is used for quick color selection.
Property Type Default Description
colors string[] material colors custom swatches colors
style ViewStyle / swatches container style
swatchStyle ViewStyle / swatch style

Note some style properties will be overwritten.

🔹Slider Props

  • HueSlider, SaturationSlider, BrightnessSlider and OpacitySlider sliders accept the following props:

▫️thumbSize

  • The size of the slider's thumb.
  • type: number
  • default: 35

▫️thumbColor

  • The color of the slider's thumb.
  • type: string
  • default: interactive*

*️⃣ interactive: the thumb color will be changed depending on the contrast ratio if no color value is passed.

▫️thumbShape

  • The shape and appearance of the slider's thumb.
  • type: string
  • default: 'ring'
  • values: 'ring' | 'solid' | 'hollow' | 'line' | 'plus' | 'pill' | 'triangleUp' | 'triangleDown' | 'doubleTriangle' | 'rect' | 'circle'

▫️reverse

  • Reverse the slider direction.
  • type: boolean
  • default: false

▫️vertical

  • Change the slider orientation.
  • type: boolean
  • default: false

▫️style

  • The style of the slider's container.
  • type: ViewStyle

Note some style properties will be overwritten.

🔹Examples

🔹License