Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Json Schema Form rwesponsive layouts#1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FalkWolsky merged 3 commits intodevfromjson-schema-form-layouts
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,114 @@
importReactfrom'react';
import{Button,Row,Col}from'antd';
import{ArrayFieldTemplateProps}from'@rjsf/utils';
import{ArrayFieldTemplateProps,getUiOptions,RJSFSchema}from'@rjsf/utils';
import{ArrowDownOutlined,ArrowUpOutlined,DeleteOutlined,PlusOutlined}from'@ant-design/icons';
importObjectFieldTemplatefrom'./ObjectFieldTemplate';// Ensure this is correctly imported

constDEFAULT_RESPONSIVE_COL_SPAN={
xs:24,
sm:24,
md:12,
lg:8,
xl:6,
};

typeUiProps={
rowGutter?:number;
colSpan?:number|Record<string,number>;
};

constArrayFieldTemplate=(props:ArrayFieldTemplateProps)=>{
const{ items, canAdd, onAddClick, title}=props;
const{ items, canAdd, onAddClick, title, uiSchema, registry}=props;

return(
<fieldset>
{title&&<legend>{title}</legend>}
<Rowgutter={[0,0]}>
{items.map((element:any)=>(
<Colkey={element.index}span={24}style={{display:'flex',alignItems:'center'}}>
{/* Content container for the array item */}
<divstyle={{flexGrow:1}}>
{element.children}
</div>
// Get UI schema configuration
const{ rowGutter=8, colSpan=DEFAULT_RESPONSIVE_COL_SPAN}=getUiOptions(uiSchema)?.["ui:props"]asUiProps||{};

{/* Container for the control buttons with vertical alignment */}
<divstyle={{display:'flex',flexDirection:'row',justifyContent:'flex-end',paddingTop:"58px"}}>
{/* Move down button */}
{element.hasMoveDown&&(
<Button
type="default"
icon={<ArrowDownOutlined/>}
onClick={element.onReorderClick(element.index,element.index+1)}
style={{marginLeft:'4px'}}
/>
)}
constcalculateResponsiveColSpan=():{span:number}=>{
if(typeofcolSpan==='number'){
return{span:colSpan};
}elseif(typeofcolSpan==='object'){
// Return span based on screen width
constwidth=window.innerWidth;
if(width>1200&&colSpan.xl!==undefined)return{span:colSpan.xl};
if(width>992&&colSpan.lg!==undefined)return{span:colSpan.lg};
if(width>768&&colSpan.md!==undefined)return{span:colSpan.md};
if(width>576&&colSpan.sm!==undefined)return{span:colSpan.sm};
return{span:colSpan.xs||DEFAULT_RESPONSIVE_COL_SPAN.xs};
}
return{span:DEFAULT_RESPONSIVE_COL_SPAN.xs};
};

{/* Move up button */}
{element.hasMoveUp&&(
<Button
type="default"
icon={<ArrowUpOutlined/>}
onClick={element.onReorderClick(element.index,element.index-1)}
style={{marginLeft:'4px'}}
/>
)}
constrenderItems=()=>{
returnitems.map((element)=>{
const{ schema, uiSchema, formData, idSchema, name}=element.children.props;

{/* Remove button */}
{element.hasRemove&&(
<Button
type="default"
icon={<DeleteOutlined/>}
danger
onClick={element.onDropIndexClick(element.index)}
style={{marginLeft:'4px'}}
/>
)}
</div>
</Col>
))}
{/* Add button for the array */}
return(
<Colkey={element.index}span={24}>
{/* Use ObjectFieldTemplate to render each array item */}
<ObjectFieldTemplate
title=""
description={schema.description}
properties={[
{
content:element.children,
name,
readonly:element.children.props.readonly,
disabled:element.children.props.disabled,
hidden:false
},
]}
schema={schema}
uiSchema={uiSchema}
formData={formData}
idSchema={idSchema}
registry={registry}
readonly={element.children.props.readonly}
disabled={element.children.props.disabled}
onAddClick={function(schema:RJSFSchema):()=>void{
thrownewError('Function not implemented.');
}}
/>

{/* Control buttons */}
<divstyle={{display:'flex',justifyContent:'flex-end',marginTop:'8px'}}>
{element.hasMoveDown&&(
<Button
type="default"
icon={<ArrowDownOutlined/>}
onClick={element.onReorderClick(element.index,element.index+1)}
style={{marginLeft:'4px'}}
/>
)}
{element.hasMoveUp&&(
<Button
type="default"
icon={<ArrowUpOutlined/>}
onClick={element.onReorderClick(element.index,element.index-1)}
style={{marginLeft:'4px'}}
/>
)}
{element.hasRemove&&(
<Button
type="default"
icon={<DeleteOutlined/>}
danger
onClick={element.onDropIndexClick(element.index)}
style={{marginLeft:'4px'}}
/>
)}
</div>
</Col>
);
});
};

return(
<fieldset>

<Rowgutter={rowGutter}>
{renderItems()}{/* Render items */}
{canAdd&&(
<Colspan={24}style={{textAlign:'center'}}>
<Colspan={24}style={{textAlign:'center',marginTop:'16px'}}>
<Buttontype="dashed"onClick={onAddClick}icon={<PlusOutlined/>}>
Add Item
</Button>
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp