![dependabot[bot]](/assets/img/avatar_default.png)
* build(deps): bump @trivago/prettier-plugin-sort-imports in /web Bumps [@trivago/prettier-plugin-sort-imports](https://github.com/trivago/prettier-plugin-sort-imports) from 2.0.4 to 3.0.0. - [Release notes](https://github.com/trivago/prettier-plugin-sort-imports/releases) - [Changelog](https://github.com/trivago/prettier-plugin-sort-imports/blob/master/CHANGELOG.md) - [Commits](https://github.com/trivago/prettier-plugin-sort-imports/commits) --- updated-dependencies: - dependency-name: "@trivago/prettier-plugin-sort-imports" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * web: update prettier config Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens.langhammer@beryju.org>
136 lines
4.6 KiB
TypeScript
136 lines
4.6 KiB
TypeScript
import { t } from "@lingui/macro";
|
|
|
|
import { CSSResult, LitElement, css } from "lit";
|
|
import { TemplateResult, html } from "lit";
|
|
import { customElement, property } from "lit/decorators";
|
|
|
|
import AKGlobal from "../../authentik.css";
|
|
import PFForm from "@patternfly/patternfly/components/Form/form.css";
|
|
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
|
|
import { FormGroup } from "./FormGroup";
|
|
|
|
@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 = "";
|
|
|
|
_invalid = false;
|
|
|
|
@property({ type: Boolean })
|
|
set invalid(v: boolean) {
|
|
this._invalid = v;
|
|
// check if we're in a form group, and expand that form group
|
|
const parent = this.parentElement?.parentElement;
|
|
if (parent && "expanded" in parent) {
|
|
(parent as FormGroup).expanded = true;
|
|
}
|
|
}
|
|
get invalid(): boolean {
|
|
return this._invalid;
|
|
}
|
|
|
|
@property()
|
|
name = "";
|
|
|
|
updated(): void {
|
|
this.querySelectorAll<HTMLInputElement>("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`<div class="pf-c-form__group">
|
|
<div class="pf-c-form__group-label">
|
|
<label class="pf-c-form__label">
|
|
<span class="pf-c-form__label-text">${this.label}</span>
|
|
${this.required
|
|
? html`<span class="pf-c-form__label-required" aria-hidden="true">*</span>`
|
|
: html``}
|
|
</label>
|
|
</div>
|
|
<div class="pf-c-form__group-control">
|
|
${this.writeOnly && !this.writeOnlyActivated
|
|
? html`<div class="pf-c-form__horizontal-group">
|
|
<input
|
|
class="pf-c-form-control"
|
|
type="password"
|
|
disabled
|
|
value="**************"
|
|
/>
|
|
</div>`
|
|
: html``}
|
|
<slot class="pf-c-form__horizontal-group"></slot>
|
|
<div class="pf-c-form__horizontal-group">
|
|
${this.writeOnly
|
|
? html`<p class="pf-c-form__helper-text" aria-live="polite">
|
|
${t`Click to change value`}
|
|
</p>`
|
|
: html``}
|
|
${this.invalid
|
|
? html`<p class="pf-c-form__helper-text pf-m-error" aria-live="polite">
|
|
${this.errorMessage}
|
|
</p>`
|
|
: html``}
|
|
</div>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
}
|