@@ -15,13 +15,11 @@ import {
15
15
Steps ,
16
16
} from "antd" ;
17
17
import styled from "styled-components" ;
18
- import type { JsonSchema } from "@jsonforms/core" ;
19
18
import type { JSONSchema7 } from "json-schema" ;
20
19
import { debounce } from "lodash" ;
21
20
import dayjs from "dayjs" ;
22
21
import { trans } from "i18n" ;
23
22
import type {
24
- JsonFormsUiSchema ,
25
23
FieldUiSchema ,
26
24
Layout ,
27
25
Categorization ,
@@ -30,10 +28,14 @@ import type {
30
28
Category ,
31
29
Control
32
30
} from "./types" ;
33
- import type { SwitchChangeEventHandler } from "antd/es/switch" ;
31
+ import { useContainerWidth } from "./jsonSchemaFormComp" ;
32
+
34
33
const { TextArea } = Input ;
35
34
36
- const Container = styled . div `
35
+ const Container = styled . div
36
+ `
37
+ gap: 16px;
38
+ width: 100%;
37
39
.ant-form-item {
38
40
margin-bottom: 16px;
39
41
}
@@ -62,11 +64,6 @@ const Container = styled.div`
62
64
}
63
65
` ;
64
66
65
- interface HorizontalLayout {
66
- type : "HorizontalLayout" ;
67
- elements : Control [ ] ;
68
- }
69
-
70
67
const JsonFormsRenderer : React . FC < JsonFormsRendererProps > = ( {
71
68
schema,
72
69
data,
@@ -78,6 +75,7 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
78
75
validationState : externalValidationState ,
79
76
onValidationChange,
80
77
} ) => {
78
+ const containerWidth = useContainerWidth ( ) ;
81
79
// Local state to handle immediate updates
82
80
const [ localData , setLocalData ] = useState ( data ) ;
83
81
// Track focused field
@@ -116,7 +114,7 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
116
114
if ( ! uiSchema ) return undefined ;
117
115
118
116
// For JSONForms UI schema, we need to find the Control element that matches the path
119
- if ( uiSchema . type === "HorizontalLayout" && Array . isArray ( uiSchema . elements ) ) {
117
+ if ( Array . isArray ( uiSchema . elements ) ) {
120
118
const control = uiSchema . elements . find ( ( element : any ) => {
121
119
if ( element . type === "Control" ) {
122
120
// Convert the scope path to match our field path
@@ -666,24 +664,41 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
666
664
667
665
// Fallback to default rendering if not a categorization
668
666
return (
669
- < Container style = { style } >
670
- < Form layout = "vertical" >
671
- { Object . entries ( schema . properties || { } ) . map (
672
- ( [ key , fieldSchema ] : [ string , any ] ) =>
673
- renderField ( key , fieldSchema , localData ?. [ key ] )
674
- ) }
675
- < Form . Item >
676
- < Button
677
- type = "primary"
678
- onClick = { handleSubmit }
679
- style = { { float : "right" } }
680
- >
681
- { trans ( "event.submit" ) }
682
- </ Button >
683
- </ Form . Item >
684
- </ Form >
685
- </ Container >
667
+ < Container >
668
+ < Form layout = "vertical" >
669
+ < Row gutter = { 16 } >
670
+ { Object . entries ( schema . properties || { } ) . map ( ( [ key , fieldSchema ] ) => {
671
+ const fieldUiSchema = uiSchema ?. [ key ] || { } ;
672
+ const colSpan = calculateColSpan ( fieldUiSchema , containerWidth ) ;
673
+
674
+ return (
675
+ < Col key = { key } { ...colSpan } >
676
+ { renderField ( key , fieldSchema , localData ?. [ key ] ) }
677
+ </ Col >
678
+ ) ;
679
+ } ) }
680
+ </ Row >
681
+ < Form . Item >
682
+ < Button
683
+ type = "primary"
684
+ onClick = { handleSubmit }
685
+ style = { { float : "right" } }
686
+ >
687
+ { trans ( "event.submit" ) }
688
+ </ Button >
689
+ </ Form . Item >
690
+ </ Form >
691
+ </ Container >
686
692
) ;
687
693
} ;
688
694
689
- export default React . memo ( JsonFormsRenderer ) ;
695
+ const calculateColSpan = ( uiSchema : any , containerWidth : number ) => {
696
+ const colSpan = uiSchema ?. [ "ui:colSpan" ] || { xs : 24 , sm : 24 , md : 12 , lg : 12 , xl : 8 } ;
697
+ if ( containerWidth > 1200 && colSpan . xl ) return { span : colSpan . xl } ;
698
+ if ( containerWidth > 992 && colSpan . lg ) return { span : colSpan . lg } ;
699
+ if ( containerWidth > 768 && colSpan . md ) return { span : colSpan . md } ;
700
+ if ( containerWidth > 576 && colSpan . sm ) return { span : colSpan . sm } ;
701
+ return { span : 24 } ;
702
+ } ;
703
+
704
+ export default React . memo ( JsonFormsRenderer ) ;
0 commit comments