import { FlatTemplatable, tempstream } from "tempstream"; import { FormControl, FormControlContext } from "./form-control.js"; import { FormFieldControl } from "./form-field-control.js"; export class FieldGroup extends FormFieldControl { constructor( public controls: FormControl[], public options: { label?: string; classes?: string[]; containerID?: string; } = {} ) { super([]); } preLabel(): FlatTemplatable { return ""; } preLabelContainer(): FlatTemplatable { return ""; } postLabel(): FlatTemplatable { return ""; } preFields(): FlatTemplatable { return ""; } postFields(): FlatTemplatable { return ""; } getGroupLabelProps(): FlatTemplatable { return `class="field-group__label"`; } async render(fctx: FormControlContext): Promise { const { label, classes } = this.options; return tempstream /* HTML */ `
${this.preLabelContainer()}
${this.preLabel()} ${label ? tempstream`` : ""} ${this.postLabel()}
${this.preFields()}
${this.controls.map((control) => control.render(fctx))}
${this.postFields()}
`; } }