JSFiddle - React, Tailwind, and code Playground
by artgas_pro
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css">
<title>Document</title>
</head>
<body>
<section class="info container">
<div class="sort"></div>
<div class="data">
<h1 class="data-title">Result</h1>
<div class="data-body"></div>
</div>
</section>
<script defer type="module" src="app.js"></script>
</body>
</html>
CSS
.info {
display: grid;
grid-template-columns: auto 1fr;
grid-gap: 10px;
}
.sort-item{
}
.data-title{
text-align: center;
}
.data-body{
display: grid;
grid-template-columns: repeat(4, auto);
gap: 0 50px;
justify-content: center;
}
.data-body div{
width: fit-content;
text-align: center;
white-space: nowrap;
margin-bottom: 20px;
font-size: 20px;
}
.sort-body{
margin-bottom: 50px;
}
h2{
margin: 10px 0px;
}
.sort-item{
margin-bottom: 15px;
}
.inactive{
color: gray;
opacity: 0.5;
}
.radio-body{
margin-bottom: 15px;
}
JavaScript
const data = [
{
"name": "John",
"email": "[email protected]",
"rating": 20,
"disabled": false
},
{
"name": "John",
"email": "[email protected]",
"rating": 14,
"disabled": false
},
{
"name": "Mike",
"email": "[email protected]",
"rating": 20,
"disabled": true
},
{
"name": "Bob",
"email": "[email protected]",
"rating": 20,
"disabled": false
},
{
"name": "Mike",
"email": "[email protected]",
"rating": 14,
"disabled": false
},
{
"name": "Bob",
"email": "[email protected]",
"rating": 14,
"disabled": true
},
{
"name": "John",
"email": "[email protected]",
"rating": 14,
"disabled": true
},
{
"name": "Mike",
"email": "[email protected]",
"rating": 20,
"disabled": true
}
]
const createSortItemBody = (sort) => {
const body = document.createElement('div');
body.dataset.sort = sort;
body.classList.add('sort-body');
return body;
}
const createSelectsAndRadio = (data, body, sortId, customSelectProperties = []) => {
const selectBody = createSelectBody(body, sortId)
if(customSelectProperties.length === 0){
const [selectKey, selectValue] = createTwoSelects(data);
const [radioBody, radioOr, radioAnd] = createInputRadio(selectBody.id);
selectBody.append(selectKey, selectValue);
body.append(selectBody, radioBody);
return [selectKey, selectValue, radioOr, radioAnd];
} else {
const [selectKey, selectValue] = createSelectWhithCostumProperties(data, customSelectProperties);
selectBody.append(selectKey, selectValue);
body.append(selectBody);
return [selectKey, selectValue];
}
}
const createSelectBody = (body, sortId)=>{
if(!body.querySelector('h2')){
const title = document.createElement('h2');
title.innerText = sortId.split('-')[0];
body.append(title);
}
const selectBody...