{"version":3,"file":"button-custom.mjs","sources":["../../../../../../packages/components/button/src/button-custom.ts"],"sourcesContent":["import { computed } from 'vue'\nimport { TinyColor } from '@ctrl/tinycolor'\nimport { useNamespace } from '@element-plus/hooks'\nimport { useFormDisabled } from '@element-plus/components/form'\nimport type { ButtonProps } from './button'\n\nexport function darken(color: TinyColor, amount = 20) {\n return color.mix('#141414', amount).toString()\n}\n\nexport function useButtonCustomStyle(props: ButtonProps) {\n const _disabled = useFormDisabled()\n const ns = useNamespace('button')\n\n // calculate hover & active color by custom color\n // only work when custom color\n return computed(() => {\n let styles: Record = {}\n\n let buttonColor = props.color\n\n if (buttonColor) {\n const match = (buttonColor as string).match(/var\\((.*?)\\)/)\n if (match) {\n buttonColor = window\n .getComputedStyle(window.document.documentElement)\n .getPropertyValue(match[1])\n }\n const color = new TinyColor(buttonColor)\n const activeBgColor = props.dark\n ? color.tint(20).toString()\n : darken(color, 20)\n\n if (props.plain) {\n styles = ns.cssVarBlock({\n 'bg-color': props.dark\n ? darken(color, 90)\n : color.tint(90).toString(),\n 'text-color': buttonColor,\n 'border-color': props.dark\n ? darken(color, 50)\n : color.tint(50).toString(),\n 'hover-text-color': `var(${ns.cssVarName('color-white')})`,\n 'hover-bg-color': buttonColor,\n 'hover-border-color': buttonColor,\n 'active-bg-color': activeBgColor,\n 'active-text-color': `var(${ns.cssVarName('color-white')})`,\n 'active-border-color': activeBgColor,\n })\n\n if (_disabled.value) {\n styles[ns.cssVarBlockName('disabled-bg-color')] = props.dark\n ? darken(color, 90)\n : color.tint(90).toString()\n styles[ns.cssVarBlockName('disabled-text-color')] = props.dark\n ? darken(color, 50)\n : color.tint(50).toString()\n styles[ns.cssVarBlockName('disabled-border-color')] = props.dark\n ? darken(color, 80)\n : color.tint(80).toString()\n }\n } else {\n const hoverBgColor = props.dark\n ? darken(color, 30)\n : color.tint(30).toString()\n const textColor = color.isDark()\n ? `var(${ns.cssVarName('color-white')})`\n : `var(${ns.cssVarName('color-black')})`\n styles = ns.cssVarBlock({\n 'bg-color': buttonColor,\n 'text-color': textColor,\n 'border-color': buttonColor,\n 'hover-bg-color': hoverBgColor,\n 'hover-text-color': textColor,\n 'hover-border-color': hoverBgColor,\n 'active-bg-color': activeBgColor,\n 'active-border-color': activeBgColor,\n })\n\n if (_disabled.value) {\n const disabledButtonColor = props.dark\n ? darken(color, 50)\n : color.tint(50).toString()\n styles[ns.cssVarBlockName('disabled-bg-color')] = disabledButtonColor\n styles[ns.cssVarBlockName('disabled-text-color')] = props.dark\n ? 'rgba(255, 255, 255, 0.5)'\n : `var(${ns.cssVarName('color-white')})`\n styles[ns.cssVarBlockName('disabled-border-color')] =\n disabledButtonColor\n }\n }\n }\n\n return styles\n })\n}\n"],"names":[],"mappings":";;;;;;;AAIO,SAAS,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE;AAC3C,EAAE,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjD,CAAC;AACM,SAAS,oBAAoB,CAAC,KAAK,EAAE;AAC5C,EAAE,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;AACtC,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AACpC,EAAE,OAAO,QAAQ,CAAC,MAAM;AACxB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC;AACpB,IAAI,IAAI,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC;AAClC,IAAI,IAAI,WAAW,EAAE;AACrB,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AACtD,MAAM,IAAI,KAAK,EAAE;AACjB,QAAQ,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1G,OAAO;AACP,MAAM,MAAM,KAAK,GA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