Skip to content

Commit

Permalink
Merge 085d766 into 69d222f
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Jan 13, 2021
2 parents 69d222f + 085d766 commit 335f33b
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 93 deletions.
62 changes: 62 additions & 0 deletions spotlight-client/src/NavigationLink/NavigationLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Recidiviz - a data platform for criminal justice reform
// Copyright (C) 2021 Recidiviz, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =============================================================================

import { useNavigate } from "@reach/router";
import React from "react";
import styled from "styled-components/macro";

const Anchor = styled.a`
&[aria-disabled="true"] {
cursor: not-allowed;
}
`;

type NavigationLinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
to: string;
disabled?: boolean;
};

/**
* An alternative to the @reach/router `Link` component.
* Can be `disabled` to render link inoperative.
*/
const NavigationLink: React.FC<NavigationLinkProps> = ({
children,
disabled,
to,
...props
}) => {
const navigate = useNavigate();

return (
<Anchor
{...props}
href={disabled ? undefined : to}
onClick={(e) => {
e.preventDefault();
if (!disabled) {
navigate(to);
}
}}
aria-disabled={disabled}
>
{children}
</Anchor>
);
};

export default NavigationLink;
18 changes: 18 additions & 0 deletions spotlight-client/src/NavigationLink/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Recidiviz - a data platform for criminal justice reform
// Copyright (C) 2021 Recidiviz, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =============================================================================

export { default } from "./NavigationLink";
Loading

0 comments on commit 335f33b

Please sign in to comment.