2023-04-19 19:18:50 +02:00
|
|
|
---
|
|
|
|
import type { HTMLAttributes } from 'astro/types';
|
|
|
|
|
|
|
|
type Props = HTMLAttributes<'a'>;
|
|
|
|
|
|
|
|
const { href, class: className, ...props } = Astro.props;
|
|
|
|
|
|
|
|
const { pathname } = Astro.url;
|
|
|
|
const isActive = href === pathname || href === pathname.replace(/\/$/, '');
|
|
|
|
---
|
|
|
|
|
|
|
|
<a href={href} class:list={[className, { active: isActive }]} {...props}>
|
2023-04-26 10:23:17 +02:00
|
|
|
<slot />
|
2023-04-19 19:18:50 +02:00
|
|
|
</a>
|
2023-04-26 10:23:17 +02:00
|
|
|
|
2023-04-19 19:18:50 +02:00
|
|
|
<style>
|
2023-04-26 10:23:17 +02:00
|
|
|
a.active {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
a.active,
|
|
|
|
a.active + a,
|
|
|
|
a:hover + a,
|
|
|
|
a + a:hover {
|
|
|
|
border-left-color: #fff;
|
|
|
|
}
|
2023-04-19 19:18:50 +02:00
|
|
|
</style>
|