Skip to content

Widget

Everything you need for building and/or displaying widgets.

Example

import { ... } from '@wuespace/telestion/widget';

Interfaces

WidgetRendererProps

Properties

widgetInstanceId
widgetInstanceId: string;

Type Aliases

BaseWidgetConfiguration

type BaseWidgetConfiguration: Record<string, Json>;

The base type for all widget configurations.

A JSON object that contains JSON-serializable values under string keys.

Functions

getWidgetById()

function getWidgetById(id): undefined | Widget<Record<string, Json>>

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()

function getWidgets(): Widget<Record<string, Json>>[]

Returns an array of all the widgets that are currently registered.

Returns

Widget<Record<string, Json>>[]

An array containing all the widgets.


useConfigureWidget()

function useConfigureWidget(): readonly [Record<string, Json>, (s) => void]

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()

function useConfigureWidgetField<T>(name, validator): readonly [T, (newValue) => void]

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()

function WidgetConfigCheckboxField(props): Element

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()

function WidgetConfigContext(props): ReactNode

Parameters

props

ProviderProps<unknown>

Returns

ReactNode


WidgetConfigTextField()

function WidgetConfigTextField(props): Element

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()

function WidgetConfigWrapper(__namedParameters): Element

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()

function WidgetRenderer(WidgetRendererProps): Element

Renders a widget based on the provided widgetInstanceId.

Parameters

WidgetRendererProps

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