Learn how to create a Custom Image Component. For this example, we'll modify the ImageBlock Component by adding a title attribute to the Image.
Let's start by looking at then modifing the type of the ImageBlockElement.
Custom Image Type
🌞 Even if you aren't using TypeScript, we recommend reading this section. You can probably follow the meaning of the type declarations (e.g. originKey: string means the originKey property takes a string type value).
This Element has its type set to "image-block". Also, this is a void Element, so it has children which is [{ text: "" }] (a requirement for void Elements).
It also has three other properties that are meaningful: An originKey, originSize and size. These properties are part of the ImageFileInterface and are required in order to use the HostedImage subcomponent which takes care of resizing, and showing the upload progress and error state.
It may seem small. This is because the HostedImage sub-component takes care of most of the hard work:
Resizing with drag handles
Showing the width/height during resize
Showing a progress bar while uploading
Showing an Error when an upload fails
Showing retina images for high DPI devices and normal resolution images for low DPI devices
From the perspective of the ImageBlock Component, we can treat it just like an img tag and it can take any img attributes like a "title" attribute for example.
Let's modify this to create our Custom TitledImageBlock Component: