-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom component by id (#3740)
Co-authored-by: Nick Grosenbacher <[email protected]>
- Loading branch information
Showing
8 changed files
with
159 additions
and
2 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
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
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,37 @@ | ||
import { FieldProps } from '@rjsf/utils'; | ||
import { FC, useState } from 'react'; | ||
|
||
const COLORS = ['red', 'green', 'blue']; | ||
|
||
const SpecialInput: FC<FieldProps<string>> = ({ onChange, formData }) => { | ||
const [text, setText] = useState<string>(formData || ''); | ||
|
||
const inputBgColor = COLORS[text.length % COLORS.length]; | ||
|
||
return ( | ||
<div className='SpecialInput'> | ||
<h3>Hey, I'm a custom component</h3> | ||
<p> | ||
I'm registered as <code>/schemas/specialString</code> and referenced in | ||
<code>Form</code>'s <code>field</code> prop to use for this schema anywhere this schema <code>$id</code> is | ||
used. | ||
</p> | ||
<div className='row'> | ||
<div className='col-sm-6'> | ||
<label>SpecialInput</label> | ||
<input | ||
className='form-control' | ||
style={{ background: inputBgColor, color: 'white', fontSize: 14 }} | ||
value={text} | ||
onChange={({ target: { value } }) => { | ||
onChange(value); | ||
setText(value); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpecialInput; |
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,28 @@ | ||
export default { | ||
schema: { | ||
title: 'A registration form', | ||
description: 'A custom-field form example.', | ||
type: 'object', | ||
definitions: { | ||
specialString: { | ||
$id: '/schemas/specialString', | ||
type: 'string', | ||
}, | ||
}, | ||
properties: { | ||
mySpecialStringField: { | ||
$ref: '#/definitions/specialString', | ||
}, | ||
mySpecialStringArray: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/definitions/specialString', | ||
}, | ||
}, | ||
}, | ||
}, | ||
uiSchema: {}, | ||
formData: { | ||
mySpecialStringField: 'special-text', | ||
}, | ||
}; |
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