import { customElement, LitElement, CSSResult, property, css } from "lit-element"; import { TemplateResult, html } from "lit-html"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFForm from "@patternfly/patternfly/components/Form/form.css"; import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; import AKGlobal from "../../authentik.css"; import { t } from "@lingui/macro"; @customElement("ak-form-element-horizontal") export class HorizontalFormElement extends LitElement { static get styles(): CSSResult[] { return [PFBase, PFForm, PFFormControl, AKGlobal, css` .pf-c-form__group { display: grid; grid-template-columns: var(--pf-c-form--m-horizontal__group-label--md--GridColumnWidth) var(--pf-c-form--m-horizontal__group-control--md--GridColumnWidth); } .pf-c-form__group-label { padding-top: var(--pf-c-form--m-horizontal__group-label--md--PaddingTop); } `]; } @property() label = ""; @property({ type: Boolean }) required = false; @property({ type: Boolean }) writeOnly = false; @property({ type: Boolean }) writeOnlyActivated = false; @property() errorMessage = ""; @property({ type: Boolean }) invalid = false; @property() name = ""; updated(): void { this.querySelectorAll("input[autofocus]").forEach(input => { input.focus(); }); this.querySelectorAll("*").forEach((input) => { switch (input.tagName.toLowerCase()) { case "input": case "textarea": case "select": case "ak-codemirror": case "ak-chip-group": (input as HTMLInputElement).name = this.name; break; default: return; } if (this.writeOnly && !this.writeOnlyActivated) { const i = (input as HTMLInputElement); i.setAttribute("hidden", "true"); const handler = () => { i.removeAttribute("hidden"); this.writeOnlyActivated = true; i.parentElement?.removeEventListener("click", handler); }; i.parentElement?.addEventListener("click", handler); } }); } render(): TemplateResult { return html`
${this.writeOnly && !this.writeOnlyActivated ? html`
` : html``}
${this.writeOnly ? html`

${ t`Click to change value` }

` : html``} ${this.invalid ? html`

${this.errorMessage}

` : html``}
`; } }