Skip to content

Commit 91d3648

Browse files
authored
refactor(chat): Adopt page styles for input area renderers (#1945)
Setting 'adoptRootStyles' will also include the renderers in the chat input area. Deprecated the 'typingIndicator' renderer and exposed a new 'typing-indicator' instead.
1 parent 5b93e17 commit 91d3648

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/components/chat/chat-input.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
ChatTemplateRenderer,
2525
IgcChatMessageAttachment,
2626
} from './types.js';
27-
import { getChatAcceptedFiles, getIconName } from './utils.js';
27+
import { adoptPageStyles, getChatAcceptedFiles, getIconName } from './utils.js';
2828

2929
type DefaultInputRenderers = {
3030
input: ChatTemplateRenderer<ChatInputRenderContext>;
@@ -119,6 +119,12 @@ export default class IgcChatInputComponent extends LitElement {
119119
addThemingController(this, all);
120120
}
121121

122+
protected override firstUpdated(): void {
123+
if (this._state.options?.adoptRootStyles) {
124+
adoptPageStyles(this);
125+
}
126+
}
127+
122128
/** @internal */
123129
public focusInput(): void {
124130
this._textInputElement.focus();

src/components/chat/chat-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
ChatTemplateRenderer,
2020
IgcChatMessage,
2121
} from './types.js';
22-
import { chatMessageAdoptPageStyles } from './utils.js';
22+
import { adoptPageStyles } from './utils.js';
2323

2424
const LIKE_INACTIVE = 'thumb_up_inactive';
2525
const LIKE_ACTIVE = 'thumb_up_active';
@@ -89,7 +89,7 @@ export default class IgcChatMessageComponent extends LitElement {
8989

9090
protected override firstUpdated(): void {
9191
if (this._state.options?.adoptRootStyles) {
92-
chatMessageAdoptPageStyles(this);
92+
adoptPageStyles(this);
9393
}
9494
}
9595

src/components/chat/chat.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const Slots = setSlots(
105105
'suggestions',
106106
'suggestions-actions',
107107
'suggestion',
108-
'empty-state'
108+
'empty-state',
109+
'typing-indicator'
109110
);
110111

111112
/**
@@ -133,6 +134,7 @@ const Slots = setSlots(
133134
* @slot suggestions-actions - Slot for rendering additional actions.
134135
* @slot suggestion - Slot for rendering a single suggestion item.
135136
* @slot empty-state - Slot shown when there are no messages.
137+
* @slot typing-indicator - Slot for the "is typing" indicator.
136138
*
137139
* @csspart chat-container - Styles the main chat container.
138140
* @csspart header - Styles the chat header container.
@@ -413,7 +415,9 @@ export default class IgcChatComponent extends EventEmitterMixin<
413415
${this._state.options?.isTyping
414416
? html`
415417
<div part="typing-indicator">
416-
${this._getRenderer('typingIndicator')(ctx)}
418+
<slot name="typing-indicator"
419+
>${this._getRenderer('typingIndicator')(ctx)}</slot
420+
>
417421
</div>
418422
`
419423
: nothing}

src/components/chat/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ export interface ChatRenderers {
234234
messageHeader?: ChatTemplateRenderer<ChatMessageRenderContext>;
235235
/**
236236
* Custom renderer for the "is typing" indicator.
237+
*
238+
* @deprecated since 6.4.0. Use the `typing-indicator` slot.
237239
*/
238240
typingIndicator?: ChatTemplateRenderer<ChatRenderContext>;
239241
/**

src/components/chat/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { adoptStyles, type LitElement } from 'lit';
22
import { last } from '../common/util.js';
3-
import type IgcChatMessageComponent from './chat-message.js';
43
import type { IgcChatMessageAttachment } from './types.js';
54

65
export type ChatAcceptedFileTypes = {
@@ -110,9 +109,7 @@ export function isImageAttachment(
110109
);
111110
}
112111

113-
export function chatMessageAdoptPageStyles(
114-
message: IgcChatMessageComponent
115-
): void {
112+
export function adoptPageStyles(element: LitElement): void {
116113
const sheets: CSSStyleSheet[] = [];
117114

118115
for (const sheet of document.styleSheets) {
@@ -129,6 +126,6 @@ export function chatMessageAdoptPageStyles(
129126
} catch {}
130127
}
131128

132-
const ctor = message.constructor as typeof LitElement;
133-
adoptStyles(message.shadowRoot!, [...ctor.elementStyles, ...sheets]);
129+
const ctor = element.constructor as typeof LitElement;
130+
adoptStyles(element.shadowRoot!, [...ctor.elementStyles, ...sheets]);
134131
}

0 commit comments

Comments
 (0)