umami/components/common/FilterLink.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-04-10 12:51:43 +02:00
import React from 'react';
import Link from 'next/link';
import classNames from 'classnames';
import usePageQuery from 'hooks/usePageQuery';
import { safeDecodeURI } from 'lib/url';
import Icon from './Icon';
import External from 'assets/arrow-up-right-from-square.svg';
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-04-18 19:23:13 +02:00
{(label && typeof label === 'string') ?? value
? safeDecodeURI(label || value)
: label || value}
2022-04-10 12:51:43 +02:00
</a>
</Link>
{externalUrl && (
<a href={externalUrl} target="_blank" rel="noreferrer noopener" className={styles.link}>
<Icon icon={<External />} className={styles.icon} />
</a>
)}
</div>
);
}