@cmstops/pro-compo 0.3.15 → 0.3.17

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.
@@ -1,4 +1,4 @@
1
- import { defineComponent, computed, openBlock, createElementBlock, createVNode, unref, withCtx, Fragment, renderList, createBlock, normalizeStyle, createCommentVNode } from "vue";
1
+ import { defineComponent, ref, computed, watch, openBlock, createElementBlock, createVNode, unref, withCtx, Fragment, renderList, createBlock, normalizeStyle, createCommentVNode } from "vue";
2
2
  import { RadioGroup, Radio } from "@arco-design/web-vue";
3
3
  import _sfc_main$1 from "./components/colorPicker.js";
4
4
  const _hoisted_1 = {
@@ -10,25 +10,53 @@ const _sfc_main = defineComponent({
10
10
  __name: "component",
11
11
  props: {
12
12
  colorList: {},
13
- color: {}
13
+ color: {},
14
+ mode: {}
14
15
  },
15
- emits: ["change", "update:color"],
16
+ emits: ["update:color"],
16
17
  setup(__props, { emit: __emit }) {
17
18
  const props = __props;
18
19
  const emit = __emit;
19
- const colorValue = computed({
20
- get() {
21
- return props.color;
22
- },
23
- set(value) {
24
- emit("update:color", value);
20
+ const _mode = props.mode || "rgb";
21
+ const colorValue = ref("");
22
+ const colorRgb = (_color) => {
23
+ if (_color.includes("rgb")) {
24
+ return _color;
25
+ }
26
+ const red = parseInt(_color.slice(1, 3), 16);
27
+ const green = parseInt(_color.slice(3, 5), 16);
28
+ const blue = parseInt(_color.slice(5, 7), 16);
29
+ return `rgb(${red},${green},${blue})`;
30
+ };
31
+ const listValues = computed(() => {
32
+ if (_mode === "rgb") {
33
+ return props.colorList.map((color) => {
34
+ return colorRgb(color);
35
+ });
25
36
  }
37
+ return props.colorList;
26
38
  });
27
39
  const colorChange = (_color) => {
28
40
  if (_color) {
29
- colorValue.value = _color.replace(/\s+/g, "");
41
+ if (_mode === "rgb") {
42
+ colorValue.value = colorRgb(_color.replace(/\s+/g, ""));
43
+ } else {
44
+ colorValue.value = _color;
45
+ }
46
+ emit("update:color", JSON.parse(JSON.stringify(colorValue.value)));
30
47
  }
31
48
  };
49
+ watch(
50
+ () => props.color,
51
+ () => {
52
+ if (_mode === "rgb") {
53
+ colorValue.value = colorRgb(props.color);
54
+ } else {
55
+ colorValue.value = props.color;
56
+ }
57
+ },
58
+ { immediate: true }
59
+ );
32
60
  return (_ctx, _cache) => {
33
61
  return _ctx.colorList && _ctx.colorList.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
34
62
  createVNode(unref(RadioGroup), {
@@ -39,7 +67,7 @@ const _sfc_main = defineComponent({
39
67
  onChange: colorChange
40
68
  }, {
41
69
  default: withCtx(() => [
42
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.colorList, (colr, index) => {
70
+ (openBlock(true), createElementBlock(Fragment, null, renderList(listValues.value, (colr, index) => {
43
71
  return openBlock(), createBlock(unref(Radio), {
44
72
  key: index,
45
73
  style: normalizeStyle({ background: `${colr} !important` }),
@@ -11,25 +11,53 @@ const _sfc_main = vue.defineComponent({
11
11
  __name: "component",
12
12
  props: {
13
13
  colorList: {},
14
- color: {}
14
+ color: {},
15
+ mode: {}
15
16
  },
16
- emits: ["change", "update:color"],
17
+ emits: ["update:color"],
17
18
  setup(__props, { emit: __emit }) {
18
19
  const props = __props;
19
20
  const emit = __emit;
20
- const colorValue = vue.computed({
21
- get() {
22
- return props.color;
23
- },
24
- set(value) {
25
- emit("update:color", value);
21
+ const _mode = props.mode || "rgb";
22
+ const colorValue = vue.ref("");
23
+ const colorRgb = (_color) => {
24
+ if (_color.includes("rgb")) {
25
+ return _color;
26
+ }
27
+ const red = parseInt(_color.slice(1, 3), 16);
28
+ const green = parseInt(_color.slice(3, 5), 16);
29
+ const blue = parseInt(_color.slice(5, 7), 16);
30
+ return `rgb(${red},${green},${blue})`;
31
+ };
32
+ const listValues = vue.computed(() => {
33
+ if (_mode === "rgb") {
34
+ return props.colorList.map((color) => {
35
+ return colorRgb(color);
36
+ });
26
37
  }
38
+ return props.colorList;
27
39
  });
28
40
  const colorChange = (_color) => {
29
41
  if (_color) {
30
- colorValue.value = _color.replace(/\s+/g, "");
42
+ if (_mode === "rgb") {
43
+ colorValue.value = colorRgb(_color.replace(/\s+/g, ""));
44
+ } else {
45
+ colorValue.value = _color;
46
+ }
47
+ emit("update:color", JSON.parse(JSON.stringify(colorValue.value)));
31
48
  }
32
49
  };
50
+ vue.watch(
51
+ () => props.color,
52
+ () => {
53
+ if (_mode === "rgb") {
54
+ colorValue.value = colorRgb(props.color);
55
+ } else {
56
+ colorValue.value = props.color;
57
+ }
58
+ },
59
+ { immediate: true }
60
+ );
33
61
  return (_ctx, _cache) => {
34
62
  return _ctx.colorList && _ctx.colorList.length ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
35
63
  vue.createVNode(vue.unref(webVue.RadioGroup), {
@@ -40,7 +68,7 @@ const _sfc_main = vue.defineComponent({
40
68
  onChange: colorChange
41
69
  }, {
42
70
  default: vue.withCtx(() => [
43
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.colorList, (colr, index) => {
71
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(listValues.value, (colr, index) => {
44
72
  return vue.openBlock(), vue.createBlock(vue.unref(webVue.Radio), {
45
73
  key: index,
46
74
  style: vue.normalizeStyle({ background: `${colr} !important` }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmstops/pro-compo",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vue",