Skip to content

Commit

Permalink
feat: add htmlTextDirection prop to SendbirdProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
AhyoungRyu committed Jun 24, 2024
1 parent cf65e06 commit eb4a0ba
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/lib/Sendbird.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
SendbirdProviderUtils,
} from './types';
import { GlobalModalProvider, ModalRoot } from '../hooks/useModal';
import { RenderUserProfileProps, UserListQuery } from '../types';
import { HTMLTextDirection, RenderUserProfileProps, UserListQuery } from '../types';
import PUBSUB_TOPICS, { SBUGlobalPubSub, SBUGlobalPubSubTopicPayloadUnion } from './pubSub/topics';
import { EmojiManager } from './emojiManager';
import { uikitConfigStorage } from './utils/uikitConfigStorage';
Expand Down Expand Up @@ -101,6 +101,7 @@ export interface SendbirdProviderProps extends CommonUIKitConfigProps, React.Pro
allowProfileEdit?: boolean;
disableMarkAsDelivered?: boolean;
breakpoint?: string | boolean;
htmlTextDirection?: HTMLTextDirection;
renderUserProfile?: (props: RenderUserProfileProps) => React.ReactElement;
onUserProfileMessage?: (channel: GroupChannel) => void;
uikitOptions?: UIKitOptions;
Expand Down Expand Up @@ -175,6 +176,7 @@ const SendbirdSDK = ({
customExtensionParams,
isMultipleFilesMessageEnabled = false,
eventHandlers,
htmlTextDirection = 'ltr',
}: SendbirdProviderProps): React.ReactElement => {
const { logLevel = '', userMention = {}, isREMUnitEnabled = false, pubSub: customPubSub } = config;
const { isMobile } = useMediaQueryContext();
Expand Down Expand Up @@ -393,6 +395,7 @@ const SendbirdSDK = ({
isTypingIndicatorEnabledOnChannelList: configs.groupChannel.channelList.enableTypingIndicator,
isMessageReceiptStatusEnabledOnChannelList: configs.groupChannel.channelList.enableMessageReceiptStatus,
showSearchIcon: sdkInitialized && configsWithAppAttr(sdk).groupChannel.setting.enableMessageSearch,
htmlTextDirection,
},
eventHandlers,
emojiManager,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SBUConfig } from '@sendbird/uikit-tools';
import { Module, ModuleNamespaces } from '@sendbird/chat/lib/__definition';

import type {
HTMLTextDirection,
RenderUserProfileProps,
ReplyType,
UserListQuery,
Expand Down Expand Up @@ -71,6 +72,7 @@ export interface SendBirdStateConfig {
appId: string;
accessToken?: string;
theme: string;
htmlTextDirection: HTMLTextDirection;
pubSub: SBUGlobalPubSub;
logger: Logger;
setCurrentTheme: (theme: 'light' | 'dark') => void;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/App/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const AppLayout = (props: AppLayoutProps) => {
currentChannel,
setCurrentChannel,
enableLegacyChannelModules,
htmlTextDirection,
} = props;

const globalStore = useSendbirdStateContext();
Expand Down Expand Up @@ -61,6 +62,7 @@ export const AppLayout = (props: AppLayoutProps) => {
threadTargetMessage={threadTargetMessage}
setThreadTargetMessage={setThreadTargetMessage}
enableLegacyChannelModules={enableLegacyChannelModules}
htmlTextDirection={htmlTextDirection}
/>
)
: (
Expand All @@ -87,6 +89,7 @@ export const AppLayout = (props: AppLayoutProps) => {
startingPoint={startingPoint}
setStartingPoint={setStartingPoint}
enableLegacyChannelModules={enableLegacyChannelModules}
htmlTextDirection={htmlTextDirection}
/>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/App/DesktopLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (props: DesktopLayout
threadTargetMessage,
setThreadTargetMessage,
enableLegacyChannelModules,
htmlTextDirection,
} = props;

const updateFocusedChannel = (channel: GroupChannelClass) => {
Expand Down Expand Up @@ -109,7 +110,7 @@ export const DesktopLayout: React.FC<DesktopLayoutProps> = (props: DesktopLayout
};

return (
<div className="sendbird-app__wrap">
<div className="sendbird-app__wrap" dir={htmlTextDirection}>
<div className="sendbird-app__channellist-wrap">
{enableLegacyChannelModules ? <ChannelList {...channelListProps} /> : <GroupChannelList {...channelListProps} />}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/modules/App/MobileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (props: MobileLayoutPro
highlightedMessage,
setHighlightedMessage,
enableLegacyChannelModules,
htmlTextDirection,
} = props;
const [panel, setPanel] = useState(PANELS.CHANNEL_LIST);

Expand Down Expand Up @@ -165,7 +166,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (props: MobileLayoutPro
};

return (
<div className="sb_mobile">
<div className="sb_mobile" dir={htmlTextDirection}>
{panel === PANELS.CHANNEL_LIST && (
<div className="sb_mobile__panelwrap">
{enableLegacyChannelModules ? <ChannelList {...channelListProps} /> : <GroupChannelList {...channelListProps} />}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface AppProps {
isMessageGroupingEnabled?: AppLayoutProps['isMessageGroupingEnabled'];
disableAutoSelect?: AppLayoutProps['disableAutoSelect'];
onProfileEditSuccess?: AppLayoutProps['onProfileEditSuccess'];
htmlTextDirection?: AppLayoutProps['htmlTextDirection'];

/**
* The default value is false.
Expand Down Expand Up @@ -100,6 +101,7 @@ export default function App(props: AppProps) {
isUserIdUsedForNickname = true,
enableLegacyChannelModules = false,
uikitOptions,
htmlTextDirection = 'ltr',
// The below configs are duplicates of the Dashboard UIKit Configs.
// Since their default values will be set in the Sendbird component,
// we don't need to set them here.
Expand Down Expand Up @@ -167,6 +169,7 @@ export default function App(props: AppProps) {
isReactionEnabled={isReactionEnabled}
replyType={replyType}
showSearchIcon={showSearchIcon}
htmlTextDirection={htmlTextDirection}
/>
</Sendbird>
);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/App/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
UserListQuery,
RenderUserProfileProps,
SendBirdProviderConfig,
HTMLTextDirection,
} from '../../types';
import { CustomExtensionParams, SBUEventHandlers, SendbirdChatInitParams } from '../../lib/types';
import { SendableMessageType } from '../../utils';

export interface AppLayoutProps {
isReactionEnabled?: boolean;
replyType?: 'NONE' | 'QUOTE_REPLY' | 'THREAD';
htmlTextDirection?: HTMLTextDirection;
isMessageGroupingEnabled?: boolean;
isMultipleFilesMessageEnabled?: boolean;
allowProfileEdit?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions src/stories/apps/GroupChannelApp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const meta: Meta<typeof App> = {
'isMessageReceiptStatusEnabledOnChannelList',
'isMessageGroupingEnabled',
'disableAutoSelect',
'htmlTextDirection',
],
},
},
Expand Down Expand Up @@ -136,6 +137,12 @@ const meta: Meta<typeof App> = {
'A property that determines whether to automatically select another channel when the currently selected channel is deleted, or the user exits the channel, causing it to be deselected in the channel list.',
control: 'boolean',
},
htmlTextDirection: {
type: 'string',
description: 'A property that sets the text direction of the HTML. `ltr` is for left-to-right, and `rtl` is for right-to-left.',
control: 'radio',
options: ['ltr', 'rtl'],
}
},
};
export default meta;
Expand Down Expand Up @@ -169,4 +176,5 @@ Default.args = {
isMessageReceiptStatusEnabledOnChannelList: true,
isMessageGroupingEnabled: true,
disableAutoSelect: false,
htmlTextDirection: 'ltr',
};
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ export enum MessageContentMiddleContainerType {
DEFAULT = 'default',
WIDE = 'wide',
}

export type HTMLTextDirection = 'ltr' | 'rtl';

0 comments on commit eb4a0ba

Please sign in to comment.