Skip to content

Commit

Permalink
Merge pull request #18 from Wolox/full-screen
Browse files Browse the repository at this point in the history
Full screen
  • Loading branch information
Martín Callegari authored Sep 25, 2017
2 parents 04f18c6 + c3dd1be commit c0dac5f
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 50 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ export default App;

#### Props

- **handleNewUserMessage:** (PropTypes.func.isRequired) Function to handle the user input, will receive the full text message when submitted
- **title:** (PropTypes.string) Title of the widget
- **subtitle:** (PropTypes.string) Subtitle of the widget
- **senderPlaceHolder:** (PropTypes.string) The placeholder of the message input
- **profileAvatar:** (PropTypes.string) The profile image that will be set on the responses
- **showCloseButton:** (PropTypes.bool) Show or hide the close button in full screen mode
| |type|required|default value|description|
|---|--- |--- |--- |--- |
|**handleNewUserMessage**|PropTypes.func|YES| |Function to handle the user input, will receive the full text message when submitted|
|**title**|PropTypes.string|NO|'Welcome'|Title of the widget|
|**subtitle**|PropTypes.string|NO|'This is your chat subtitle'|Subtitle of the widget|
|**senderPlaceHolder**|PropTypes.string|NO|'Type a message...'|The placeholder of the message input|
|**profileAvatar**|PropTypes.string|NO| |The profile image that will be set on the responses|
|**showCloseButton**|PropTypes.bool|NO|false|Show or hide the close button in full screen mode|
|**fullScreenMode**|PropTypes.bool|NO|false|Allow the use of full screen in full desktop mode|

#### Styles

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-chat-widget",
"version": "2.0.1",
"version": "2.1.0",
"description": "Chat web widget for React apps",
"main": "lib/index.js",
"repository": "git@github.com:Wolox/react-chat-widget.git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "variables.scss";
@import "common.scss";

.header {
background-color: $turqois-1;
Expand All @@ -20,29 +21,40 @@
display: none;
}


.full-screen {

.header {
@include header-fs;
}

.title {
@include title-fs;
}

.close-button {
@include close-button-fs;
}

.close {
@include close-fs;
}
}

@media screen and (max-width: 800px) {
.header {
border-radius: 0;
flex-shrink: 0;
position: relative;
@include header-fs;
}

.title {
padding: 0 0 15px 0;
@include title-fs;
}

.close-button {
background-color: $turqois-1;
border: 0;
display: block;
position: absolute;
right: 10px;
top: 20px;
width: 40px;
@include close-button-fs;
}

.close {
width: 20px;
height: 20px;
@include close-fs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Messages extends Component {
this.props.messages.map((message, index) =>
<div className="message" key={index}>
{
this.props.profileAvatar &&
message.get('showAvatar') &&
<img src={this.props.profileAvatar} className="avatar" alt="profile" />
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "variables.scss";
@import "common.scss";

.messages-container {
background-color: $white;
Expand All @@ -8,9 +9,15 @@
padding-top: 10px;
}

.full-screen {

.messages-container {
@include messages-container-fs;
}
}

@media screen and (max-width: 800px) {
.messages-container {
height: 100%;
max-height: none;
@include messages-container-fs;
}
}
12 changes: 9 additions & 3 deletions src/components/Widget/components/Conversation/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "common.scss";
@import "variables.scss";
@import "animation.scss";

Expand All @@ -11,10 +12,15 @@
@include animation(0, 0.5s, slide-out);
}

.full-screen {

.conversation-container {
@include conversation-container-fs;
}
}

@media screen and (max-width: 800px) {
.conversation-container {
display: flex;
flex-direction: column;
height: 100%;
@include conversation-container-fs;
}
}
6 changes: 2 additions & 4 deletions src/components/Widget/components/Launcher/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "common.scss";
@import "variables.scss";
@import "animation.scss";

Expand Down Expand Up @@ -28,10 +29,7 @@

@media screen and (max-width: 800px){
.launcher {
bottom: 0;
margin: 20px;
position: fixed;
right: 0;
@include launcher-fs;
}

.hide-sm {
Expand Down
19 changes: 10 additions & 9 deletions src/components/Widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { toggleChat, addUserMessage } from 'actions';
import WidgetLayout from './layout';

class Widget extends Component {
componentWillReceiveProps(nextProps) {
if (nextProps.fullScreenMode) {
this.props.dispatch(toggleChat());
}
}

toggleConversation = () => {
this.props.dispatch(toggleChat());
}
Expand All @@ -30,25 +36,20 @@ class Widget extends Component {
senderPlaceHolder={this.props.senderPlaceHolder}
profileAvatar={this.props.profileAvatar}
showCloseButton={this.props.showCloseButton}
fullScreenMode={this.props.fullScreenMode}
/>
);
}
}

Widget.propTypes = {
handleNewUserMessage: PropTypes.func.isRequired,
title: PropTypes.string,
subtitle: PropTypes.string,
handleNewUserMessage: PropTypes.func.isRequired,
senderPlaceHolder: PropTypes.string,
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool
};

Widget.defaultProps = {
title: 'Welcome',
subtitle: 'This is your chat subtitle',
senderPlaceHolder: 'Type a message...',
showCloseButton: true
showCloseButton: PropTypes.bool,
fullScreenMode: PropTypes.bool
};

export default connect()(Widget);
14 changes: 9 additions & 5 deletions src/components/Widget/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Launcher from './components/Launcher';
import './style.scss';

const WidgetLayout = props =>
<div className="widget-container">
<div className={props.fullScreenMode ? 'widget-container full-screen' : 'widget-container'}>
{
props.showChat &&
<Conversation
Expand All @@ -22,9 +22,12 @@ const WidgetLayout = props =>
disabledInput={props.disabledInput}
/>
}
<Launcher
toggle={props.onToggleConversation}
/>
{
!props.fullScreenMode &&
<Launcher
toggle={props.onToggleConversation}
/>
}
</div>;

WidgetLayout.propTypes = {
Expand All @@ -36,7 +39,8 @@ WidgetLayout.propTypes = {
senderPlaceHolder: PropTypes.string,
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool,
disabledInput: PropTypes.bool
disabledInput: PropTypes.bool,
fullScreenMode: PropTypes.bool
};

export default connect(store => ({
Expand Down
12 changes: 7 additions & 5 deletions src/components/Widget/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "animation.scss";
@import "common.scss";

.widget-container {
bottom: 0;
Expand All @@ -10,13 +11,14 @@
right: 0;
width: 90vw;
z-index: 9999;

&.full-screen {
@include widget-container-fs;
}
}

@media screen and (max-width: 800px) {
@media screen and (max-width: 800px) {
.widget-container {
height: 100%;
margin: 0;
max-width: none;
width: 100%;
@include widget-container-fs;
}
}
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ConnectedWidget = props =>
senderPlaceHolder={props.senderPlaceHolder}
profileAvatar={props.profileAvatar}
showCloseButton={props.showCloseButton}
fullScreenMode={props.fullScreenMode}
/>
</Provider>;

Expand All @@ -23,7 +24,16 @@ ConnectedWidget.propTypes = {
handleNewUserMessage: PropTypes.func.isRequired,
senderPlaceHolder: PropTypes.string,
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool
showCloseButton: PropTypes.bool,
fullScreenMode: PropTypes.bool
};

ConnectedWidget.defaultProps = {
title: 'Welcome',
subtitle: 'This is your chat subtitle',
senderPlaceHolder: 'Type a message...',
showCloseButton: true,
fullScreenMode: false
};

export default ConnectedWidget;
50 changes: 50 additions & 0 deletions src/sass/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,53 @@
max-width: 215px;
text-align: left;
}

@mixin widget-container-fs {
height: 100%;
margin: 0;
max-width: none;
width: 100%;
}

@mixin header-fs {
border-radius: 0;
flex-shrink: 0;
position: relative;
}

@mixin title-fs {
padding: 0 0 15px 0;
}

@mixin close-button-fs {
background-color: $turqois-1;
border: 0;
display: block;
position: absolute;
right: 10px;
top: 20px;
width: 40px;
}

@mixin close-fs {
width: 20px;
height: 20px;
}

@mixin messages-container-fs {
height: 100%;
max-height: none;
}

@mixin conversation-container-fs {
display: flex;
flex-direction: column;
height: 100%;
}

@mixin launcher-fs {
bottom: 0;
margin: 20px;
position: fixed;
right: 0;
}

0 comments on commit c0dac5f

Please sign in to comment.