UNPKG

@xdp/button

Version:

button el-button vue3

91 lines (88 loc) 3.42 kB
import { defineComponent, computed, h } from 'vue'; import { ElButton } from 'element-plus'; import { useConfig, useComponentProps } from '@xdp/config'; import { generateProps, generateEmits, setFieldValue } from '@d-render/shared'; import { componentScheme } from './component.scheme'; import { useButtonConfigMap } from './use-button-config-map'; import { getFieldValue } from '@xdp/utils'; var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var index = defineComponent({ name: "CipButton", props: generateProps(componentScheme), emits: generateEmits(componentScheme), setup(props, context) { const xdpConfig = useConfig(); const buttonConfigMap = useButtonConfigMap(); const buttonConfig = computed(() => { const config = buttonConfigMap.value[props.buttonType] || {}; return Object.keys(config).reduce((acc, key) => { if (config[key]) { setFieldValue(acc, `button.${key}`, config[key]); } return acc; }, {}); }); const buttonPropsKey = [ ["size", "default"], "type", "plain", "bg", "link", "round", "circle", "loading", "loadingIcon", "disabled", "icon", "autofocus", "nativeType", "autoInsertSpace", "color", "dark" ]; const customPropsKey = ["square", "map"]; const elButtonProps = useComponentProps(props, "button", buttonPropsKey, [buttonConfig, xdpConfig]); const customProps = useComponentProps(props, "button", customPropsKey, [buttonConfig, xdpConfig]); const buttonText = getFieldValue(buttonConfig.value, "button.text"); return () => h(ElButton, __spreadProps(__spreadValues({ class: ["cip-button", { "cip-button--square": customProps.value.square, "cip-button--map": customProps.value.map, "cip-button-text": elButtonProps.value.link, [`cip-button-text--${elButtonProps.value.size}`]: elButtonProps.value.link }], text: props.text }, elButtonProps.value), { onClick: (...args) => context.emit("click", ...args) }), { default: customProps.value.circle || customProps.value.square ? void 0 : () => { var _a, _b; return ((_b = (_a = context.slots).default) == null ? void 0 : _b.call(_a, { text: buttonText != null ? buttonText : "" })) || buttonText; }, icon: !elButtonProps.value.icon ? void 0 : () => typeof elButtonProps.value.icon === "string" ? h("i", { class: elButtonProps.value.icon }) : h(elButtonProps.value.icon) }); } }); export { index as default };