Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app">
    <vue-checkbox-toggle 
        v-model="foo" 
        show-labels
        label-checked="i am active"
        label-unchecked="i am not active"
    >
    </vue-checkbox-toggle>

    <vue-checkbox-toggle 
        v-model="bar" 
        showLabels
    >
    </vue-checkbox-toggle>

    <vue-checkbox-toggle 
        v-model="baz" 
        showLabels 
        disabled
    >
    </vue-checkbox-toggle>
    <ul>
        <li>Foo: {{ foo }}</li>
        <li>Bar: {{ bar }}</li>
        <li>Baz: {{ baz }}</li>        
    </ul>
</div>

<!--
TODO
show labels
-->
              
            
!

CSS

              
                $slideWidth: 4em
$borderRadius: 0.25em

$switchWidth: $slideWidth/2
$switchHeight: $slideWidth/2

$distance: $slideWidth/2

$switchColor: rgb(56, 74, 93)
$sliderColorActive: rgb(103, 175, 127)
$sliderColorInactive: rgb(211, 211, 211)

$transitionTime: 350ms

.checkbox-toggle
  width: $slideWidth * 3
  display: flex
  flex-direction: row
  justify-content: flex-start
  align-items: center
  margin: 0.5em

.checkbox-slide
  width: $slideWidth
  padding: 0
  margin: 0
  border-radius: .25em
  cursor: pointer
  
.checkbox-switch 
  padding: 0
  margin: 0
  width: $switchWidth
  height: $switchHeight
  border-radius: $borderRadius
  background: $switchColor
  cursor: pointer

.checkbox-label
  margin-left: 0.5em

.checkbox-switch.checked
  transform: translateX($distance)
  transition: all $transitionTime

.checkbox-switch.unchecked
  transition: all $transitionTime
 
.checkbox-slide.checked
  transition: all $transitionTime
  background: $sliderColorActive

.checkbox-slide.unchecked
  transition: all $transitionTime
  background: $sliderColorInactive  
  
.checkbox-switch.disabled
  cursor: not-allowed
  background: lighten($switchColor, 35%)

.checkbox-slide.disabled
  cursor: not-allowd
  background: lighten($sliderColorInactive, 5%)
              
            
!

JS

              
                Vue.component("vue-checkbox-toggle", {
    template: `
    <div 
        class="checkbox-toggle" 
        role="checkbox" 
        @keydown="toggle" 
        @click.stop="toggle" 
        tabindex="0" 
        :aria-checked="toggled"
    >
        <div 
            class="checkbox-slide" 
            :class="classes"
        >
            <div 
                class="checkbox-switch" 
                :class="classes"
            ></div>
        </div>
        <div
            v-show="showLabels"
            class="checkbox-label"
            v-html="label"
        ></div>
   </div>
   `,
    computed: {
        classes: function() {
            return {
                checked: this.toggled,
                unchecked: !this.toggled,
                disabled: this.disabled
            };
        },

        label: function() {
            return this.toggled && this.showLabels
                ? this.labelChecked
                : this.labelUnchecked;
        }
    },

    data() {
        return {
            toggled: this.value
        };
    },

    methods: {
        toggle: function(e) {
            if (this.disabled || e.keyCode === 9) { // not if disabled or tab is pressed
                e.stop();
            }

            this.toggled = ! this.toggled;

            this.$emit("input", this.toggled);
        }
    },

    props: {
        disabled: {
            type: Boolean,
            default: false
        },

        value: {
            type: Boolean,
            default: ""
        },

        showLabels: {
            type: Boolean,
            default: false
        },

        labelChecked: {
            type: String,
            default: ""
        },

        labelUnchecked: {
            type: String,
            default: ""
        }
    },  
});

new Vue({
    el: "#app",
    data: {
        foo: false,
        bar: true,
        baz: true
    },
    watch: {}
});

              
            
!
999px

Console