JSFiddle - React, Tailwind, and code Playground
HTML
<div class="workers__toggle-switch">
<input type="checkbox" name="toggle" id="toggle" value="switch">
<label for="toggle"><i></i></label>
<span id="worker-status">
ON
</span>
</div>
CSS
.workers__toggle-switch input {
top: 0;
right: 0;
bottom: 0;
left: 0;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
-moz-opacity: 0;
opacity: 0;
z-index: 100;
position: absolute;
width: 100%;
height: 100%;
cursor: pointer;
}
.workers__toggle-switch {
width: 180px;
height: 55px;
position: relative;
margin: auto;
font-family: sans-serif;
}
.workers__toggle-switch label {
display: block;
width: 80%;
height: 100%;
position: relative;
background: #66BB6A;
border-radius: 30px 30px 30px 30px;
box-shadow:
inset 0 3px 8px 1px rgba(0,0,0,0.5),
inset 0 1px 0 rgba(0,0,0,0.5),
0 1px 0 rgba(255,255,255,0.2);
transition: all .5s ease;
}
.workers__toggle-switch input ~ label i {
display: block;
height: 51px;
width: 51px;
position: absolute;
left: 2px;
top: 2px;
z-index: 2;
border-radius: inherit;
background: #f5f5f5;
box-shadow:
inset 0 1px 0 rgba(255,255,255,0.2),
0 0 8px rgba(0,0,0,0.3),
0 12px 12px rgba(0,0,0,0.4);
transition: all .5s ease;
}
/* Toggle */
.workers__toggle-switch input:checked ~ label {
background: #EC535E;
}
.workers__toggle-switch input:checked ~ label i {
left: auto;
left: 63%;
box-shadow:
inset 0 1px 0 rgba(255,255,255,0.2),
0 0 8px rgba(0,0,0,0.3),
0 8px 8px rgba(0,0,0,0.3),
inset -1px 0 1px #b9f3fe;
transition: all .5s ease;
}
.workers__toggle-switch span {
position: absolute;
top: 13px;
z-index: 1;
right: 70px;
font-size: 30px;
color: #f5f5f5;
text-shadow: 0.05px 0.05px rgba(0,0,0,0.4);
}
.workers__toggle-switch input:checked ~ span {
right: 100px;
color: #f5f5f5;
}
#worker-status {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
JavaScript
$(document).ready(function () {
$('input').click(function() {
var checked;
if ($(this).is(':checked')) {
checked = true;
} else {
checked = false;
}
var status = checked ? "off" : "on";
//if (confirm("Are you sure you want to turn the workers " + status + "?")) {
var workerStatus = checked ? "OFF" : "ON";
$('#worker-status').text(workerStatus)
//} else {
//$(this).attr('checked', false);
//}
});
});