Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support link text #95

Merged
merged 12 commits into from
Sep 27, 2024
215 changes: 26 additions & 189 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"negotiator": "^0.6.3"
},
"devDependencies": {
"@prismicio/client": "^7.2.0",
"@prismicio/mock": "^0.3.1",
"@prismicio/client": "7.9.0-alpha.2",
"@prismicio/mock": "0.3.8-alpha.0",
"@size-limit/preset-small-lib": "^9.0.0",
"@types/negotiator": "^0.6.3",
"@types/react-test-renderer": "^18.0.2",
Expand Down Expand Up @@ -99,5 +99,9 @@
},
"publishConfig": {
"access": "public"
},
"overrides": {
"@prismicio/client": "7.9.0-alpha.2",
"@prismicio/mock": "0.3.8-alpha.0"
}
}
13 changes: 8 additions & 5 deletions src/PrismicNextLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export type PrismicNextLinkProps = Omit<
export const PrismicNextLink = React.forwardRef<
HTMLAnchorElement,
PrismicNextLinkProps
>(function PrismicNextLink(
{ field, document, linkResolver, ...restProps },
ref,
): JSX.Element | null {
>(function PrismicNextLink(props, ref): JSX.Element | null {
const { field, document, linkResolver, children, ...restProps } = props;
const {
href: computedHref,
rel: computedRel,
Expand All @@ -45,11 +43,16 @@ export const PrismicNextLink = React.forwardRef<
});

const href = ("href" in restProps ? restProps.href : computedHref) || "";
const text = prismic.isFilled.link(field) ? field.text : undefined;

let rel = computedRel;
if ("rel" in restProps && typeof restProps.rel !== "function") {
rel = restProps.rel;
}

return <Link ref={ref} {...attrs} {...restProps} href={href} rel={rel} />;
return (
<Link ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
{"children" in props ? children : text}
</Link>
);
});
Loading
Loading