JSFiddle - React, Tailwind, and code Playground
HTML
<div id="activate" class="toggle-switch" data-ts-color="green">
<label for="ts4" class="ts-label">Activate Account</label>
<input id="ts4" type="checkbox" hidden="hidden">
<label for="ts4" class="ts-helper"></label>
</div>
CSS
.toggle-switch {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none
}
.toggle-switch {
display: inline-block;
vertical-align: top;
-moz-user-select: none;
-ms-user-select: none;
user-select: none
}
.toggle-switch .ts-label {
display: inline-block;
margin: 0 20px 0 0;
vertical-align: top;
-webkit-transition: color .56s cubic-bezier(.4, 0, .2, 1);
transition: color .56s cubic-bezier(.4, 0, .2, 1)
}
.toggle-switch .ts-helper {
display: inline-block;
position: relative;
width: 40px;
height: 16px;
border-radius: 8px;
background: rgba(0, 0, 0, .26);
-webkit-transition: background .28s cubic-bezier(.4, 0, .2, 1);
transition: background .28s cubic-bezier(.4, 0, .2, 1);
vertical-align: middle;
cursor: pointer
}
.toggle-switch .ts-helper:before {
content: '';
position: absolute;
top: -4px;
left: -4px;
width: 24px;
height: 24px;
background: #fafafa;
box-shadow: 0 2px 8px rgba(0, 0, 0, .28);
border-radius: 50%;
webkit-transition: left .28s cubic-bezier(.4, 0, .2, 1), background .28s cubic-bezier(.4, 0, .2, 1), box-shadow .28s cubic-bezier(.4, 0, .2, 1);
transition: left .28s cubic-bezier(.4, 0, .2, 1), background .28s cubic-bezier(.4, 0, .2, 1), box-shadow .28s cubic-bezier(.4, 0, .2, 1)
}
.toggle-switch:not(.disabled) .ts-helper:active:before {
box-shadow: 0 2px 8px rgba(0, 0, 0, .28), 0 0 0 20px rgba(128, 128, 128, .1)
}
.toggle-switch input {
position: absolute;
z-index: 1;
width: 46px;
margin: 0 0 0 -4px;
height: 24px;
opacity: 0;
filter: alpha(opacity=0);
cursor: pointer
}
.toggle-switch input:checked+.ts-helper:before {
left: 20px
}
.toggle-switch:not([data-ts-color]) input:not(:disabled):checked+.ts-helper {
background: rgba(0, 150, 136, .5)
}
.toggle-switch:not([data-ts-color]) input:not(:disabled):checked+.ts-helper:before {
background:...
JavaScript
if (false) {
// turn toggle switch off
$("#ts4").attr("checked", false);
$('#activate').click();
} else {
// turn toggle switch off
$('#ts4').attr("checked", true);
$('#activate').click();
}