ew-color-picker 1.9.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +17 -162
- package/index.cjs +5 -0
- package/index.d.ts +2 -0
- package/index.mjs +2 -0
- package/package.json +29 -31
- package/README-zh_CN.md +0 -159
- package/dist/ew-color-picker.esm.js +0 -2172
- package/dist/ew-color-picker.esm.min.js +0 -1
- package/dist/ew-color-picker.js +0 -2180
- package/dist/ew-color-picker.min.css +0 -1
- package/dist/ew-color-picker.min.js +0 -1
- package/src/color/cloneColor.js +0 -10
- package/src/color/color.js +0 -238
- package/src/config.js +0 -29
- package/src/const/console.js +0 -9
- package/src/const/en.js +0 -4
- package/src/const/error.js +0 -13
- package/src/const/zh.js +0 -4
- package/src/destroy/destroy.js +0 -18
- package/src/globalAPI.js +0 -48
- package/src/handler/bindEvent.js +0 -25
- package/src/handler/clickOutSide.js +0 -19
- package/src/handler/openOrClosePicker.js +0 -107
- package/src/index.js +0 -65
- package/src/init/beforeInit.js +0 -44
- package/src/init/init.js +0 -45
- package/src/init/initColor.js +0 -18
- package/src/init/initConfig.js +0 -56
- package/src/init/startInit.js +0 -23
- package/src/layout/box.js +0 -4
- package/src/layout/changeAlphaBarBackground.js +0 -11
- package/src/layout/changeElementColor.js +0 -26
- package/src/layout/clearAndSure.js +0 -26
- package/src/layout/hueAndAlpha.js +0 -50
- package/src/layout/input.js +0 -37
- package/src/layout/main.js +0 -191
- package/src/layout/mode.js +0 -43
- package/src/layout/panelAndCursor.js +0 -39
- package/src/layout/predefineColor.js +0 -20
- package/src/layout/setColorValue.js +0 -57
- package/src/layout/showColorPickerWithNoBox.js +0 -13
- package/src/layout/updateColor.js +0 -16
- package/src/observe/dep.js +0 -39
- package/src/observe/proxy.js +0 -63
- package/src/render/render.js +0 -162
- package/src/render/renderWatcher.js +0 -47
- package/src/style/ew-color-picker.css +0 -393
- package/src/utils/animation.js +0 -154
- package/src/utils/query.js +0 -15
- package/src/utils/util.js +0 -118
- package/types/index.d.ts +0 -80
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 夕水
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 夕水
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,162 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
npm install ew-color-picker --save-dev
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
### import
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
<script src="./dist/ew-color-picker.min.js"></script>
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
A colorPicker as follows:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
//default configuration
|
|
32
|
-
var color = new ewColorPicker('.demo');
|
|
33
|
-
// or var color = new ewColorPicker(document.getElementByClassName('demo'));
|
|
34
|
-
//click the sure button
|
|
35
|
-
color.config.sure = function(color){
|
|
36
|
-
//return color value
|
|
37
|
-
}
|
|
38
|
-
//click the cancel button
|
|
39
|
-
color.config.clear = function(defaultColor){
|
|
40
|
-
//return default color value
|
|
41
|
-
}
|
|
42
|
-
// when the color changed
|
|
43
|
-
color.config.changeColor = function(color){
|
|
44
|
-
//return the changed color
|
|
45
|
-
}
|
|
46
|
-
//Custom configuration
|
|
47
|
-
var color = new ewColorPicker({
|
|
48
|
-
el:'.demo2',//the dom element
|
|
49
|
-
alpha:true,//open the alpha
|
|
50
|
-
hue:false,//open the hue
|
|
51
|
-
size:{
|
|
52
|
-
width:100,
|
|
53
|
-
height:50
|
|
54
|
-
},//the colorPicker type,contained four value such as normal,medium,small,mini or an object that you defined by yourself,the min value is 25px
|
|
55
|
-
predefineColor:['#223456','rgba(122,35,77,.5)'],//predefine color is an array
|
|
56
|
-
disabled:false,//disabled all event
|
|
57
|
-
defaultColor:'#eeff22',//the default color
|
|
58
|
-
pickerAnimation:'opacity',//or 'height',`default`,the animation of open the colorPicker,the default value is `default`
|
|
59
|
-
pickerAnimationTime:300,//Animation execution time,200 is default,the max time is 10000
|
|
60
|
-
sure:function(color){
|
|
61
|
-
console.log(color);
|
|
62
|
-
},//the handler of sure
|
|
63
|
-
clear:function(){
|
|
64
|
-
console.log(this)
|
|
65
|
-
},//the handler of clear
|
|
66
|
-
togglePicker:(el,flag,context) => {
|
|
67
|
-
console.log('current root element',el);
|
|
68
|
-
console.log('current color picker',context);
|
|
69
|
-
if(flag){
|
|
70
|
-
console.log("opened");
|
|
71
|
-
}else{
|
|
72
|
-
console.log("closed");
|
|
73
|
-
}
|
|
74
|
-
},//Click the box event callback, you need to pay attention to the event trigger must be set `hasBox` to true
|
|
75
|
-
isLog:false, //Whether to turn on printing information, the default is true if the value is not specified
|
|
76
|
-
changeColor:(color) => {
|
|
77
|
-
console.log('the color value changed:',color);
|
|
78
|
-
},
|
|
79
|
-
hasBox:true //The default is true, or false, indicating whether to display the box
|
|
80
|
-
isClickOutside:true, //The default is true, or false,Indicates whether it is allowed to click outside the colorPicker area to close the colorPicker
|
|
81
|
-
hasClear:true,//Whether to show the clear button,the default is true
|
|
82
|
-
hasSure:true, //Whether to show the sure button,the default is true,it is not recommended to set to false
|
|
83
|
-
hasColorInput:true, //Whether to show the sure input,the default is true,it is not recommended to set to false
|
|
84
|
-
boxDisabled:true,//The default is false,set it to true and set haxBox to true,then click on the box not to open the color picker
|
|
85
|
-
openChangeColorMode:true,//Whether to turn on the color switching mode, note that you must set alpha and hue to true to turn on this mode
|
|
86
|
-
hueDirection:"horizontal",//Or `vertical`, the default is a vertical layout display, indicating whether the hue color scale column is displayed in a horizontal or vertical layout
|
|
87
|
-
alphaDirection:"horizontal",//Or vertical, the default is a vertical layout display, indicating whether the transparency column is displayed in a horizontal or vertical layout
|
|
88
|
-
lang:"zh",//Or `en`, means whether to enable Chinese mode or English mode
|
|
89
|
-
clearText:"clear",//The clear button text, if you want to customize the value, you need to set `userDefineText` to true
|
|
90
|
-
sureText:"sure",//The sure button text, if you want to customize the value, you need to set `userDefineText` to true
|
|
91
|
-
userDefineText:false,//The default is false, after setting it to true, the switch of the `lang` attribute will be invalid
|
|
92
|
-
})
|
|
93
|
-
//If you don’t like the way to instantiate to create a color picker, you can also use the `createColorPicker` method
|
|
94
|
-
ewColorPicker.createColorPicker(config);//the param is the configuration
|
|
95
|
-
//You can get the default configuration object by `getDefaultConfig` method
|
|
96
|
-
ewColorPicker.getDefaultConfig();
|
|
97
|
-
//For the instantiated color picker class, we also provide 3 APIs, as follows:
|
|
98
|
-
color.openPicker(pickerAnimation,time);//Open the color picker manually, the parameter is the animation type, namely `height` or `opacity`
|
|
99
|
-
color.closePicker(pickerAnimation,time);//Manually close the color picker, the parameters are the same as the manual open method
|
|
100
|
-
color.updateColor(color);//Manually update the color value, the parameter is the color value, the unqualified color value will give an error prompt, and the color picker panel must be open
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## import from cdn
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
//import the css
|
|
107
|
-
CDN:https://www.unpkg.com/ew-color-picker/dist/ew-color-picker.min.css
|
|
108
|
-
CDN:https://www.unpkg.com/ew-color-picker/dist/ew-color-picker.min.js
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## use in component
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
```js
|
|
115
|
-
import ewColorPicker from 'ewColorPicker';
|
|
116
|
-
import "ew-color-picker/dist/ew-color-picker.min.css"
|
|
117
|
-
import "ew-color-picker/src/style/ew-color-picker.css"
|
|
118
|
-
var pluginName = new ewColorPicker(option);//option is the configuration object, see above for details
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
> tips: It should be noted that starting from version 1.6.4, if there are multiple dom elements passed in, only the first dom element will be rendered as a colorPicker. If multiple colorPickers need to be rendered, an array can be used for instance. E.g:
|
|
122
|
-
```js
|
|
123
|
-
let els = document.querySelectorAll('.demo');
|
|
124
|
-
els.forEach(item => {
|
|
125
|
-
new ewColorPicker(item);
|
|
126
|
-
//or new ewColorPicker({
|
|
127
|
-
// el:item,
|
|
128
|
-
// }) //and the configuration
|
|
129
|
-
})
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
For more details, please refer to the official website of the document [ewColorPicker](https://eveningwater.github.io/ew-color-picker/);
|
|
133
|
-
|
|
134
|
-
> Domestic access is slow and accessible [ewColorPicker](https://eveningwater.gitee.io/ew-color-picker/)
|
|
135
|
-
|
|
136
|
-
# the update logs
|
|
137
|
-
|
|
138
|
-
* 1.9.9 Fixed the horizontal layout positioning problem of the alpha bar, adjusted the `$` tool method, and added the `$$` tool method.
|
|
139
|
-
* 1.9.8 fixes some problems,add the animation type,now contains "height","opacity","default".
|
|
140
|
-
* 1.9.7 fixes some problems
|
|
141
|
-
* 1.9.6 Fixed some problems of the color picker, and added the method `destroy` to destroy the color picker instance globally.
|
|
142
|
-
* 1.9.5 Fixed the problem of multiple color selector configuration objects, and added the method `destroy` to destroy the color selector instance.
|
|
143
|
-
* 1.9.4 Fixed the problem of responsive update.
|
|
144
|
-
* 1.9.0 ~ 1.9.3 fixed some problems, and modified the introduction and configuration of dependent packages.
|
|
145
|
-
* 1.8.9 Added the `lang` language configuration attribute, added the `clearText` and `sureText` attributes, used to customize the text of the clear button and the OK button, and added the `userDefineText` attribute, used to open the user Customize the text of the clear button and the OK button. If this attribute is not enabled, then the manual setting of the `clearText` and `sureText` attribute values is invalid. If the value is enabled, the language mode is invalid.
|
|
146
|
-
* 1.8.8 Changed el configuration properties and isLog properties into non-responsive properties, modified the type definition, modified the minimum width and height limits of size, modified the maximum limit of animation execution time, and changed the `openAndClosePicker` configuration object property method The name is changed to `togglePicker`, and the return parameter of togglePicker is modified.
|
|
147
|
-
* 1.8.7 Fixed the problem of clicking on predefined color elements
|
|
148
|
-
* 1.8.6 The color picker configuration object has added a responsive function. Whether it is adding, deleting or changing the properties of the color picker, it will trigger the update of the color picker. At the same time, the `pickerAnimationTime` property has been added to indicate the time to execute the animation. The time is set too long and some codes are optimized.
|
|
149
|
-
* 1.8.5 Cancel the verification of the el attribute and not passing the dom element. If no parameters are passed, the color selector will be added to the body by default (but a container element will be generated to contain it).
|
|
150
|
-
* 1.8.3 ~ 1.8.4 fixed some problems and optimized some codes
|
|
151
|
-
* 1.8.2 Fixed the issue of transparency change in the horizontal direction, adjusted the layout and optimized some codes.
|
|
152
|
-
* 1.8.1 Fixed some problems and added `hueDirection` and `alphaDirection` attributes.
|
|
153
|
-
* 1.8.0 Fixed the problem of adding to the body, and modified the problem of setting disabled to true.
|
|
154
|
-
* 1.7.9 Fixed the problem of hiding color blocks.
|
|
155
|
-
* 1.7.8 Fixed the problem of hiding the input, optimized the code, and changed the `openPickerAni` configuration property name to `pickerAnimation`.
|
|
156
|
-
* 1.7.7 Fixed some problems with predefined colors and optimized some codes.
|
|
157
|
-
* 1.7.6 Fixed some problems, opened the internal tool methods, can access all tool methods through `ewColorPicker.util`, and modified the verification of the color value to support the input of English color words, such as setting predefined colors and The default color.
|
|
158
|
-
* 1.7.5 Fixed the problem of default assignment of transparency, renamed the callback of the original `openPicker` to open or close the color block by clicking on it, and renamed it to `openOrClosePicker`, and optimized the code.
|
|
159
|
-
* 1.7.4: Fixed the problem that the transparency of color mode switching does not change, and added the `changeBoxByChangeColor` configuration property, which indicates whether the background color of the color block changes when the color panel is opened and the color value is triggered. If you do not click OK Button, the color panel will be restored to the default color after closing the color panel. The predefined color array `predefineColor` has added an array item that can be passed as an object or a string. The object is defined as `{ color:"#123",disabled:true }(color Is a qualified color value, disabled is true or false, indicating whether to disable the predefined click to change color)`.
|
|
160
|
-
* 1.7.3: Optimized the color value algorithm, and added the `boxDisabled` and `openChangeColorMode` configuration properties.
|
|
161
|
-
* 1.7.2: Added the ability to add a color selector to the `body`, but a container element will be generated to contain it, and the `disabled` configuration attribute is changed to prohibit all clicks.
|
|
162
|
-
* 1.3.3 ~ 1.7.1: The basic function of the color picker has been added.
|
|
1
|
+
# ew-color-picker
|
|
2
|
+
|
|
3
|
+
ew-color-picker v2 的聚合入口包,兼容 v1 的包名。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i ew-color-picker
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
内部等价于安装 `@ew-color-picker/ew-color-picker` 与 `@ew-color-picker/style`。
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import ewColorPicker from "ew-color-picker"
|
|
13
|
+
import "@ew-color-picker/style/dist/index.css"
|
|
14
|
+
import "@ew-color-picker/style/dist/input-number.css"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
文档:https://eveningwater.github.io/ew-color-picker/
|
package/index.cjs
ADDED
package/index.d.ts
ADDED
package/index.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ew-color-picker",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "EW Color Picker 聚合入口,内部指向 @ew-color-picker/ew-color-picker",
|
|
5
|
+
"main": "index.cjs",
|
|
6
|
+
"module": "index.mjs",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.cjs",
|
|
10
|
+
"index.mjs",
|
|
11
|
+
"index.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"color-picker",
|
|
15
|
+
"colorpicker",
|
|
16
|
+
"typescript",
|
|
17
|
+
"plugin",
|
|
18
|
+
"ui"
|
|
19
|
+
],
|
|
20
|
+
"author": "eveningwater(854806732@qq.com)",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@ew-color-picker/ew-color-picker": "^2.0.0",
|
|
24
|
+
"@ew-color-picker/style": "^2.0.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
12
28
|
},
|
|
13
29
|
"repository": {
|
|
14
30
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/eveningwater/ew-color-picker.git"
|
|
31
|
+
"url": "git+https://github.com/eveningwater/ew-color-picker.git",
|
|
32
|
+
"directory": "packages/ew-color-picker-compat"
|
|
16
33
|
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"ew-color-picker",
|
|
19
|
-
"plugin"
|
|
20
|
-
],
|
|
21
|
-
"author": "eveningwater",
|
|
22
|
-
"license": "ISC",
|
|
23
34
|
"bugs": {
|
|
24
35
|
"url": "https://github.com/eveningwater/ew-color-picker/issues"
|
|
25
36
|
},
|
|
26
|
-
"homepage": "https://github.
|
|
27
|
-
|
|
28
|
-
"@babel/core": "^7.10.2",
|
|
29
|
-
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
|
30
|
-
"@vuepress/plugin-back-to-top": "^1.8.2",
|
|
31
|
-
"cross-env": "^7.0.3",
|
|
32
|
-
"cssnano": "^4.1.10",
|
|
33
|
-
"postcss-cssnext": "^3.1.0",
|
|
34
|
-
"rollup-plugin-babel": "^4.4.0",
|
|
35
|
-
"rollup-plugin-postcss": "^4.0.0",
|
|
36
|
-
"rollup-plugin-terser": "^6.1.0",
|
|
37
|
-
"typescript": "^4.1.3",
|
|
38
|
-
"vuepress": "^1.5.0"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
37
|
+
"homepage": "https://eveningwater.github.io/ew-color-picker/"
|
|
38
|
+
}
|
package/README-zh_CN.md
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
[English](./README.md) | [简体中文](./README-zh_CN.md)
|
|
3
|
-
|
|
4
|
-
# ew-color-picker
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/ew-color-picker)
|
|
7
|
-

|
|
8
|
-

|
|
9
|
-
[](https://github.com/eveningwater/ew-color-picker/stargazers)
|
|
10
|
-
[](https://github.com/eveningwater/ew-color-picker/network/members)
|
|
11
|
-
|
|
12
|
-
一个基于原生js而封装的颜色选择器插件。
|
|
13
|
-
|
|
14
|
-
## 安装与使用
|
|
15
|
-
|
|
16
|
-
### 安装
|
|
17
|
-
```
|
|
18
|
-
npm install ew-color-picker --save-dev
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
### 引入
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
<script src="./dist/ew-color-picker.min.js"></script>
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
颜色选择器插件如下:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
//默认配置
|
|
32
|
-
var color = new ewColorPicker('.demo');
|
|
33
|
-
或 var color = new ewColorPicker(document.getElementByClassName('demo'));
|
|
34
|
-
//点击确定
|
|
35
|
-
color.config.sure = function(color){
|
|
36
|
-
//返回颜色值
|
|
37
|
-
}
|
|
38
|
-
//点击取消
|
|
39
|
-
color.config.clear = function(defaultColor){
|
|
40
|
-
//返回默认颜色值
|
|
41
|
-
}
|
|
42
|
-
// 当颜色值改变时触发
|
|
43
|
-
color.config.changeColor = function(color){
|
|
44
|
-
//返回改变后的颜色值,即color
|
|
45
|
-
}
|
|
46
|
-
//自定义配置
|
|
47
|
-
var color = new ewColorPicker({
|
|
48
|
-
el:'.demo2',//绑定选择器的dom元素
|
|
49
|
-
alpha:true,//是否开启透明度
|
|
50
|
-
hue:false,//是否开启色调
|
|
51
|
-
size:{
|
|
52
|
-
width:100,
|
|
53
|
-
height:50
|
|
54
|
-
},//颜色选择器类型,有四个字符串值normal,medium,small,mini或者一个对象自定义宽高,如果自定义宽高,最小宽高为25px
|
|
55
|
-
predefineColor:['#223456','rgba(122,35,77,.5)'],//预定义颜色是一个数组
|
|
56
|
-
disabled:false,//是否禁止所有的点击
|
|
57
|
-
defaultColor:'#eeff22',//默认颜色
|
|
58
|
-
pickerAnimation:'opacity',//或者'height',开启颜色选择器面板的动画
|
|
59
|
-
pickerAnimationTime:300,//动画执行时间,默认是200,最大动画时间为10000
|
|
60
|
-
sure:function(color){
|
|
61
|
-
console.log(color);
|
|
62
|
-
},//点击确定按钮的回调
|
|
63
|
-
clear:function(){
|
|
64
|
-
console.log(this)
|
|
65
|
-
},//点击清空按钮的回调
|
|
66
|
-
togglePicker:(el,flag,context) => {
|
|
67
|
-
console.log('当前根元素',el);
|
|
68
|
-
console.log('当前颜色选择器实例对象',context);
|
|
69
|
-
if(flag){
|
|
70
|
-
console.log("opened");
|
|
71
|
-
}else{
|
|
72
|
-
console.log("closed");
|
|
73
|
-
}
|
|
74
|
-
},//点击色块事件回调,需要注意该事件触发必须要将hasBox设置为true
|
|
75
|
-
isLog:false, //是否开启打印信息,默认是true如果不指定该值的话
|
|
76
|
-
changeColor:(color) => {
|
|
77
|
-
console.log('颜色值改变时触发:',color);
|
|
78
|
-
},
|
|
79
|
-
hasBox:true //默认为true,或者为false,表示是否显示颜色选择器
|
|
80
|
-
isClickOutside:true, //默认为true,或者设置为false,表示是否允许点击颜色选择器区域之外关闭颜色选择器
|
|
81
|
-
hasClear:true,//是否显示清空按钮,默认为true
|
|
82
|
-
hasSure:true, //是否显示确定按钮,默认为true,不建议设置为false
|
|
83
|
-
hasColorInput:true, //是否显示输入框,默认为true,不建议设置为false
|
|
84
|
-
boxDisabled:true,//默认是false,设置为true并且hasBox为true,禁止点击色块打开颜色选择器
|
|
85
|
-
openChangeColorMode:true,//是否打开颜色切换模式,注意打开这个模式必须要将alpha和hue设置为true
|
|
86
|
-
hueDirection:"horizontal",//或者vertical,默认是垂直布局显示,表示hue色阶柱是水平还是垂直布局显示
|
|
87
|
-
alphaDirection:"horizontal",//或者vertical,默认是垂直布局显示,表示透明度柱是水平还是垂直布局显示
|
|
88
|
-
lang:"zh",//或en,表示启用中文模式还是英文模式
|
|
89
|
-
clearText:"清空",//清空按钮文本,如果想要自定义该值,需要设置userDefineText为true
|
|
90
|
-
sureText:"确定",//确定按钮文本,如果想要自定义该值,则需要设置userDefineText为true
|
|
91
|
-
userDefineText:false,//默认为false,设置为true之后,lang属性的切换将无效
|
|
92
|
-
})
|
|
93
|
-
//如果不喜欢实例化的方式来创建一个颜色选择器,也可以使用createColorPicker方法
|
|
94
|
-
ewColorPicker.createColorPicker(config);//config为属性配置对象
|
|
95
|
-
//当然还提供了一个api,可以获取默认的配置对象
|
|
96
|
-
ewColorPicker.getDefaultConfig();
|
|
97
|
-
//实例化的颜色选择器类,我们还提供了三个api,如下:
|
|
98
|
-
color.openPicker(pickerAnimation,time);//手动打开颜色选择器,参数为动画类型,即height或opacity
|
|
99
|
-
color.closePicker(pickerAnimation,time);//手动关闭颜色选择器,参数同手动打开方法一样
|
|
100
|
-
color.updateColor(color);//手动更新颜色值,参数为颜色值,不合格的颜色值会给出错误提示,并且颜色选择器面板要处于开启状态
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## cdn引入
|
|
104
|
-
//样式引入
|
|
105
|
-
CDN:https://www.unpkg.com/ew-color-picker/dist/ew-color-picker.min.css
|
|
106
|
-
CDN:https://www.unpkg.com/ew-color-picker/dist/ew-color-picker.min.js
|
|
107
|
-
|
|
108
|
-
## 在组件中使用
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```js
|
|
112
|
-
import ewColorPicker from 'ewColorPicker';
|
|
113
|
-
import "ew-color-picker/dist/ew-color-picker.min.css"
|
|
114
|
-
import "ew-color-picker/src/style/ew-color-picker.css"
|
|
115
|
-
var pluginName = new ewColorPicker(option);//option为配置对象,详情见前述
|
|
116
|
-
|
|
117
|
-
```
|
|
118
|
-
> tips: 需要注意的是,从1.6.4版本开始,如果传入的dom元素是多个,则只有第一个dom元素渲染成颜色选择器,如果需要渲染多个颜色选择器,可使用一个数组来实例化。例如:
|
|
119
|
-
```js
|
|
120
|
-
let els = document.querySelectorAll('.demo');
|
|
121
|
-
els.forEach(item => {
|
|
122
|
-
new ewColorPicker(item);
|
|
123
|
-
//或new ewColorPicker({
|
|
124
|
-
// el:item,
|
|
125
|
-
// }) //以及一些相关配置属性
|
|
126
|
-
})
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
更多详情参阅文档官网介绍[ewColorPicker](https://eveningwater.github.io/ew-color-picker/);
|
|
130
|
-
|
|
131
|
-
> 国内访问速度慢可访问[ewColorPicker](https://eveningwater.gitee.io/ew-color-picker/)
|
|
132
|
-
|
|
133
|
-
# 更新日志
|
|
134
|
-
|
|
135
|
-
* 1.9.9 修复了透明度柱的横向布局定位问题,调整了`$`工具方法,增加了`$$`工具方法。
|
|
136
|
-
* 1.9.8 修复了一些问题,增加了默认动画,动画选项值先包含"height","opacity","default"三种。
|
|
137
|
-
* 1.9.7 修复了一些问题
|
|
138
|
-
* 1.9.6 修复了颜色选择器的一些问题,并添加了全局销毁颜色选择器实例的方法`destroy`。
|
|
139
|
-
* 1.9.5 修复了多个颜色选择器配置对象问题,并添加了销毁颜色选择器实例的方法`destroy`。
|
|
140
|
-
* 1.9.4 修复了响应式更新的问题。
|
|
141
|
-
* 1.9.0 ~ 1.9.3 修复了一些问题,并修改了依赖包的引入和配置。
|
|
142
|
-
* 1.8.9 新增了`lang`语言配置属性,新增了`clearText`与`sureText`属性,用于自定义清空按钮和确定按钮的文本,新增了`userDefineText`属性,用于开启用户自定义清空按钮和确定按钮的文本,如果不开启该属性,那么手动设置`clearText`与`sureText`属性值无效,如果开启了该值,则语言模式失效。
|
|
143
|
-
* 1.8.8 将el配置属性和isLog属性变成非响应式属性,修改了类型定义,修改了size的最小宽高限制,修改了动画执行时间的最大限制,并将`openAndClosePicker`配置对象属性方法名更改为`togglePicker`,修改了togglePicker的返回参数。
|
|
144
|
-
* 1.8.7 修复了点击预定义颜色元素的问题
|
|
145
|
-
* 1.8.6 颜色选择器配置对象添加了响应式功能,无论是增删改颜色选择器的属性,都会触发颜色选择器的更新,同时添加了`pickerAnimationTime`属性,表示执行动画的时间,当然不建议将时间设置的过长,优化了一些代码。
|
|
146
|
-
* 1.8.5 取消el属性和不传dom元素的验证,如果不传任何参数,则默认将颜色选择器添加到body中(但会生成一个容器元素来包含)。
|
|
147
|
-
* 1.8.3 ~ 1.8.4 修复了一些问题,优化了一些代码
|
|
148
|
-
* 1.8.2 修复了水平方向透明度改变问题,并调整了一下布局和优化了一些代码。
|
|
149
|
-
* 1.8.1 修复了一些问题,并添加了`hueDirection`和`alphaDirection`属性。
|
|
150
|
-
* 1.8.0 修复了添加到body中的问题,以及修改了将disabled设置为true的问题。
|
|
151
|
-
* 1.7.9 修复了隐藏色块的问题。
|
|
152
|
-
* 1.7.8 修复了将input隐藏的问题,优化了代码,将`openPickerAni`配置属性名更改为`pickerAnimation`。
|
|
153
|
-
* 1.7.7 修复了预定义颜色的一些问题,优化了一些代码。
|
|
154
|
-
* 1.7.6 修复了一些问题,开放了内部工具方法,可通过`ewColorPicker.util`访问到所有工具方法,并修改了颜色值的验证,支持英文颜色单词的传入,例如设置预定义颜色以及默认颜色。
|
|
155
|
-
* 1.7.5 修复了透明度默认赋值问题,将原`openPicker`点击色块打开或关闭的回调更名为`openOrClosePicker`,优化了代码。
|
|
156
|
-
* 1.7.4:修复了颜色模式切换透明度不改变问题,新增了`changeBoxByChangeColor`配置属性,该属性表示是否在打开颜色面板,颜色值触发的时候,色块的背景色更改,如果不点击确定按钮,关闭颜色面板后会恢复到默认颜色,预定义颜色数组`predefineColor`新增了可以传数组项为对象或字符串,对象定义为`{ color:"#123",disabled:true }(color为合格的颜色值,disabled为true或者false,表示是否禁用该预定义点击更换颜色)`。
|
|
157
|
-
* 1.7.3:优化了颜色值算法,新增了`boxDisabled`和`openChangeColorMode`配置属性。
|
|
158
|
-
* 1.7.2:新增了允许将颜色选择器添加到`body`中,但会生成一个容器元素来包含,将`disabled`配置属性更改成了全部禁止点击。
|
|
159
|
-
* 1.3.3 ~ 1.7.1:添加了颜色选择器的基本功能。
|