Skip to content

Commit

Permalink
Merge pull request #15 from Codebrahma/react-css-themr
Browse files Browse the repository at this point in the history
React css themr - update components for applying custom themes.
  • Loading branch information
rishichawda committed Aug 1, 2018
2 parents e0425c2 + 1ccf0a9 commit c468374
Show file tree
Hide file tree
Showing 25 changed files with 2,795 additions and 2,888 deletions.
5,004 changes: 2,502 additions & 2,502 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"file-loader": "^1.1.11",
"prop-types": "^15.6.2",
"react": "^16.3.2",
"react-css-themr": "^2.1.2",
"react-dom": "^16.3.2"
},
"config": {
Expand Down
13 changes: 9 additions & 4 deletions src/components/ChatList.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react'
import PropTypes from 'prop-types'
import ChatListItem from './ChatListItem'
import defaultTheme from '../themes/_default_theme.scss'
import { themr } from 'react-css-themr';

const ChatList = (props) => (
<div className={props.chatListClass}>
const ChatList = (props) => {
const { theme } = props;
return (
<div className={theme.userlist}>
{
props.userData.length === 0
? <span className='no-user-found'>No User Found</span>
? <span>No User Found</span>
: props.userData.map(item => (
<props.customChatListItem
key={item.id}
Expand All @@ -22,6 +26,7 @@ const ChatList = (props) => (
}
</div>
)
}

ChatList.propTypes = {
userData: PropTypes.array.isRequired,
Expand All @@ -35,4 +40,4 @@ ChatList.defaultProps = {
chatListClass: "user-list",
}

export default ChatList
export default themr('ThemedChatList', defaultTheme, { composeTheme : "softly" })(ChatList)
17 changes: 11 additions & 6 deletions src/components/ChatListHeader.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react'
import PropTypes from 'prop-types'
import { themr } from 'react-css-themr';
import defaultTheme from '../themes/_default_theme.scss'

const ChatListHeader = (props) => (
<div className={props.chatHeaderClass}>
<span>Active Users ({props.userData.filter(data => data.onlineStatus==="online").length})</span>
</div>
)
const ChatListHeader = (props) => {
const { theme } = props;
return (
<div className={theme.header}>
<span>Active Users ({props.userData.filter(data => data.onlineStatus === "online").length})</span>
</div>
)
}

ChatListHeader.propTypes = {
userData: PropTypes.array.isRequired,
Expand All @@ -17,4 +22,4 @@ ChatListHeader.defaultProps = {
chatHeaderClass: "chat-list-header",
}

export default ChatListHeader
export default themr('ThemedChatListHeader', defaultTheme, { composeTheme : "softly" })(ChatListHeader)
14 changes: 8 additions & 6 deletions src/components/ChatListItem.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from 'react'
import PropTypes from 'prop-types'
import defaultTheme from '../themes/_default_theme.scss'
import { themr } from 'react-css-themr';

const ChatListItem = (props) => {
const {lastSeen} = props
const lastSeenTime = new Date() - lastSeen
const lastSeenMinutes = Math.ceil(lastSeenTime / (1000*60))
const lastSeenHours = Math.floor(lastSeenMinutes / 60)
const lastSeenDays = Math.floor(lastSeenHours / 24)

const { theme } = props;
return (
<div id={props.id} className="user-item" onClick={() => props.handleChatItemClick(props.id)}>
<img src={props.avatar} className="user-avatar" alt={props.name.slice(0,1).toUpperCase()}/>
<span className="user-name">{props.name}</span>
<span className={props.onlineStatus}>
<div id={props.id} className={theme.useritem} onClick={() => props.handleChatItemClick(props.id)}>
<img src={props.avatar} className={theme.useravatar} alt={props.name.slice(0,1).toUpperCase()}/>
<span className={theme.username}>{props.name}</span>
<span className={theme[props.onlineStatus]}>
{ props.onlineStatus === "offline" && (
lastSeenDays > 0
? `${lastSeenDays}d`
Expand All @@ -36,4 +38,4 @@ ChatListItem.propTypes = {
handleChatItemClick: PropTypes.func.isRequired
}

export default ChatListItem
export default themr('ThemedChatListItem', defaultTheme, { composeTheme : "softly" })(ChatListItem)
14 changes: 7 additions & 7 deletions src/components/ChatListProvider.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import {
ChatListItem,
} from './index.js'
import ChatListHeader from './ChatListHeader'
import ChatList from './ChatList'
import ChatListSearch from './ChatListSearch'
import { themr } from 'react-css-themr';
import defaultTheme from '../themes/_default_theme.scss'

const ChatListProvider = (props) => {
const { theme } = props;
return (
<div className={`${props.chatProviderClass} chat-list-wrapper`}>
<div className={theme.provider}>
{
props.children
? ( Array.isArray(props.children)
Expand All @@ -18,9 +18,9 @@ const ChatListProvider = (props) => {
)
: (
<div>
<props.customHeader userData={props.userData} />
<props.customHeader userData={props.userData} {...props}/>
<props.customList userData={props.userData} {...props}/>
<props.customSearch handleSearchChange={props.handleSearchChange}/>
<props.customSearch handleSearchChange={props.handleSearchChange} />
</div>
)
}
Expand All @@ -43,4 +43,4 @@ ChatListProvider.defaultProps = {
customSearch: ChatListSearch,
}

export default ChatListProvider
export default themr('ThemedChatListProvider',defaultTheme, { composeTheme : "softly" })(ChatListProvider)
15 changes: 10 additions & 5 deletions src/components/ChatListSearch.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react'
import PropTypes from 'prop-types'
import { themr } from 'react-css-themr';
import defaultTheme from '../themes/_default_theme.scss'

const ChatListSearch = (props) => (
<div className={props.chatSearchClass}>
const ChatListSearch = (props) => {
const { theme } = props;
return (
<div className={theme.searchbox}>
<input
className={`${props.chatSearchClass}-input`}
className={theme.input}
type="text"
placeholder="Search users..."
onChange={props.handleSearchChange}
/>
</div>
)
)
}

ChatListSearch.propTypes = {
handleSearchChange: PropTypes.func,
Expand All @@ -21,4 +26,4 @@ ChatListSearch.defaultProps = {
chatSearchClass: "search-user",
}

export default ChatListSearch
export default themr('ThemedChatSearch', defaultTheme, { composeTheme: "softly" })(ChatListSearch)
25 changes: 0 additions & 25 deletions src/examples/chat-window/MyChatWindow.js

This file was deleted.

14 changes: 6 additions & 8 deletions src/examples/chat-window/chat-window-styles.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.chat-window-container {
max-width: 350px !important;
border-radius: 5px;
.animated {
animation-duration: 0.1s;
}


.chat-window-header {
background: $chat-header;
padding: 5px 10px;
Expand Down Expand Up @@ -31,6 +27,9 @@
height: 50vh;
padding: 5px 10px;
overflow-y: scroll;
.animated {
animation-duration: 0.1s;
}
.message {
margin: 4px;
word-wrap: break-word;
Expand Down Expand Up @@ -90,5 +89,4 @@
}
}
}
}
}
}
1 change: 0 additions & 1 deletion src/examples/chat-window/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class WindowIndex extends Component {
<ChatListProvider
myData={this.props.myData}
userData={this.props.userData}
chatProviderClass="chat-window-container animated fadeInUp"
handleInputMessage={this.handleInputMessage}
onSend={this.onSend}
inputValue={this.state.inputMessage}
Expand Down
3 changes: 1 addition & 2 deletions src/examples/demoPage/DemoChatListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class DemoChatList extends Component {
{
this.state.open &&
<div className="demo-chat-list animated slideInRight">
<ChatListProvider
userData={this.props.userData}
<ChatListProvider userData={this.props.userData}
handleChatItemClick={(id) => this.props.updateChatWindow(id)}
handleSearchChange={this.props.handleSearchChange}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/examples/demoPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styles from './demopageStyle.scss';
import DemoPageNavbar from './DemoPageNavbar';
import DemoChatListBox from './DemoChatListBox';
import DemoChatWindowBox from './DemoChatWindowBox';
import './resources/animate.css';
import './resources/animate.scss';


class DemoPage extends Component {
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions src/examples/exampleChat2/ExampleChatListHeader.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/examples/exampleChat2/ExampleChatListItem.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/examples/exampleChat2/index.js

This file was deleted.

0 comments on commit c468374

Please sign in to comment.