Skip to content

Commit

Permalink
🔧 Refactor component imports and add language selection feature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcode24 committed Dec 4, 2024
1 parent c6a35e8 commit eb09b6d
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 16 deletions.
26 changes: 17 additions & 9 deletions src/components/App.astro
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
---
import About from '@components/About.astro';
import ButtonTop from '@components/buttons/button-top.svelte';
import Contact from '@components/Contact.astro';
import Header from '@components/Header.astro';
import Hero from '@components/Hero.astro';
import Navigation from '@components/Navigation.svelte';
import Portfolio from '@components/Portfolio.astro';
import Skills from '@components/Skills.astro';
import { getI18n } from '@i18n/index';
import Layout from '@layouts/Layout.astro';
import About from './About.astro';
import Contact from './Contact.astro';
import Hero from './Hero.astro';
import Portfolio from './Portfolio.astro';
import Skills from './Skills.astro';
const { currentLocale } = Astro;
const i18n = getI18n({ currentLocale });
---

<Layout title={i18n.SEO_TITLE} description={i18n.SEO_DESCRIPTION} language={i18n.LANGUAGE}>
<Layout
title={i18n.SEO_TITLE}
description={i18n.SEO_DESCRIPTION}
language={i18n.LANGUAGE}
>
<div class="wrapper">
<Header />
<Navigation client:load/>
<Navigation client:load />
<div class="content">
<div class="blur bottom"></div>
<div class="blur top"></div>
Expand All @@ -29,14 +34,17 @@ const i18n = getI18n({ currentLocale });
<Contact />
</div>
</div>
<ButtonTop client:idle/>
<ButtonTop client:idle />
</Layout>

<style>
.wrapper {
opacity: 1;
visibility: visible;
transition: opacity 2.2s ease-in-out, visibility 2.2s ease-in-out, height 2.2s ease-in-out;
transition:
opacity 2.2s ease-in-out,
visibility 2.2s ease-in-out,
height 2.2s ease-in-out;
overflow: hidden;
max-width: 1200px;
min-width: 380px;
Expand Down
9 changes: 6 additions & 3 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import GithubIcon from '@components/icons/github-icon.astro';
import LinkedinIcon from '@components/icons/linkedin-icon.astro';
import LanguageSelect from '@components/selects/language.astro';
import { GITHUB_URL, LINKEDIN_URL } from '@constants/urls.ts';
---

Expand All @@ -10,12 +11,14 @@ import { GITHUB_URL, LINKEDIN_URL } from '@constants/urls.ts';
</p>
<div class="social-icons">
<a target="_blank" href={GITHUB_URL} class="icon" aria-label="Github">
<GithubIcon height={45} width={45} />
<GithubIcon height={35} width={35} />
</a>
<a target="_blank" href={LINKEDIN_URL} class="icon" aria-label="Linkedin">
<LinkedinIcon height={45} width={45} />
<LinkedinIcon height={35} width={35} />
</a>
<LanguageSelect />
</div>
</header>

<style>
header {
Expand All @@ -31,7 +34,7 @@ import { GITHUB_URL, LINKEDIN_URL } from '@constants/urls.ts';
}

header p.logo-header {
font-family: "Yellowtail", cursive;
font-family: 'Yellowtail', cursive;
font-size: 52px;
color: var(--primary-color);
}
Expand Down
15 changes: 11 additions & 4 deletions src/components/Hero.astro
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ const i18n = getI18n({ currentLocale });
class="btn"
href="pdf/cv.pdf"
download="cv - marco cruz.pdf"
aria-label={i18n.HERO_SECTION.CV.ARIA_LABEL}>
aria-label={i18n.HERO_SECTION.CV.ARIA_LABEL}
>
{i18n.HERO_SECTION.CV.BTN_TEXT}
</a>
<div class="social">
<a target="_blank" href={GITHUB_URL} class="icon" aria-label="Github">
<GithubIcon height={40} width={40} />
</a>
<a target="_blank" href={LINKEDIN_URL} class="icon" aria-label="Linkedin">
<a
target="_blank"
href={LINKEDIN_URL}
class="icon"
aria-label="Linkedin"
>
<LinkedinIcon height={40} width={40} />
</a>
</div>
</div>
</div>

<img src="/me.webp" alt={i18n.HERO_SECTION.IMAGE.ALT} class="profile">
<img src="/me.webp" alt={i18n.HERO_SECTION.IMAGE.ALT} class="profile" />
</section>

<style>
Expand Down Expand Up @@ -87,7 +93,8 @@ const i18n = getI18n({ currentLocale });
color: var(--primary-color);
}

h1.title, h2.title {
h1.title,
h2.title {
font-weight: bold;
font-size: 64px;
cursor: default;
Expand Down
55 changes: 55 additions & 0 deletions src/components/icons/flags/english.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
interface Props {
height?: number;
width?: number;
}
const { height = 40, width = 40 }: Props = Astro.props;
---

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
id="united-states-of-america"
width={width}
height={height}
>
<path fill="#f0f0f0" d="M0 85.331h512v341.337H0z"></path>
<path
fill="#d80027"
d="M0 127.994h512v42.663H0zM0
213.331h512v42.663H0zM0 298.657h512v42.663H0zM0 383.994h512v42.663H0z"
></path>
<path fill="#2e52b2" d="M0 85.331h256v183.797H0z"></path>
<path
fill="#f0f0f0"
d="m99.822 160.624-4.123 12.684H82.363l10.791
7.835-4.123 12.683 10.791-7.835 10.784
7.835-4.122-12.683 10.791-7.835h-13.337zM103.938
219.08l-4.116-12.683-4.123 12.683H82.363l10.791
7.836-4.123 12.683 10.791-7.836 10.784
7.836-4.122-12.683 10.791-7.836zM47.577
219.08l-4.117-12.683-4.123 12.683H26.001l10.791
7.836-4.123 12.683 10.791-7.836 10.785 7.836-4.122-12.683
10.789-7.836zM43.46 160.624l-4.123 12.684H26.001l10.791
7.835-4.123 12.683 10.791-7.835 10.785 7.835-4.122-12.683
10.789-7.835H47.577zM99.822 114.85l-4.123 12.685H82.363l10.791
7.836-4.123 12.683 10.791-7.836 10.784 7.836-4.122-12.683
10.791-7.836h-13.337zM43.46 114.85l-4.123 12.685H26.001l10.791
7.836-4.123 12.683 10.791-7.836 10.785 7.836-4.122-12.683
10.789-7.836H47.577zM156.183 160.624l-4.122 12.684h-13.336l10.79
7.835-4.121 12.683 10.789-7.835 10.786 7.835-4.123-12.683
10.791-7.835h-13.336zM160.301 219.08l-4.118-12.683-4.122
12.683h-13.336l10.79 7.836-4.121 12.683 10.789-7.836
10.786 7.836-4.123-12.683 10.791-7.836zM216.663
219.08l-4.117-12.683-4.123 12.683h-13.335l10.789 7.836-4.122
12.683 10.791-7.836 10.785 7.836-4.123-12.683
10.791-7.836zM212.546 160.624l-4.123 12.684h-13.335l10.789
7.835-4.122 12.683 10.791-7.835 10.785
7.835-4.123-12.683 10.791-7.835h-13.336zM156.183
114.85l-4.122 12.685h-13.336l10.79 7.836-4.121 12.683
10.789-7.836 10.786 7.836-4.123-12.683 10.791-7.836h-13.336zM212.546
114.85l-4.123 12.685h-13.335l10.789 7.836-4.122 12.683 10.791-7.836
10.785 7.836-4.123-12.683 10.791-7.836h-13.336z"
></path>
</svg>
44 changes: 44 additions & 0 deletions src/components/icons/flags/spanish.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
interface Props {
height?: number;
width?: number;
}
const { height = 40, width = 40 }: Props = Astro.props;
---

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 47.5 47.5"
id="spain"
width={width}
height={height}
>
<defs>
<clipPath id="a">
<path d="M0 38h38V0H0v38Z"></path>
</clipPath>
</defs>
<g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 0 47.5)">
<path
fill="#dd2e44"
d="M37 10a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v18a4 4 0 0 0 4 4h28a4 4 0 0 0 4-4V10Z"
></path>
<path fill="#ffcc4d" d="M37 13H1v12h36V13Z"></path>
<path fill="#ea596e" d="M10 20v-3a3 3 0 1 1 6 0v3h-6Z"></path>
<path fill="#f4a2b2" d="M13 18h3v3h-3v-3z"></path>
<path fill="#dd2e44" d="M13 18h-3v3h3v-3z"></path>
<path
fill="#ea596e"
d="M16 22.5c0-.829-1.343-1.5-3-1.5s-3 .671-3 1.5 1.343 1.5 3 1.5 3-.671 3-1.5"
></path>
<path
fill="#ffac33"
d="M16 23.25c0 .414-1.343.75-3 .75s-3-.336-3-.75 1.343-.75 3-.75 3 .336 3 .75"
></path>
<path fill="#99aab5" d="M8 14h1v7H8v-7zm10 0h-1v7h1v-7z"></path>
<path
fill="#66757f"
d="M10 14H7v1h3v-1zm9 0h-3v1h3v-1zM9 21H8v1h1v-1zm9 0h-1v1h1v-1z"></path>
</g>
</svg>
135 changes: 135 additions & 0 deletions src/components/selects/language.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
import EnglishFlag from '@components/icons/flags/english.astro';
import SpanishFlag from '@components/icons/flags/spanish.astro';
const LANGUAGES_SUPPORTED = [
{
id: 'es',
name: 'Español',
flag: SpanishFlag,
},
{
id: 'en',
name: 'English',
flag: EnglishFlag,
},
];
const path = Astro.url.pathname;
const currentLocale = LANGUAGES_SUPPORTED.find(({ id }) => path.startsWith(`/${id}`))
|| LANGUAGES_SUPPORTED[0];
const LANGUAGES_FILTERED = LANGUAGES_SUPPORTED.filter(
({ id }) => id !== currentLocale.id,
);
---

<div class="custom-select">
<div class="select-selected">
<currentLocale.flag height={30} width={30} />
</div>
<div class="select-items">
{
LANGUAGES_FILTERED.map((lang) => (
<div class="language-option" data-lang-id={lang.id}>
<lang.flag height={20} width={20} />
{lang.name}
</div>
))
}
</div>
</div>

<style>
.custom-select {
position: relative;
display: inline-block;
width: fit-content;
}

.select-selected {
padding: 10px;
cursor: pointer;
display: flex;
align-items: center;
transition: 0.3s ease;
border-radius: 1rem;
gap: 0.5rem;
}

.select-selected:hover {
background-color: var(--bg-color-button-hover);
}

.select-items {
display: none;
position: absolute;
z-index: 1;
width: 100%;
min-width: 10rem;
right: 0;
}

.select-items div {
padding: 10px;
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
}

.select-items div:nth-child(1) {
border-radius: 1rem 1rem 0 0;
}

.select-items div:last-child {
border-radius: 0 0 1rem 1rem;
}
.select-items div:hover {
background-color: var(--bg-color-button-hover);
}

.select-items:has(div:only-child) div {
border-radius: 1rem;
}

.custom-select.active .select-items {
display: block;
border-radius: 1rem;
border: 1px solid var(--border-color-nav);
margin-top: 5px;
}
</style>

<script>
function changeLanguage(langId: string) {
const currentPath = window.location.pathname;
const hasLangPrefix = /^\/[a-z]{2}(\/|$)/.test(currentPath);

let newPath;
if (hasLangPrefix) {
newPath = currentPath.replace(/^\/[a-z]{2}/, `/${langId}`);
} else {
newPath = `/${langId}${currentPath}`;
}

window.location.pathname = newPath;
}

document.addEventListener('DOMContentLoaded', () => {
const selectSelected = document.querySelector('.select-selected');
const languageOptions = document.querySelectorAll('.language-option');

languageOptions.forEach((option) => {
option.addEventListener('click', () => {
const langId = option.getAttribute('data-lang-id');
langId && changeLanguage(langId);
});
});

if (selectSelected) {
selectSelected.addEventListener('click', () => {
selectSelected.parentElement?.classList.toggle('active');
});
}
});
</script>
5 changes: 5 additions & 0 deletions src/pages/es/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import App from '@/components/App.astro';
---

<App />

0 comments on commit eb09b6d

Please sign in to comment.