2022-04-10 12:51:43 +02:00
|
|
|
import classNames from 'classnames';
|
2022-08-29 05:20:54 +02:00
|
|
|
import Link from 'next/link';
|
|
|
|
import { safeDecodeURI } from 'next-basics';
|
2022-04-10 12:51:43 +02:00
|
|
|
import usePageQuery from 'hooks/usePageQuery';
|
2023-01-31 06:44:07 +01:00
|
|
|
import { Icon, Icons } from 'react-basics';
|
2022-04-10 12:51:43 +02:00
|
|
|
import styles from './FilterLink.module.css';
|
|
|
|
|
|
|
|
export default function FilterLink({ id, value, label, externalUrl }) {
|
2023-02-15 02:23:20 +01:00
|
|
|
const { resolveUrl, query } = usePageQuery();
|
2022-04-10 12:51:43 +02:00
|
|
|
const active = query[id] !== undefined;
|
|
|
|
const selected = query[id] === value;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.row}>
|
2023-03-09 05:23:32 +01:00
|
|
|
<Link
|
|
|
|
href={resolveUrl({ [id]: value })}
|
|
|
|
className={classNames(styles.label, {
|
|
|
|
[styles.inactive]: active && !selected,
|
|
|
|
[styles.active]: active && selected,
|
|
|
|
})}
|
|
|
|
replace
|
|
|
|
>
|
|
|
|
{safeDecodeURI(label || value)}
|
2022-04-10 12:51:43 +02:00
|
|
|
</Link>
|
|
|
|
{externalUrl && (
|
2022-08-29 05:20:54 +02:00
|
|
|
<a className={styles.link} href={externalUrl} target="_blank" rel="noreferrer noopener">
|
2022-12-27 01:57:59 +01:00
|
|
|
<Icon className={styles.icon}>
|
2023-01-31 06:44:07 +01:00
|
|
|
<Icons.External />
|
2022-12-27 01:57:59 +01:00
|
|
|
</Icon>
|
2022-04-10 12:51:43 +02:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|