JSFiddle - React, Tailwind, and code Playground

by Rajeswaritest

HTML

<div style="width: 100%;">
  <input type="text" tabindex="0" value="Flipswitch"/>
 </div>
 
<div tabindex="0" id="chkdiv" onKeyPress="changeCheckbox(this)" onclick="changeCheckbox(this)" class="ui-flipswitch ui-shadow-inset ui-corner-all ui-flipswitch-active">
<a id="chkPref" class="ui-flipswitch-on ui-btn ui-shadow ui-btn-inherit"  role="switch" aria-checked="false" aria-disabled="false" aria-label="No" onclick="javascript:changeCheckbox(this)" href="javascript:;">Yes</a>
<span class="ui-flipswitch-off">No</span>
<input name="flip-checkbox-1" tabindex="-1" class="ui-flipswitch-input" id="flip-checkbox-1" type="checkbox" data-role="flipswitch"></div>

<div style="width: 100%;">
  <input type="text" tabindex="0" value="Toggle"/>
 </div>

CSS

.ui-flipswitch {
    display: inline-block;
    vertical-align: middle;
    width: 5.875em;
    height: 1.875em;
    border-width: 1px;
    border-style: solid;
    margin: .5em 0;
    overflow: hidden;
    -webkit-transition-property: padding,width,background-color,color,border-color;
    -moz-transition-property: padding,width,background-color,color,border-color;
    -o-transition-property: padding,width,background-color,color,border-color;
    transition-property: padding,width,background-color,color,border-color;
    -webkit-transition-duration: 100ms;
    -moz-transition-duration: 100ms;
    -o-transition-duration: 100ms;
    transition-duration: 100ms;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: pointer;
}


.ui-flipswitch.ui-flipswitch-active {
        padding-left: 4em;
        width: 1.875em;
    }

.ui-flipswitch-input {
    position: absolute;
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(1px,1px,1px,1px);
    border: 0;
    outline: 0;
    filter: Alpha(Opacity=0);
    opacity: 0;
}

.ui-flipswitch .ui-btn.ui-flipswitch-on, .ui-flipswitch .ui-flipswitch-off {
    float: left;
    height: 1.75em;
    margin: .0625em;
    line-height: 1.65em;
}

.ui-flipswitch .ui-btn.ui-flipswitch-on {
    width: 1.75em;
    padding: 0;
    text-indent: -2.6em;
    text-align: left;
    border-width: 1px;
    border-style: solid;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    border-radius: inherit;
    overflow: visible;
    color: inherit;
    text-shadow: inherit;
}

.ui-flipswitch .ui-flipswitch-off {
    padding: 1px;
    text-indent: 1em;
}





.ui-shadow-inset {
    -webkit-box-shadow: inset 0 1px 3px rgba(0,0,0,.2);
    -moz-box-shadow: inset 0 1px 3px rgba(0,0,0,.2);
    box-shadow: inset 0 1px 3px...

JavaScript

/*
ui-flipswitch
 ui-shadow-inset
 ui-bar-inherit
 ui-corner-all
 ui-flipswitch-active
 ui-flipswitch-on 
 ui-btn
 ui-shadow 
 ui-btn-inherit --
 ui-flipswitch-input
 ui-flipswitch-active
*/

function changeCheckbox(event) {
    let item = document.getElementById('chkPref');
    let  mainDiv= document.getElementById('chkdiv');
    switch(item.getAttribute('aria-checked')) {
        case "true":
            item.setAttribute('aria-checked', "false");
            item.setAttribute('aria-label', "No");
             mainDiv.setAttribute('class', "ui-flipswitch ui-shadow-inset ui-bar-inherit ui-corner-all"); 
            break;
        case "false":
            item.setAttribute('aria-checked', "true");
            item.setAttribute('aria-label', "Yes");
             mainDiv.setAttribute('class', "ui-flipswitch ui-shadow-inset ui-bar-inherit ui-corner-all ui-flipswitch-active"); 
            break;
    }
}