You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
6.2 KiB
1 line
6.2 KiB
{"ast":null,"code":"import { inject, ref, computed, toRaw } from 'vue';\nimport { isEqual } from 'lodash-unified';\nimport '../../../form/index.mjs';\nimport '../../../../utils/index.mjs';\nimport { checkboxGroupContextKey } from '../constants.mjs';\nimport { isPropAbsent, isBoolean } from '../../../../utils/types.mjs';\nimport { isArray, isObject } from '@vue/shared';\nimport { useFormSize } from '../../../form/src/hooks/use-form-common-props.mjs';\nconst useCheckboxStatus = (props, slots, {\n model\n}) => {\n const checkboxGroup = inject(checkboxGroupContextKey, void 0);\n const isFocused = ref(false);\n const actualValue = computed(() => {\n if (!isPropAbsent(props.value)) {\n return props.value;\n }\n return props.label;\n });\n const isChecked = computed(() => {\n const value = model.value;\n if (isBoolean(value)) {\n return value;\n } else if (isArray(value)) {\n if (isObject(actualValue.value)) {\n return value.map(toRaw).some(o => isEqual(o, actualValue.value));\n } else {\n return value.map(toRaw).includes(actualValue.value);\n }\n } else if (value !== null && value !== void 0) {\n return value === props.trueValue || value === props.trueLabel;\n } else {\n return !!value;\n }\n });\n const checkboxButtonSize = useFormSize(computed(() => {\n var _a;\n return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;\n }), {\n prop: true\n });\n const checkboxSize = useFormSize(computed(() => {\n var _a;\n return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;\n }));\n const hasOwnLabel = computed(() => {\n return !!slots.default || !isPropAbsent(actualValue.value);\n });\n return {\n checkboxButtonSize,\n isChecked,\n isFocused,\n checkboxSize,\n hasOwnLabel,\n actualValue\n };\n};\nexport { useCheckboxStatus };","map":{"version":3,"names":["useCheckboxStatus","props","slots","model","checkboxGroup","inject","checkboxGroupContextKey","isFocused","ref","actualValue","computed","isPropAbsent","value","label","isChecked","isBoolean","isArray","isObject","map","toRaw","some","o","isEqual","includes","trueValue","trueLabel","checkboxButtonSize","useFormSize","_a","size","prop","checkboxSize","hasOwnLabel","default"],"sources":["../../../../../../../packages/components/checkbox/src/composables/use-checkbox-status.ts"],"sourcesContent":["import { computed, inject, ref, toRaw } from 'vue'\nimport { isEqual } from 'lodash-unified'\nimport { useFormSize } from '@element-plus/components/form'\nimport { isArray, isBoolean, isObject, isPropAbsent } from '@element-plus/utils'\nimport { checkboxGroupContextKey } from '../constants'\n\nimport type { ComponentInternalInstance } from 'vue'\nimport type { CheckboxProps } from '../checkbox'\nimport type { CheckboxModel } from '../composables'\n\nexport const useCheckboxStatus = (\n props: CheckboxProps,\n slots: ComponentInternalInstance['slots'],\n { model }: Pick<CheckboxModel, 'model'>\n) => {\n const checkboxGroup = inject(checkboxGroupContextKey, undefined)\n const isFocused = ref(false)\n const actualValue = computed(() => {\n // In version 2.x, if there's no props.value, props.label will act as props.value\n // In version 3.x, remove this computed value, use props.value instead.\n if (!isPropAbsent(props.value)) {\n return props.value\n }\n return props.label\n })\n const isChecked = computed<boolean>(() => {\n const value = model.value\n if (isBoolean(value)) {\n return value\n } else if (isArray(value)) {\n if (isObject(actualValue.value)) {\n return value.map(toRaw).some((o) => isEqual(o, actualValue.value))\n } else {\n return value.map(toRaw).includes(actualValue.value)\n }\n } else if (value !== null && value !== undefined) {\n return value === props.trueValue || value === props.trueLabel\n } else {\n return !!value\n }\n })\n\n const checkboxButtonSize = useFormSize(\n computed(() => checkboxGroup?.size?.value),\n {\n prop: true,\n }\n )\n const checkboxSize = useFormSize(computed(() => checkboxGroup?.size?.value))\n\n const hasOwnLabel = computed<boolean>(() => {\n return !!slots.default || !isPropAbsent(actualValue.value)\n })\n\n return {\n checkboxButtonSize,\n isChecked,\n isFocused,\n checkboxSize,\n hasOwnLabel,\n actualValue,\n }\n}\n\nexport type CheckboxStatus = ReturnType<typeof useCheckboxStatus>\n"],"mappings":";;;;;;;;AAKY,MAACA,iBAAiB,GAAGA,CAACC,KAAK,EAAEC,KAAK,EAAE;EAAEC;AAAK,CAA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