Documentation

extend()

Extends this builder with custom methods, returning a new builder object.

extend<E extends object>(
extensions: E & ThisType<this & E>,
defer?: (result: this & E, base: this) => void,
): this & E;

Notes

Parameters

Return value

A new builder with both the original and extension methods.

Examples

function Card(title: string) {
  let content: ViewBuilder[] = [];
  return UI.Column()
    .padding(16)
    .border(1)
    .extend({
      content(...views: ViewBuilder[]) {
        content = views;
        return this;
      },
      accent() {
        this.background("accent");
        return this;
      },
    }, (b) => {
      b.with(UI.Text(title).style("title"), ...content);
    });
}

Related