UNPKG

@navinc/base-react-components

Version:
81 lines (65 loc) 3.21 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import { styled } from 'styled-components'; import { Link as ReactRouterLink } from 'react-router-dom'; import { Text } from './text.js'; const StyledLink = styled(Text).withConfig({ displayName: "brc-sc-StyledLink", componentId: "brc-sc-ixdf0k" }) ` font-size: inherit; color: ${({ theme }) => theme.primary}; text-decoration: none; &:hover { color: ${({ theme }) => theme.primaryDim}; } &:active { color: ${({ theme }) => theme.primaryDim}; } &:focus { outline: ${({ theme }) => theme.focusOutline}; } `; StyledLink.displayName = 'StyledLink'; const BaseLink = (_a) => { var { to = '', href = to, target = '', onClick = () => { }, className = '', bold } = _a, props = __rest(_a, ["to", "href", "target", "onClick", "className", "bold"]); return (_jsx(StyledLink, Object.assign({ target: target }, (target ? { href } : { to: href }), { as: target ? 'a' : href ? ReactRouterLink : 'span', className: className, onClick: (e) => { e.persist(); onClick(e); }, rel: target === '_blank' ? 'noopener noreferrer' : undefined, "$bold": bold }, props))); }; BaseLink.displayName = 'Link'; /** # <Link /> The `Link` component is a Nav styled React Router Link component by default. 99% of the time, this is what we want to use. ## href `<Link />` requires an `href` prop. This differs from the api for the React Router Link which requires a `to` prop. The `Link` component will map the `href` prop to React Router Link's `to` prop in most cases. ```jsx <Link href="/home">Take me home</Link> ``` ## target If we find ourselves in need of a traditional anchor link, adding a standard `target` prop to the component will switch the underlying component from a React Router Link to a traditional anchor link. A value of `_blank` will open the link in a new tab/window. A value of `_self` will force a full page load at the specified `href` in the same window. If a link is meant to leave the app and stay in the same window, `_self` _must_ be set as the `target` value or the link will not work. ```jsx <Link href="/full/page/reload" target="_self"> Reload page </Link> ``` ```jsx <Link href="https://partner-site.com" target="_blank"> New tab </Link> ``` ## onClick Specify a custom action to take place when the link is clicked. The `<Link />` component automatically handles tracking functionality and is configurable with props. It is not necessary to manually add a `track` call unless tracking something other than a click interaction. */ export const Link = styled(BaseLink).withConfig({ displayName: "brc-sc-Link", componentId: "brc-sc-1xvvh9w" }) ``; //# sourceMappingURL=link.js.map