JSFiddle - React, Tailwind, and code Playground
by mqchen
HTML
<div class="buttonbar">
<button class="primarybutton icon-b icon-icomoon" data-icon="s">Lagre</button>
</div>
<div class="buttonbar" data-buttonbar="opened">
<button class=""><a href="http://google.com" target="_blank">Avbryt</a></button>
<button class="icon icon-icomoon" data-icon="T">Slett</button>
<button class="icon icon-icomoon" data-icon="Ø">Ok</button>
<button class="icon icon-icomoon buttonbar-toggle" data-icon="=">Icon</button>
</div>
<div class="buttonbar">
<button class="icon icon-icomoon" data-icon="J">Thumbs up</button>
<button class="icon icon-icomoon" data-icon="j">Thumbs down</button>
<button class="icon icon-icomoon" data-icon="§">Irrelevant</button>
</div>
<div class="buttonbar">
<button class="activebutton icon-a icon-icomoon" disabled="disabled" data-icon="!">Call</button>
<button class="icon-b icon-icomoon" disabled="disabled" data-icon="^">Disabled</button>
</div>
<div class="buttonbar" data-buttonbar="opened">
<button class="buttonbar-toggle">Status</button>
<button class="">Start tilsyn</button>
<button class="">Avslutt tilsyn</button>
</div>
CSS
body {
padding: 40px;
font-family: Arial, sans-serif;
}
/** Icons */
@font-face {
font-family: 'Entypo';
src: url('https://dl.dropbox.com/s/uydr0f8lcx81brq/entypo-webfont.woff?dl=1') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'IcoMoon';
src: url('https://dl.dropbox.com/s/zo8l769zo9uryb3/icomoon.woff?dl=1') format('woff');
font-weight: normal;
font-style: normal;
}
.icon-b, .icon-a, .icon {
position: relative;
}
.icon-b:before, .icon-a:after, .icon:after {
text-indent: 0;
text-transform: none;
font-weight: normal;
content: attr(data-icon);
font-family: 'IcoMoon';
line-height: inherit;
position: absolute;
display: block;
top: 50%;
margin: -20% 0 0 0;
}
.icon-b {
padding-left: 28px;
}
.icon-b:before {
left: 10px;
}
.icon-a {
padding-right: 28px;
}
.icon-a:after {
right: 10px;
}
.icon {
text-indent: -999px;
overflow: hidden;
}
.icon:after {
left: 10px;
}
/** Entypo */
.icon-entypo.icon-b:before, .icon-entypo.icon-a:after, .icon-entypo.icon:after {
font-family: 'Entypo';
margin: -45% 0 0 0;
}
button.icon-entypo.icon-b:before, button.icon-entypo.icon-a:after, button.icon-entypo.icon:after {
font-size: 2em;
}
/** IcoMoon */
.icon-icomoon.icon-b:before, .icon-icomoon.icon-a:after, .icon-icomoon.icon:after {
font-family: 'IcoMoon';
margin: -20% 0 0 0;
}
/** Button bar */
.buttonbar {
float: left;
margin: 0 10px 20px 10px;
}
.buttonbar button {
border-radius: 0;
position: relative;
margin-left: -1px;
white-space: nowrap;
}
.buttonbar button:first-child,
.buttonbar button.visiblebutton {
-webkit-border-top-left-radius: 3px;
-webkit-border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.buttonbar button:last-child,
.buttonbar button.visiblebutton {
-webkit-border-top-right-radius: 3px;
...
JavaScript
var Udir = {};
Udir.buttonBarToggle = function(toggleButton, options) {
var options = {
"eventNS" : ".buttonbar-toggle",
"buttonbarSelector" : ".buttonbar",
"buttonBarStateAttr" : "data-buttonbar",
"toggleButtonShowClass" : "activebutton", // Class when other buttons are shown
"toggleButtonHideClass" : "visiblebutton", // Class when other buttons are hidden
"otherButtonsHideClass" : "hiddenbutton"
};
var buttonBar = null;
var toggle = null;
var otherButtons = [];
var methods = {
init : function(toggleButton, customOptions) {
$.extend(options, customOptions);
buttonBar = $(toggleButton).parentsUntil("body", options.buttonbarSelector);
toggle = $(toggleButton);
// Add events
buttonBar.bind("open" + options.eventNS, methods.open);
buttonBar.bind("close" + options.eventNS, methods.close);
toggle.bind("click" + options.eventNS, function(e) {
e.preventDefault();
methods.toggle();
});
// Consider init state
var initState = methods._getButtonBarState();
if(initState === "opened") {
// methods.open();
buttonBar.trigger("open" + options.eventNS);
}
else if(initState === "closed") {
// methods.close();
buttonBar.trigger("close" + options.eventNS);
}
},
_getOtherButtons : function(bar, toggleButton) {
bar = $(bar === undefined ? buttonBar : bar);
toggleButton = $(toggleButton === undefined ? toggle : toggleButton);
// All children of bar but is not parent of toggle
otherButtons = [];
var barChildren = bar.children("button");
//console.debug(barChildren);
...