Skip to content

Commit 2ac547c

Browse files
committed
feat(form): use custom ui:padding prop instead of custom template for schema ui settings
1 parent 2471f1c commit 2ac547c

File tree

7 files changed

+53
-63
lines changed

7 files changed

+53
-63
lines changed

src/admin/components/Customize.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const Customize = () => {
7575
className="scrollableTabs"
7676
centered
7777
style={{ height: "100%", width: "100%" }}
78+
tabBarStyle={{ marginBottom: "0px" }}
7879
items={[
7980
{
8081
key: "1",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Collapse, Space } from "antd";
2+
import { partition } from "lodash-es";
3+
4+
const PropKeyEditorObjectFieldTemplate = ({ properties }) => {
5+
const [[uiOptions], otherProps] = partition(
6+
properties,
7+
(prop) => prop.name === "ui:options",
8+
);
9+
const elements = [
10+
uiOptions,
11+
{ title: "Field UI Options", content: otherProps },
12+
];
13+
14+
return uiOptions ? (
15+
<div style={{ padding: "10px", width: "100%" }}>
16+
<Collapse
17+
className="propKeyCollapse"
18+
defaultActiveKey={Array.from(Array(properties.length).keys())}
19+
expandIconPosition="end"
20+
items={elements.map((item, index) => ({
21+
key: index,
22+
label: item.title || item.content.props.schema.title,
23+
children: item.content.length
24+
? item.content.map((i) => i.content)
25+
: item.content,
26+
}))}
27+
/>
28+
</div>
29+
) : (
30+
<Space direction="vertical" style={{ padding: "10px", width: "100%" }}>
31+
{properties.map((item) => item.content)}
32+
</Space>
33+
);
34+
};
35+
36+
export default PropKeyEditorObjectFieldTemplate;

src/admin/utils/fieldTypes.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
UploadOutlined,
2222
} from "@ant-design/icons";
2323
import { placeholder } from "@codemirror/view";
24-
import PropKeyEditorObjectFieldTemplate from "../../forms/templates/PropKeyEditorObjectFieldTemplate";
25-
import UiOptionsObjectFieldTemplate from "../../forms/templates/UiOptionsObjectFieldTemplate";
24+
import PropKeyEditorObjectFieldTemplate from "../formComponents/PropKeyEditorObjectFieldTemplate";
2625

2726
// COMMON / EXTRA PROPERTIES:
2827

@@ -121,7 +120,8 @@ export const common = {
121120
"ui:widget": "switch",
122121
},
123122
"ui:order": ["showAsModal", "modal", "*"],
124-
"ui:ObjectFieldTemplate": UiOptionsObjectFieldTemplate,
123+
"ui:padding": 0,
124+
"ui:label": false,
125125
},
126126
"ui:label": {
127127
"ui:widget": "switch",
@@ -546,6 +546,9 @@ const simple = {
546546
tooltipIsMarkdown: true,
547547
},
548548
},
549+
convertToUppercase: {
550+
"ui:widget": "switch",
551+
},
549552
},
550553
},
551554
default: {

src/forms/Form.less

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,13 @@
162162
}
163163
}
164164

165-
.propKeyCollapse
166-
.ant-collapse-content-box
167-
fieldset
168-
.ant-col
169-
.ant-col:last-of-type
170-
.ant-form-item:last-of-type {
171-
margin-bottom: 0;
172-
}
173-
174-
.propKeyCollapse
175-
.ant-collapse-content-box
176-
> .form-group:last-of-type
177-
> .ant-form-item:last-of-type {
178-
margin-bottom: 0;
165+
.propKeyCollapse .ant-collapse-content-box {
166+
fieldset .ant-col .ant-col:last-of-type .ant-form-item:last-of-type {
167+
margin-bottom: 0;
168+
}
169+
> .form-group:last-of-type > .ant-form-item:last-of-type {
170+
margin-bottom: 0;
171+
}
179172
}
180173
}
181174

src/forms/templates/ObjectFieldTemplate.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const ObjectFieldTemplate = ({
2222
schema,
2323
title,
2424
uiSchema,
25-
isUiOptions,
2625
}) => {
2726
const {
2827
colSpan = 24,
@@ -98,12 +97,12 @@ const ObjectFieldTemplate = ({
9897
return (
9998
<fieldset
10099
style={{
101-
padding: isUiOptions && 0,
100+
padding: uiSchema["ui:padding"],
102101
}}
103102
id={idSchema.$id}
104103
>
105104
<Row gutter={rowGutter} style={{ margin: 0 }}>
106-
{!isUiOptions && (
105+
{(uiSchema["ui:label"] || title) && (
107106
<Col
108107
style={{
109108
padding: "0",
@@ -125,7 +124,7 @@ const ObjectFieldTemplate = ({
125124
<Col
126125
span={24}
127126
className="nestedObject"
128-
style={{ padding: isUiOptions && 0 }}
127+
style={{ padding: uiSchema["ui:padding"] }}
129128
>
130129
<Row gutter={10}>
131130
{properties

src/forms/templates/PropKeyEditorObjectFieldTemplate.jsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/forms/templates/UiOptionsObjectFieldTemplate.jsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)