JSFiddle - React, Tailwind, and code Playground

by Константин Дралюк

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<div id="app">
  <Quiz />
</div>

SCSS

.Questions {
  margin: 10px;
}
.Question {
  padding: 10px;
  margin: 0 0 15px;
  border: 1px solid #ccc;
  &__title {
    font-size: 18px;
    margin-bottom: 10px;
  }
}
.Answer {
  display: block;
  margin-top: 5px;
}
.Submit {
  &__button {
    background-color:#3bb3e0;
    padding:10px;
    position:relative;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    border: solid 1px #186f8f;
    background-image: linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    background-image: -o-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    background-image: -moz-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    background-image: -webkit-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    background-image: -ms-linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    background-image: -webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0, rgb(44,160,202)),
    color-stop(1, rgb(62,184,229))
    );
    -webkit-box-shadow: inset 0px 1px 0px #7fd2f1, 0px 1px 0px #fff;
    -moz-box-shadow: inset 0px 1px 0px #7fd2f1, 0px 1px 0px #fff;
    box-shadow: inset 0px 1px 0px #7fd2f1, 0px 1px 0px #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    margin: 10px;
    outline: none;
    cursor: pointer;
    &:active {
      padding-bottom:9px;
      padding-left:10px;
      padding-right:10px;
      padding-top:11px;
      top:1px;
      background-image: linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
      background-image: -o-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
      background-image: -moz-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
      background-image: -webkit-linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
      background-image:...

Babel + JSX

const qs = {
  questions: [{
  	id: 1,
    title: 'How old are you?',
    type: 'radio',
    answers: [
      { letter: 'a', title: 10 }, 
      { letter: 'b', title: 15 }, 
      { letter: 'c', title: 18 }, 
      { letter: 'd', title: 20}, 
    ],
  }, {
  	id: 2,
    title: 'What is your name?',
    type: 'radio',
    answers: [
      { letter: 'a', title: 'Konstantin' }, 
      { letter: 'b', title: 'Vladimir' }, 
      { letter: 'c', title: 'Petr' }, 
      { letter: 'd', title: 'Denis'}, 
    ],
  }, {
  	id: 3,
    title: 'Where do you live?',
    type: 'checkbox',
    answers: [
      { letter: 'a', title: 'Kiev' }, 
      { letter: 'b', title: 'Khmelnitskiy' }, 
      { letter: 'c', title: 'Rovno' }, 
      { letter: 'd', title: 'Kharkov'}, 
    ],
  }, {
  	id: 4,
    title: 'What is your surname?',
    type: 'string',
  }],
};

Vue.component('Quiz', {
	template: 
  	`<div class="Quiz">
    	<form class="Quiz__form" @submit.prevent="checkAnswers($event)" action="" method="post" enctype="application/x-www-form-urlencoded">
      	<Questions />
        <Submit />
      </form>
    </div>`,
    methods: {
    	checkAnswers: function(e) {
      	const $form = $(e.target);
        console.log($form.serialize());
      },
    },
});

Vue.component('Questions', {
	template:
  	`<div class="Questions">
    	<Question v-for="question in questions" :key="question.id" :question="question" />
    </div>`,
  data() {
  	return qs;
  },
});

Vue.component('Question', {
	template:
  	`<div class="Question">
  	  <div class="Question__title">{{question.title}}</div>
      <div class="Question__answers" v-if="question.type === 'radio' || question.type === 'checkbox'">
        <Answer v-for="answer in question.answers" :key="answer.letter" :id="question.id" :type="question.type" :answer="answer" />
      </div>
      <div class="Question__answer" v-if="question.type === 'string'">
      	<Answer :id="question.id" :type="question.type" />
      </div>
  	</div>`,
  props:...