Get started with developing your own custom widget.
Custom widgets are web components that allow you to add specific types of content blocks to News or Pages on the Staffbase platform. Learn more about custom widgets here.
Staffbase makes developing custom widgets easy with the Staffbase widget generator. The Staffbase widget generator is a project generator to help you kickstart your widget development. It provides a widget SDK to enable your custom widget to communicate with the Staffbase platform.
The generated project uses:
With this widget generator, you are completely equipped to create a custom widget easily.
You can develop widgets with your in-house team or outsource development to our partners or vendors. Staffbase has built a network of technical implementation partners and we are happy to support you in finding the right partner or vendor.
Custom widgets cannot be made available in the public area of your app.
Custom widgets are developed and owned by your organization. Although Staffbase as the platform is not liable for the content or services used for the custom widget, we recommend that the custom widgets comply with Staffbase’s Terms of Service and Acceptable Use Policy defined by the platform.
As a first step, create a custom widget project that will act as the framework for you to develop your custom widget.
Use the Staffbase widget generator and follow these steps:
The create widget project prompts you to provide a name for your organization and custom widget.
Provide a name for your organization.
For example: windstar
Provide a name for your custom widget.
For example: custom-widget
Run the command to navigate to the directory you created.
For example, if the name you provided is custom-widget
, run the command:
Now, you have created your custom widget project. You can start adding functionalities to your custom widget.
Once you have created your custom widget project, define the look of your custom widget, add custom properties, and add the functionalities you want. Later test, build, and host the widget on a web server.
Requirement:
You need to define the custom widget so that it registers itself to the platform when the custom widget URL is installed to the Staffbase Studio. This happens by calling the window.defineBlock
method and passing the definition as the parameter during registration.
The definition needs to follow the following structure and conventions:
By default, a placeholder icon is used for any new custom widget. You can add a custom icon to your custom widget to make it more visually appealing.
You can also reference an external URL for the icon.
Icon Requirements:
You can add more properties to customize your widget. The properties are explained in the Widget SDK via TypeScript typings.
To do this:
The script follows the following structure:
You need to:
const widgetAttributes: string[]
array in the widget classAfter adding the name, the code will look like this:
This is done in the configuration-schema.ts
file and follows the JSON Schema format. Learn more about the possibilities here.
Your configuration-schema.ts
file should look like this:
A preview of the configuration dialog is shown in the developer preview mentioned below.
You can add functionalities to your custom widget to show a specific content block in News and Pages. Based on the business use case, add functionalities to your custom widget, such as showing weather updates, feeds from other platforms and so on. If you want the content block in the widget to display a simple message, you can add the function accordingly.
For example:
You can find your custom widget project file in src with a tsx extension. For example, if your custom widget name is custom-widget, you will find the file custom-widget.tsx in your project.
Once you have added the functionalities, build the custom widget and get it ready to integrate with the Staffbase platform.
Build the custom widget by running the command:
Once you type the command a new dist folder is added to your project folder. The bundled sources will be available in the dist
folder following the naming convention <organization-name>.<widget-name>.js
. For example: dist/windstar.custom-widget.js
You can preview and test the custom widget you have developed to ensure that it works as expected.
Run the following command to:
Alternatively, use github-pages for testing before hosting it on the production web server.
Host your custom widget on a web server or a content delivery network (CDN) after testing and ensuring it functions as desired.
Provide the Staffbase platform administrator the widget bundle URL to integrate the custom widget with the Staffbase platform. The administrator can then install the URL in Staffbase Studio.
You can also have multiple custom widgets in a bundle. If the widget bundle URL contains more than one widget, each widget in the bundle must register itself separately during installation. Read define custom widget for more information.