SColorPicker.js 3.1 KB

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