Skip to content

Commit 25669af

Browse files
authored
feat: add new header config (#1030)
1 parent a932840 commit 25669af

File tree

91 files changed

+4448
-1154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4448
-1154
lines changed

demo/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"@carbon/web-components": "^2.46.0",
2121
"lit": "^3.1.0",
2222
"react": "^19.0.0",
23-
"react-dom": "^19.0.0",
24-
"uuid": "^11.1.0"
23+
"react-dom": "^19.0.0"
2524
},
2625
"devDependencies": {
2726
"@babel/core": "^7.26.0",

demo/src/customSendMessage/doPreviewCard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { ChatInstance, MessageResponseTypes } from "@carbon/ai-chat";
11-
import { v4 as uuid } from "uuid";
11+
import { uuid } from "@carbon/ai-chat-components/es/globals/utils/uuid.js";
1212

1313
function doPreviewCard(
1414
instance: ChatInstance,

demo/src/framework/demo-header-switcher.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,61 @@ import "@carbon/web-components/es/components/text-input/index.js";
1212
import "@carbon/web-components/es/components/checkbox/index.js";
1313

1414
import { PublicConfig, MinimizeButtonIconType } from "@carbon/ai-chat";
15+
import Help16 from "@carbon/icons/es/help/16.js";
16+
import Information16 from "@carbon/icons/es/information/16.js";
17+
import Document16 from "@carbon/icons/es/document/16.js";
18+
import Chat16 from "@carbon/icons/es/chat/16.js";
19+
import UserAvatar16 from "@carbon/icons/es/user--avatar/16.js";
20+
import Settings16 from "@carbon/icons/es/settings/16.js";
21+
import Share16 from "@carbon/icons/es/share/16.js";
22+
import Download16 from "@carbon/icons/es/download/16.js";
1523
import { css, html, LitElement } from "lit";
1624
import { customElement, property } from "lit/decorators.js";
1725

26+
// Sample actions for demo
27+
const sampleActions = [
28+
{
29+
icon: Help16,
30+
text: "Help",
31+
onClick: () => alert("Help clicked!"),
32+
},
33+
{
34+
icon: Information16,
35+
text: "About",
36+
onClick: () => alert("About clicked!"),
37+
},
38+
{
39+
icon: Document16,
40+
text: "Documentation",
41+
onClick: () => alert("Documentation clicked!"),
42+
},
43+
{
44+
icon: Chat16,
45+
text: "Feedback",
46+
onClick: () => alert("Feedback clicked!"),
47+
},
48+
{
49+
icon: UserAvatar16,
50+
text: "Profile",
51+
onClick: () => alert("Profile clicked!"),
52+
},
53+
{
54+
icon: Settings16,
55+
text: "Settings",
56+
onClick: () => alert("Settings clicked!"),
57+
},
58+
{
59+
icon: Share16,
60+
text: "Share",
61+
onClick: () => alert("Share clicked!"),
62+
},
63+
{
64+
icon: Download16,
65+
text: "Export Chat",
66+
onClick: () => alert("Export Chat clicked!"),
67+
},
68+
];
69+
1870
@customElement("demo-header-switcher")
1971
export class DemoHeaderSwitcher extends LitElement {
2072
static styles = css`
@@ -136,10 +188,20 @@ export class DemoHeaderSwitcher extends LitElement {
136188
text: "Help",
137189
handler: () => alert("Help clicked!"),
138190
},
191+
{
192+
text: "Documentation",
193+
href: "https://chat.carbondesignsystem.com/tag/latest/docs/documents/Overview.html",
194+
target: "_blank",
195+
},
139196
{
140197
text: "Settings",
141198
handler: () => alert("Settings clicked!"),
142199
},
200+
{
201+
text: "Disabled Option",
202+
handler: () => alert("This should not appear!"),
203+
disabled: true,
204+
},
143205
];
144206
} else {
145207
delete header.menuOptions;
@@ -162,6 +224,20 @@ export class DemoHeaderSwitcher extends LitElement {
162224
this._updateConfig({ header });
163225
};
164226

227+
private _onSampleActionsChanged = (event: Event) => {
228+
const customEvent = event as CustomEvent;
229+
const checked = customEvent.detail.checked;
230+
const header = { ...this.config.header };
231+
232+
if (checked) {
233+
header.actions = sampleActions;
234+
} else {
235+
delete header.actions;
236+
}
237+
238+
this._updateConfig({ header });
239+
};
240+
165241
private _getCurrentMinimizeButtonType(): string {
166242
if (this.config?.header?.hideMinimizeButton) {
167243
return "none";
@@ -243,6 +319,15 @@ export class DemoHeaderSwitcher extends LitElement {
243319
Show AI label
244320
</cds-checkbox>
245321
</div>
322+
323+
<div class="header-section">
324+
<cds-checkbox
325+
?checked=${(header?.actions?.length ?? 0) > 0}
326+
@cds-checkbox-changed=${this._onSampleActionsChanged}
327+
>
328+
Add menu actions
329+
</cds-checkbox>
330+
</div>
246331
`;
247332
}
248333
}

demo/src/mockServiceDesk/mockServiceDesk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
UserType,
2929
} from "@carbon/ai-chat";
3030

31-
import { v4 as uuid } from "uuid";
31+
import { uuid } from "@carbon/ai-chat-components/es/globals/utils/uuid.js";
3232

3333
import { MARKDOWN } from "../customSendMessage/constants";
3434

demo/src/react/DemoApp.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ function DemoApp({ config, settings, onChatInstanceReady }: AppProps) {
147147
parentStateText={stateText}
148148
/>
149149
),
150+
headerFixedActionsElement: (
151+
<WriteableElementExample
152+
location="headerFixedActionsElement"
153+
parentStateText={stateText}
154+
/>
155+
),
150156
welcomeNodeBeforeElement: (
151157
<WriteableElementExample
152158
location="welcomeNodeBeforeElement"

demo/src/react/WriteableElementExample.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
border-end-start-radius: var(--cds-aichat-rounded-modifier-radius-end-start);
2222
border-end-end-radius: var(--cds-aichat-rounded-modifier-radius-end-end);
2323
}
24+
25+
.writeable-element-external--compact {
26+
padding: 0.25rem 0.5rem;
27+
font-size: 0.75rem;
28+
border-radius: 0;
29+
}

demo/src/react/WriteableElementExample.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ function WriteableElementExample({
2323
if (location === "aiTooltipAfterDescriptionElement") {
2424
classNames += " writeable-element-external--not-rounded";
2525
}
26+
27+
// Special compact display for header fixed actions
28+
if (location === "headerFixedActionsElement") {
29+
return (
30+
<div className="writeable-element-external writeable-element-external--compact">
31+
{location}
32+
</div>
33+
);
34+
}
35+
2636
return (
2737
<div className={classNames}>
2838
Location: {location}. Parent prop: {parentStateText}

demo/src/web-components/writeable-element-example.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class WriteableElementExample extends LitElement {
3434
);
3535
border-end-end-radius: var(--cds-aichat-rounded-modifier-radius-end-end);
3636
}
37+
.external--compact {
38+
padding: 0.25rem 0.5rem;
39+
font-size: 0.75rem;
40+
border-radius: 0;
41+
}
3742
`;
3843

3944
@property({ type: String })
@@ -47,6 +52,14 @@ class WriteableElementExample extends LitElement {
4752
if (this.location === "aiTooltipAfterDescriptionElement") {
4853
classNames += " writeable-element-external--not-rounded";
4954
}
55+
56+
// Special compact display for header fixed actions
57+
if (this.location === "headerFixedActionsElement") {
58+
return html`<div class="external external--compact">
59+
${this.location}
60+
</div>`;
61+
}
62+
5063
return html`<div class="${classNames}">
5164
Location: ${this.location}. Parent prop: ${this.valueFromParent}.
5265
</div> `;

demo/tests/setChatConfig.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ test("setChatConfig configuration mode functionality", async ({ page }) => {
8686
page.getByTestId(DemoPageObjectId.LEAVE_SET_CHAT_CONFIG_MODE_BUTTON),
8787
).toBeVisible();
8888

89-
// Check if title was updated
90-
await expect(page.getByTestId(PageObjectId.HEADER_TITLE)).toContainText(
91-
"Test Title 1",
92-
);
89+
// Check if title was updated (scoped to chat_header)
90+
await expect(
91+
page
92+
.getByTestId(PageObjectId.CHAT_HEADER)
93+
.getByTestId(PageObjectId.HEADER_TITLE),
94+
).toContainText("Test Title 1");
9395

9496
// Phase 2: Page Refresh & Error State
9597

@@ -136,10 +138,12 @@ test("setChatConfig configuration mode functionality", async ({ page }) => {
136138

137139
// 8. Assertions for recovery - sidebar should be visible again with Leave button
138140

139-
// Verify the header name is also applied in the main panel
140-
await expect(page.getByTestId(PageObjectId.HEADER_NAME)).toContainText(
141-
"Test Assistant",
142-
);
141+
// Verify the header name is also applied in the main panel (scoped to chat_header)
142+
await expect(
143+
page
144+
.getByTestId(PageObjectId.CHAT_HEADER)
145+
.getByTestId(PageObjectId.HEADER_NAME),
146+
).toContainText("Test Assistant");
143147

144148
await expect(
145149
page.getByTestId(DemoPageObjectId.SET_CHAT_CONFIG_NOTIFICATION_ERROR),

docs/developer-handbook.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Developer Handbook
22

33
<!-- prettier-ignore-start -->
4-
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
5-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
64
## Table of Contents
75

86
- [Getting started](#getting-started)
@@ -23,11 +21,10 @@
2321
- [Start a new `block` or `element`?](#start-a-new-block-or-element)
2422
- [Red flags](#red-flags)
2523
- [Maintainers](#maintainers)
26-
- [Continuous integration and deployment](#ontinuous-integration-and-eployment)
24+
- [Continuous integration and deployment](#continuous-integration-and-deployment)
2725
- [Publishing](#publishing)
2826
- [Automated dependency updates](#automated-dependency-updates)
2927

30-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3128
<!-- prettier-ignore-end -->
3229

3330
## Getting started

0 commit comments

Comments
 (0)