项目作者: tariqulislam

项目描述 :
Color Picker with Textbox and React Color. Integrated the React Color with Textbox
高级语言: JavaScript
项目地址: git://github.com/tariqulislam/react-color-picker.git
创建时间: 2018-11-21T17:43:47Z
项目社区:https://github.com/tariqulislam/react-color-picker

开源协议:

下载


React Color Picker

react-color-picker

Color picker is a important form element, which are used in website, which has color functionality, such as e-commerce site, garments related online software. Project management software and diagram related online application.

NPM Package Link

  1. https://www.npmjs.com/package/react-color-picker-text

Installation and Configure

  1. npm install --save react-color-picker-text

Import the library to jsx or js file of react application

  1. import ColorPicker from "react-color-picker-text";

Sample Code

  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3. import ColorPicker from "react-color-picker-text";
  4. import "./styles.css";
  5. class App extends Component {
  6. onColorPickerInfoChange = color => {
  7. console.log("Main Color Change", color);
  8. };
  9. render() {
  10. // change the default design of the color picker
  11. const styles = {
  12. title: "Color Picker",
  13. labelStyle: {
  14. paddingBottom: "7px",
  15. fontSize: "11px"
  16. },
  17. colorTextBoxStyle: {
  18. height: "35px",
  19. border: "none",
  20. borderBottom: "1px solid lightgray",
  21. paddingLeft: "35px"
  22. }
  23. };
  24. return (
  25. <ColorPicker
  26. onColorChange={this.onColorPickerInfoChange}
  27. title={styles.title}
  28. labelStyle={styles.labelStyle}
  29. colorTextBoxStyle={styles.colorTextBoxStyle}
  30. pickerType={"Chrome"}
  31. defaultColor={"#554"}
  32. />
  33. );
  34. }
  35. }
  36. const rootElement = document.getElementById("root");
  37. ReactDOM.render(<App ></App>, rootElement);

Get Color from Picker

From Picker we can get RGBA color and Hex Color pattern. We also get Hue Pattern by calling this function
named onColorChange as <ColorPicker> props

  1. <ColorPicker
  2. onColorChange={this.onColorPickerInfoChange} />

Then You just call the method to react class

  1. onColorPickerInfoChange = color => {
  2. console.log("Main Color Change", color);
  3. };

Change the Style of Textbox of Color picker within render function

  1. const styles = {
  2. ......
  3. colorTextBoxStyle: {
  4. height: "35px",
  5. border: "none",
  6. borderBottom: "1px solid lightgray",
  7. paddingLeft: "35px"
  8. }
  9. };

Then add it to <ColorPicker > props just like that

  1. <ColorPicker
  2. colorTextBoxStyle={styles.colorTextBoxStyle}
  3. />

Change the Style of Label and Label name of Color picker by

  1. const styles = {
  2. title: "Color Picker",
  3. labelStyle: {
  4. paddingBottom: "7px",
  5. fontSize: "11px"
  6. },
  7. };

Then add it to <ColorPicker > props just like that

  1. <ColorPicker
  2. labelStyle={styles.labelStyle}
  3. title={styles.title}
  4. />

Picker Type (pickerType: )

  1. 1. Chrome,
  2. 2. Sketch,
  3. 3. Photoshop,
  4. 4. Github,
  5. 5. Twitter,
  6. 6. Swatches,
  7. 7. Compact

Change the Type just add the props to <ColorPicker >

  1. <ColorPicker
  2. pickerType={"Github"}
  3. />

By Default This <ColorPicker /> Initial Color is Gray or #999999
Developer Can change this color by using defaultColor props in <ColorPicker>

  1. <ColorPicker
  2. defaultColor={"#554"}
  3. />