vue-admin-core
Version:
A Component Library for Vue 3
100 lines (97 loc) • 3.54 kB
JavaScript
import { connect, mapProps, mapReadPretty } from '@formily/vue';
import { defineComponent, computed, h } from 'vue';
import '../../__builtins__/shared/index.mjs';
import '../../preview-text/index.mjs';
import { ElRadioGroup, ElRadioButton, ElRadio } from 'element-plus';
import '../../../components/config-provider/index.mjs';
import { isFunction } from 'lodash-es';
import { transformComponent } from '../../__builtins__/shared/transform-component.mjs';
import { useGlobalConfig } from '../../../components/config-provider/src/hooks/use-global-config.mjs';
import { resolveComponent } from '../../__builtins__/shared/resolve-component.mjs';
import { PreviewText } from '../../preview-text/src/index.mjs';
import { composeExport } from '../../__builtins__/shared/utils.mjs';
const TransformElRadioGroup = transformComponent(ElRadioGroup, {
change: "input"
});
const RadioGroupOption = defineComponent({
name: "FRadioGroup",
props: {
options: {
type: Array,
default: () => []
},
optionType: {
type: String,
default: "default"
},
props: {
type: Object,
default: () => ({
children: "children",
label: "label",
value: "value",
disabled: "disabled"
})
}
},
setup(customProps, { attrs, slots }) {
const config = useGlobalConfig();
const label = computed(() => customProps.props.label || "label");
const value = computed(() => customProps.props.value || "value");
const options = computed(() => customProps.options || []);
return () => {
const OptionType = customProps.optionType === "button" ? ElRadioButton : ElRadio;
const children = options.value.length !== 0 ? {
default: () => options.value.map((option) => {
var _a, _b, _c, _d;
if (typeof option === "string") {
return h(
OptionType,
{ label: option },
{
default: () => {
var _a2;
return [resolveComponent((_a2 = slots == null ? void 0 : slots.option) != null ? _a2 : option, { option })];
}
}
);
} else {
return h(
OptionType,
{
...option,
value: void 0,
label: option[value.value] || option[config.value.dictValueKey],
disabled: isFunction((_a = customProps.props) == null ? void 0 : _a.disabled) ? (_b = customProps.props) == null ? void 0 : _b.disabled(option) : ((_c = customProps.props) == null ? void 0 : _c.disabled) ? option[(_d = customProps.props) == null ? void 0 : _d.disabled] : false
},
{
default: () => {
var _a2;
return [
resolveComponent(
(_a2 = slots == null ? void 0 : slots.option) != null ? _a2 : option[label.value] || option[config.value.dictLabelKey],
{
option
}
)
];
}
}
);
}
})
} : slots;
return h(TransformElRadioGroup, attrs, children);
};
}
});
const RadioGroup = connect(
RadioGroupOption,
mapProps({ dataSource: "options", value: "modelValue" }),
mapReadPretty(PreviewText.Select)
);
const Radio = composeExport(ElRadio, {
Group: RadioGroup
});
export { Radio, Radio as default };
//# sourceMappingURL=index.mjs.map