WIDGET_TEMPLATE.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Template for creating new widgets
  2. // Copy this file and customize it for your needs
  3. import { Component, createSignal, onMount } from 'solid-js';
  4. import type { WidgetSettings, WidgetSchema } from '../types/widget';
  5. // Define your widget's props interface
  6. interface MyWidgetProps {
  7. settings: WidgetSettings;
  8. }
  9. // Create your widget component
  10. export const MyWidget: Component<MyWidgetProps> = (props) => {
  11. // Add any state or signals you need
  12. const [data, setData] = createSignal<string>('');
  13. // Initialize your widget
  14. onMount(() => {
  15. // Fetch data, set up intervals, etc.
  16. // Access settings via props.settings.yourSettingName
  17. });
  18. return (
  19. <div style={{
  20. border: '1px solid var(--border)',
  21. padding: '1rem',
  22. 'min-width': '200px'
  23. }}>
  24. {/* Your widget content here */}
  25. <div style={{ 'font-weight': 'bold' }}>
  26. {props.settings.title as string}
  27. </div>
  28. <div>
  29. {data()}
  30. </div>
  31. </div>
  32. );
  33. };
  34. // Define your widget's schema
  35. export const myWidgetSchema: WidgetSchema = {
  36. name: 'My Widget',
  37. description: 'Description of what this widget does',
  38. settingsSchema: {
  39. // Define all configurable settings here
  40. title: {
  41. type: 'string',
  42. label: 'Widget Title',
  43. default: 'My Widget',
  44. required: true
  45. },
  46. refreshInterval: {
  47. type: 'number',
  48. label: 'Refresh Interval (ms)',
  49. default: 60000
  50. },
  51. enabled: {
  52. type: 'boolean',
  53. label: 'Enabled',
  54. default: true
  55. },
  56. mode: {
  57. type: 'select',
  58. label: 'Display Mode',
  59. default: 'compact',
  60. options: ['compact', 'detailed', 'minimal']
  61. }
  62. }
  63. };
  64. // Don't forget to:
  65. // 1. Save this file in src/widgets/
  66. // 2. Register it in src/widgets/registry.ts
  67. // 3. Import it: import { MyWidget, myWidgetSchema } from './MyWidget';
  68. // 4. Add to registry: 'my-widget': { schema: myWidgetSchema, Component: MyWidget }