@@ -15,13 +15,11 @@ import {
1515 Steps ,
1616} from "antd" ;
1717import styled from "styled-components" ;
18- import type { JsonSchema } from "@jsonforms/core" ;
1918import type { JSONSchema7 } from "json-schema" ;
2019import { debounce } from "lodash" ;
2120import dayjs from "dayjs" ;
2221import { trans } from "i18n" ;
2322import type {
24- JsonFormsUiSchema ,
2523 FieldUiSchema ,
2624 Layout ,
2725 Categorization ,
@@ -30,10 +28,14 @@ import type {
3028 Category ,
3129 Control
3230} from "./types" ;
33- import type { SwitchChangeEventHandler } from "antd/es/switch" ;
31+ import { useContainerWidth } from "./jsonSchemaFormComp" ;
32+
3433const { TextArea } = Input ;
3534
36- const Container = styled . div `
35+ const Container = styled . div
36+ `
37+ gap: 16px;
38+ width: 100%;
3739 .ant-form-item {
3840 margin-bottom: 16px;
3941 }
@@ -62,11 +64,6 @@ const Container = styled.div`
6264 }
6365` ;
6466
65- interface HorizontalLayout {
66- type : "HorizontalLayout" ;
67- elements : Control [ ] ;
68- }
69-
7067const JsonFormsRenderer : React . FC < JsonFormsRendererProps > = ( {
7168 schema,
7269 data,
@@ -78,6 +75,7 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
7875 validationState : externalValidationState ,
7976 onValidationChange,
8077} ) => {
78+ const containerWidth = useContainerWidth ( ) ;
8179 // Local state to handle immediate updates
8280 const [ localData , setLocalData ] = useState ( data ) ;
8381 // Track focused field
@@ -116,7 +114,7 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
116114 if ( ! uiSchema ) return undefined ;
117115
118116 // 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 ) ) {
120118 const control = uiSchema . elements . find ( ( element : any ) => {
121119 if ( element . type === "Control" ) {
122120 // Convert the scope path to match our field path
@@ -666,24 +664,41 @@ const JsonFormsRenderer: React.FC<JsonFormsRendererProps> = ({
666664
667665 // Fallback to default rendering if not a categorization
668666 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 >
686692 ) ;
687693} ;
688694
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