-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace @jupyterlab/rjsf with FormComponent from @jupyterlab/ui-compo…
…nents (#625) * added form component * custom array field * custom form field validation * css color picker * removed lumino * array field error validation * handle different types of input in custom array fields. * eslint * ui test update * input step option added * input step option added * updated schema * rebase on main * removed unused properties. * hide additional properties fields. * css edit * css for required span. * submit form with enter. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Playwright Snapshots --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
872bc06
commit 3b38e52
Showing
11 changed files
with
434 additions
and
801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React from 'react'; | ||
|
||
interface IProps { | ||
formData?: any[]; | ||
name: string; | ||
required: boolean; | ||
schema: any; | ||
errorSchema?: { [key: string]: any }; | ||
onChange: (updatedValue: any[]) => void; | ||
onBlur: (name: string, value: any) => void; | ||
} | ||
|
||
const CustomArrayField: React.FC<IProps> = props => { | ||
const { | ||
formData = [], | ||
name, | ||
required, | ||
schema, | ||
errorSchema = {}, | ||
onChange, | ||
onBlur | ||
} = props; | ||
|
||
const handleInputChange = (index: number, value: any) => { | ||
const updatedValue = [...formData]; | ||
updatedValue[index] = value; | ||
onChange(updatedValue); | ||
}; | ||
|
||
const renderInputField = (value: any, index: number) => { | ||
const { enum: enumOptions, type: itemType } = schema.items || {}; | ||
if (enumOptions) { | ||
return ( | ||
<select | ||
value={value || ''} | ||
required={required} | ||
onChange={e => handleInputChange(index, e.target.value)} | ||
onBlur={() => onBlur(name, value)} | ||
> | ||
{enumOptions.map((option: string, i: number) => ( | ||
<option key={i} value={option}> | ||
{option} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} else if (itemType === 'number') { | ||
return ( | ||
<input | ||
type="number" | ||
value={value} | ||
step="any" | ||
required={required} | ||
onChange={e => | ||
handleInputChange( | ||
index, | ||
e.target.value === '' ? null : parseFloat(e.target.value) | ||
) | ||
} | ||
onBlur={() => onBlur(name, value)} | ||
/> | ||
); | ||
} else if (itemType === 'boolean') { | ||
return ( | ||
<input | ||
type="checkbox" | ||
checked={!!value} | ||
onChange={e => handleInputChange(index, e.target.checked)} | ||
onBlur={() => onBlur(name, value)} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<input | ||
type="text" | ||
value={value} | ||
required={required} | ||
onChange={e => handleInputChange(index, e.target.value)} | ||
onBlur={() => onBlur(name, value)} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
return ( | ||
<fieldset> | ||
<legend>{name}</legend> | ||
<p className="field-description">{schema.description}</p> | ||
<div className="custom-array-wrapper"> | ||
{formData.map((value: any, index: number) => ( | ||
<div key={index} className="array-item"> | ||
{renderInputField(value, index)} | ||
|
||
{errorSchema?.[index]?.__errors?.length > 0 && ( | ||
<div className="validationErrors"> | ||
{errorSchema?.[index]?.__errors.map( | ||
(error: string, errorIndex: number) => ( | ||
<div key={`${index}-${errorIndex}`} className="error"> | ||
{error} | ||
</div> | ||
) | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
</fieldset> | ||
); | ||
}; | ||
|
||
export default CustomArrayField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.