UNPKG

@omiu/switch

Version:
84 lines (72 loc) 2.25 kB
:host { display: inline-block; } * { padding: 0; margin: 0; box-sizing: border-box; } .o-switch { -webkit-appearance: none; appearance: none; display: inline-block; } .o-switch-cp { display: inline-block; } .o-switch, .o-switch-cp__box { position: relative; width: 40px; height: 20px; border: 1px solid #DFDFDF; outline: 0; border-radius: 16px; box-sizing: border-box; background-color: #DFDFDF; -webkit-transition: background-color 0.1s, border 0.1s; transition: background-color 0.1s, border 0.1s; } .o-switch:before, .o-switch-cp__box:before { content: " "; position: absolute; top: 0; left: 0; width: 38px; height: 18px; border-radius: 15px; background-color: #FDFDFD; -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.45, 1, 0.4, 1); transition: -webkit-transform 0.35s cubic-bezier(0.45, 1, 0.4, 1); transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1); transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1), -webkit-transform 0.35s cubic-bezier(0.45, 1, 0.4, 1); } .o-switch:after, .o-switch-cp__box:after { content: " "; position: absolute; top: 0; left: 0; width: 18px; height: 18px; border-radius: 15px; background-color: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35); transition: -webkit-transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35); transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35); transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35), -webkit-transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35); } .o-switch:checked, .o-switch-cp__input:checked ~ .o-switch-cp__box { border-color: #07c160; border-color: var(--o-primary, #07c160); background-color: #07c160; background-color: var(--o-primary, #07c160); } .o-switch:checked:before, .o-switch-cp__input:checked ~ .o-switch-cp__box:before { -webkit-transform: scale(0); transform: scale(0); } .o-switch:checked:after, .o-switch-cp__input:checked ~ .o-switch-cp__box:after { -webkit-transform: translateX(20px); transform: translateX(20px); } .o-switch-cp__input { position: absolute; left: -9999px; } .o-switch-cp__box { display: block; }