SColorPicker.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { ref as C, computed as w, openBlock as d, createElementBlock as v, createVNode as f, withCtx as c, normalizeStyle as i, createElementVNode as t, Fragment as S, renderList as x, normalizeClass as I, toDisplayString as L } from "vue";
  2. import { n as N, I as z } from "./index2.js";
  3. import { _ as V } from "./index6.js";
  4. const $ = { class: "s-color-picker-common" }, B = { class: "picker-panel" }, E = { class: "palette" }, F = ["onClick"], P = { class: "native-row" }, U = ["value"], j = { class: "native-tip" }, A = {
  5. __name: "SColorPicker",
  6. props: {
  7. // 颜色值(hex),支持 v-model:value
  8. value: {
  9. type: String,
  10. default: ""
  11. },
  12. // 色块宽度,单位 px
  13. width: {
  14. type: Number,
  15. default: 40
  16. },
  17. // 透传给色块的样式
  18. blockStyle: {
  19. type: Object,
  20. default() {
  21. return {};
  22. }
  23. }
  24. },
  25. emits: ["update:value", "change"],
  26. setup(a, { emit: _ }) {
  27. const r = a, u = _, l = C(!1), m = [
  28. "#1677ff",
  29. "#1167ff",
  30. "#722ed1",
  31. "#eb2f96",
  32. "#f5222d",
  33. "#fa541c",
  34. "#fa8c16",
  35. "#faad14",
  36. "#13c2c2",
  37. "#52c41a",
  38. "#1afa29",
  39. "#44d7b6"
  40. ], n = w(
  41. () => /^#([0-9a-fA-F]{6})$/.test(r.value) ? r.value.toLowerCase() : "#1677ff"
  42. ), s = (e) => {
  43. u("update:value", e), u("change", e);
  44. }, k = (e) => {
  45. s(e), l.value = !1;
  46. }, h = (e) => {
  47. s(e.target.value);
  48. }, y = (e) => {
  49. s(e);
  50. };
  51. return (e, p) => {
  52. const b = z, g = V;
  53. return d(), v("div", $, [
  54. f(g, {
  55. trigger: "click",
  56. placement: "bottomLeft",
  57. open: l.value,
  58. "onUpdate:open": p[0] || (p[0] = (o) => l.value = o)
  59. }, {
  60. content: c(() => [
  61. t("div", B, [
  62. t("div", E, [
  63. (d(), v(S, null, x(m, (o) => t("span", {
  64. class: I(["swatch", { active: o.toLowerCase() === n.value }]),
  65. key: o,
  66. style: i({ backgroundColor: o }),
  67. onClick: (D) => k(o)
  68. }, null, 14, F)), 64))
  69. ]),
  70. t("div", P, [
  71. t("input", {
  72. type: "color",
  73. class: "native-color",
  74. value: n.value,
  75. onInput: h
  76. }, null, 40, U),
  77. t("span", j, L(e.$l("自定义颜色")), 1)
  78. ])
  79. ])
  80. ]),
  81. default: c(() => [
  82. f(b, {
  83. class: "color-input",
  84. value: a.value,
  85. style: i({ width: a.width + "px" }),
  86. placeholder: "",
  87. "onUpdate:value": y
  88. }, {
  89. prefix: c(() => [
  90. t("span", {
  91. class: "color-block",
  92. style: i([{ backgroundColor: n.value }, a.blockStyle])
  93. }, null, 4)
  94. ]),
  95. _: 1
  96. }, 8, ["value", "style"])
  97. ]),
  98. _: 1
  99. }, 8, ["open"])
  100. ]);
  101. };
  102. }
  103. }, H = /* @__PURE__ */ N(A, [["__scopeId", "data-v-4b31c826"]]);
  104. export {
  105. H as default
  106. };