Skip to content

Commit 45ef73d

Browse files
authored
fix: Include renderIconButton into the renderHeader range (#375)
1 parent 41f4334 commit 45ef73d

File tree

4 files changed

+64
-52
lines changed

4 files changed

+64
-52
lines changed

scripts/index_d_ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ declare module "SendbirdUIKitGlobal" {
369369

370370
export interface ChannelListHeaderInterface {
371371
renderHeader?: (props: void) => React.ReactNode | React.ReactElement;
372+
renderTitle?: (props: void) => React.ReactNode | React.ReactElement;
372373
renderIconButton?: (props: void) => React.ReactNode | React.ReactElement;
373374
onEdit?: (props: void) => void;
374375
allowProfileEdit?: boolean;

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ interface ChannelListProps extends ChannelListProviderInterface, ChannelListUIPr
377377

378378
interface ChannelListHeaderInterface {
379379
renderHeader?: (props: void) => React.ReactElement;
380+
renderTitle?: (props: void) => React.ReactElement;
380381
renderIconButton?: (props: void) => React.ReactElement;
381382
onEdit?: (props: void) => void;
382383
allowProfileEdit?: boolean;

src/smart-components/ChannelList/components/ChannelListHeader/index.tsx

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@ import React, { useContext } from 'react';
33
import { LocalizationContext } from '../../../../lib/LocalizationContext';
44
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
55
import Label, { LabelTypography, LabelColors } from '../../../../ui/Label';
6-
import IconButton from '../../../../ui/IconButton';
76

87
import './index.scss';
98
import Avatar from '../../../../ui/Avatar';
109

1110
interface ChannelListHeaderInterface {
1211
renderHeader?: (props: void) => React.ReactElement;
12+
renderTitle?: () => React.ReactElement;
1313
renderIconButton?: (props: void) => React.ReactElement;
1414
onEdit?: (props: void) => void;
1515
allowProfileEdit?: boolean;
1616
}
1717

18-
const ChannelListHeader : React.FC<ChannelListHeaderInterface> = ({
18+
const ChannelListHeader: React.FC<ChannelListHeaderInterface> = ({
1919
renderHeader,
20+
renderTitle,
2021
renderIconButton,
2122
onEdit,
2223
allowProfileEdit,
2324
}: ChannelListHeaderInterface) => {
24-
const sbState = useSendbirdStateContext();
25-
const { user } = sbState?.stores?.userStore;
25+
const { stores, config } = useSendbirdStateContext?.();
26+
const { user } = stores?.userStore;
27+
const { logger } = config;
2628

2729
const { stringSet } = useContext(LocalizationContext);
30+
31+
if (renderHeader) {
32+
logger?.warning('Recomend to use "renderTitle" instead of "renderHeader". It will be deprecated.');
33+
}
34+
// renderTitle should have higher priority
35+
const titleRenderer = renderHeader || renderTitle;
36+
2837
return (
2938
<div
3039
className={[
@@ -33,45 +42,43 @@ const ChannelListHeader : React.FC<ChannelListHeaderInterface> = ({
3342
].join(' ')}
3443
>
3544
{
36-
renderHeader
37-
? renderHeader()
38-
: (
39-
<div
40-
className="sendbird-channel-header__title"
41-
role="button"
42-
onClick={() => { onEdit() }}
43-
onKeyDown={() => { onEdit() }}
44-
tabIndex={0}
45-
>
46-
<div className="sendbird-channel-header__title__left">
47-
<Avatar
48-
width="32px"
49-
height="32px"
50-
src={user.profileUrl}
51-
alt={user.nickname}
52-
/>
53-
</div>
54-
<div className="sendbird-channel-header__title__right">
55-
<Label
56-
className="sendbird-channel-header__title__right__name"
57-
type={LabelTypography.SUBTITLE_2}
58-
color={LabelColors.ONBACKGROUND_1}
59-
>
60-
{user.nickname || stringSet.NO_NAME}
61-
</Label>
62-
<Label
63-
className="sendbird-channel-header__title__right__user-id"
64-
type={LabelTypography.BODY_2}
65-
color={LabelColors.ONBACKGROUND_2}
66-
>
67-
{user.userId}
68-
</Label>
69-
</div>
45+
titleRenderer?.() || (
46+
<div
47+
className="sendbird-channel-header__title"
48+
role="button"
49+
onClick={() => { onEdit?.() }}
50+
onKeyDown={() => { onEdit?.() }}
51+
tabIndex={0}
52+
>
53+
<div className="sendbird-channel-header__title__left">
54+
<Avatar
55+
width="32px"
56+
height="32px"
57+
src={user.profileUrl}
58+
alt={user.nickname}
59+
/>
60+
</div>
61+
<div className="sendbird-channel-header__title__right">
62+
<Label
63+
className="sendbird-channel-header__title__right__name"
64+
type={LabelTypography.SUBTITLE_2}
65+
color={LabelColors.ONBACKGROUND_1}
66+
>
67+
{user.nickname || stringSet.NO_NAME}
68+
</Label>
69+
<Label
70+
className="sendbird-channel-header__title__right__user-id"
71+
type={LabelTypography.BODY_2}
72+
color={LabelColors.ONBACKGROUND_2}
73+
>
74+
{user.userId}
75+
</Label>
7076
</div>
71-
)
77+
</div>
78+
)
7279
}
7380
<div className="sendbird-channel-header__right-icon">
74-
{renderIconButton() || <IconButton />}
81+
{renderIconButton?.()}
7582
</div>
7683
</div>
7784
);

src/smart-components/ChannelList/components/ChannelListUI/index.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,21 @@ const ChannelListUI: React.FC<ChannelListUIProps> = (props: ChannelListUIProps)
9999
return (
100100
<>
101101
<div className="sendbird-channel-list__header">
102-
<ChannelListHeader
103-
renderHeader={renderHeader}
104-
onEdit={() => {
105-
if (allowProfileEdit) {
106-
setShowProfileEdit(true);
107-
}
108-
}}
109-
allowProfileEdit={allowProfileEdit}
110-
renderIconButton={() => (
111-
<AddChannel />
112-
)}
113-
/>
102+
{
103+
renderHeader?.() || (
104+
<ChannelListHeader
105+
onEdit={() => {
106+
if (allowProfileEdit) {
107+
setShowProfileEdit(true);
108+
}
109+
}}
110+
allowProfileEdit={allowProfileEdit}
111+
renderIconButton={() => (
112+
<AddChannel />
113+
)}
114+
/>
115+
)
116+
}
114117
</div>
115118
{
116119
showProfileEdit && (

0 commit comments

Comments
 (0)