From ffc4fe36a00fffa0136507951a28ae341973f8d3 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 15 Aug 2022 15:16:23 -0600 Subject: [PATCH] Kanban: Fix display of resources on card by adding Et2AvatarGroup --- api/js/etemplate/Et2Avatar/Et2Avatar.ts | 9 +- api/js/etemplate/Et2Avatar/Et2AvatarGroup.ts | 95 ++++++++++++++++++++ api/js/etemplate/etemplate2.ts | 1 + 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 api/js/etemplate/Et2Avatar/Et2AvatarGroup.ts diff --git a/api/js/etemplate/Et2Avatar/Et2Avatar.ts b/api/js/etemplate/Et2Avatar/Et2Avatar.ts index e0cc8ca265..ef4bee7bc3 100644 --- a/api/js/etemplate/Et2Avatar/Et2Avatar.ts +++ b/api/js/etemplate/Et2Avatar/Et2Avatar.ts @@ -120,7 +120,14 @@ export class Et2Avatar extends Et2Widget(SlotMixin(SlAvatar)) implements et2_IDe } if (changedProperties.has("size")) { - this.getDOMNode().setAttribute('style', `--size:${this.size}`); + if(this.size) + { + this.getDOMNode().setAttribute('style', `--size:${this.size}`); + } + else + { + this.style.removeProperty("--size") + } } } diff --git a/api/js/etemplate/Et2Avatar/Et2AvatarGroup.ts b/api/js/etemplate/Et2Avatar/Et2AvatarGroup.ts new file mode 100644 index 0000000000..90fd680804 --- /dev/null +++ b/api/js/etemplate/Et2Avatar/Et2AvatarGroup.ts @@ -0,0 +1,95 @@ +import {Et2Widget} from "../Et2Widget/Et2Widget"; +import {css, html, LitElement, repeat} from "@lion/core"; +import shoelace from "../Styles/shoelace"; + +/** + * Show multiple avatars + */ +export class Et2AvatarGroup extends Et2Widget(LitElement) +{ + + static get styles() + { + return [ + ...super.styles, + shoelace, + // TODO: More work on sizing needed to better adapt to available space + css` + :host { + display: flex; + } + et2-avatar { + --size: 1.5rem; + flex: 0 0 auto; + min-width: 20px; + transition-delay: 0s; + transition-duration:0.1s; + } + et2-avatar:not(:first-of-type) { + margin-left: -1rem; + } + et2-avatar::part(base) { + border: solid 2px var(--sl-color-neutral-0); + } + et2-avatar:hover { + --size: 2.5rem; + overflow: visible; + z-index: 11; + transition-delay: 1s; + transition-suration:0.5s + } + ` + ]; + } + + static get properties() + { + return { + ...super.properties, + /** + * List of contact IDs + */ + value: { + type: Array + }, + } + } + + constructor() + { + super(); + this.value = [] + } + + set_value(new_value) + { + if(typeof new_value !== "object") + { + new_value = new_value.split(","); + } + this.value = new_value; + } + + avatarTemplate(contact : { id : string, label? : string }) + { + if(typeof contact == "string") + { + contact = {id: contact}; + } + return html` + `; + } + + render() + { + return html` + ${repeat(this.value, (contact) => contact.id, (contact) => this.avatarTemplate(contact))}`; + } +} + +customElements.define("et2-avatar-group", Et2AvatarGroup); \ No newline at end of file diff --git a/api/js/etemplate/etemplate2.ts b/api/js/etemplate/etemplate2.ts index 3f79328276..4dcd523a8a 100644 --- a/api/js/etemplate/etemplate2.ts +++ b/api/js/etemplate/etemplate2.ts @@ -28,6 +28,7 @@ import './Layout/Et2Tabs/Et2Tab'; import './Layout/Et2Tabs/Et2Tabs'; import './Layout/Et2Tabs/Et2TabPanel'; import './Et2Avatar/Et2Avatar'; +import './Et2Avatar/Et2AvatarGroup'; import './Et2Button/Et2Button'; import './Et2Button/Et2ButtonTimestamper'; import './Et2Checkbox/Et2Checkbox';