In this tutorial, we’ll show you how to create an editor add-on from scratch. This add-on lets users import icons from a predefined library directly into their site by uploading them to the site's media files and applying them to a selected element in the Wix Editor.
We'll follow these steps to build the app:
While we’re using Vite as the build tool, you can choose any local development server that suits your needs.
Before getting started, make sure that:
Start by setting up a new React project with Vite. We’ll follow these steps:
Run the following command in your terminal:
Navigate to your new project folder:
package.json
file and install themNext, we'll install the required dependencies for the app. These include:
@wix/design-system
– Ensures the UI follows Wix’s design guidelines, providing components like Box
, Text
, and Button
.@wix/editor
– Enables interaction with the Wix Editor, including selecting and modifying site elements.@wix/media
– Handles uploading the selected icon to Wix Media storage for use on the site.@wix/sdk
– Provides API access to Wix services like files
and elements
, allowing the add-on to modify editor elements.vite-plugin-mkcert
– Enables HTTPS support for local development, which is required for secure communication with Wix.vite-plugin-node-polyfills
– Ensures compatibility with Node.js APIs within a Vite-based front-end environment.@emotion/react
& @emotion/styled
– Required by Material UI for styling components dynamically.@mui/icons-material
& @mui/material
– Provides the Material UI components and icons used for the icon selection interface.Open package.json
and add the following dependencies under "dependencies"
:
Under "devDependencies"
, add:
Install the dependencies:
Update the vite.config.ts
file in your project root with the following code to enable HTTPS for local development and add Node.js polyfills:
We'll now create the core application files needed for the project:
main.tsx
: This is the entry point of your application. Update it to import Wix Design System's style sheet.App.tsx
: This file contains the main structure of the app, showing a button for adding icons, a loader for upload states, and a message for the user.Icons.tsx
: Displays the available icons in the library using Material UI's IconButton
. Icons can be selected, and a state is updated for the chosen icon.useIconsManager.tsx
: Manages icon selection, uploading, and handling interactions with the Wix media service. This includes logic for converting the selected icon into an SVG and uploading it to site's media files, and applying it to the selected element in the Wix editor.Ensure your src
directory includes App.tsx
and main.tsx
files and update their content as follows:
src/main.tsx
src/App.tsx
In your src
directory create the following files:
src/Icons.tsx
src/useIconsManager.tsx
Start the development server by running the following command in your terminal:
Once the server starts, Vite will provide a local development URL (typically https://localhost:5173
). Open your browser and navigate to this URL to preview your app.
You can view and interact with the UI in your browser. However, the add-on functionality will not work outside the Wix Editor. In the next step, we'll set it up as a Wix app extension so we can test it properly within the Wix Editor.
To make the add-on available for installation on sites, we'll create a Wix app and set up an add-on extension.
In the Custom Apps page, go to My Apps, and then click Create New App.
Select Build from scratch.
In the left sidebar, select Extensions, and then click Create Extension.
A panel opens, showing the available extension types.
Find the Editor Add-on extension and click Create.
Configure the add-on’s basic data:
Get Icons
.Small
to match the size of most native editor panels.400 px
.Under Market listing, fill in the Teaser field with a short description, such as Import icons from the Material UI library
.
Click Save.
Add the required permissions to the app so it can access a site's media files:
In the left sidebar, select Permissions, and then click Add Permissions.
Find the Manage Media Manager permission scope, select it, and then click Save.
Your add-on extension is now available for installation on a site.
To test the add-on, we'll install it on a site:
In your app's dashboard, click Test Your App, and then click Editor.
Select a site on which you want to install the app, and click Add to Site.
When prompted for consent, click Agree & Add.
Your app is now installed on a site and your add-on is available in the editor.
In the editor's Tools menu, select Editor Add-ons, and then select your add-on.
Your add-on’s panel is displayed.
Add an image element to the page and select it.
Select one of the icons in the add-on panel and click Add Icon.
The add-on should successfully upload the icon to the site's media files and apply it to the selected image element.
Now that you've learned how to set up a self-hosted editor add-on, you can start thinking about building your own app. Here are a few resources to get you started: