JSFiddle - React, Tailwind, and code Playground

by NerfAnarchist

HTML

<div id="container">
    <div id="header">
        <div class="content">
            Messages
        </div>
    </div>
    <div id="messages">
        
    </div>
    <div id="message_bar">
        <div class="content">
            <table id="message_bar_format">
                <tr>
                    <td><textarea id="new_message"></textarea></td>
                    <td id="send_message"><div>Send</div></td>
                </tr>
            </div>
        </div>
    </div>
</div>

CSS

body, html, #container {
    width: 100%;
    height: 100%;
    margin: 0px;
    background-color: #559FDA;
}

#header {
    height: 40px;
}

#header .content {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 40px;
    background-color: #BADA55;
    text-align: center;
    padding:10px;
    box-sizing: border-box;
    box-shadow: 0px 1px 8px #000;
}

#message_bar {
    height: 40px;
}

#message_bar .content {
    position: fixed;
    bottom: 0px;
    left: 0px;
    width: 100%;
    height: 40px;
    background-color: #BADA55;
    text-align: center;
    padding:0px;
    box-sizing: border-box;
    box-shadow: 0px 1px 8px #000;
}

#message_bar_format {
    width: 100%;
}

#new_message {
    height: 35px;
    width: 100%;
    margin: 0px;
    resize: none;
    box-sizing: border-box;
}

#send_message {
    width: 40px;
}

#send_message div {
    height: 30px;
    width: 40px;
    margin: -4px 0px 0px 0px;
    padding: 7px 3px;
    background-color: #5560DA;
    color: #FFFFFF;
    cursor: pointer;
    border-radius: 3px;
    box-sizing: border-box;
}

.message {
    margin: 6px;
    padding: 6px;
    background-color: #F5F5F5;
    border-radius: 10px;
}

.message.you {
    background-color: #DDD;
}

.message.them {
    text-align: right;
}

.message_header {
    font-size: 10px;
    color: #AAAAAA;
}

.message_header {
    
}

JavaScript

// ui test (just for fun)

// nunzio you can copy all of this if you want

// you can change this template function to use your data format (dont change the HTML)
function template_messages() {
    var i, len, html = '';
    
    for (i = 0, len = messages.length; i < len; i = i + 1) {
        html +=
        '<div class="message ' + (messages[i].from === 'you' ? 'you': 'them') + '">' +
            '<div class="message_header">' + messages[i].from + '</div>' +
            '<div class="message_content">' + messages[i].message + '</div>' +
        '</div>';
    }
    
    return html;
}

// the from can be from anyone but if it is the conecting user then it needs to be: 'you'
var messages = [
    {'from': 'you',     'message': 'hi'},
    {'from': 'nunzio',  'message': 'hello'},
    {'from': 'nunzio',  'message': 'whats up'},
    {'from': 'you',     'message': 'not much you?'},
    {'from': 'nunzio',  'message': 'same here'},
    {'from': 'you',     'message': 'i have been testing some CSS'},
    {'from': 'nunzio',  'message': 'cool for what?'},
    {'from': 'you',     'message': 'a message website'},
    {'from': 'you',     'message': 'its coming along nicely'},
    {'from': 'nunzio',  'message': 'sweet'}
];

// append the templated HTML
$('#messages').append(template_messages());

// scroll to the bottom of the messages box
$('body').scrollTop($('body')[0].scrollHeight);