{"version":3,"file":"form-item.vue.mjs","sources":["../../../../../packages/components/form/src/form-item.vue"],"sourcesContent":["<template>\n  <div ref=\"formItemRef\" :class=\"formItemClass\">\n    <label\n      v-if=\"currentLabel\"\n      :for=\"field\"\n      :title=\"currentLabel\"\n      :class=\"ns.e('label')\"\n      :style=\"labelStyle\"\n    >\n      <span :class=\"ns.e('label-text')\">\n        <slot name=\"label\" :label=\"currentLabel\">\n          {{ currentLabel }}\n        </slot>\n      </span>\n\n      <ElTooltip v-if=\"tips\" :content=\"tips\" raw-content>\n        <ElIcon>\n          <InfoFilled />\n        </ElIcon>\n      </ElTooltip>\n    </label>\n\n    <div :class=\"ns.e('content')\">\n      <slot></slot>\n\n      <transition name=\"el-zoom-in-top\">\n        <div v-if=\"errorVisible\" :class=\"ns.e('error')\">\n          {{ validateMessage }}\n        </div>\n      </transition>\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\">\nimport { computed, defineComponent, inject, ref, nextTick, provide } from 'vue'\nimport { formItemKey, formKey } from '@element-ultra/tokens'\nimport { addUnit } from '@element-ultra/utils'\nimport { InfoFilled } from 'icon-ultra'\nimport type { CSSProperties } from 'vue'\nimport ElIcon from '@element-ultra/components/icon'\nimport ElTooltip from '@element-ultra/components/tooltip'\nimport { useNamespace, useSize } from '@element-ultra/hooks'\n\nexport default defineComponent({\n  name: 'ElFormItem',\n  componentName: 'ElFormItem',\n\n  components: {\n    InfoFilled,\n    ElIcon,\n    ElTooltip\n  },\n\n  props: {\n    label: String,\n    field: String,\n    tips: String,\n    required: {\n      type: Boolean\n    },\n    labelWidth: {\n      type: [String, Number],\n      default: ''\n    }\n  },\n  setup(props) {\n    const elForm = inject(formKey)\n    const ns = useNamespace('form-item')\n    const validateMessage = ref('')\n    const formItemRef = ref<HTMLDivElement>()\n\n    const labelStyle = computed(() => {\n      const ret: CSSProperties = {}\n\n      if (!elForm) return ret\n\n      const { props } = elForm\n      if (props.labelPosition === 'top') return ret\n      const labelWidth = addUnit(props.labelWidth)\n      if (labelWidth) {\n        ret.width = labelWidth\n      }\n      return ret\n    })\n\n    const isRequired = computed(() => {\n      if (!elForm || !props.field) return false\n      return props.required ?? elForm.formRules?.[props.field]?.required\n    })\n\n    const validate = async () => {\n      if (!props.field || !elForm) return null\n      const errMsg = await elForm?.validateField(props.field)\n      validateMessage.value = errMsg || ''\n      return !errMsg\n    }\n\n    const clearValidate = () => {\n      validateMessage.value = ''\n    }\n\n    // 重置字段值\n    const reset = () => {\n      if (!props.field) return\n\n      elForm?.resetField(props.field)\n\n      nextTick(() => clearValidate())\n    }\n\n    const formItem = {\n      reset,\n      clearValidate,\n      validate\n    }\n\n    provide(formItemKey, formItem)\n\n    const formItemSize = useSize({ props })\n\n    const formItemClass = computed(() => {\n      const ret = [ns.b(), ns.m(formItemSize.value)]\n\n      isRequired.value && ret.push('is-required')\n      errorVisible.value && ret.push('is-error')\n\n      return ret\n    })\n\n    const errorVisible = computed(() => !!validateMessage.value)\n\n    const currentLabel = computed(() =>\n      props.label ? props.label + (elForm?.props.labelSuffix || '') : ''\n    )\n\n    return {\n      formItemRef,\n      formItemClass,\n      errorVisible,\n      elForm,\n      labelStyle,\n      validate,\n      validateMessage,\n      reset,\n      clearValidate,\n      currentLabel,\n      ns,\n      isRequired\n    }\n  }\n})\n</script>\n"],"names":["_resolveComponent","_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_createBlock","_withCtx","_createVNode","_createCommentVNode","_createElementVNode","_renderSlot","_Transition"],"mappings":";;;;;;;;+BACEA,iBA8BM,WAAA,CAAA,CAAA;AA9BuB,EAAA,OAAAC,WAAA,EAAAC,kBAAA;AAAA,IAAE,KAAA;AAAA,IAAa;AAAA,MAAA,GAAA,EAAA,aAAA;AAAA,aAElCC,cAAY,CAAA,IAAA,CAAA,aAAA,CAAA;AAAA,KAAA;AAAA;oCACZ,EAAA,EAAKD,mBAAA,OAAA,EAAA;AAAA,QACV,GAAK,EAAA,CAAA;AAAA,QACL,KAAK,IAAA,CAAA,KAA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