UNPKG

@cmstops/pro-compo

Version:

[物料平台文档中心](https://arco.design/docs/material/guide)

91 lines (90 loc) 2.97 kB
"use strict"; var vue = require("vue"); var webVue = require("@arco-design/web-vue"); var colorPicker = require("./components/colorPicker.js"); const _hoisted_1 = { key: 0, class: "color-palette-container" }; const _sfc_main = vue.defineComponent({ ...{ name: "colorPalette" }, __name: "component", props: { colorList: {}, color: {}, mode: {} }, emits: ["update:color"], setup(__props, { emit: __emit }) { const props = __props; const emit = __emit; const _mode = props.mode || "rgb"; const colorValue = vue.ref(""); const colorRgb = (_color) => { if (_color.includes("rgb")) { return _color; } const red = parseInt(_color.slice(1, 3), 16); const green = parseInt(_color.slice(3, 5), 16); const blue = parseInt(_color.slice(5, 7), 16); return `rgb(${red},${green},${blue})`; }; const listValues = vue.computed(() => { if (_mode === "rgb") { return props.colorList.map((color) => { return colorRgb(color); }); } return props.colorList; }); const colorChange = (_color) => { if (_color) { if (_mode === "rgb") { colorValue.value = colorRgb(_color.replace(/\s+/g, "")); } else { colorValue.value = _color; } emit("update:color", JSON.parse(JSON.stringify(colorValue.value))); } }; vue.watch( () => props.color, () => { if (_mode === "rgb") { colorValue.value = colorRgb(props.color); } else { colorValue.value = props.color; } }, { immediate: true } ); return (_ctx, _cache) => { return _ctx.colorList && _ctx.colorList.length ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [ vue.createVNode(vue.unref(webVue.RadioGroup), { modelValue: colorValue.value, "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => colorValue.value = $event), class: "color-radio-group", type: "button", onChange: colorChange }, { default: vue.withCtx(() => [ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(listValues.value, (colr, index) => { return vue.openBlock(), vue.createBlock(vue.unref(webVue.Radio), { key: index, style: vue.normalizeStyle({ background: `${colr} !important` }), value: colr }, null, 8, ["style", "value"]); }), 128)), vue.createVNode(colorPicker, { modelValue: colorValue.value, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => colorValue.value = $event), onChange: colorChange }, null, 8, ["modelValue"]) ]), _: 1 }, 8, ["modelValue"]) ])) : vue.createCommentVNode("v-if", true); }; } }); module.exports = _sfc_main;