-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1356 from maapteh/chore/chat-example-update
Chore: update Chat example
- Loading branch information
Showing
5 changed files
with
195 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
import React, { Component } from 'react'; | ||
import Room from './Room'; | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Room } from './Room'; | ||
|
||
class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
const Input = styled.div` | ||
padding: 4px; | ||
margin: 0 0 4px; | ||
this.state = { | ||
name: 'tester', | ||
channel: '#gophers', | ||
} | ||
input { | ||
border: 1px solid #ccc; | ||
padding: 2px; | ||
font-size: 14px; | ||
} | ||
render() { | ||
return (<div> | ||
name: <br/> | ||
<input value={this.state.name} onChange={(e) => this.setState({name: e.target.value })} /> <br /> | ||
`; | ||
|
||
channel: <br /> | ||
<input value={this.state.channel} onChange={(e) => this.setState({channel: e.target.value })}/> <br/> | ||
export const App = () => { | ||
const [name, setName] = useState('tester'); | ||
const [channel, setChannel] = useState('#gophers'); | ||
|
||
<Room channel={this.state.channel} name={this.state.name} /> | ||
</div> | ||
); | ||
} | ||
} | ||
return ( | ||
<> | ||
<Input> | ||
name: <input value={name} onChange={(e) => setName(e.target.value)} /> | ||
</Input> | ||
<Input> | ||
channel: <input value={channel} onChange={(e) => setChannel(e.target.value)} /> | ||
</Input> | ||
|
||
<Room channel={channel} name={name} /> | ||
</> | ||
); | ||
|
||
export default App; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Chat = styled.div` | ||
padding: 4px; | ||
margin: 0 0 12px; | ||
max-width: 400px; | ||
max-height: 400px; | ||
border: 1px solid #ccc; | ||
background-color: #babdc6; | ||
overflow-x: hidden; | ||
overflow-y: scroll; | ||
position: relative; | ||
font: 14px verdana; | ||
`; | ||
|
||
export const ChatContainer = styled.div` | ||
&:after { | ||
content: ""; | ||
display: table; | ||
clear: both; | ||
} | ||
`; | ||
|
||
const ChatLine = styled.div` | ||
color: #000; | ||
clear: both; | ||
line-height: 120%; | ||
padding: 8px; | ||
position: relative; | ||
margin: 8px 0; | ||
max-width: 85%; | ||
word-wrap: break-word; | ||
z-index: 1; | ||
&:after { | ||
position: absolute; | ||
content: ""; | ||
width: 0; | ||
height: 0; | ||
border-style: solid; | ||
} | ||
span { | ||
display: inline-block; | ||
float: right; | ||
padding: 0 0 0 7px; | ||
position: relative; | ||
bottom: -4px; | ||
} | ||
}`; | ||
|
||
export const MessageReceived = styled(ChatLine)` | ||
background: #fff; | ||
border-radius: 0px 5px 5px 5px; | ||
float: left; | ||
&:after { | ||
border-width: 0px 10px 10px 0; | ||
border-color: transparent #fff transparent transparent; | ||
top: 0; | ||
left: -4px; | ||
} | ||
span { | ||
display: block; | ||
color: #bbb; | ||
font-size: 10px; | ||
} | ||
`; | ||
|
||
export const Message = styled(ChatLine)` | ||
background: #e1ffc7; | ||
border-radius: 5px 0px 5px 5px; | ||
float: right; | ||
&:after { | ||
border-width: 0px 0 10px 10px; | ||
border-color: transparent transparent transparent #e1ffc7; | ||
top: 0; | ||
right: -4px; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters