Use this approach when you want to give users the ability to quickly replace a default placeholder image in their design with a custom photo. This is useful for flyers, posters, and other templates where large images can be swapped out.
1. Mark an Image as a Placeholder
2. Detect When the Placeholder Is Selected
Watch for changes in store.selectedElements
. If a placeholder image is selected, show an “Upload Your Picture” button or open a file picker immediately.
3. Replace the Placeholder Image
Once a user selects an image file, set the element’s src to the url of that file and clear out custom.isPlaceholder
.
Implementation Example
Below is a minimal React-based implementation. The key points are:
A hidden file input used to pick images.
A MobX reaction or state check to detect when the user selects the placeholder.
Replacing the placeholder image with the uploaded file.
Then we can use such hook in the app:
Alternative UI Approaches
Manual Button: Instead of automatically triggering the file input, you can display a button in the Toolbar or Tooltip. Clicking it would open the same file dialog.
Side Panel Section: Create a custom side panel tab that appears only when a placeholder is selected, displaying an “Upload Image” button inside the panel.
Tips
Use a custom property (
custom.isPlaceholder
) or any property you prefer to mark which images can be replaced.Provide instructions or hints to the end user so they know where and how to upload.
When the user’s image is loaded, consider adjusting its bounding box or aspect ratio if needed.