UNPKG

winbox-ui-next

Version:

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

115 lines (114 loc) 3.16 kB
import { defineComponent, ref, computed, createVNode } from "vue"; import { on, off } from "evtd"; const HANDLE_SIZE = "12px"; const RADIUS = "6px"; var Pallete = 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 = ref(null); function handleMouseDown(e) { if (!palleteRef.value) return; on("mousemove", document, handleMouseMove); 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; off("mousemove", document, handleMouseMove); off("mouseup", document, handleMouseUp); (_a = props.onComplete) == null ? void 0 : _a.call(props); } return { palleteRef, handleColor: computed(() => { const { rgba } = props; if (!rgba) return ""; return `rgb(${rgba[0]}, ${rgba[1]}, ${rgba[2]})`; }), handleMouseDown }; }, render() { const { clsPrefix } = this; return createVNode("div", { "class": `${clsPrefix}-color-picker-pallete`, "onMousedown": this.handleMouseDown, "ref": "palleteRef" }, [createVNode("div", { "class": `${clsPrefix}-color-picker-pallete__layer`, "style": { backgroundImage: `linear-gradient(90deg, white, hsl(${this.displayedHue}, 100%, 50%))` } }, null), 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 && 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})` } }, [createVNode("div", { "class": `${clsPrefix}-color-picker-handle__fill`, "style": { backgroundColor: this.handleColor, borderRadius: RADIUS, width: HANDLE_SIZE, height: HANDLE_SIZE } }, null)])]); } }); export { Pallete as default };