Skip to content

Commit

Permalink
feat(generator): 自定义渲染函数
Browse files Browse the repository at this point in the history
  • Loading branch information
F-loat committed Dec 1, 2021
1 parent 38943d7 commit eab36aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tools/schema-generator/src/Provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function Provider(props, ref) {
widgets = {},
mapping = {},
children,
fieldRender,
fieldWrapperRender,
} = props;

const transformer = {
Expand Down Expand Up @@ -201,6 +203,8 @@ function Provider(props, ref) {
frProps,
displaySchema,
displaySchemaString,
fieldRender,
fieldWrapperRender,
...rootState,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RenderField = ({
children,
}) => {
const { schema, data } = item;
const { onItemChange, flatten, widgets, mapping, frProps = {} } = useStore();
const { onItemChange, flatten, widgets, mapping, frProps = {}, fieldRender } = useStore();
const { labelWidth, displayType, showValidate } = frProps;
const { title, description, required } = schema;

Expand Down Expand Up @@ -81,7 +81,7 @@ const RenderField = ({
...schema['props'],
});

return (
const originNode = (
<>
{schema.title ? (
<div className={labelClass} style={labelStyle}>
Expand Down Expand Up @@ -117,6 +117,9 @@ const RenderField = ({
</div>
</>
);

if (!fieldRender) return originNode;
return fieldRender(schema, usefulWidgetProps, originNode);
};

export default RenderField;
10 changes: 8 additions & 2 deletions tools/schema-generator/src/components/Canvas/core/Wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../../utils';
import './Wrapper.less';

export default function Wrapper({
function Wrapper({
$id,
item,
inside = false,
Expand All @@ -24,6 +24,7 @@ export default function Wrapper({
selected,
userProps,
errorFields,
fieldWrapperRender,
} = useStore();
const {
controlButtons,
Expand Down Expand Up @@ -242,7 +243,7 @@ export default function Wrapper({
.map(key => flatten[key].schema.$id)
.filter(key => key === schema.$id).length > 1;

return (
const originNode = (
<div
ref={boxRef}
style={overwriteStyle}
Expand Down Expand Up @@ -295,4 +296,9 @@ export default function Wrapper({
)}
</div>
);

if (!fieldWrapperRender) return originNode;
return fieldWrapperRender(schema, isSelected, originNode);
}

export default Wrapper;

0 comments on commit eab36aa

Please sign in to comment.