How to use react-color to implement the front-end color picker

How to use react-color to implement the front-end color picker

background

We can use react-color to implement the color picker of the front-end interface, as shown in the following figure:

insert image description here

Install

npm i react-color -S

use

import React, { Component, Fragment, createRef } from 'react';
import { Popover } from 'antd';
import { SketchPicker } from 'react-color';

type StateType = {
  subtitleColor: string;
};
type PropType = {
  [propName: string]: any;
};
interface HandleCreateVideoByHotNews {
  state: StateType;
  props: PropType;
}

class HandleCreateVideoByHotNews extends Component {
  constructor(props: any) {
    super(props);
    this.state = {
      subtitleColor: '#FFF',
    }
  }

  // Change the subtitle font color private setSubtitleFontColor = (e: any): void => {
    console.log(e);
    this.setState({
      subtitleColor: e.hex,
    });
  }

  render() {
    const { subtitleColor } = this.state;

    return (
      <Popover
        content={<SketchPicker color={subtitleColor}
        onChange={(e) => {this.setSubtitleFontColor(e)}}
        onChangeComplete={(e) => {this.setSubtitleFontColor(e)}} />}
        trigger="click"
      >
        <div className="create-hotnews-video-popup-operate-item-titleset-item-operate font-color-set">
          <div className="font-color-set-value">{subtitleColor}</div>
          <div className="font-color-set-show" style={{backgroundColor: subtitleColor}}></div>
        </div>
      </Popover>
    )
  }
}

export default HandleCreateVideoByHotNews;


This is the end of this article about using react-color to implement a front-end color picker. For more related ct-color front-end color picker content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Teach you how to implement a circular/fan-shaped menu in 2 minutes (basic version)

>>:  Detailed analysis of compiling and installing vsFTP 3.0.3

Recommend

Vue implements automatic jump to login page when token expires

The project was tested these days, and the tester...

MySQL 8.0.24 installation and configuration method graphic tutorial

This article shares the installation tutorial of ...

Detailed explanation of Vue's monitoring properties

Table of contents Vue monitor properties What is ...

HTML is actually the application of learning several important tags

After the article "This Will Be a Revolution&...

Detailed explanation of Linx awk introductory tutorial

Awk is an application for processing text files, ...

A practical record of an accident caused by MySQL startup

Table of contents background How to determine whe...

Detailed instructions for installing SuPHP on CentOS 7.2

By default, PHP on CentOS 7 runs as apache or nob...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

Example code for making the pre tag automatically wrap

The pre element defines preformatted text. Text en...

A detailed discussion of components in Vue

Table of contents 1. Component Registration 2. Us...

Two methods of restoring MySQL data

1. Introduction Some time ago, there were a serie...

Gradient slide effect implemented by CSS3

Achieve results Code html <div class="css...