Skip to content

Commit 49eb484

Browse files
committed
feat(chat): code snippets styles
1 parent 8c35235 commit 49eb484

File tree

10 files changed

+80
-18
lines changed

10 files changed

+80
-18
lines changed

src/components/chat/extras/markdown-renderer.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,33 @@ export async function createMarkdownRenderer(
7070
markedShiki({
7171
highlight(code, lang, _) {
7272
try {
73-
return highlighter.codeToHtml(code, { lang, themes });
73+
const html = highlighter.codeToHtml(code, { lang, themes });
74+
75+
const colorMap: Record<string, string> = {
76+
'6f42c1': 'var(--shiki-purple)',
77+
'032f62': 'var(--shiki-dark-blue)',
78+
'24292e': 'var(--shiki-navy)',
79+
d73a49: 'var(--shiki-red)',
80+
'005cc5': 'var(--shiki-blue)',
81+
'22863a': 'var(--shiki-green)',
82+
e36209: 'var(--shiki-orange)',
83+
};
84+
85+
const processed = html.replace(
86+
/style="([^"]*)"/g,
87+
(_m, styleContent) => {
88+
const replaced = styleContent.replace(
89+
/#([0-9a-fA-F]{6})/g,
90+
(_full: any, hex: string) => {
91+
const rep = colorMap[hex.toLowerCase()];
92+
return rep ?? `#${hex}`;
93+
}
94+
);
95+
return `style="${replaced}"`;
96+
}
97+
);
98+
99+
return processed;
74100
} catch {
75101
return `<pre><code>${sanitizer(code)}</code></pre>`;
76102
}

src/components/chat/themes/dark/_themes.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use 'styles/utilities' as *;
22
@use 'igniteui-theming/sass/themes/schemas/components/dark/chat' as *;
33

4+
$base: digest-schema($dark-base-chat);
45
$material: digest-schema($dark-material-chat);
56
$bootstrap: digest-schema($dark-bootstrap-chat);
67
$fluent: digest-schema($dark-fluent-chat);
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@use 'styles/utilities' as *;
22
@use 'themes' as *;
3-
@use '../light/themes' as light;
43

54
$theme: $bootstrap;
65

76
:host {
8-
@include css-vars-from-theme(diff(light.$base, $theme), 'ig-chat');
7+
@include css-vars-from-theme(diff($base, $theme), 'ig-chat');
98
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@use 'styles/utilities' as *;
22
@use 'themes' as *;
3-
@use '../light/themes' as light;
43

54
$theme: $fluent;
65

76
:host {
8-
@include css-vars-from-theme(diff(light.$base, $theme), 'ig-chat');
7+
@include css-vars-from-theme(diff($base, $theme), 'ig-chat');
98
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@use 'styles/utilities' as *;
22
@use 'themes' as *;
3-
@use '../light/themes' as light;
43

54
$theme: $indigo;
65

76
:host {
8-
@include css-vars-from-theme(diff(light.$base, $theme), 'ig-chat');
7+
@include css-vars-from-theme(diff($base, $theme), 'ig-chat');
98
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
@use 'styles/utilities' as *;
22
@use 'themes' as *;
3-
@use '../light/themes' as light;
43

54
$theme: $material;
65

76
:host {
8-
@include css-vars-from-theme(diff(light.$base, $theme), 'ig-chat');
7+
@include css-vars-from-theme(diff($base, $theme), 'ig-chat');
98
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@use 'styles/utilities' as *;
2+
@use './themes' as *;
3+
4+
$theme: $base;
5+
6+
:host {
7+
@include css-vars-from-theme($theme, 'ig-chat');
8+
9+
igc-chat-message::part(message-container) {
10+
--shiki-purple: #b392f0;
11+
--shiki-navy: #e1e4e8;
12+
--shiki-dark-blue: #9ecbff;
13+
--shiki-red: #f97583;
14+
--shiki-blue: #79bbff;
15+
--shiki-green: #85e89d;
16+
--shiki-orange: #ffab70;
17+
}
18+
}

src/components/chat/themes/message.base.scss

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@
3535
color: color(primary, 500);
3636
}
3737

38-
pre, code {
39-
white-space: pre-wrap;
40-
overflow-wrap: break-word;
41-
overflow-x: auto;
42-
margin-block: unset;
38+
pre.shiki {
39+
font-size: rem(14px);
40+
line-height: rem(24px);
41+
padding: rem(16px);
42+
border-radius: rem(4px);
43+
max-height: rem(320px);
44+
max-width: rem(680px);
45+
overflow-y: auto;
4346
}
4447
}
4548

4649
[part~='message-header'],
4750
[part~='message-attachments'],
48-
[part~='message-actions'] {
51+
[part~='message-actions'],
52+
[part~='plain-text'] {
4953
&:empty {
5054
display: none;
5155
}

src/components/chat/themes/shared/chat-message/chat-message.common.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@
33

44
$theme: $material;
55

6+
:host {
7+
--shiki-navy: #24292e;
8+
--shiki-dark-blue: #032F62;
9+
--shiki-purple: #6f42c1;
10+
--shiki-red: #d73a49;
11+
--shiki-blue: #005cc5;
12+
--shiki-green: #22863a;
13+
--shiki-orange: #e36209;
14+
}
15+
616
[part~='sent'] {
717
background: var-get($theme, 'message-background');
818
}
919

1020
[part~='message-container'] {
1121
color: var-get($theme, 'message-color');
22+
23+
// override shiki styles
24+
pre.shiki {
25+
background-color: var-get($theme, 'code-background') !important;
26+
border: rem(1px) solid var-get($theme, 'code-border');
27+
}
1228
}
1329

1430
[part~='message-actions'] {

src/components/chat/themes/themes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import { styles as bootstrapDark } from './dark/chat.bootstrap.css.js';
66
import { styles as fluentDark } from './dark/chat.fluent.css.js';
77
import { styles as indigoDark } from './dark/chat.indigo.css.js';
88
import { styles as materialDark } from './dark/chat.material.css.js';
9+
import { styles as sharedDark } from './dark/chat.shared.css.js';
910
// Light Overrides
1011
import { styles as bootstrapLight } from './light/chat.bootstrap.css.js';
1112
import { styles as fluentLight } from './light/chat.fluent.css.js';
1213
import { styles as indigoLight } from './light/chat.indigo.css.js';
1314
import { styles as materialLight } from './light/chat.material.css.js';
15+
import { styles as sharedLight } from './light/chat.shared.css.js';
1416
// Shared Styles
15-
import { styles as shared } from './light/chat.shared.css.js';
1617
import { styles as bootstrap } from './shared/chat.bootstrap.css.js';
1718
import { styles as fluent } from './shared/chat.fluent.css.js';
1819
import { styles as indigo } from './shared/chat.indigo.css.js';
1920

2021
const light = {
2122
shared: css`
22-
${shared}
23+
${sharedLight}
2324
`,
2425
bootstrap: css`
2526
${bootstrap} ${bootstrapLight}
@@ -37,7 +38,7 @@ const light = {
3738

3839
const dark = {
3940
shared: css`
40-
${shared}
41+
${sharedDark}
4142
`,
4243
bootstrap: css`
4344
${bootstrap} ${bootstrapDark}

0 commit comments

Comments
 (0)