Skip to content

Commit

Permalink
Merge pull request #30 from thiagofqs/implementacao-sass
Browse files Browse the repository at this point in the history
refactor: conversão de CSS para SASS
  • Loading branch information
levxyca authored Sep 27, 2023
2 parents c2b23b9 + 7cd1449 commit 3acd68c
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 111 deletions.
75 changes: 52 additions & 23 deletions assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions assets/css/var.css

This file was deleted.

18 changes: 18 additions & 0 deletions assets/js/dark_mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const body = document.body;
const darkModeToggle = document.querySelector("#dark-mode-toggle");
const headerSubtitle = document.querySelector(".header__subtitle");
const moonIcon = document.querySelector(".ph-moon");
const sunIcon = document.querySelector(".ph-sun");

darkModeToggle.addEventListener("click", () => {
body.classList.toggle("body-dark-mode");
headerSubtitle.classList.toggle("text-dark-mode");

if (body.classList.contains("body-dark-mode")) {
moonIcon.style.display = "none";
sunIcon.style.display = "inline";
} else {
sunIcon.style.display = "none";
moonIcon.style.display = "inline";
}
});
50 changes: 26 additions & 24 deletions assets/js/script.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
import "./dark_mode.js";

const searchInput = document.querySelector("#search-input");
const cardsSection = document.querySelector("#cards");

function searchCards() {
const inputValue = searchInput.value.toLowerCase();
const listOfCards = document.querySelectorAll(".card");
const inputValue = searchInput.value.toLowerCase();
const listOfCards = document.querySelectorAll(".card");

for (const card of listOfCards) {
const cardContent = card.textContent.toLowerCase();
card.style.display = cardContent.includes(inputValue) ? "" : "none";
}
for (const card of listOfCards) {
const cardContent = card.textContent.toLowerCase();
card.style.display = cardContent.includes(inputValue) ? "" : "none";
}
}

function insertCardsIntoHtml(data) {
let cards = "";
data.forEach((card) => {
cards += `
let cards = "";
data.forEach((card) => {
cards += `
<section class="card">
<h3 class="card__title">${card.title}</h3>
<p class="card__description">${card.description}</p>
`;
if (card.content && card.content.code) {
cards += `
if (card.content && card.content.code) {
cards += `
<div class="card__content">
<code class="card__code">${card.content.code}</code>
</div>
`;
}
cards += "</section>";
});
cardsSection.innerHTML = cards;
}
cards += "</section>";
});
cardsSection.innerHTML = cards;
}

async function sortCardsByTitle(data) {
return data.cards.sort((a, b) => a.title.localeCompare(b.title));
return data.cards.sort((a, b) => a.title.localeCompare(b.title));
}

async function getCardsFromJson() {
try {
const res = await fetch("./assets/data/cards_pt-br.json");
const data = await res.json();
const sortedCards = await sortCardsByTitle(data);
insertCardsIntoHtml(sortedCards);
} catch (error) {
console.error("An error occurred while fetching card data.", error);
}
try {
const res = await fetch("./assets/data/cards_pt-br.json");
const data = await res.json();
const sortedCards = await sortCardsByTitle(data);
insertCardsIntoHtml(sortedCards);
} catch (error) {
console.error("An error occurred while fetching card data.", error);
}
}

searchInput.addEventListener("input", searchCards);
Expand Down
17 changes: 17 additions & 0 deletions assets/sass/_variables.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$light-green: #5e9188
$dark-green: #3e5954
$dark-blue: #253342
$black: #232226
$white: #ffffff
$purple-500: #6e6197
$gray-500: #9698a0
$gray-300: #cccccc
$gray-100: #f2f2f2

// Light Mode
$light-background-color: #ffffff
$light-text-color: #333333

// Dark Mode
$dark-background-color: #333333
$dark-text-color: #ffffff
Loading

0 comments on commit 3acd68c

Please sign in to comment.