| 1 |
<template> |
| 2 |
<div class="switch" :class="[size, type]"> |
| 3 |
<input ref="checkbox" type="checkbox" :id="id || $id('switch')" @change="$emit('change', $event.target.checked)" :checked="checked" v-bind="$attrs" /> |
| 4 |
<label :for="id || $id('switch')" aria-hidden="true"> |
| 5 |
<span v-text="textOn || wpb.trans.enabled"></span> |
| 6 |
<span v-text="textOff || wpb.trans.disabled"></span> |
| 7 |
</label> |
| 8 |
</div> |
| 9 |
</template> |
| 10 |
|
| 11 |
<script> |
| 12 |
export default { |
| 13 |
props: { |
| 14 |
name: String, |
| 15 |
textOn: String, |
| 16 |
textOff: String, |
| 17 |
id: String, |
| 18 |
size: String, |
| 19 |
type: String, |
| 20 |
checked: Boolean |
| 21 |
}, |
| 22 |
model: { |
| 23 |
prop: 'checked', |
| 24 |
event: 'change' |
| 25 |
} |
| 26 |
} |
| 27 |
</script> |
| 28 |
|
| 29 |
<style> |
| 30 |
.switch { |
| 31 |
display: inline-block; |
| 32 |
} |
| 33 |
.switch input[type="checkbox"] { |
| 34 |
position: absolute; |
| 35 |
top: auto; |
| 36 |
overflow: hidden; |
| 37 |
clip: rect(1px, 1px, 1px, 1px); |
| 38 |
width: 1px; |
| 39 |
height: 1px; |
| 40 |
white-space: nowrap; |
| 41 |
} |
| 42 |
.switch input[type="checkbox"] + label { |
| 43 |
display: block; |
| 44 |
position: relative; |
| 45 |
background: #e5e5e5; |
| 46 |
-webkit-border-radius: 20px; |
| 47 |
border-radius: 20px; |
| 48 |
min-width: 40px; |
| 49 |
height: 32px; |
| 50 |
padding: 6px; |
| 51 |
transition: background 0.3s ease; |
| 52 |
user-select: none; |
| 53 |
cursor: pointer; |
| 54 |
} |
| 55 |
.switch input[type="checkbox"][disabled] + label { |
| 56 |
opacity: 0.5; |
| 57 |
} |
| 58 |
.switch input[type="checkbox"] + label:after { |
| 59 |
content: ''; |
| 60 |
position: absolute; |
| 61 |
left: 3px; |
| 62 |
top: 4px; |
| 63 |
background: white; |
| 64 |
border-radius: 20px; |
| 65 |
width: 24px; |
| 66 |
height: 24px; |
| 67 |
transition: all 0.1s ease; |
| 68 |
box-shadow: 0 0 3px rgba(0, 0, 0, 0.3); |
| 69 |
} |
| 70 |
.switch input[type="checkbox"]:active + label, |
| 71 |
.switch input[type="checkbox"]:focus + label { |
| 72 |
box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30,140,190,.8); |
| 73 |
outline: 1px solid transparent; |
| 74 |
} |
| 75 |
.switch input[type="checkbox"]:active + label::after, |
| 76 |
.switch input[type="checkbox"]:focus + label::after { |
| 77 |
background: radial-gradient(#d6d6d6, #d6d6d6 20%, #fff 24%, #fff); |
| 78 |
} |
| 79 |
.switch input[type="checkbox"] + label span { |
| 80 |
display: block; |
| 81 |
padding: 0 8px; |
| 82 |
height: 0; |
| 83 |
color: #282c2f; |
| 84 |
font-family: sans-serif; |
| 85 |
font-size: 12px; |
| 86 |
font-weight: bold; |
| 87 |
text-align: center; |
| 88 |
line-height: 20px; |
| 89 |
transition: opacity 0.3s ease; |
| 90 |
} |
| 91 |
.switch input[type="checkbox"] + label span:first-child { |
| 92 |
padding-right: 26px; |
| 93 |
opacity: 0; |
| 94 |
visibility: hidden; |
| 95 |
} |
| 96 |
.switch input[type="checkbox"] + label span:last-child { |
| 97 |
padding-left: 26px; |
| 98 |
} |
| 99 |
.switch input[type="checkbox"]:checked + label { |
| 100 |
background: #23d160; |
| 101 |
} |
| 102 |
.switch input[type="checkbox"]:checked + label span { |
| 103 |
color: #003116; |
| 104 |
} |
| 105 |
.switch.danger input[type="checkbox"]:checked + label { |
| 106 |
background: #C94F26; |
| 107 |
} |
| 108 |
.switch.danger input[type="checkbox"]:checked + label span { |
| 109 |
color: #fff; |
| 110 |
} |
| 111 |
.switch.warning input[type="checkbox"]:checked + label { |
| 112 |
background: #ffdd57; |
| 113 |
} |
| 114 |
.switch.warning input[type="checkbox"]:checked + label span { |
| 115 |
color: rgba(0, 0, 0, 0.7019607843137254); |
| 116 |
} |
| 117 |
.switch input[type="checkbox"]:checked + label span:first-child { |
| 118 |
opacity: 1; |
| 119 |
visibility: visible; |
| 120 |
} |
| 121 |
.switch input[type="checkbox"]:checked + label span:last-child { |
| 122 |
opacity: 0; |
| 123 |
visibility: hidden; |
| 124 |
} |
| 125 |
.switch input[type="checkbox"]:checked + label:after { |
| 126 |
left: 100%; |
| 127 |
margin-left: -27px; |
| 128 |
} |
| 129 |
|
| 130 |
.switch.small input[type="checkbox"] + label { |
| 131 |
height: 22px; |
| 132 |
padding: 2px 1px 0 1px; |
| 133 |
} |
| 134 |
.switch.small input[type="checkbox"] + label:after { |
| 135 |
left: 5px; |
| 136 |
top: 5px; |
| 137 |
width: 14px; |
| 138 |
height: 14px; |
| 139 |
} |
| 140 |
.switch.small input[type="checkbox"]:checked + label:after { |
| 141 |
left: 100%; |
| 142 |
margin-left: -19px; |
| 143 |
} |
| 144 |
.switch.small input[type="checkbox"] + label span:first-child { |
| 145 |
padding-right: 22px; |
| 146 |
} |
| 147 |
.switch.small input[type="checkbox"] + label span:last-child { |
| 148 |
padding-left: 22px; |
| 149 |
} |
| 150 |
</style> |
| 151 |
|