Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Last active September 18, 2020 19:42
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/e490b66565c177916b08511587b6ca25 to your computer and use it in GitHub Desktop.
Save IgorDePaula/e490b66565c177916b08511587b6ca25 to your computer and use it in GitHub Desktop.
Radio Button puro em vuejs e tailwindcss (classe input-text é um conjunto add com ```@apply``` do tailwindcss)
<radio-button :checked="radio" name="teste" valor="1" label="teste 1" v-model="radio"></radio-button>
const RadioButton = {
name: 'RadioButton',
template: '<div>' +
'<div class="input-text cursor-pointer flex h-10" @click="$emit(\'input\', valor)">' +
'<div class="h-4 w-4 rounded-full 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 == valor" viewBox="0 0 20 20"><path d="M0 11l2-2 5 5L18 3l2 2L7 18z"/></svg>' +
'</div>' +
'<div class="self-center flex-1 px-2 pb-1">{{label}}</div>' +
'</div>',
computed: {
newClass() {
return this.checked == this.valor ? ['bg-green-700'] : ['bg-white']
}
},
props: {
valor: {
type: String,
required: true
},
name: {
type: String,
required: true
},
label: {
type: String,
required: true
},
checked: '',
}
}
@IgorDePaula
Copy link
Author

Captura de tela de 2020-09-18 16-40-21

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