element-plus
Version:
A Component Library for Vue 3
1 lines • 1.41 kB
Source Map (JSON)
{"version":3,"file":"use-common-color.mjs","names":[],"sources":["../../../../../../../packages/components/color-picker-panel/src/composables/use-common-color.ts"],"sourcesContent":["import { reactive, watch } from 'vue'\nimport Color from '../utils/color'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\n\ntype CommonColorProps = {\n modelValue?: string | null\n showAlpha: boolean\n colorFormat?: string\n}\ntype CommonColorEmits = (event: 'update:modelValue', ...args: any[]) => void\n\nexport const useCommonColor = <\n P extends CommonColorProps,\n E extends CommonColorEmits,\n>(\n props: P,\n emit: E\n) => {\n const color = reactive(\n new Color({\n enableAlpha: props.showAlpha,\n format: props.colorFormat || '',\n value: props.modelValue,\n })\n ) as Color\n\n watch(\n () => [props.colorFormat, props.showAlpha],\n () => {\n color.enableAlpha = props.showAlpha\n color.format = props.colorFormat || color.format\n color.doOnChange()\n emit(UPDATE_MODEL_EVENT, color.value)\n }\n )\n\n return {\n color,\n }\n}\n"],"mappings":";;;;;AAWA,MAAa,kBAIX,OACA,SACG;CACH,MAAM,QAAQ,SACZ,IAAI,MAAM;EACR,aAAa,MAAM;EACnB,QAAQ,MAAM,eAAe;EAC7B,OAAO,MAAM;EACd,CAAC,CACH;AAED,aACQ,CAAC,MAAM,aAAa,MAAM,UAAU,QACpC;AACJ,QAAM,cAAc,MAAM;AAC1B,QAAM,SAAS,MAAM,eAAe,MAAM;AAC1C,QAAM,YAAY;AAClB,OAAK,oBAAoB,MAAM,MAAM;GAExC;AAED,QAAO,EACL,OACD"}