Skip to content

Commit

Permalink
refactor: updated filters for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiRepinskyi committed Oct 20, 2023
1 parent 1ebe88e commit 7ffc62f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
18 changes: 18 additions & 0 deletions js/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const refs = {
buttonsFilter: document.querySelectorAll('.filters-list button'),
projects: document.querySelectorAll('.grid-portfolio__item'),
};

refs.buttonsFilter.forEach(button => {
button.addEventListener('click', () => {
const btnCategory = button.dataset.category;

refs.projects.forEach(project => {
const projectCategory = project.dataset.category;
if (btnCategory === 'all' || btnCategory === projectCategory) {
return (project.style.display = 'block');
}
return (project.style.display = 'none');
});
});
});
35 changes: 6 additions & 29 deletions portfolio.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,21 @@ <h1 class="title-section hidden">Portfolio</h1>

<ul class="filters-list">
<li>
<button
type="button"
class="btn-secondary btn-secondary--all"
onclick="filterProjects('all')"
>
<button type="button" class="btn-secondary btn-secondary--all" data-category="all">
Усі
</button>
</li>
<li>
<button type="button" class="btn-secondary" onclick="filterProjects('web')">
Веб-сайти
</button>
<button type="button" class="btn-secondary" data-category="web">Веб-сайти</button>
</li>
<li>
<button type="button" class="btn-secondary" onclick="filterProjects('app')">
Додатки
</button>
<button type="button" class="btn-secondary" data-category="app">Додатки</button>
</li>
<li>
<button type="button" class="btn-secondary" onclick="filterProjects('design')">
Дизайн
</button>
<button type="button" class="btn-secondary" data-category="design">Дизайн</button>
</li>
<li>
<button type="button" class="btn-secondary" onclick="filterProjects('marketing')">
<button type="button" class="btn-secondary" data-category="marketing">
Маркетинг
</button>
</li>
Expand Down Expand Up @@ -609,19 +599,6 @@ <h2 class="project__card-title">Growing Business</h2>
</div>
</footer>
<script src="./js/menu.js"></script>

<script>
function filterProjects(category) {
const projects = document.querySelectorAll('.grid-portfolio__item');
projects.forEach(project => {
const projectCategory = project.getAttribute('data-category');
if (category === 'all' || category === projectCategory) {
project.style.display = 'block';
} else {
project.style.display = 'none';
}
});
}
</script>
<script src="./js/filter.js"></script>
</body>
</html>

0 comments on commit 7ffc62f

Please sign in to comment.