diff --git a/docs/src/routes/components/colorpicker.svelte b/docs/src/routes/components/colorpicker.svelte new file mode 100644 index 0000000..edda848 --- /dev/null +++ b/docs/src/routes/components/colorpicker.svelte @@ -0,0 +1,60 @@ + + + + + + + import { ColorPicker } from 'svelma-pro' + let color = "#1ec131"; + + + function change(e){ + console.log(e.detail) + } + + + + `}> +
+ +
+
+ +
+ +

面板模式

+ + + import { ColorPicker } from 'svelma-pro' + let color = "#1ec131"; + + + +`}> +
+ +
+
+ + \ No newline at end of file diff --git a/docs/src/routes/components/jsdocs.json b/docs/src/routes/components/jsdocs.json index a82a0a3..b46a1ff 100644 --- a/docs/src/routes/components/jsdocs.json +++ b/docs/src/routes/components/jsdocs.json @@ -2330,5 +2330,45 @@ "defaultvalue": "center", "name": "navPosition", "values": "center,start,end" - }] + }], + "ColorPicker": [ + { + "description": "初始化色值,支持hex,rgba,hsla格式色值", + "type": [ + "String" + ], + "defaultvalue":"#1ec131", + "name": "color", + "values": "hex,rgba,hsla" + },{ + "description": "显示模式,模式1表示按钮模式,2表示面板模式", + "type": [ + "Number" + ], + "defaultvalue":"1", + "name": "mode", + "values": "1,2" + },{ + "description": "按钮模式下宽度", + "type": [ + "String" + ], + "defaultvalue":"200px", + "name": "width", + "values": "" + },{ + "description": "色值类别,0:hex,1:rgba,2:hsla", + "type": [ + "Number" + ], + "defaultvalue":"0", + "name": "fieldsIndex", + "values": "0,1,2" + },{ + "isEvent": true, + "description": "选择改变事件", + "name": "change", + "values": "" + } + ] } \ No newline at end of file diff --git a/docs/src/routes/install/index.svelte b/docs/src/routes/install/index.svelte index 588fbd6..165e124 100644 --- a/docs/src/routes/install/index.svelte +++ b/docs/src/routes/install/index.svelte @@ -99,6 +99,7 @@ module.export = { `}> diff --git a/package-lock.json b/package-lock.json index b8eee00..6e381a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelma-pro", - "version": "1.0.6", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1953,14 +1953,6 @@ } } }, - "dom7": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/dom7/-/dom7-2.1.3.tgz", - "integrity": "sha512-QTxHHDox+M6ZFz1zHPAHZKI3JOHY5iY4i9BK2uctlggxKQwRhO3q3HHFq1BKsT25Bm/ySSj70K6Wk/G4bs9rMQ==", - "requires": { - "ssr-window": "^1.0.1" - } - }, "dot-prop": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", @@ -10385,11 +10377,6 @@ "tweetnacl": "~0.14.0" } }, - "ssr-window": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ssr-window/-/ssr-window-1.0.1.tgz", - "integrity": "sha512-dgFqB+f00LJTEgb6UXhx0h+SrG50LJvti2yMKMqAgzfUmUXZrLSv2fjULF7AWGwK25EXu8+smLR3jYsJQChPsg==" - }, "standard-version": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-6.0.1.tgz", @@ -10815,15 +10802,6 @@ "strip-indent": "^2.0.0" } }, - "swiper": { - "version": "5.3.8", - "resolved": "https://registry.npmjs.org/swiper/-/swiper-5.3.8.tgz", - "integrity": "sha512-bCxrayTgzC2bZBRuFwAx7T4exWeHqMADBpcuTQ7PNCOIIzJRPqNh4ySIvW06LEEU3Q0KncaNre4hrn+jXcWivQ==", - "requires": { - "dom7": "^2.1.3", - "ssr-window": "^1.0.1" - } - }, "tar": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.2.tgz", @@ -10893,6 +10871,11 @@ "readable-stream": "2 || 3" } }, + "tinycolor2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.1.tgz", + "integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g=" + }, "tinydate": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tinydate/-/tinydate-1.0.1.tgz", diff --git a/package.json b/package.json index ae3b9e5..f37311e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "svelma-pro", "svelte": "src/index.js", "description": "Based on svelma project extension and modification", - "version": "1.0.9", + "version": "1.1.0", "author": "KeiferJu", "license": "MIT", "keywords": [ @@ -27,7 +27,8 @@ "src" ], "peerDependencies": { - "bulma": "^0.8.0" + "bulma": "^0.8.0", + "tinycolor2": "^1.4.1" }, "devDependencies": { "autoprefixer": "^9.6.0", diff --git a/src/components/ColorPicker/Alpha.svelte b/src/components/ColorPicker/Alpha.svelte new file mode 100755 index 0000000..e9a9851 --- /dev/null +++ b/src/components/ColorPicker/Alpha.svelte @@ -0,0 +1,41 @@ + + + + +
+
+ console.log(event.detail)} /> +
+
\ No newline at end of file diff --git a/src/components/ColorPicker/Chrome.svelte b/src/components/ColorPicker/Chrome.svelte new file mode 100755 index 0000000..baefbb7 --- /dev/null +++ b/src/components/ColorPicker/Chrome.svelte @@ -0,0 +1,380 @@ + + + + + + +
+ +
+ update({h, s: event.detail.s, v: event.detail.v, a})} /> +
+ +
+ +
+ +
+ +
+
+ update({h: event.detail, s, v, a})} /> +
+ + {#if !disableAlpha} +
+ +
+ {/if} +
+
+ +
+ +
+ {#if fieldsIndex === 0} +
+ update(event.target.value)} + /> + +
+ {:else if fieldsIndex === 1} +
+
+ update({r: parseInt(event.target.value), g, b, a})} + /> + +
+
+ update({r, g: parseInt(event.target.value), b, a})} + /> + +
+
+ update({r, g, b: parseInt(event.target.value), a})} + /> + +
+ {#if !disableAlpha} +
+ updateAlpha(parseFloat(event.target.value))} + /> + +
+ {/if} +
+ {:else if fieldsIndex === 2} +
+
+ update({h: parseInt(event.target.value), s, l, a})} + /> + +
+
+ update({h, s: parseFloat(event.target.value) / 100, l, a})} + /> + +
+
+ update({h, s, l: parseFloat(event.target.value) / 100, a})} + /> + +
+ {#if !disableAlpha} +
+ updateAlpha(parseFloat(event.target.value))} + /> + +
+ {/if} +
+ {/if} +
+ +
+
fieldsIndex = (fieldsIndex === 0 ? 2 : (fieldsIndex - 1) % 3)}>
+
fieldsIndex = (fieldsIndex + 1) % 3}>
+
+
+ +
\ No newline at end of file diff --git a/src/components/ColorPicker/ColorPicker.svelte b/src/components/ColorPicker/ColorPicker.svelte new file mode 100644 index 0000000..212118e --- /dev/null +++ b/src/components/ColorPicker/ColorPicker.svelte @@ -0,0 +1,66 @@ + + + + +{#if mode === 1} +
+ + {#if active} +
+ +
+ {/if} +
+{:else} + +{/if} + diff --git a/src/components/ColorPicker/ColorSquare.svelte b/src/components/ColorPicker/ColorSquare.svelte new file mode 100755 index 0000000..89b8280 --- /dev/null +++ b/src/components/ColorPicker/ColorSquare.svelte @@ -0,0 +1,22 @@ + + + + +
+
+
\ No newline at end of file diff --git a/src/components/ColorPicker/Hue.svelte b/src/components/ColorPicker/Hue.svelte new file mode 100755 index 0000000..9dc631f --- /dev/null +++ b/src/components/ColorPicker/Hue.svelte @@ -0,0 +1,40 @@ + + + + +
+ +
\ No newline at end of file diff --git a/src/components/ColorPicker/SaturationValue.svelte b/src/components/ColorPicker/SaturationValue.svelte new file mode 100755 index 0000000..dc0b866 --- /dev/null +++ b/src/components/ColorPicker/SaturationValue.svelte @@ -0,0 +1,111 @@ + + + + +
+
+
+
+
\ No newline at end of file diff --git a/src/components/ColorPicker/Slider.svelte b/src/components/ColorPicker/Slider.svelte new file mode 100755 index 0000000..665957c --- /dev/null +++ b/src/components/ColorPicker/Slider.svelte @@ -0,0 +1,115 @@ + + + + +
+
+
\ No newline at end of file diff --git a/src/components/ColorPicker/utils.js b/src/components/ColorPicker/utils.js new file mode 100755 index 0000000..5d4e7a9 --- /dev/null +++ b/src/components/ColorPicker/utils.js @@ -0,0 +1,31 @@ +import tinycolor from "tinycolor2"; + +export const limitatePercent = (num) => Math.max(0, Math.min(1, num)); + +export const getValidColor = (input) => { + + if(typeof input !== "string"){ + + for(const key in input){ + if(isNaN(input[key])){ + return false; + } + } + + const {h, s, l, v, r, g, b, a} = input; + + if( + (h !== null && (h < 0 || h > 360)) || + (a !== null && (a < 0 || a > 1)) || + (s !== null && (s < 0 || s > 1)) || + (v !== null && (v < 0 || v > 1)) || + (l !== null && (l < 0 || l > 1)) || + (r !== null && (r < 0 || r > 255)) || + (g !== null && (g < 0 || g > 255)) || + (b !== null && (b < 0 || b > 255)) + ) return false; + } + + const color = tinycolor(input); + return color.isValid() && color; +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 5224d01..84c19bf 100644 --- a/src/index.js +++ b/src/index.js @@ -32,6 +32,8 @@ import { NavItem, NavLayout } from './components/Nav' +import ColorPicker from './components/ColorPicker/ColorPicker.svelte'; + export { Button, Collapse, @@ -59,7 +61,8 @@ export { Carousel, Nav, NavItem, - NavLayout + NavLayout, + ColorPicker } export const Svelma = { @@ -89,5 +92,6 @@ export const Svelma = { Carousel, Nav, NavItem, - NavLayout + NavLayout, + ColorPicker } \ No newline at end of file