@vrx-arco/pro-components
Version:
<p align="center"> <img src="https://vrx-arco.github.io/arco-design-pro/favicon.svg" width="200" height="250"> </p>
45 lines (44 loc) • 1.65 kB
JavaScript
import { injectSearchBar } from "./context.js";
import { formGridItemProps } from "../FormGrid/props.js";
import { FormGridItem } from "../FormGrid/FormGridItem.js";
import { createVNode, defineComponent, mergeProps } from "vue";
const SearchBarItem = /* @__PURE__ */ defineComponent({
name: "vrx-arco-search-bar-item",
props: {
...formGridItemProps(),
gridProps: Object,
autoUpdate: [Boolean, String]
},
setup: (props, { slots }) => {
const { gridProps, model, autoUpdate: pAutoUpdate } = injectSearchBar();
return () => {
const { autoUpdate,...otherProps } = props;
const renderDefaultSlot = () => {
const defaultSlot = slots.default?.();
const { field } = props;
const isAutoUpdate = autoUpdate || pAutoUpdate.value;
const firstDefaultSlotProps = defaultSlot?.[0];
if (!firstDefaultSlotProps) return defaultSlot;
if (isAutoUpdate && field) {
firstDefaultSlotProps.props ||= {};
firstDefaultSlotProps.dynamicProps ||= [];
const modelKey = autoUpdate === true || !autoUpdate ? "modelValue" : autoUpdate;
firstDefaultSlotProps.dynamicProps.push(modelKey);
firstDefaultSlotProps.patchFlag = 8;
firstDefaultSlotProps.props[modelKey] = model.value[field];
firstDefaultSlotProps.props[`onUpdate:${modelKey}`] = (value) => {
model.value[field] = value;
};
}
return defaultSlot;
};
return createVNode(FormGridItem, mergeProps(otherProps, { "gridProps": otherProps.gridProps || gridProps.value }), {
default: () => [renderDefaultSlot()],
label: slots.label,
help: slots.help,
extra: slots.extra
});
};
}
});
export { SearchBarItem };