UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

116 lines (115 loc) 3.17 kB
"use strict"; var vue = require("vue"); var evtd = require("evtd"); const HANDLE_SIZE = "12px"; const RADIUS = "6px"; var Pallete = vue.defineComponent({ name: "Pallete", props: { clsPrefix: { type: String, required: true }, rgba: { type: Array, default: null }, displayedHue: { type: Number, required: true }, displayedSv: { type: Array, required: true }, onUpdateSV: { type: Function, required: true }, onComplete: Function }, setup(props) { const palleteRef = vue.ref(null); function handleMouseDown(e) { if (!palleteRef.value) return; evtd.on("mousemove", document, handleMouseMove); evtd.on("mouseup", document, handleMouseUp); handleMouseMove(e); } function handleMouseMove(e) { const { value: palleteEl } = palleteRef; if (!palleteEl) return; const { width, height, left, bottom } = palleteEl.getBoundingClientRect(); const newV = (bottom - e.clientY) / height; const newS = (e.clientX - left) / width; const normalizedNewS = 100 * (newS > 1 ? 1 : newS < 0 ? 0 : newS); const normalizedNewV = 100 * (newV > 1 ? 1 : newV < 0 ? 0 : newV); props.onUpdateSV(normalizedNewS, normalizedNewV); } function handleMouseUp() { var _a; evtd.off("mousemove", document, handleMouseMove); evtd.off("mouseup", document, handleMouseUp); (_a = props.onComplete) == null ? void 0 : _a.call(props); } return { palleteRef, handleColor: vue.computed(() => { const { rgba } = props; if (!rgba) return ""; return `rgb(${rgba[0]}, ${rgba[1]}, ${rgba[2]})`; }), handleMouseDown }; }, render() { const { clsPrefix } = this; return vue.createVNode("div", { "class": `${clsPrefix}-color-picker-pallete`, "onMousedown": this.handleMouseDown, "ref": "palleteRef" }, [vue.createVNode("div", { "class": `${clsPrefix}-color-picker-pallete__layer`, "style": { backgroundImage: `linear-gradient(90deg, white, hsl(${this.displayedHue}, 100%, 50%))` } }, null), vue.createVNode("div", { "class": `${clsPrefix}-color-picker-pallete__layer ${clsPrefix}-color-picker-pallete__layer--shadowed`, "style": { backgroundImage: "linear-gradient(180deg, rgba(0, 0, 0, 0%), rgba(0, 0, 0, 100%))" } }, null), this.rgba && vue.createVNode("div", { "class": `${clsPrefix}-color-picker-handle`, "style": { width: HANDLE_SIZE, height: HANDLE_SIZE, borderRadius: RADIUS, left: `calc(${this.displayedSv[0]}% - ${RADIUS})`, bottom: `calc(${this.displayedSv[1]}% - ${RADIUS})` } }, [vue.createVNode("div", { "class": `${clsPrefix}-color-picker-handle__fill`, "style": { backgroundColor: this.handleColor, borderRadius: RADIUS, width: HANDLE_SIZE, height: HANDLE_SIZE } }, null)])]); } }); module.exports = Pallete;