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';
|
|
|
|
import External from 'assets/arrow-up-right-from-square.svg';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { Icon } 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 }) {
|
|
|
|
const { resolve, query } = usePageQuery();
|
|
|
|
const active = query[id] !== undefined;
|
|
|
|
const selected = query[id] === value;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.row}>
|
|
|
|
<Link href={resolve({ [id]: value })} replace>
|
|
|
|
<a
|
|
|
|
className={classNames(styles.label, {
|
|
|
|
[styles.inactive]: active && !selected,
|
|
|
|
[styles.active]: active && selected,
|
|
|
|
})}
|
|
|
|
>
|
2022-06-23 22:44:30 +02:00
|
|
|
{safeDecodeURI(label || value)}
|
2022-04-10 12:51:43 +02:00
|
|
|
</a>
|
|
|
|
</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}>
|
|
|
|
<External />
|
|
|
|
</Icon>
|
2022-04-10 12:51:43 +02:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|