1.0.9 • Published 2 years ago

v3-color-picker-teleport v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

v3-color-picker

Vue3.0 原生颜色选择器,与浏览器自带几乎一样,支持 Vite2.0,可以实现将选择器添加到指定 Element,也能解决相对定位问题,npm 地址

演示

安装

NPM

npm install v3-color-picker-teleport

yarn add v3-color-picker-teleport

使用(Vite 情况下同样使用)

// 全局注册组件、指令、方法
import { createApp } from "vue";
import V3ColorPicker from "v3-color-picker-teleport";
import App from "./App.vue";
const app = createApp(App);
app.use(V3ColorPicker);
app.mount("#app");
// 单个注册某个,以下三种方式均可在单个文件内使用
import { createApp } from "vue";
import { directive, colorEvent, V3ColorPicker } from "v3-color-picker-teleport";
import App from "./App.vue";
const app = createApp(App);
app.component("v3-color-picker", V3ColorPicker); // 只注册组件
app.directive("color", directive); // 只注册指令
app.config.globalProperties.colorEvent = colorEvent; // 只绑定方法
app.mount("#app");
<template>
  <div>
    <v3-color-picker v-model:value="color"></v3-color-picker>
    <div class="demo" v-color="colorOptions" :style="{backgroundColor: colorOptions.value}"></div>
    <div
      class="demo"
      @click="(event) => colorEvent(event, colorOptions)"
      :style="{backgroundColor: colorOptions.value}"
    ></div>
  </div>
</template>
<script>
  import { defineComponent, ref } from "vue";

  export default defineComponent({
    name: "App",
    setup() {
      const color = Vue.ref("rgba(255,0,0,0.5)");
      const colorOptions = ref({
        value: "rgba(255,0,0,0.5)",
        btn: true,
        theme: "light",
        teleport: "选择器",
      });
      return { color, colorOptions };
    },
  });
</script>

<style>
  .demo {
    height: 100px;
    width: 100%;
  }
</style>

指令方式使用

<template>
  <div class="demo" v-color="colorOptions" :style="{backgroundColor: colorOptions.value}">
    指令方式使用
  </div>
</template>
<script>
  import { defineComponent, shallowRef } from "vue";

  export default defineComponent({
    name: "App",
    directives: {
      color: directive,
    },
    setup() {
      const colorOptions = ref({
        value: "rgba(255,0,0,0.5)",
        btn: true,
        theme: "light",
        teleport: "选择器",
      });
      return { colorOptions };
    },
  });
</script>
<style>
  .demo {
    height: 100px;
    width: 100%;
  }
</style>

方法方式使用

<template>
  <div class="demo" @click="onClick" :style="{backgroundColor: colorOptions.value}"></div>
</template>
<script>
  import { defineComponent, shallowRef } from "vue";
  import { colorEvent } from "v3-color-picker-teleport";

  export default defineComponent({
    name: "App",
    setup() {
      const colorOptions = ref({
        value: "rgba(255,0,0,0.5)",
        btn: true,
        theme: "light",
        teleport: "选择器",
      });
      function onClick(event) {
        colorEvent(event, colorOptions.value);
        event.preventDefault();
      }
      return { onClick };
    },
  });
</script>

组件方式使用

<template>
  <v3-color-picker v-model:value="color" btn></v3-color-picker>
  <v3-color-picker v-model:value="color" size="medium" theme="light"></v3-color-picker>
  <v3-color-picker v-model:value="color" size="small"></v3-color-picker>
  <v3-color-picker v-model:value="color" :width="300"></v3-color-picker>
</template>
<script>
  import { defineComponent, nextTick, ref, shallowRef } from "vue";
  import { V3ColorPicker } from "v3-color-picker-teleport";

  export default defineComponent({
    name: "App",
    components: {
      V3ColorPicker,
    },
    setup() {
      const color = ref("rgba(255,0,0,0.5)");
      return { color };
    },
  });
</script>

参数说明

方法使用参数

colorEvent(event, options),event:事件对象,options:公共参数与方法参数

公共参数

属性描述类型是否必填默认值
value初始颜色值string | rbg | hslfalse#fff
theme主题dark | lightfalsedark
height颜色选择器区域高度numberfalse150
width颜色选择器区域宽度numberfalse233
colors预选颜色列表[string]false[]
btn是否显示按钮按钮booleanfalsefalse
zIndex菜单层级numberfalse2
teleport插入节点位置elementfalsebody

组件参数

属性描述类型是否必填默认值
size组件大小undefined | medium | small | minifalseundefined

指令、方法参数

属性描述类型是否必填默认值
change颜色值发生改变时触发事件Functionfalsenone
1.0.9

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago