ideaz-element
Version:
<p align="center"> <a href="" target="_blank" rel="noopener noreferrer"> <img src="./docs/public/logo.svg" alt="Ideaz Element" width="180" style="width: 180px;" /> </a> </p>
1 lines • 2.58 kB
Source Map (JSON)
{"version":3,"file":"useFormSlots.mjs","sources":["../../../../../../packages/element/form/src/hooks/useFormSlots.tsx"],"sourcesContent":["// import { h } from 'vue';\nimport { isFunction, isSlot } from '@ideaz/utils'\nimport type { VNode } from 'vue'\nimport FormItemLabel from '../FormItemLabel'\nimport type { FormProps } from '../props'\nimport type { FormColumn, Slots } from '../../../types'\n\nexport function useFormSlots(col: FormColumn, slots: Slots, props: FormProps) {\n const scopedSlots: Slots = {}\n\n const getLabelSlotName = () => {\n if (isSlot(col.label))\n return col.label as string\n return 'label'\n }\n\n scopedSlots[getLabelSlotName()] = () => {\n const labelSlotName = getLabelSlotName()\n if (isSlot(col.label) && isFunction(slots[labelSlotName]))\n return (slots[labelSlotName] as (() => VNode))()\n\n if (isFunction(col.label))\n return col.label()\n\n if (col.formItemProps && isFunction(col.formItemProps.label))\n return col.formItemProps.label()\n\n return (\n <FormItemLabel\n {...{\n ...col.formItemProps,\n colon: Object.prototype.hasOwnProperty.call(\n col.formItemProps || {},\n 'colon',\n )\n ? col.formItemProps?.colon\n : props.colon,\n }}\n />\n )\n }\n\n if (col.error) {\n if (isSlot(col.error) && isFunction(slots[col.error as string])) {\n const error = col.error as string\n scopedSlots[error] = () => <div class=\"el-form-item__error\">{(slots[error!] as (() => VNode))()}</div>\n }\n else if (isFunction(col.error)) {\n scopedSlots.error = () => <div class=\"el-form-item__error\">{(col.error as (() => VNode))()}</div>\n }\n else {\n scopedSlots.error = () => <div class=\"el-form-item__error\">{col.error}</div>\n }\n }\n\n return { scopedSlots }\n}\n"],"names":["useFormSlots","col","slots","props","scopedSlots","labelSlotName","getLabelSlotName","isFunction","isSlot","error"],"mappings":";;;;AAOO,SAAAA,EAAAC,GAAAC,GAAAC,GAAA;iDAMH;MAGFC,EAAAA,EAAAA,CAAAA,IAAAA,MAAAA;;AACE,UAAAC,IAAAC,EAAA;4CAIAC,EAAAN,EAAA,KAAA,IAAAA,EAAA,MAAA;;;IAeqB,GAAA,IAAA;AAAA;AAOrB,QAAAO,EAAAP,EAAA,KAAA,KAAAM,EAAAL,EAAAD,EAAA,KAAA,CAAA,GAAA;AACE,YAAAQ,IAAAR,EAAA;AACAG,MAAAA,EAAAA,CAAAA,IAAAA,MAAAA,EAAAA,OAAAA;AAAAA,QAAqB,OAAA;AAAA,MAAA,GAAA,CAAAF,EAAAO,CAAA,EAAA,CAAA,CAAA;AAAA,wBAGrBL,EAAAA,QAAAA,MAAAA,EAAAA,OAAAA;AAAAA,MAAoB,OAAA;AAAA,IAAA,GAAA,CAAAH,EAAA,MAAA,CAAA,CAAA,IAGpBG,EAAAA,QAAAA,MAAAA,EAAAA,OAAAA;AAAAA,MAAoB,OAAA;AAAA;;IAIfA,aAAAA;AAAAA;AACX;"}