@paperbits/forms
Version:
Paperbits components for form builder.
51 lines (41 loc) • 1.63 kB
text/typescript
import * as ko from "knockout";
import template from "./submitEditor.html";
import { StyleService } from "@paperbits/styles";
import { SubmitModel } from "../submitModel";
import { Component, OnMounted, Param, Event } from "@paperbits/common/ko/decorators";
export class SubmitEditor {
public readonly label: ko.Observable<string>;
public readonly appearanceStyle: ko.Observable<string>;
public readonly appearanceStyles: ko.ObservableArray<any>;
constructor(private readonly styleService: StyleService) {
this.label = ko.observable<string>();
this.appearanceStyles = ko.observableArray();
this.appearanceStyle = ko.observable();
}
public model: SubmitModel;
public onChange: (model: SubmitModel) => void;
public async initialize(): Promise<void> {
this.label(this.model.label);
if (this.model.styles) {
const variations = await this.styleService.getComponentVariations("button");
this.appearanceStyles(variations.filter(x => x.category === "appearance"));
this.appearanceStyle(<string>this.model.styles?.appearance);
}
this.appearanceStyle.subscribe(this.applyChanges);
this.label.subscribe(this.applyChanges);
}
private applyChanges(): void {
this.model.label = this.label();
this.model.styles = {
appearance: this.appearanceStyle()
};
this.onChange(this.model);
}
}