1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <template>
- <div class="track aria-theme-independent" :class="value ? 'on' : 'off'"
- @click.passive="onClick"
- @keydown.enter.passive="onEnter"
- >
- <div class="slider"></div>
- <input v-show="false" type="checkbox" :id="id">
- </div>
- </template>
- <script>
- export default {
- props: {
- value: {
- type: Boolean,
- required: true,
- },
- id: {
- type: String,
- default: '',
- }
- },
- methods: {
- onClick() {
- this.$emit('input', !this.value)
- },
- onEnter() {
- this.$emit('input', !this.value)
- },
- }
- }
- </script>
- <style lang="less" scoped>
- .track {
- width: 40px;
- height: 20px;
- border-radius: 10px;
- position: relative;
- transition: all 0.3s;
- cursor: pointer;
- display: inline-block;
- vertical-align: middle;
- .slider {
- width: 16px;
- height: 16px;
- border-radius: 50%;
- background: white;
- position: absolute;
- top: 2px;
- }
- }
- .off {
- background: #DCDFE6;
- .slider {
- left: 2px;
- right: auto;
- }
- }
- .on {
- background: #AB3434;
- .slider {
- left: auto;
- right: 2px;
- }
- }
- </style>
|