GithubHelp home page GithubHelp logo

doc22940 / vue-colorpicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caohenghu/vue-colorpicker

1.0 2.0 0.0 786 KB

Colorpicker of Vue Components

Home Page: https://caohenghu.github.io/vue-colorpicker

JavaScript 20.87% Vue 79.13%

vue-colorpicker's Introduction

vue-colorpicker

preview-dark preview-light

Install

$ yarn add @caohenghu/vue-colorpicker

Example

<template>
    <div :style="{background: color}">
        <color-picker
            theme="light"
            :color="color"
            :sucker-hide="false"
            :sucker-canvas="suckerCanvas"
            :sucker-area="suckerArea"
            @changeColor="changeColor"
            @openSucker="openSucker"
        />
    </div>
</template>

<script>
    import colorPicker from '@caohenghu/vue-colorpicker'

    export default {
        components: {
            colorPicker
        },
        data() {
            return {
                color: '#59c7f9',
                suckerCanvas: null,
                suckerArea: [],
                isSucking: false
            }
        },
        methods: {
            changeColor(color) {
                const { r, g, b, a } = color.rgba
                this.color = `rgba(${r}, ${g}, ${b}, ${a})`
            },
            openSucker(isOpen) {
                if (isOpen) {
                    // ... canvas be created
                    // this.suckerCanvas = canvas
                    // this.suckerArea = [x1, y1, x2, y2]
                } else {
                    // this.suckerCanvas && this.suckerCanvas.remove
                }
            }
        }
    }
</script>

Options

Name Type Default Description
theme String dark dark or light
color String #000000 rgba or hex
colors-default Array ['#000000', '#FFFFFF', '#FF1900', '#F47365', '#FFB243', '#FFE623', '#6EFF2A', '#1BC7B1', '#00BEFF', '#2E81FF', '#5D61FF', '#FF89CF', '#FC3CAD', '#BF3DCE', '#8E00A7', 'rgba(0,0,0,0)'] like ['#ff00ff', '#0f0f0f', ...]
colors-history-key String vue-colorpicker-history
sucker-hide Boolean true true or false
sucker-canvas HTMLCanvasElement null like document.createElement('canvas')
sucker-area Array [] like [x1, y1, x2, y2]

color is one-way data flow, so you can't use v-model. why? because you'll listen changeColor event do more things, so i think it's not necessary here.

Events

Name Type Args Description
changeColor Function color { rgba: {}, hsv: {}, hex: ''}
openSucker Function isOpen true or false

if you want use sucker, then openSucker, sucker-hide, sucker-canvas, sucker-area is necessary. when you click sucker button, you can click it again or press key of esc to exit.

vue-colorpicker's People

Contributors

caohenghu avatar cs09g avatar jbienesdev avatar

Stargazers

Acampbell avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.