web/elements: add Chip and ChipGroup

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-10 20:12:32 +02:00
parent 7c761ff3d9
commit 75bc7c1cbd
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
import PFButton from "@patternfly/patternfly/components/Button/button.css";
import PFChip from "@patternfly/patternfly/components/Chip/chip.css";
import AKGlobal from "../../authentik.css";
@customElement("ak-chip")
export class Chip extends LitElement {
@property()
value?: number | string;
@property({type: Boolean})
removable = false;
static get styles(): CSSResult[] {
return [PFBase, PFButton, PFChip, AKGlobal];
}
render(): TemplateResult {
return html`<li class="pf-c-chip-group__list-item">
<div class="pf-c-chip">
<span class="pf-c-chip__text">
<slot></slot>
</span>
${this.removable ? html`<button class="pf-c-button pf-m-plain" type="button" @click=${() => {
this.dispatchEvent(new CustomEvent("remove", {
bubbles: true,
composed: true,
}));
}}>
<i class="fas fa-times" aria-hidden="true"></i>
</button>` : html``}
</div>
</li>`;
}
}

View File

@ -0,0 +1,37 @@
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
import PFChip from "@patternfly/patternfly/components/Chip/chip.css";
import PFChipGroup from "@patternfly/patternfly/components/ChipGroup/chip-group.css";
import PFButton from "@patternfly/patternfly/components/Button/button.css";
import AKGlobal from "../../authentik.css";
import { Chip } from "./Chip";
@customElement("ak-chip-group")
export class ChipGroup extends LitElement {
static get styles(): CSSResult[] {
return [PFBase, PFChip, PFChipGroup, PFButton, AKGlobal];
}
set value(v: (string | number | undefined)[]) {}
get value(): (string | number | undefined)[] {
const values: (string | number | undefined)[] = [];
this.querySelectorAll<Chip>("ak-chip").forEach(chip => {
values.push(chip.value);
});
return values;
}
render(): TemplateResult {
return html`<div class="pf-c-chip-group">
<div class="pf-c-chip-group__main">
<ul class="pf-c-chip-group__list" role="list">
<slot></slot>
</ul>
</div>
</div>`;
}
}