This template should help you get started developing a FWC plugin with React + Typescript + Vite. It provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
- Generating plugin
- Recommended IDE Setup
- Installing
- Running
- Building and importing into dashboard app
- Theming
- Including Static Assets
FWC provides a cli tool which generates a sample plugin that can be used to help get you started with writing your own plugin:
npm init fwc@latest <name>Note: You'll need node installed to run the above command: https://nodejs.org/en/download/
To get started, open a terminal and enter in the following command:
npm init fwc@latest my-first-pluginAfter being prompted with a few questions to help setup your plugin, the plugin project will be created and installed. The cli tool provides templates to create components using lit, react or svelte:
To install run the following command:
npm installTo run the dashboard in dev mode cd into the directory that was created in the last step and run the following command:
npm run devYou should see the following in the terminal:
The dashboard should launch automatically in the browser. If not, open it manually using link shown in the terminal. (http://localhost:5173 for me)
You should see the dashboard in the browser:
From here you should be able to navigate to your component which you can add and test in the browser:
Before the plugin can be imported into the dashboard app the plugin must first be built. Run the following command to build
npm run buildA plugin folder should be generated:
Warning
This folder should not modified manually since your changes will be overwritten whenever the build command is run.
Within the build file you'll find a few important files and folders:
index.jswhich is the root javascript file which the dashboard app will import.assetsfolder which contains images and other static files that your plugin uses. These are copied over from thepublic/assetsfolder.plugin.jsonwhich contains metadata like the plugin name, description and version used by the dashboard app for display purposes.
To import the plugin open the app and click the File > Plugins menu item:
This should open the plugins dialog:
Click Load Plugin which open up an open folder dialog. Navigate to your plugin and select the plugin folder generated with the npm run build command:
You should now see the plugin loaded in the dialog:
The app must be refreshed to view the changes:
Theming in the FWC dashboard app is done using CSS variables.
As an example take the following style rule for the my-react-element component:
color: white;To make this rule themable change it to the following:
color: var(--my-react-element-color, white);--my-react-element-color is the CSS variable. CSS variables are prefixed with --. To ensure uniqueness and to prevent accidentally overwriting existing rules prepend your variable with the element name. white is the default value if a theme is not set.
To add per theme rules add the following code:
import { addThemeRules } from '@frc-web-components/app';
addThemeRules('dark', {
'--my-react-element-background': 'cadetblue',
'--my-react-element-color': 'black',
});
addThemeRules('light', {
'--my-react-element-background': 'cornflowerblue',
'--my-react-element-color': 'white',
});Static assets like such as images should be placed in the /public/assets folder. They can be included into the app by calling the getAssetUrl function. For example:
import { getAssetUrl } from '@frc-web-components/app';
const url: string = getAssetUrl('party.svg');The above URL can then be used as the src of an image element:
<img src="{url}" />








