Skip to content

Commit de66d0c

Browse files
author
Sravan S
authored
feat: Open prop breakpoint (#618)
`breakpoint?: boolean` open on `@sendbird/uikit-react/App` and `@sendbird/uikit-react/SendbirdProvider` ``` const isMobile = true // or --- // const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); // or --- // const isMobile = /^https?:\/\/m\./i.test(window.location.href) // ^^checks of url is like `m.sendbird.com` // or --- // const isMobile = "768px" // ^^ UIKit will behave like mobile under 768px browser width <SendbirdProvider breakpoint={isMobile} /> ``` fixes: https://sendbird.atlassian.net/browse/UIKIT-4107
1 parent bd562d0 commit de66d0c

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

scripts/index_d_ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare module "SendbirdUIKitGlobal" {
5151
customApiHost?: string,
5252
customWebSocketHost?: string,
5353
// not-ready yet
54-
// breakpoint?: string | boolean,
54+
breakpoint?: string | boolean,
5555
theme?: 'light' | 'dark';
5656
userListQuery?(): UserListQuery;
5757
nickname?: string;
@@ -232,6 +232,7 @@ declare module "SendbirdUIKitGlobal" {
232232
configureSession?: (sdk: SendbirdChat | SendbirdGroupChat | SendbirdOpenChat) => SessionHandler;
233233
customApiHost?: string,
234234
customWebSocketHost?: string,
235+
breakpoint?: string | boolean,
235236
children?: React.ReactElement;
236237
theme?: 'light' | 'dark';
237238
replyType?: ReplyType;

src/lib/MediaQueryContext.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ const DEFAULT_MOBILE = false;
55
// const DEFAULT_MOBILE = '768px';
66
const MOBILE_CLASSNAME = 'sendbird--mobile-mode';
77

8-
const MediaQueryContext = React.createContext({
8+
export type useMediaQueryContextType = () => ({
9+
breakpoint: string | boolean;
10+
isMobile: boolean;
11+
});
12+
13+
const MediaQueryContext = React.createContext<ReturnType<useMediaQueryContextType>>({
914
breakpoint: DEFAULT_MOBILE,
1015
isMobile: false,
1116
});
@@ -39,7 +44,7 @@ const MediaQueryProvider = (props: MediaQueryProviderProps): React.ReactElement
3944
children,
4045
logger,
4146
} = props;
42-
const breakpoint = props?.breakpoint || DEFAULT_MOBILE;
47+
const breakpoint = props?.breakpoint || false;
4348
const [isMobile, setIsMobile] = useState(false);
4449
useEffect(() => {
4550
const updateSize = () => {
@@ -81,11 +86,6 @@ const MediaQueryProvider = (props: MediaQueryProviderProps): React.ReactElement
8186
);
8287
};
8388

84-
export type useMediaQueryContextType = () => ({
85-
breakpoint: string | boolean;
86-
isMobile: boolean;
87-
});
88-
8989
const useMediaQueryContext: useMediaQueryContextType = () => React.useContext(MediaQueryContext);
9090

9191
export { MediaQueryProvider, useMediaQueryContext };

src/lib/Sendbird.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export interface SendbirdProviderProps extends CommonUIKitConfigProps {
8888
allowProfileEdit?: boolean;
8989
disableMarkAsDelivered?: boolean;
9090
showSearchIcon?: boolean;
91+
breakpoint?: string | boolean;
9192
renderUserProfile?: () => React.ReactElement;
9293
onUserProfileMessage?: () => void;
9394
}
@@ -158,9 +159,8 @@ const SendbirdSDK = ({
158159
disableMarkAsDelivered = false,
159160
renderUserProfile = null,
160161
onUserProfileMessage = null,
162+
breakpoint = false,
161163
}: SendbirdProviderProps): React.ReactElement => {
162-
const breakpoint = false;
163-
164164
const {
165165
logLevel = '',
166166
userMention = {},

src/modules/App/index.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ App.propTypes = {
104104
userListQuery: PropTypes.func,
105105
nickname: PropTypes.string,
106106
profileUrl: PropTypes.string,
107-
breakpoint: PropTypes.string,
107+
breakpoint: PropTypes.oneOf([
108+
PropTypes.string,
109+
PropTypes.bool,
110+
]),
108111
allowProfileEdit: PropTypes.bool,
109112
disableUserProfile: PropTypes.bool,
110113
disableMarkAsDelivered: PropTypes.bool,

0 commit comments

Comments
 (0)