Widget
Everything you need for building and/or displaying widgets.
Example¶
Interfaces¶
WidgetRendererProps¶
Properties¶
widgetInstanceId¶
Type Aliases¶
BaseWidgetConfiguration¶
The base type for all widget configurations.
A JSON object that contains JSON-serializable values under string keys.
Functions¶
getWidgetById()¶
Retrieves a widget by its unique type ID.
Parameters¶
id¶
string
The unique type ID of the widget.
Returns¶
undefined
| Widget
<Record
<string
, Json
>>
The widget associated with the ID, or null if the widget is not found.
getWidgets()¶
Returns an array of all the widgets that are currently registered.
Returns¶
Widget
<Record
<string
, Json
>>[]
An array containing all the widgets.
useConfigureWidget()¶
Similar to useState
but for widget configurations.
Only works inside a widget configuration context. Values returned and passed into the setter are always validated and transformed by the widget’s Widget.createConfig function.
Returns¶
readonly [Record
<string
, Json
>, (s
) => void
]
the current widget configuration and a function to update it
useConfigureWidgetField()¶
A hook to get and set a specific field of the current widget configuration.
Only works inside a widget configuration context. Values returned and passed into the setter are always validated and transformed by the widget’s Widget.createConfig function.
To validate the type of the individual field, the validator
function is used.
Type Parameters¶
• T extends Json
Parameters¶
name¶
string
the name of the field to get and set
validator¶
(v
) => T
a function to validate the type of the field
Returns¶
readonly [T
, (newValue
) => void
]
the current value of the field and a function to update it
See¶
useConfigureWidget
Throws¶
Error - if the field does not exist in the widget configuration
Throws¶
Error - if the type of the field does not match the validator
Example¶
// Config: { text: string }
const [text, setText] = useConfigureWidgetField('text', s => z.string().parse(s));
return <input value={text} onChange={e => setText(e.target.value)} />;
WidgetConfigCheckboxField()¶
A checkbox field for the widget configuration.
Parameters¶
props¶
the props for the checkbox field
label¶
string
name¶
string
Returns¶
Element
Example¶
// Config: { enabled: boolean }
configElement: <WidgetConfigWrapper>
<WidgetConfigCheckboxField label={'Enabled'} name={'enabled'} />
</WidgetConfigWrapper>
See¶
Widget.configElement
WidgetConfigContext()¶
Parameters¶
props¶
ProviderProps
<unknown
>
Returns¶
ReactNode
WidgetConfigTextField()¶
A text field for the widget configuration.
Parameters¶
props¶
the props for the text field
label¶
string
name¶
string
Returns¶
Element
Example¶
// Config: { text: string }
configElement: <WidgetConfigWrapper>
<WidgetConfigTextField label={'Text'} name={'text'} />
</WidgetConfigWrapper>
See¶
Widget.configElement
WidgetConfigWrapper()¶
Wraps the widget configuration controls and gives them the correct margins.
Should be used inside the widget configuration element.
Parameters¶
__namedParameters¶
children¶
ReactNode
Returns¶
Element
See¶
Widget.configElement
WidgetRenderer()¶
Renders a widget based on the provided widgetInstanceId.
Parameters¶
WidgetRendererProps¶
The props for the WidgetRenderer.
Returns¶
Element
The rendered widget.
Throws¶
Error If the widget instance is not found.
References¶
registerWidgets¶
Re-exports registerWidgets
Widget¶
Re-exports Widget