npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v3-color-picker-teleport

v1.0.9

Published

Vue3.0 颜色选择器, colorEvent 选择器设置可动态添加到固定位置

Downloads

2

Readme

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 | hsl | false | #fff | | theme | 主题 | dark | light | false | dark | | height | 颜色选择器区域高度 | number | false | 150 | | width | 颜色选择器区域宽度 | number | false | 233 | | colors | 预选颜色列表 | [string] | false | [] | | btn | 是否显示按钮按钮 | boolean | false | false | | zIndex | 菜单层级 | number | false | 2 | | teleport | 插入节点位置 | element | false | body |

组件参数

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

指令、方法参数

| 属性 | 描述 | 类型 | 是否必填 | 默认值 | | :----: | :----------------------: | :--------: | :------: | :----: | | change | 颜色值发生改变时触发事件 | Function | false | none |