Skip to content

Commit

Permalink
Merge pull request #38 from Thomas-Negrault/notification-badge
Browse files Browse the repository at this point in the history
Add notification badge
  • Loading branch information
Martín Callegari authored Mar 4, 2018
2 parents c8621d5 + 61228a6 commit 25ae9ce
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default App;
|**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|
|**badge**|PropTypes.number|NO|0|Display a notification badge on the launcher if the value is greater than 0|

#### Styles

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';

import './style.scss';

const Badge = ({ badge }) =>
badge > 0 &&
<span className="badge">{badge}</span>;

Badge.propTypes = {
badge: PropTypes.number
};

export default Badge;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "variables.scss";

.launcher {
.badge{
position: fixed;
top: -10px;
right: -5px;
background-color: $red;
color: white;
width: 25px;
height: 25px;
text-align: center;
line-height: 25px;
border-radius: 50%;
}
}
7 changes: 5 additions & 2 deletions src/components/Widget/components/Launcher/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Badge from './components/Badge';

import openLauncher from 'assets/launcher_button.svg';
import close from 'assets/clear-button.svg';
import './style.scss';

const Launcher = ({ toggle, chatOpened }) =>
const Launcher = ({ toggle, chatOpened, badge }) =>
<button type="button" className={chatOpened ? 'launcher hide-sm' : 'launcher'} onClick={toggle}>
<Badge badge ={badge} />
{
chatOpened ?
<img src={close} className="close-launcher" alt="" /> :
Expand All @@ -17,7 +19,8 @@ const Launcher = ({ toggle, chatOpened }) =>

Launcher.propTypes = {
toggle: PropTypes.func,
chatOpened: PropTypes.bool
chatOpened: PropTypes.bool,
badge: PropTypes.number
};

export default connect(store => ({
Expand Down
4 changes: 3 additions & 1 deletion src/components/Widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Widget extends Component {
profileAvatar={this.props.profileAvatar}
showCloseButton={this.props.showCloseButton}
fullScreenMode={this.props.fullScreenMode}
badge={this.props.badge}
/>
);
}
Expand All @@ -49,7 +50,8 @@ Widget.propTypes = {
senderPlaceHolder: PropTypes.string,
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool,
fullScreenMode: PropTypes.bool
fullScreenMode: PropTypes.bool,
badge: PropTypes.number
};

export default connect()(Widget);
4 changes: 3 additions & 1 deletion src/components/Widget/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const WidgetLayout = props =>
!props.fullScreenMode &&
<Launcher
toggle={props.onToggleConversation}
badge={props.badge}
/>
}
</div>;
Expand All @@ -40,7 +41,8 @@ WidgetLayout.propTypes = {
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool,
disabledInput: PropTypes.bool,
fullScreenMode: PropTypes.bool
fullScreenMode: PropTypes.bool,
badge: PropTypes.number
};

export default connect(store => ({
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ConnectedWidget = props =>
profileAvatar={props.profileAvatar}
showCloseButton={props.showCloseButton}
fullScreenMode={props.fullScreenMode}
badge={props.badge}
/>
</Provider>;

Expand All @@ -25,15 +26,17 @@ ConnectedWidget.propTypes = {
senderPlaceHolder: PropTypes.string,
profileAvatar: PropTypes.string,
showCloseButton: PropTypes.bool,
fullScreenMode: PropTypes.bool
fullScreenMode: PropTypes.bool,
badge: PropTypes.number
};

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

export default ConnectedWidget;
1 change: 1 addition & 0 deletions src/sass/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ $grey-3: #b5b5b5;
$turqois-1: #35cce6;
$turqois-2: #a3eaf7;
$white: #fff;
$red: #ff0000;

0 comments on commit 25ae9ce

Please sign in to comment.