Skip to content

Commit d008b96

Browse files
authored
feat: add custom class to ConnectionStatus component (#1924)
1 parent f144e9a commit d008b96

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/components/MessageList/ConnectionStatus.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ const UnMemoizedConnectionStatus = <
2626
}, [client, online]);
2727

2828
return (
29-
<CustomNotification active={!online} type='error'>
29+
<CustomNotification
30+
active={!online}
31+
className='str-chat__connection-status-notification'
32+
type='error'
33+
>
3034
{t<string>('Connection failure, reconnecting now...')}
3135
</CustomNotification>
3236
);

src/components/MessageList/CustomNotification.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import React, { PropsWithChildren } from 'react';
2+
import clsx from 'clsx';
23

34
export type CustomNotificationProps = {
45
type: string;
56
active?: boolean;
7+
className?: string;
68
};
79

810
const UnMemoizedCustomNotification = (props: PropsWithChildren<CustomNotificationProps>) => {
9-
const { active, children, type } = props;
11+
const { active, children, className, type } = props;
1012

1113
if (!active) return null;
1214

1315
return (
1416
<div
1517
aria-live='polite'
16-
className={`str-chat__custom-notification notification-${type} str-chat__notification`}
18+
className={clsx(
19+
`str-chat__custom-notification notification-${type}`,
20+
`str-chat__notification`,
21+
className,
22+
)}
1723
data-testid='custom-notification'
1824
>
1925
{children}

src/components/MessageList/__tests__/CustomNotification.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ describe('CustomNotification', () => {
4242

4343
expect(getByTestId('custom-notification').className).toContain(`notification-${type}`);
4444
});
45+
46+
it('should add custom class to className', () => {
47+
const className = 'custom-classname-xxx';
48+
49+
const { getByTestId } = render(
50+
<CustomNotification active={true} className={className}>
51+
x
52+
</CustomNotification>,
53+
);
54+
55+
expect(getByTestId('custom-notification').className).toContain(className);
56+
});
4557
});

0 commit comments

Comments
 (0)