Skip to content

Commit 121dd43

Browse files
Merge pull request #12 from BrainbaseHQ/kartik/bra2-1177-add-close-button-to-chat-widget-and-fix-storybook-v10-config
feat: add close button to widget and fix Storybook v10 config
2 parents 9815cfb + 1a7ffb2 commit 121dd43

4 files changed

Lines changed: 79 additions & 17 deletions

File tree

.storybook/preview.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,26 @@ import '../src/styles/variables.css';
33

44
const preview: Preview = {
55
parameters: {
6-
actions: { argTypesRegex: '^on[A-Z].*' },
76
controls: {
87
matchers: {
98
color: /(background|color)$/i,
109
date: /Date$/i,
1110
},
1211
},
1312
backgrounds: {
14-
options: {
15-
light: { name: 'light', value: '#f5f5f5' },
16-
dark: { name: 'dark', value: '#1a1a2e' },
17-
white: { name: 'white', value: '#ffffff' }
18-
}
13+
values: [
14+
{ name: 'light', value: '#f5f5f5' },
15+
{ name: 'dark', value: '#1a1a2e' },
16+
{ name: 'white', value: '#ffffff' },
17+
],
1918
},
2019
},
2120

2221
initialGlobals: {
2322
backgrounds: {
24-
value: 'light'
25-
}
26-
}
23+
value: '#f5f5f5',
24+
},
25+
},
2726
};
2827

2928
export default preview;

src/components/ChatWidget/ChatWidget.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export const ChatWidget: React.FC<ChatWidgetProps> = ({
325325
onStartChat={handleStartChat}
326326
onNavigate={handleNavigate}
327327
currentPage="home"
328+
onClose={isInline ? undefined : handleClose}
328329
/>
329330
) : (
330331
<ChatContainer

src/components/HomePage/HomePage.module.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,52 @@
4242
z-index: 1;
4343
}
4444

45+
.headerTopRow {
46+
display: flex;
47+
align-items: center;
48+
justify-content: space-between;
49+
}
50+
4551
.agentInfo {
4652
display: flex;
4753
align-items: center;
4854
gap: var(--bb-spacing-md);
4955
}
5056

57+
.closeButton {
58+
width: 32px;
59+
height: 32px;
60+
border-radius: var(--bb-radius-full);
61+
background: rgba(0, 0, 0, 0.1);
62+
border: none;
63+
cursor: pointer;
64+
display: flex;
65+
align-items: center;
66+
justify-content: center;
67+
color: var(--bb-header-text-color, var(--bb-text-inverse));
68+
transition: background var(--bb-transition-fast), transform var(--bb-transition-fast);
69+
flex-shrink: 0;
70+
}
71+
72+
.closeButton:hover {
73+
background: rgba(0, 0, 0, 0.2);
74+
transform: scale(1.05);
75+
}
76+
77+
.closeButton:active {
78+
transform: scale(0.95);
79+
}
80+
81+
.closeButton:focus-visible {
82+
outline: 2px solid rgba(255, 255, 255, 0.5);
83+
outline-offset: 2px;
84+
}
85+
86+
.closeButton svg {
87+
width: 18px;
88+
height: 18px;
89+
}
90+
5191
.headerLogo {
5292
width: 42px;
5393
height: 42px;

src/components/HomePage/HomePage.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface HomePageProps {
1212
onStartChat: () => void;
1313
onNavigate: (page: 'home' | 'messages') => void;
1414
currentPage: 'home' | 'messages';
15+
onClose?: () => void;
1516
}
1617

1718
export const HomePage: React.FC<HomePageProps> = ({
@@ -24,6 +25,7 @@ export const HomePage: React.FC<HomePageProps> = ({
2425
onStartChat,
2526
onNavigate,
2627
currentPage,
28+
onClose,
2729
}) => {
2830
const handleHomeCardClick = () => {
2931
if (homeLink) {
@@ -36,15 +38,35 @@ export const HomePage: React.FC<HomePageProps> = ({
3638
<div className={styles.header}>
3739
<div className={styles.headerBackground} />
3840
<div className={styles.headerContent}>
39-
<div className={styles.agentInfo}>
40-
{agentLogoUrl ? (
41-
<img src={agentLogoUrl} alt={agentName} className={styles.headerLogo} />
42-
) : (
43-
<div className={styles.headerLogoPlaceholder}>
44-
<BrainbaseLogo className={styles.headerBrainbaseLogo} color="white" cutoutColor="var(--bb-primary-color)" />
45-
</div>
41+
<div className={styles.headerTopRow}>
42+
<div className={styles.agentInfo}>
43+
{agentLogoUrl ? (
44+
<img src={agentLogoUrl} alt={agentName} className={styles.headerLogo} />
45+
) : (
46+
<div className={styles.headerLogoPlaceholder}>
47+
<BrainbaseLogo className={styles.headerBrainbaseLogo} color="white" cutoutColor="var(--bb-primary-color)" />
48+
</div>
49+
)}
50+
<span className={styles.headerAgentName}>{agentName}</span>
51+
</div>
52+
{onClose && (
53+
<button
54+
className={styles.closeButton}
55+
onClick={onClose}
56+
aria-label="Close chat"
57+
type="button"
58+
>
59+
<svg viewBox="0 0 24 24" fill="none">
60+
<path
61+
d="M6 18L18 6M6 6L18 18"
62+
stroke="currentColor"
63+
strokeWidth="2"
64+
strokeLinecap="round"
65+
strokeLinejoin="round"
66+
/>
67+
</svg>
68+
</button>
4669
)}
47-
<span className={styles.headerAgentName}>{agentName}</span>
4870
</div>
4971
</div>
5072
</div>

0 commit comments

Comments
 (0)