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 ai-verify-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 type="text" id="fname" value={props.data["fname"]} onChange={(e)=>props.onChangeData("fname",e.target.value)} />
<label htmlFor="lname">Last name:</label>
<input 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.