Skip to content

Commit 3b731fc

Browse files
authored
feature: Add renderHeader props to the ChannelSettingsUIProps (#1012)
### ChangeLog & Fix * Add a `renderHeader` props to the ChannelSettingsUIProps ``` <ChannelSettingsUI renderHeader={() => ...} /> ```
1 parent 17ba9b2 commit 3b731fc

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { MouseEvent } from 'react';
2+
3+
import { useLocalization } from '../../../../lib/LocalizationContext';
4+
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
5+
6+
import Label, { LabelColors, LabelTypography } from '../../../../ui/Label';
7+
import IconButton from '../../../../ui/IconButton';
8+
import Icon, { IconTypes } from '../../../../ui/Icon';
9+
10+
export interface ChannelSettingsHeaderProps {
11+
onCloseClick?: (e: MouseEvent<HTMLButtonElement>) => void;
12+
}
13+
export const ChannelSettingsHeader = ({
14+
onCloseClick,
15+
}: ChannelSettingsHeaderProps) => {
16+
const { stringSet } = useLocalization();
17+
const { config } = useSendbirdStateContext();
18+
const { logger } = config;
19+
20+
return (
21+
<div className="sendbird-channel-settings__header">
22+
<Label type={LabelTypography.H_2} color={LabelColors.ONBACKGROUND_1}>
23+
{stringSet.CHANNEL_SETTING__HEADER__TITLE}
24+
</Label>
25+
<div className="sendbird-channel-settings__header-icon">
26+
<IconButton
27+
width="32px"
28+
height="32px"
29+
onClick={(e) => {
30+
logger.info('ChannelSettings: Click close');
31+
onCloseClick(e);
32+
}}
33+
>
34+
<Icon className="sendbird-channel-settings__close-icon" type={IconTypes.CLOSE} height="22px" width="22px" />
35+
</IconButton>
36+
</div>
37+
</div>
38+
);
39+
};

src/modules/ChannelSettings/components/ChannelSettingsUI/index.tsx

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import React, { useContext, useState } from 'react';
55
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
66
import { useChannelSettingsContext } from '../../context/ChannelSettingsProvider';
77

8+
import { ChannelSettingsHeader, type ChannelSettingsHeaderProps } from './ChannelSettingsHeader';
9+
810
import PlaceHolder, { PlaceHolderTypes } from '../../../../ui/PlaceHolder';
911
import Label, { LabelTypography, LabelColors } from '../../../../ui/Label';
1012
import { LocalizationContext } from '../../../../lib/LocalizationContext';
1113
import Icon, { IconTypes, IconColors } from '../../../../ui/Icon';
12-
import IconButton from '../../../../ui/IconButton';
1314
import ChannelProfile from '../ChannelProfile';
1415
import ModerationPanel from '../ModerationPanel';
1516
import LeaveChannelModal from '../LeaveChannel';
1617
import UserPanel from '../UserPanel';
1718

1819
export interface ChannelSettingsUIProps {
20+
renderHeader?: (props: ChannelSettingsHeaderProps) => React.ReactElement;
1921
renderChannelProfile?: () => React.ReactElement;
2022
renderModerationPanel?: () => React.ReactElement;
2123
renderLeaveChannel?: () => React.ReactElement;
@@ -24,61 +26,38 @@ export interface ChannelSettingsUIProps {
2426
}
2527

2628
const ChannelSettingsUI: React.FC<ChannelSettingsUIProps> = ({
29+
renderHeader = (props) => <ChannelSettingsHeader {...props}/>,
2730
renderLeaveChannel,
2831
renderChannelProfile,
2932
renderModerationPanel,
3033
renderPlaceholderError,
3134
renderPlaceholderLoading,
3235
}: ChannelSettingsUIProps) => {
33-
const { stringSet } = useContext(LocalizationContext);
34-
3536
const state = useSendbirdStateContext();
37+
const isOnline = state?.config?.isOnline;
38+
const { stringSet } = useContext(LocalizationContext);
3639
const { channel, invalidChannel, onCloseClick, loading } = useChannelSettingsContext();
37-
3840
const [showLeaveChannelModal, setShowLeaveChannelModal] = useState(false);
3941

40-
const isOnline = state?.config?.isOnline;
41-
const logger = state?.config?.logger;
42-
43-
const renderHeaderArea = () => {
44-
return (
45-
<div className="sendbird-channel-settings__header">
46-
<Label type={LabelTypography.H_2} color={LabelColors.ONBACKGROUND_1}>
47-
{stringSet.CHANNEL_SETTING__HEADER__TITLE}
48-
</Label>
49-
<div className="sendbird-channel-settings__header-icon">
50-
<IconButton
51-
width="32px"
52-
height="32px"
53-
onClick={() => {
54-
logger.info('ChannelSettings: Click close');
55-
onCloseClick?.();
56-
}}
57-
>
58-
<Icon className="sendbird-channel-settings__close-icon" type={IconTypes.CLOSE} height="22px" width="22px" />
59-
</IconButton>
60-
</div>
61-
</div>
62-
);
63-
};
64-
6542
if (loading) {
6643
if (renderPlaceholderLoading) return renderPlaceholderLoading();
6744
return <PlaceHolder type={PlaceHolderTypes.LOADING} />;
6845
}
6946

47+
const headerProps: ChannelSettingsHeaderProps = { onCloseClick };
48+
7049
if (invalidChannel || !channel) {
7150
return (
7251
<div>
73-
{renderHeaderArea()}
52+
{renderHeader(headerProps)}
7453
<div>{renderPlaceholderError ? renderPlaceholderError() : <PlaceHolder type={PlaceHolderTypes.WRONG} />}</div>
7554
</div>
7655
);
7756
}
7857

7958
return (
8059
<>
81-
{renderHeaderArea()}
60+
{renderHeader(headerProps)}
8261
<div className="sendbird-channel-settings__scroll-area">
8362
{renderChannelProfile?.() || <ChannelProfile />}
8463
{renderModerationPanel?.() || (channel?.myRole === 'operator' ? <ModerationPanel /> : <UserPanel />)}

0 commit comments

Comments
 (0)