Skip to content

Commit 9741957

Browse files
committed
Add dark theme support
1 parent aef8999 commit 9741957

File tree

7 files changed

+18
-6
lines changed

7 files changed

+18
-6
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017-2021 Chatwoot Inc.
3+
Copyright (c) 2017-2023 Chatwoot Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare module '@chatwoot/react-native-widget' {
55
websiteToken: string;
66
locale?: string;
77
baseUrl: string;
8+
darkMode?: string;
89
closeModal: () => void;
910
isModalVisible: boolean;
1011
user?: {
@@ -21,4 +22,3 @@ declare module '@chatwoot/react-native-widget' {
2122
class ChatWootWidget extends React.Component<ChatWootWidgetProps, any> {}
2223
export default ChatWootWidget;
2324
}
24-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chatwoot/react-native-widget",
3-
"version": "0.0.10",
3+
"version": "0.0.12",
44
"description": "React Native widget for Chatwoot",
55
"main": "index.js",
66
"scripts": {

src/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const propTypes = {
1919
identifier_hash: PropTypes.string,
2020
}),
2121
locale: PropTypes.string,
22+
darkMode: PropTypes.string,
2223
customAttributes: PropTypes.shape({}),
2324
closeModal: PropTypes.func,
2425
};
@@ -27,6 +28,7 @@ const defaultProps = {
2728
cwCookie: '',
2829
user: {},
2930
locale: 'en',
31+
darkMode: 'light',
3032
customAttributes: {},
3133
};
3234

@@ -36,6 +38,7 @@ const ChatWootWidget = ({
3638
websiteToken,
3739
user,
3840
locale,
41+
darkMode,
3942
customAttributes,
4043
closeModal,
4144
}) => {
@@ -55,8 +58,7 @@ const ChatWootWidget = ({
5558
isVisible={isModalVisible}
5659
onBackButtonPress={closeModal}
5760
onBackdropPress={closeModal}
58-
style={styles.modal}
59-
>
61+
style={styles.modal}>
6062
<SafeAreaView style={styles.headerView} />
6163
<SafeAreaView style={styles.mainView}>
6264
<WebView
@@ -65,6 +67,7 @@ const ChatWootWidget = ({
6567
user={user}
6668
baseUrl={baseUrl}
6769
locale={locale}
70+
darkMode={darkMode}
6871
customAttributes={customAttributes}
6972
closeModal={closeModal}
7073
/>

src/WebView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const propTypes = {
77
websiteToken: PropTypes.string.isRequired,
88
baseUrl: PropTypes.string.isRequired,
99
cwCookie: PropTypes.string,
10+
darkMode: PropTypes.string,
1011
user: PropTypes.shape({
1112
name: PropTypes.string,
1213
avatar_url: PropTypes.string,
@@ -23,13 +24,15 @@ const defaultProps = {
2324
user: {},
2425
locale: 'en',
2526
customAttributes: {},
27+
darkMode: 'light',
2628
};
2729

2830
const WebViewComponent = ({
2931
baseUrl,
3032
websiteToken,
3133
cwCookie,
3234
locale,
35+
darkMode,
3336
user,
3437
customAttributes,
3538
closeModal,
@@ -43,6 +46,7 @@ const WebViewComponent = ({
4346
user,
4447
locale,
4548
customAttributes,
49+
darkMode,
4650
});
4751

4852
const onShouldStartLoadWithRequest = (request) => {

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const POST_MESSAGE_EVENTS = {
33
SET_LOCALE: 'set-locale',
44
SET_CUSTOM_ATTRIBUTES: 'set-custom-attributes',
55
SET_USER: 'set-user',
6+
SET_DARK_MODE: 'set-dark-mode',
67
};
78
export const BG_COLOR = '#f1f5f8';
89
export const COLOR_WHITE = '#fff';

src/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const createWootPostMessage = (object) => {
1919

2020
export const getMessage = (data) => data.replace(WOOT_PREFIX, '');
2121

22-
export const generateScripts = ({ user, locale, customAttributes }) => {
22+
export const generateScripts = ({ darkMode, user, locale, customAttributes }) => {
2323
let script = '';
2424
if (user) {
2525
const userObject = {
@@ -40,6 +40,10 @@ export const generateScripts = ({ user, locale, customAttributes }) => {
4040
};
4141
script += createWootPostMessage(attributeObject);
4242
}
43+
if (darkMode) {
44+
const darkModeObject = { event: POST_MESSAGE_EVENTS.SET_DARK_MODE, darkMode };
45+
script += createWootPostMessage(darkModeObject);
46+
}
4347
return script;
4448
};
4549
export const storeHelper = {

0 commit comments

Comments
 (0)