|
1 | 1 | import { ContextProvider } from '@lit/context'; |
2 | 2 | import { html, LitElement, nothing, type TemplateResult } from 'lit'; |
3 | | -import { property, query } from 'lit/decorators.js'; |
| 3 | +import { property, query, state } from 'lit/decorators.js'; |
4 | 4 | import { addThemingController } from '../../theming/theming-controller.js'; |
5 | 5 | import IgcButtonComponent from '../button/button.js'; |
6 | 6 | import { chatContext } from '../common/context.js'; |
@@ -157,6 +157,9 @@ export default class IgcChatComponent extends EventEmitterMixin< |
157 | 157 | initialValue: this._chatState, |
158 | 158 | }); |
159 | 159 |
|
| 160 | + @state() |
| 161 | + private _hasContent = false; |
| 162 | + |
160 | 163 | @query(IgcChatInputComponent.tagName) |
161 | 164 | private _chatInput!: IgcChatInputComponent; |
162 | 165 |
|
@@ -246,12 +249,10 @@ export default class IgcChatComponent extends EventEmitterMixin< |
246 | 249 |
|
247 | 250 | private renderHeader() { |
248 | 251 | return html` <div part="header"> |
249 | | - <div part="info"> |
250 | | - <slot name="prefix" part="prefix"></slot> |
251 | | - <slot name="title" part="title" |
252 | | - >${this._chatState.options?.headerText}</slot |
253 | | - > |
254 | | - </div> |
| 252 | + <slot name="prefix" part="prefix"></slot> |
| 253 | + <slot name="title" part="title" |
| 254 | + >${this._chatState.options?.headerText}</slot |
| 255 | + > |
255 | 256 | <slot name="actions" part="actions"></slot> |
256 | 257 | </div>`; |
257 | 258 | } |
@@ -284,10 +285,23 @@ export default class IgcChatComponent extends EventEmitterMixin< |
284 | 285 | this._context.setValue(this._chatState, true); |
285 | 286 | } |
286 | 287 |
|
| 288 | + protected override createRenderRoot(): HTMLElement | DocumentFragment { |
| 289 | + const root = super.createRenderRoot(); |
| 290 | + root.addEventListener('slotchange', () => { |
| 291 | + this._hasContent = |
| 292 | + this._chatState?.hasSlotContent('prefix') || |
| 293 | + this._chatState?.hasSlotContent('title') || |
| 294 | + this._chatState?.hasSlotContent('actions'); |
| 295 | + }); |
| 296 | + return root; |
| 297 | + } |
| 298 | + |
287 | 299 | protected override render() { |
288 | 300 | return html` |
289 | 301 | <div part="chat-container"> |
290 | | - ${this.renderHeader()} |
| 302 | + ${this._hasContent || this._chatState.options?.headerText |
| 303 | + ? this.renderHeader() |
| 304 | + : nothing} |
291 | 305 | ${this.messages.length === 0 |
292 | 306 | ? html`<div part="empty-state"> |
293 | 307 | <slot name="empty-state"> </slot> |
|
0 commit comments