Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Created September 21, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorDePaula/b4d52c05c70813e30481d77e360fa63d to your computer and use it in GitHub Desktop.
Save IgorDePaula/b4d52c05c70813e30481d77e360fa63d to your computer and use it in GitHub Desktop.
Checkbox com vue and tailwindcss
const Checkbox = {
name: 'Checkbox',
template: '<div>' +
'<div class="input-text cursor-pointer flex h-10" @click="emit">' +
'<div class="h-4 w-4 rounded border-2 border-green-700 m-auto" :class="newClass">' +
'<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 fill-current text-white" v-if="checked" viewBox="0 0 20 20"><path d="M0 11l2-2 5 5L18 3l2 2L7 18z"/></svg>' +
'</div>' +
'<div class="self-center flex-1 px-1 pb-1" v-html="label"></div>' +
'</div>' +
'</div>',
data() {
return {
checked: false
}
},
computed: {
newClass() {
return this.checked ? ['bg-green-700'] : ['bg-white']
}
},
props: {
label: {
type: String,
required: true
}
},
methods:{
emit(){
this.checked = !this.checked
this.$emit('input', this.checked)
}
}
}
@IgorDePaula
Copy link
Author

Captura de tela de 2020-09-21 15-05-04
Captura de tela de 2020-09-21 15-04-46
Captura de tela de 2020-09-21 15-04-27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment