firq-dev-website/src/components/navbarEntry.astro

85 lines
1.5 KiB
Text
Raw Normal View History

2023-03-04 19:11:52 +01:00
---
export interface Props {
2023-03-09 11:44:18 +01:00
currentPage?: string
navtype: "mobile" | "desktop"
2023-03-09 11:44:18 +01:00
link: string
text: string
2023-12-29 22:57:30 +01:00
icon: ImageMetadata
2023-03-04 19:11:52 +01:00
}
const { icon, text, link, navtype, currentPage } = Astro.props
2023-03-04 19:11:52 +01:00
2023-03-09 11:44:18 +01:00
let currPage = ''
const slug = link.replace(new RegExp('/', 'g'), '')
2023-03-04 19:11:52 +01:00
2023-03-04 22:35:49 +01:00
if (currentPage === slug) {
2023-03-09 11:44:18 +01:00
currPage = 'current'
} else if (currentPage === 'home' && link === '/') {
currPage = 'current'
2023-03-04 19:11:52 +01:00
}
2023-03-04 22:35:49 +01:00
2023-12-29 22:57:30 +01:00
const icon_src_url = `url("${icon.src}")`;
2023-03-09 11:44:18 +01:00
const fulllink = `/${slug}`
let extraattributes = navtype === "mobile" ? { tabindex: "0"} : {}
2023-03-04 19:11:52 +01:00
---
<li>
2023-03-09 11:44:18 +01:00
<a
href={fulllink}
rel="noopener noreferrer"
aria-label={text}
class={currPage}
2024-01-01 20:54:14 +01:00
role="navigation"
{...extraattributes}
2023-03-09 11:44:18 +01:00
>
2023-12-29 22:57:30 +01:00
<div class="icon"></div>
2023-03-09 11:44:18 +01:00
{text}
</a>
2023-03-04 19:11:52 +01:00
</li>
2023-12-29 22:57:30 +01:00
<style define:vars={{ icon_src_url }}>
2023-03-09 11:44:18 +01:00
li {
align-items: center;
justify-content: center;
text-align: left;
display: flex;
width: 200px;
}
2023-12-29 22:57:30 +01:00
2023-03-09 11:44:18 +01:00
li > a {
display: inline-flex;
2023-03-09 11:44:18 +01:00
color: white;
text-decoration: none;
justify-content: center;
2023-12-21 11:39:45 +01:00
align-items: center;
2023-03-09 11:44:18 +01:00
font-size: 1.4em;
height: 100%;
font-weight: bold;
gap: 0.2em;
2023-03-09 11:44:18 +01:00
}
2023-12-29 22:57:30 +01:00
2023-03-09 11:44:18 +01:00
li > a:hover {
color: var(--c-purplepink);
}
2023-12-29 22:57:30 +01:00
li > a:hover > .icon {
background-color: var(--c-purplepink);
}
2023-03-09 11:44:18 +01:00
.current {
color: var(--c-darkpurple) !important;
2023-03-09 11:44:18 +01:00
}
2023-12-29 22:57:30 +01:00
.current > .icon {
background-color: var(--c-darkpurple) !important;
}
.icon {
mask: var(--icon_src_url) no-repeat center;
background-color: white;
width: 1.4em;
height: 1.4em;
}
2023-03-09 11:44:18 +01:00
</style>