1.1.9 • Published 11 months ago

vue-color-cmstop v1.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

vue-color-cmstop

LiveDemo

preview-dark preview-light

Install

$ yarn add vue-color-cmstop

Example

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

<script>
  import { ColorPicker } from 'vue-color-cmstop'
  import 'vue-color-cmstop/dist/vue-color-cmstop.css'

  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
        }
      },
      inputFocus(event: FocusEvent) {
        // this will get triggered on input field (hex and rgba) get focus
        // prop value will be FocusEvent object associated with the input
      },
      inputBlur(event: FocusEvent) {
        // this  will get triggeredon input field (hex and rgba) get out of focus (blur event)
        // prop value will be FocusEvent object associated with the input
      },
    },
  }
</script>

Options

NameTypeDefaultDescription
themeStringdarkdark or light
colorString#000000rgba or hex
colors-defaultArray['#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-keyStringvue-color-cmstop-history
sucker-hideBooleantruetrue or false
sucker-canvasHTMLCanvasElementnulllike document.createElement('canvas')
sucker-areaArray[]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

NameTypeArgsDescription
changeColorFunctioncolor{ rgba: {}, hsv: {}, hex: ''}
openSuckerFunctionisOpentrue or false
inputFocusFunctionEventFocusEvent Object
inputBlurFunctionEventFocusEvent Object

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.

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.9

11 months ago

1.0.8

12 months ago