switch.less 3.78 KB
@switch-prefix-cls: ~"@{css-prefix}switch";

.@{switch-prefix-cls} {
    display: inline-block;
    width: 44px;
    height: 22px;
    line-height: 20px;
    border-radius: 22px;
    vertical-align: middle;
    border: 1px solid tint(@mew-common-color, 20%);
    background-color: #efefef;
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: all @transition-time @ease-in-out;

    &-loading{
        opacity: .4;
    }

    &-inner {
        color: #999;
        font-size: @font-size-small;
        position: absolute;
        left: 23px;

        i {
            width: 12px;
            height: 12px;
            text-align: center;
            position: relative;
            top: -1px;
        }
    }

    /*wynn*/
    &:after {
        content: '';
        width: 18px;
        height: 18px;
        border-radius: 18px;
        background-color: tint(@mew-common-color, 50%);
        position: absolute;
        left: 1px;
        top: 1px;
        cursor: pointer;
        transition: left @transition-time @ease-in-out, width @transition-time @ease-in-out;
    }

    &:active:after {
        width: 26px;
    }

    /*wynn*/
    &:before{
        content: '';
        display: none;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background-color: transparent;
        position: absolute;
        left: 3px;
        top: 3px;
        z-index: 1;
        border: 1px solid @mew-common-color;
        border-color: transparent transparent transparent @mew-common-color;
        animation: switch-loading 1s linear;
        animation-iteration-count: infinite;
    }
    &-loading:before{
        display: block;
    }

    /*wynn*/
    &:focus {
        box-shadow: 0 0 0 2px fade(@mew-common-color, 5%);
        outline: 0;
    }

    &:focus:hover {
        box-shadow: none;
    }

    &-small {
        width: 28px;
        height: 16px;
        line-height: 14px;
        &:after {
            width: 12px;
            height: 12px;
        }
        &:active:after {
            width: 14px;
        }
        &:before{
            width: 10px;
            height: 10px;
            left: 2px;
            top: 2px;
        }
    }

    &-small&-checked:after {
        left: 13px;
    }
    &-small&-checked:before {
        left: 14px;
    }

    &-small:active&-checked:after {
        left: 11px;
    }

    &-large{
        width: 56px;
        &:active:after {
            width: 26px;
        }
    }

    &-large:active:after {
        width: 30px;
    }

    &-large&-checked:after {
        left: 35px;
    }
    &-large&-checked:before {
        left: 37px;
    }

    &-large:active&-checked:after {
        left: 23px;
    }

    /*wynn*/
    &-checked {
        border-color: @mew-common-color;
        background-color: #e8e8e8;

        .@{switch-prefix-cls}-inner {
            left: 7px;
        }

        &:after {
            background-color: @mew-common-color;
            left: 23px;
        }
        &:before{
            left: 25px;
        }

        &:active:after {
            left: 15px;
        }

        .@{switch-prefix-cls}-inner {
            color: @mew-common-color;
        }
    }

    &-disabled {
        cursor: @cursor-disabled;
        opacity: .4;

        &:after {
            background: #fff;
            cursor: not-allowed;
        }

        .@{switch-prefix-cls}-inner {
            color: #fff;
        }
    }

    /*wynn*/
    &-disabled&-checked{
        border-color: @mew-common-color;
        background-color: #e8e8e8;
        opacity: .4;
        
        &:after {
            background: @mew-common-color;
        }

        .@{switch-prefix-cls}-inner {
            color: #fff;
        }
    }

}

@keyframes switch-loading {
    0% {
        transform: rotate(0);
    }
    100% {
        transform: rotate(360deg);
    }
}