|
| 1 | +import "./chat-bubble-base"; |
| 2 | + |
| 3 | +import { html, LitElement, nothing } from "lit"; |
| 4 | +import { property } from "lit/decorators.js"; |
| 5 | +import { classMap } from "lit/directives/class-map.js"; |
| 6 | +import { |
| 7 | + BaseSlots, |
| 8 | + STATUS_TO_ICON_MAP, |
| 9 | + STATUS_TO_LOCALE_MAP, |
| 10 | + type STATES, |
| 11 | +} from "./constants"; |
| 12 | + |
| 13 | +export class ChatBubbleIn extends LitElement { |
| 14 | + /** |
| 15 | + * The timestamp of chat element. |
| 16 | + */ |
| 17 | + @property({ type: String }) |
| 18 | + public timestamp!: string; |
| 19 | + |
| 20 | + /** |
| 21 | + * The status of the chat element. |
| 22 | + * |
| 23 | + * @default "sent" |
| 24 | + */ |
| 25 | + @property({ type: String }) |
| 26 | + public status: (typeof STATES)[number] = "sent"; |
| 27 | + |
| 28 | + /** |
| 29 | + * Whether or not the bubble should be fully rounded. |
| 30 | + * |
| 31 | + * @default false |
| 32 | + */ |
| 33 | + @property({ type: Boolean, attribute: "fully-rounded" }) |
| 34 | + public fullyRounded: boolean = false; |
| 35 | + |
| 36 | + private _renderFailureIndicator() { |
| 37 | + if (this.status !== "failed") return nothing; |
| 38 | + |
| 39 | + const icon = STATUS_TO_ICON_MAP.failed; |
| 40 | + |
| 41 | + return html` |
| 42 | + <div |
| 43 | + class="failure-indicator" |
| 44 | + part="failure-indicator" |
| 45 | + > |
| 46 | + ${icon} |
| 47 | + </div> |
| 48 | + `; |
| 49 | + } |
| 50 | + |
| 51 | + private _renderStatus() { |
| 52 | + if (this.status === "failed") return nothing; |
| 53 | + |
| 54 | + const stateMessage = STATUS_TO_LOCALE_MAP[this.status]; |
| 55 | + const icon = STATUS_TO_ICON_MAP[this.status]; |
| 56 | + |
| 57 | + return html` |
| 58 | + <div |
| 59 | + slot=${BaseSlots.FOOTER} |
| 60 | + class="status" |
| 61 | + part="status" |
| 62 | + > |
| 63 | + ${icon} |
| 64 | + <span>${stateMessage}</span> |
| 65 | + </div> |
| 66 | + `; |
| 67 | + } |
| 68 | + |
| 69 | + protected override render() { |
| 70 | + const rootClasses = classMap({ |
| 71 | + [String(this.status)]: Boolean(this.status), |
| 72 | + }); |
| 73 | + |
| 74 | + return html` |
| 75 | + <div |
| 76 | + class="root ${rootClasses}" |
| 77 | + part="root" |
| 78 | + > |
| 79 | + ${this._renderFailureIndicator()} |
| 80 | + <tap-chat-bubble-base |
| 81 | + class="base" |
| 82 | + part="base" |
| 83 | + author="in" |
| 84 | + ?fully-rounded=${this.fullyRounded} |
| 85 | + timestamp=${this.timestamp} |
| 86 | + > |
| 87 | + <slot slot=${BaseSlots.BODY}></slot> |
| 88 | + ${this._renderStatus()} |
| 89 | + </tap-chat-bubble-base> |
| 90 | + </div> |
| 91 | + `; |
| 92 | + } |
| 93 | +} |
0 commit comments