Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

color picker in react js

import React from 'react'
import { SketchPicker } from 'react-color'
import reactCSS from 'reactcss'

class ColorPicker extends React.Component {
    
    state = {
      showPicker: false,
      color: {
        r: '225',
        g: '155',
        b: '99',
        a: '2',
      },
    };
 
    onClick = () => {
        this.setState({ 
          showPicker: !this.state.showPicker 
        })
    };
 
    onClose = () => {
      this.setState({ 
        showPicker: false 
      })
    };
 
    onChange = (color) => {
        this.setState({ 
          color: color.rgb 
        })
    };
 
    render() {
 
      const styles = reactCSS({
        'default': {
          color: {
            width: '40px',
            height: '15px',
            borderRadius: '3px',
            background: `rgba(${ this.state.color.r }, ${ this.state.color.g }, ${ this.state.color.b }, ${ this.state.color.a })`,
          },
          popover: {
            position: 'absolute',
            zIndex: '3',
          },
          cover: {
            position: 'fixed',
            top: '0px',
            right: '0px',
            bottom: '0px',
            left: '0px',
          },
          swatch: {
            padding: '6px',
            background: '#ffffff',
            borderRadius: '2px',
            cursor: 'pointer',
            display: 'inline-block',
            boxShadow: '0 0 0 1px rgba(0,0,0,.2)',
          },          
        },
      });
 
      return (
        <div>
          <div style={ styles.swatch } onClick={ this.onClick }>
            <div style={ styles.color } />
          </div>
          { this.state.showPicker ? <div style={ styles.popover }>
            <div style={ styles.cover } onClick={ this.onClose }/>
            <SketchPicker color={ this.state.color } onChange={ this.onChange } />
          </div> : null }
 
        </div>
      )
    }
}
 
export default ColorPicker
Comment

react color picker

import React from 'react';
import { SketchPicker } from 'react-color';

class Component extends React.Component {

  render() {
    return <SketchPicker />;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: mariadb javascript 
Javascript :: remove btn 
Javascript :: multiselect 
Javascript :: can we get the value of form control after disabling it angular 
Javascript :: push element in array javascript 
Javascript :: examples of Conditional Operator js 
Javascript :: axios display nested json console.log 
Javascript :: is missing in props validationeslintreact/prop-types 
Javascript :: javascript get name from steamid 
Javascript :: angular turn text into input 
Javascript :: use axios cancel token in react.js useEffect 
Javascript :: react use media query 
Javascript :: What Is A ReadableStream 
Javascript :: javascript rest parameters vs spread operator 
Javascript :: get coords of html element js 
Javascript :: jest test thunk 
Javascript :: today tomorrow day after tomorrow button html and javascript 
Javascript :: discord.js bot presence 
Javascript :: react hooks example 
Javascript :: create a drop down to select time javascript 
Javascript :: jquery slick drag goes back 
Javascript :: Calendar Time momentjs 
Javascript :: mongodb find array with element 
Javascript :: shopify get list of all products ajax api 
Javascript :: js show element 
Javascript :: update password using comparePassword() Method 
Javascript :: canvas set line opacity 
Javascript :: javascript concatenation 
Javascript :: phaser generate frame numbers 
Javascript :: promise .then javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =