JSFiddle - React, Tailwind, and code Playground
by Walter Rumsby
HTML
<div class="x-Form x-Form-collapsed">
<div class="x-Form_header">
<h2 class="x-Form_title">Email</h2>
</div>
<div class="x-Form_body">
<div class="x-Field">
<label class="x-Field_label x-Field_label-left">Email Address</label>
<input type="text" placeholder="[email protected]" class="x-Field_input" />
</div>
<div class="x-Field">
<label class="x-Field_label x-Field_label">Name</label>
<input type="text" placeholder="Nathaniel Hornblower" class="x-Field_input" />
</div>
</div>
<div class="x-Form_footer u-cf">
<button class="x-Button x-Button-green u-pullRight">OK</button>
</div>
</div>
SCSS
body {
font-family: sans-serif;
font-size: 12px;
padding: 10px;
}
.u-cf:before,
.u-cf:after {
content: ' ';
display: table;
}
.u-cf:after {
clear: both;
}
.u-pullRight {
float: right;
}
.x-Form {
border: 1px solid #ccc;
border-radius: 4px;
background-color: lighten(#f3f3f3, 3%);
background-image: linear-gradient(to bottom, #fff, #f3f3f3);
}
.x-Form_header {
border-radius: 4px 4px 0 0;
background-color: #fff;
padding: 6px;
cursor: pointer;
}
.x-Form_title {
font-size: 16px;
font-weight: bold;
display: inline;
}
.x-Form_body,
.x-Form_footer {
border-top: 1px solid #aaa;
padding: 6px;
}
.x-Form_body {
padding-top: 12px;
padding-bottom: 12px;
}
.x-Form_footer {
border-radius: 0 0 4px 4px;
background-color: #fff;
min-height: 32px;
}
.x-Form-collapsed {
.x-Form_header {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}
.x-Form_body,
.x-Form_footer {
display: none;
}
}
.x-Field {
line-height: 36px;
}
.x-Field_label {
display: block;
font-weight: bold;
}
.x-Field_label-left {
display: inline-block;
width: 140px;
}
.x-Field_input {
outline: none;
}
.x-Field_input:focus {
border: 1px solid blue;
}
input.x-Field_input {
border: 1px solid #ccc;
padding-left: 4px;
padding-right: 4px;
height: 24px;
min-width: 200px;
}
.x-Button {
font-weight: bold;
padding: 6px 12px;
border-style: solid;
border-width: 0px;
border-radius: 4px;
font-size: 12px;
min-width: 80px;
text-align: center;
cursor: pointer;
}
.x-Button-green {
border-color: #5cac00;
background-color: #519800;
background-image: linear-gradient(to bottom, #6fbc00,#5f9d01);
color: #fff;
}
JavaScript
function Form (el) {
var me = this;
this.$el = $(el);
this.$el.on('click', '.x-Form_header', me.toggle.bind(me));
}
Form.prototype = {
toggle: function () {
this.$el.toggleClass('x-Form-collapsed');
}
}
$('.x-Form').each(function (index, el) {
new Form(el);
});