Skip to content

Commit

Permalink
refactoring styles for widget
Browse files Browse the repository at this point in the history
fix for old mobile devices
  • Loading branch information
yamaha252 committed Dec 10, 2018
1 parent 5059117 commit f8d4504
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
9 changes: 6 additions & 3 deletions src/widget/chat-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ export default class ChatFrame extends Component {
let encodedConf = encodeURIComponent(JSON.stringify({...conf, ...dynamicConf}));
return (
<iframe src={iFrameSrc + '?id=' + intergramId + '&host=' + host + '&conf=' + encodedConf }
width='100%'
height='100%'
frameborder='0' >
frameborder='0'
style={{
flex: '1',
width: '100%',
height: 0,
}}>
</iframe>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/chat-title-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h, Component } from 'preact';

export default class ChatTitleMsg extends Component {

render({isOpened, conf},{}) {
render({conf}, {}) {
return (
<div style={{position: 'relative', cursor: 'pointer'}} onClick={this.props.onClick}>
<div
Expand Down
6 changes: 6 additions & 0 deletions src/widget/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ export const mobileTitleStyle = {
webkitBoxShadow: '1px 1px 4px rgba(101,119,134,.75)',
boxShadow: '1px 1px 4px rgba(101,119,134,.75)'
};

export const titleStyle = {
display: 'flex',
alignItems: 'center',
padding: '0px 30px 0px 0px'
};
71 changes: 30 additions & 41 deletions src/widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
desktopWrapperStyle,
mobileOpenWrapperStyle,
mobileClosedWrapperStyle,
desktopClosedWrapperStyleChat
desktopClosedWrapperStyleChat,
titleStyle
} from "./style";

export default class Widget extends Component {
Expand All @@ -26,51 +27,39 @@ export default class Widget extends Component {
const desktopHeight = (window.innerHeight - 100 < conf.desktopHeight) ? window.innerHeight : conf.desktopHeight;
const wrapperHeight = {height: desktopHeight};

let wrapperStyle;
if (!isChatOpen && (isMobile || conf.alwaysUseFloatingButton)) {
wrapperStyle = { ...mobileClosedWrapperStyle}; // closed mobile floating button
} else if (!isMobile){
wrapperStyle = (conf.closedStyle === 'chat' || isChatOpen || this.wasChatOpened()) ?
(isChatOpen) ?
{ ...desktopWrapperStyle, ...wrapperWidth, ...wrapperHeight} // desktop mode, button style
:
{ ...desktopWrapperStyle}
:
{ ...desktopClosedWrapperStyleChat}; // desktop mode, chat style
} else {
wrapperStyle = mobileOpenWrapperStyle; // open mobile wrapper should have no border
}

return (
<div style={wrapperStyle}>

{/* Open/close button */}
{ (isMobile || conf.alwaysUseFloatingButton) && !isChatOpen ?

<ChatFloatingButton color={conf.mainColor} onClick={this.onClick}/>

:

(conf.closedStyle === 'chat' || isChatOpen || this.wasChatOpened()) ?
<div style={{background: conf.mainColor, ...desktopTitleStyle}} onClick={this.onClick}>
<div style={{display: 'flex', alignItems: 'center', padding: '0px 30px 0px 0px'}}>
{isChatOpen ? conf.titleOpen : conf.titleClosed}
</div>
<ArrowIcon isOpened={isChatOpen}/>
<div>
{/*CLOSED STATE*/}
<div style={{display: isChatOpen ? 'none' : 'block'}}>
{(isMobile || conf.alwaysUseFloatingButton) ?
<div style={mobileClosedWrapperStyle}>
<ChatFloatingButton color={conf.mainColor} onClick={this.onClick}/>
</div>
:
<ChatTitleMsg onClick={this.onClick} conf={conf}/>
}

{/*Chat IFrame*/}
<div style={{
display: isChatOpen ? 'block' : 'none',
height: 0, // flexbug
flex: 1,
}}>
{pristine ? null : <ChatFrame {...this.props} /> }
(conf.closedStyle === 'chat' || this.wasChatOpened()) ?
<div style={desktopWrapperStyle}>
<div style={{background: conf.mainColor, ...desktopTitleStyle}} onClick={this.onClick}>
<div style={titleStyle}>{conf.titleClosed}</div>
<ArrowIcon isOpened={false}/>
</div>
</div>
:
<div style={desktopClosedWrapperStyleChat}>
<ChatTitleMsg onClick={this.onClick} conf={conf}/>
</div>
}
</div>

{/*OPENED STATE*/}
<div style={{display: isChatOpen ? 'block' : 'none'}}>
<div style={isMobile ? mobileOpenWrapperStyle : {...desktopWrapperStyle, ...wrapperWidth, ...wrapperHeight}}>
<div style={{background: conf.mainColor, ...desktopTitleStyle}} onClick={this.onClick}>
<div style={titleStyle}>{conf.titleOpen}</div>
<ArrowIcon isOpened={true}/>
</div>
{pristine ? null : <ChatFrame {...this.props} />}
</div>
</div>
</div>
);
}
Expand Down

0 comments on commit f8d4504

Please sign in to comment.