Configuration
This section covers configuring your widget's metadata, appearance, settings, and preview functionality. Proper configuration ensures your widget integrates seamlessly with the platform and provides users with a flexible, customizable experience.
Table of Contents
- Configuring Widget Metadata
- Using Theming and Styling
- Creating Widget Settings
- Implementing Widget Preview
Configuring Widget Metadata
Reference:
Note: This configuration is already set up during the 'Run Setup Wizard' step described in Section 2.
Basic Widget Configuration
widget-config.json:
{
"id": 210,
"port": 5210,
"name": "ACME_KpiTracker",
"widgetType": 1,
"vendorPrefix": "acme",
"tenentSlug": "acme",
"exposes": {
"./Widget": "./src/widget/widget",
"./WidgetSettings": "./src/widget/widget-settings",
"./WidgetPreview": "./src/widget-preview/widget-preview"
},
"widgetDetails": {
"title": "KPI Tracker",
"type": "Informer",
"description": "Displays key performance indicators with real-time updates and third-party integrations",
"issuer": "ACME Corporation",
"innerTags": [],
"tags": ["Analytics", "Dashboard", "KPI", "Real-time"]
},
"layout": {
"minW": 5,
"maxW": 24,
"minH": 5,
"maxH": 12
},
"settingsSchema": {
"title": "KPI Tracker Settings",
"uiSchema": {
"ui:order": [
"title",
"titleTooltip",
"apiUrl",
"refreshInterval",
"showTrend",
"enableNotifications"
],
"title": {
"ui:widget": "InputWidget",
"ui:options": {}
},
"titleTooltip": {
"ui:widget": "InputWidget",
"ui:options": {}
},
"apiUrl": {
"ui:widget": "InputWidget",
"ui:options": {}
},
"refreshInterval": {
"ui:widget": "InputWidget",
"ui:options": {
"inputType": "number"
}
},
"showTrend": {
"ui:widget": "CheckboxWidget",
"ui:options": {}
},
"enableNotifications": {
"ui:widget": "CheckboxWidget",
"ui:options": {}
}
},
"jsonSchema": {
"type": "object",
"required": ["apiUrl"],
"properties": {
"title": {
"type": "string",
"title": "Widget Title",
"default": "KPI Tracker"
},
"titleTooltip": {
"type": "string",
"title": "Title Tooltip"
},
"apiUrl": {
"type": "string",
"title": "API URL",
"default": "_internal_api_"
},
"refreshInterval": {
"type": "number",
"title": "Refresh Interval (seconds)",
"default": 30,
"minimum": 10,
"maximum": 300
},
"showTrend": {
"type": "boolean",
"title": "Show Trend Indicators",
"default": true
},
"enableNotifications": {
"type": "boolean",
"title": "Enable Notifications",
"default": false
}
}
},
"extraErrors": {},
"formType": "json"
}
}
Widget Types
Reference: Widget Store Migrations
enum WidgetType {
Platform = 0, // Navigation/toolbar widgets
Dashboard = 1, // Dashboard widgets
Universal = 2, // Can be both
}
Preview Image
Create a preview image at public/preview.svg:
- Format: SVG
- Dimensions: 88x64 pixels
- Purpose: Displays in Micro App Library
Context Rules
Reference: Widget Metadata
Context rules determine when widgets can be added to a dashboard based on URL query parameters. These rules control widget availability in the Micro App Library menu within the Dashboard Composer (Host application).
Context Rule Types
none - Widget doesn't depend on query parameters (default behavior)
{
"contextRules": {
"type": "none"
}
}
Widget appears in Micro App Library regardless of URL parameters.
dynamic - Widget appears if any of the specified keys are present OR if none are present
{
"contextRules": {
"type": "dynamic",
"keys": ["contactId", "branchId"]
}
}
Widget appears when:
- URL contains
/dashboard?contactId=123, OR - URL contains
/dashboard?branchId=456, OR - URL has no query parameters (
/dashboard)
strict - Widget appears only if all specified keys are present
{
"contextRules": {
"type": "strict",
"keys": ["contactId"]
}
}
Widget appears only when URL contains /dashboard?contactId=123
Regular Expressions
For flexible pattern matching, use regular expressions in keys:
{
"contextRules": {
"type": "strict",
"keys": ["/^phone/i"]
}
}
Matches URLs like:
/dashboard?phoneNumber=555-1234/dashboard?phoneNum=555-1234/dashboard?phoneUser=john
Advanced Example
{
"contextRules": {
"type": "dynamic",
"keys": ["accountId", "userId", "/^contact/i"]
}
}
Widget appears when URL contains accountId, userId, any parameter starting with "contact" (case-insensitive), or no parameters.
Using Theming and Styling
Reference:
Theme Structure
The platform provides themes with:
- ColorPalette: primary, secondary, tertiary, background, surface, danger, warning, success
- FontsT: primary and secondary fonts with sources
- sizeUnit: Base spacing unit (typically 4px)
- borderRadius: Default border radius
- chartColors: Array of colors for charts
- typography: Typography definitions (Heading1, Heading2, Body1, etc.)
Using useTheme Hook
import { useTheme } from "styled-components";
import type { IThemeProps } from "@invent/shared-types";
const MyComponent = () => {
const theme = useTheme();
// Access theme properties
const primaryColor = theme.colors.primary;
const sizeUnit = theme.sizeUnit;
return <div>Theme applied</div>;
};
Theme Utility Functions
Import from @invent/wl-ui-kit:
import {
getColor,
getColorShade,
getChartColor,
getGradient,
getSizeUnit,
getSizeBy,
getBorderThickness,
getFontFamily,
getTypography,
injectFontFaces,
getElevation,
getWidgetShadowOptions,
getThemeProp,
getPropOrElse,
ifPropExist,
getHintColor,
getMixinFromTheme,
} from "@invent/wl-ui-kit";
Color Utilities
// Basic color
color: ${getColor('primary')}; // Returns: rgb(19, 183, 209)
// Color with opacity shade
color: ${getColor('primary', 'mediumEmphasis')};
// Returns: color-mix(in srgb, rgb(19, 183, 209) 72%, rgb(255, 255, 255))
// RGB color with alpha
color: ${getColorShade('primary', 'mediumEmphasis')};
// Returns: rgb(19 183 209 / 0.72)
// Chart color by index
background-color: ${getChartColor(0)}; // First chart color
background-color: ${getChartColor(1)}; // Second chart color
// Gradient
background: linear-gradient(${getGradient('primary', [
{ opacity: 0, gradientSlicePercent: 0 },
{ opacity: 1, gradientSlicePercent: 100 }
])}); // Returns: rgb(19 183 209 / 0) 0%, rgb(19 183 209 / 1) 100%
// Hint/status colors
color: ${getHintColor('success')}; // Success color with high emphasis
color: ${getHintColor('error')}; // Error color with high emphasis
Size Utilities
// Base size unit
line-height: ${getSizeUnit}; // Returns: 4
// Size with multiplier
padding: ${getSizeBy(2)}; // Returns: 8px (4 * 2)
margin: ${getSizeBy(4)}; // Returns: 16px (4 * 4)
// Size with modifier (small, medium, large)
padding: ${getSizeBy(2, 'large')}; // Returns: 11px (4 * 2 * 1.33)
margin: ${getSizeBy(3, 'small')}; // Returns: 10px (4 * 3 * 0.83)
// Border thickness
border-width: ${getBorderThickness()}; // Theme-based thickness
Typography Utilities
// Font family
font-family: ${getFontFamily('primary')}; // Returns: 'DM Sans, sans-serif'
font-family: ${getFontFamily('secondary')}; // Secondary font
// Typography preset (applies fontSize, fontWeight, lineHeight)
${getTypography('Heading1')}
${getTypography('Heading2')}
${getTypography('Body1')}
${getTypography('Caption')}
${getTypography('ButtonText')}
// Inject font faces
${injectFontFaces('/assets')} // Generates @font-face CSS