Creating your First Input Block Component
In this example, you will be building an input block component that prompts the user to enter their first and last name in a web form.
There are three learning objectives in this tutorial:
- Create a input block component in the plugin project.
- Modify the input block component to create a web form with inputs for first and last name
Generating a input block component
Widgets are stored in the my_plugin/inputs folder. Use aiverify-plugin gib to generate your widget.
Run the following command to generate a new input block.
Verify that the directory inputs
exists in your current directory with the files for the input block generated inside.
The following files are created:
- my_inputblock.mdx
- my_inputblock.summary.mdx
- my_inputblock.meta.json
Check the Input Block Meta Data
Open the file my_inputblock.meta.json
under the inputs folder and check that the properties are set correctly as shown below:
{
"cid": "my_inputblock",
"name": "My Input Block",
"description": "My first Input Block"
}
Editing MDX
Open and edit my_inputblock.mdx
to implement the MDX content.
<div style={{ display:"flex", flexDirection:"column" }}>
<label htmlFor="fname">First name:</label>
<input style={{ color:'black' }} type="text" id="fname" value={props.data["fname"]} onChange={(e)=>props.onChangeData("fname",e.target.value)} />
<label htmlFor="lname">Last name:</label>
<input style={{ color:'black' }} type="text" id="lname" value={props.data["lname"]} onChange={(e)=>props.onChangeData("lname",e.target.value)} />
</div>
Editing Summary MDX
Open and edit my_inputblock.summary.mdx
to update the summary MDX content as highlighted.
Once you have build your input block, you can proceed to create a widget.
(Optional) Use the Playground to view the Input Block.
Run the following command under the plugin directory to launch the Playground.
Navigate to http://localhost:5000/InputBlock/my_inputblock to view the input block you have created.
Once you make any edit to my_inputblock.mdx
, you can click the Refresh button to view your changes. The Input Block Meta
tab on the right panel display your Input Block meta information.
Type some characters in the First and Last Name fields, then select the Data Output
tab on the right panel. You should see the field values captured in the data output.
To exit the Playground, type ctrl+c
to terminate the application.