Skip to main content

Custom Widgets - Server

Describing the Attribute Object Model​

To create a custom widget, you need to define an attribute object model. This ensures type safety when using the widget in layout creation.

tip

Use ValueReferenceHolder if you want the attributes of your custom widget to be marked for use within components.

Use AnimatedPropertyOwner if you wish to support Duit animation in your custom widget.

interface SvgAttributes extends ValueReferenceHolder<SvgAttributes>, AnimatedPropertyOwner  {
width?: number;
height?: number;
content: string;
}

Creating a Constructor Function​

Constructor functions in the Duit DSL style help maintain consistent layout semantics and allow custom widgets to be used uniformly alongside basic widgets.

//notexport classes as independent member
class _SvgWidget extends CustomWidget<SvgAttributes> {

constructor(attrs: SvgAttributes, tag: string, id?: string) {
super(attrs, tag, id, undefined, false);
}
}

//use functions as constructor
export const Svg = (attributes: SvgAttributes, id?: string) => new SvgWidget(attributes, "SvgCustomWidget", id);
info

Custom widgets must have a unique tag.

After this setup, you can use the new functions to create layouts in the same manner as standard widgets supported by Duit.