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

Introduction to using the MySQL mysqladmin client

Table of contents 1. Check the status of the serv...

Nginx external network access intranet site configuration operation

background: The site is separated from the front ...

Clever use of webkit-box-reflect to achieve various dynamic effects (summary)

In an article a long time ago, I talked about the...

How to make vue long list load quickly

Table of contents background Main content 1. Comp...

Several ways to improve the readability of web pages

1. Use contrasting colours. The contrast here ref...

Summary of common commands for Linux user and group management

This article summarizes the common commands for L...

Implementation of Bootstrap web page layout grid

Table of contents 1. How the Bootstrap grid syste...

A simple method to regularly delete expired data records in MySQL

1. After connecting and logging in to MySQL, firs...

Vue uses Baidu Maps to realize city positioning

This article shares the specific code of Vue usin...

How to implement nginx smooth restart

1. Background During the server development proce...

How MySQL uses transactions

Basics A transaction is an atomic operation on a ...

CSS+HTML to realize the top navigation bar function

Implementation of navigation bar, fixed top navig...

Discussion on the problem of iframe node initialization

Today I suddenly thought of reviewing the producti...

Example of how to install kong gateway in docker

1. Create a Docker network docker network create ...