import { FlatTemplatable, tempstream } from "tempstream";
import { FieldGroup } from "./field-group.js";
import { randomUUID } from "crypto";
import { FormControl } from "./form-control.js";
type CollapsibleFieldGroupOptions = {
label?: string;
classes?: string[];
openOnStart?: boolean;
textWhenOpen?: string;
textWhenClosed?: string;
groupID?: string;
};
export class CollapsibleFieldGroup extends FieldGroup {
public collapseID: string;
constructor(
public controls: FormControl[],
public options: CollapsibleFieldGroupOptions = {}
) {
super([]);
if (this.options.groupID == undefined) {
this.options.groupID = "A" + randomUUID(); // "A" is needed as ids always have to start with a letter
}
this.collapseID = this.options.groupID + "collapse";
}
getGroupLabelProps() {
return tempstream`${super.getGroupLabelProps()} for="${
this.collapseID
}"`;
}
preLabelContainer(): FlatTemplatable {
return /* HTML */ `
`;
}
postLabel(): FlatTemplatable {
return /* HTML */ ``;
}
}