11# colorpicker
22
3- 非常漂亮的一款拾色器,灵感来源于 [ 凡科建站 ] ( https://fkw.com/ ) 的拾色器。同时参照了 [ element-plus ] ( https://element-plus.org/#/zh-CN/component/ color- picker) 以及 [ vue- color] ( https://github.com/xiaokaike/vue-color ) 的思路;作为一名纯粹的后端人员,我从来没有想过我竟然来写拾色器这个 vue 插件。
3+ A very beautiful color picker, supports input and output of multiple color formats, and supports gradient color selection.
44
5- ![ ] ( https://aesoper101.github.io/vue3-colorpicker/1.png )
5+ Note: This document is for Vue3ColorPicker v2. If you are looking for an older versions, refer to the v1 branches.The v2 version is a destructive update, and some functions in v1 are no longer supported. Please use it with caution
66
7- [ 在线 demo 演示 ] ( https://aesoper101.github.io/vue3-colorpicker/ )
7+ [ Live Demo ] ( https://aesoper101.github.io/vue3-colorpicker/ )
88
9- ## 安装
9+ [ 中文文档] ( ./README.ZH-cn.md )
10+
11+ ## Installation
1012
1113```
1214yarn add vue3-colorpicker
1315```
1416
15- 或者
17+ OR
1618
1719```
1820npm install vue3-colorpicker
1921```
2022
21- ## 如何使用
23+ ## How to use
2224
23- ### 第一步全局注册
25+ ### The first step is global registration
2426
2527```
2628import Vue3ColorPicker from "vue3-colorpicker";
@@ -32,104 +34,39 @@ createApp(App)
3234 .mount("#app");
3335```
3436
35- ### 使用组件
36-
37- ``` vue
38- <fk-color-picker v-model:color="color" />
39- ```
40-
41- ![ ] ( https://aesoper101.github.io/vue3-colorpicker/2.PNG )
42-
43- ``` vue
44- <chrome-color-picker v-model:color="color" :history-round="true" />
45- ```
46-
47- ![ ] ( https://aesoper101.github.io/vue3-colorpicker/3.PNG )
48-
49- ``` vue
50- <ele-color-picker v-model:color="color" />
51- ```
37+ OR
5238
53- ![ ] ( https://aesoper101.github.io/vue3-colorpicker/4.PNG )
54-
55- ```
56- <!-- 有弹出功能的拾色器 -->
57- <popu-color-picker v-model:color="color" />
58- ```
59-
60- ![ ] ( https://aesoper101.github.io/vue3-colorpicker/5.PNG )
61-
62- ## 数据输入输出
63-
64- ``` js
65- // 不同格式的数据输入输出
66-
67- const colors: ColorAttrs = {
68- // 默认的color输出格式
69- hsl: {
70- h: 0 ,
71- s: 0.56 ,
72- l: 0.38 ,
73- a: 1 ,
74- },
75- hex: " #992B2B" ,
76- hex8: " #992B2BFF" ,
77- rgb: {
78- r: 153 ,
79- g: 43 ,
80- b: 43 ,
81- a: 1 ,
82- },
83- hsv: {
84- h: 0 ,
85- s: 0.72 ,
86- v: 0.6 ,
87- a: 1 ,
88- },
89- oldHue: 0 ,
90- source: " saturation" ,
91- alpha: 1 ,
92- };
93- // or
94- const colors = " #194d33" ;
95- // or
96- const colors = " #194D33A8" ;
97- // or
98- const colors = { h: 150 , s: 0.66 , v: 0.3 };
99- // or
100- const colors = { r: 255 , g: 0 , b: 0 };
101- ```
39+ ``` vue3
40+ import { ColorPicker } from "vue3-colorpicker";
41+ import "vue3-colorpicker/style.css";
10242
103- 如果你需要一种固定的 color 值输出格式,您需要给组件的 formate 属性赋值(除了 popu-color-picker);format 允许的类型如下:
104-
105- ``` typescript
106- export type ColorFormat =
107- | " rgb"
108- | " prgb"
109- | " hex"
110- | " hex6"
111- | " hex3"
112- | " hex4"
113- | " hex8"
114- | " name"
115- | " hsl"
116- | " hsv" ;
43+ export default defineComponent({
44+ components: { ColorPicker },
45+ });
11746```
11847
119- 如果想让 popu-color-picker 组件也输出固定格式的 color 值,需要给 popu-color-picker 组件的 pickerProps 属性赋值, pickerProps 属性选项跟您填入的 mode 属性相关; mode 的值如下:
48+ ### Usage
12049
121- ``` typescript
122- export type PickerMode = " fk" | " chrome" | " ele" ;
123- ```
50+ ``` vue3
51+ <template>
52+ <div>
53+ <color-picker v-model:pureColor="pureColor" v-model:gradientColor="gradientColor"/>
54+ </div>
55+ </template>
56+ <script lang="ts">
57+ import { ref } from "vue";
58+ import { ColorInputWithoutInstance } from "tinycolor2";
12459
125- 如果您` mode="chrome" ` ,则弹出的拾色器为` chrome-color-picker ` .此时 pickerProps 的值即为` chrome-color-picker ` 组件的属性值。下同如果您` mode="fk" ` ,则弹出的拾色器为` fk-color-picker ` . 默认为` fk ` 如果您` mode="ele" ` ,则弹出的拾色器为` ele-color-picker ` .
60+ export default defineComponent({
61+ setup() {
62+ const pureColor = ref<ColorInputWithoutInstance>("red");
63+ const gradientColor = ref("linear-gradient(0deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 100%)");
12664
127- 举例:
65+ return { pureColor, gradientColor }
66+ }
67+ });
68+ </script>
12869
129- ``` vue
130- <popu-color-picker v-model:color="color" mode="chrome" :chrome-color-picker="{ format: 'hex' }" />
13170```
13271
133- 说明: 以上组件弹出的拾色器为` chrome-color-picker ` , 输出的 color 格式为 ` hex ` 字符串类型, ![ ] ( https://aesoper101.github.io/vue3-colorpicker/6.PNG )
134-
135- ## 由于写得匆忙,文档以及代码结构很烂。后续优化更新
72+ [ Live Demo] ( https://aesoper101.github.io/vue3-colorpicker/ )
0 commit comments