2023-03-31 14:55:28 +02:00
|
|
|
import { Icon, Icons } from 'react-basics';
|
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-03-31 14:55:28 +02:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-04-10 12:51:43 +02:00
|
|
|
import styles from './FilterLink.module.css';
|
|
|
|
|
2023-04-24 04:52:44 +02:00
|
|
|
export function FilterLink({ id, value, label, externalUrl, children, className }) {
|
2023-03-31 14:55:28 +02:00
|
|
|
const { formatMessage, labels } = useMessages();
|
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 (
|
2023-04-24 04:52:44 +02:00
|
|
|
<div className={classNames(styles.row, className)}>
|
|
|
|
{children}
|
2023-04-02 00:44:30 +02:00
|
|
|
{!value && `(${label || formatMessage(labels.unknown)})`}
|
2023-03-31 14:55:28 +02:00
|
|
|
{value && (
|
|
|
|
<Link
|
|
|
|
href={resolveUrl({ [id]: value })}
|
|
|
|
className={classNames(styles.label, {
|
|
|
|
[styles.inactive]: active && !selected,
|
|
|
|
[styles.active]: active && selected,
|
|
|
|
})}
|
|
|
|
replace
|
|
|
|
>
|
|
|
|
{safeDecodeURI(label || value)}
|
|
|
|
</Link>
|
|
|
|
)}
|
2022-04-10 12:51:43 +02:00
|
|
|
{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>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default FilterLink;
|