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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.7.0-alpha.0](https://github.com/prismicio/prismic-next/compare/v1.5.0...v1.7.0-alpha.0) (2024-09-10)


### Features

* support link text ([bdc244e](https://github.com/prismicio/prismic-next/commit/bdc244e50a35fffc342968811621fac6720ec461))
* Support Next 15 & React 19 ([864bfed](https://github.com/prismicio/prismic-next/commit/864bfedb14a31401ae6ce2e8799767d217e2562d))


### Chore

* **release:** 1.6.0 ([e97fcca](https://github.com/prismicio/prismic-next/commit/e97fcca55e599131d0945d90dd6bb3f8732092ca))

## [1.6.0](https://github.com/prismicio/prismic-next/compare/v1.5.0...v1.6.0) (2024-05-30)


Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/next",
"version": "1.6.0",
"version": "1.7.0-alpha.0",
"description": "Helpers to integrate Prismic into Next.js apps",
"keywords": [
"typescript",
Expand Down Expand Up @@ -57,8 +57,8 @@
"negotiator": "^0.6.3"
},
"devDependencies": {
"@prismicio/client": "7.9.0-alpha.2",
"@prismicio/mock": "0.3.8-alpha.0",
"@prismicio/client": "7.9.0-alpha.3",
"@prismicio/mock": "0.3.8-alpha.2",
"@size-limit/preset-small-lib": "^9.0.0",
"@types/negotiator": "^0.6.3",
"@types/react-test-renderer": "^18.0.2",
Expand Down Expand Up @@ -101,7 +101,7 @@
"access": "public"
},
"overrides": {
"@prismicio/client": "7.9.0-alpha.2",
"@prismicio/mock": "0.3.8-alpha.0"
"@prismicio/client": "7.9.0-alpha.3",
"@prismicio/mock": "0.3.8-alpha.2"
}
}
3 changes: 1 addition & 2 deletions src/PrismicNextLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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") {
Expand All @@ -52,7 +51,7 @@ export const PrismicNextLink = React.forwardRef<

return (
<Link ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
{"children" in props ? children : text}
{"children" in props ? children : field?.text}
</Link>
);
});
14 changes: 10 additions & 4 deletions test/PrismicNextLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ it("forwards ref", (ctx) => {
});

it("renders a next/link with text", (ctx) => {
const model = ctx.mock.model.link({ text: true, allowTargetBlank: false });
const field = ctx.mock.value.link({ type: "Web", model });
const model = ctx.mock.model.link({
allowText: true,
allowTargetBlank: false,
});
const field = ctx.mock.value.link({ type: "Web", model, withText: true });

const actual = renderJSON(<PrismicNextLink field={field} />);
const expected = renderJSON(
Expand All @@ -253,8 +256,11 @@ it("renders a next/link with text", (ctx) => {
});

it("renders a next/link with the given children, overriding the link's text", (ctx) => {
const model = ctx.mock.model.link({ text: true, allowTargetBlank: false });
const field = ctx.mock.value.link({ type: "Web", model });
const model = ctx.mock.model.link({
allowText: true,
allowTargetBlank: false,
});
const field = ctx.mock.value.link({ type: "Web", model, withText: true });
const children = ctx.mock.value.keyText();

const actual = renderJSON(
Expand Down
16 changes: 8 additions & 8 deletions test/createLocaleRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ it("creates a redirect with the request's preferred locale", async () => {

mockGetRepository({
client,
languages: [{ id: "fr-fr", name: "French (France)" }],
languages: [{ id: "fr-fr", name: "French (France)", is_master: true }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 #nice: Thanks for updating these tests.

});

const redirect = await createLocaleRedirect(config);
Expand All @@ -74,8 +74,8 @@ it("returns undefined if the request already contains a locale", async () => {
mockGetRepository({
client,
languages: [
{ id: "fr-fr", name: "French (France)" },
{ id: "en-us", name: "English (US)" },
{ id: "fr-fr", name: "French (France)", is_master: false },
{ id: "en-us", name: "English (US)", is_master: true },
],
});

Expand All @@ -98,8 +98,8 @@ it("uses the default locale if the request's preferred language is unavailable",
mockGetRepository({
client,
languages: [
{ id: "en-us", name: "English (US)" },
{ id: "en-uk", name: "English (UK)" },
{ id: "en-us", name: "English (US)", is_master: true },
{ id: "en-uk", name: "English (UK)", is_master: false },
],
});

Expand Down Expand Up @@ -127,7 +127,7 @@ it("allows for custom locale codes", async () => {

mockGetRepository({
client,
languages: [{ id: "fr-fr", name: "French (France)" }],
languages: [{ id: "fr-fr", name: "French (France)", is_master: true }],
});

const redirect = await createLocaleRedirect(config);
Expand All @@ -150,7 +150,7 @@ it("returns undefined when omitDefaultLocale is true and the preferred locale is

mockGetRepository({
client,
languages: [{ id: "fr-fr", name: "French (France)" }],
languages: [{ id: "fr-fr", name: "French (France)", is_master: true }],
});

const redirect = await createLocaleRedirect(config);
Expand All @@ -171,7 +171,7 @@ it("uses the default locale when the accept-language header is not set", async (

mockGetRepository({
client,
languages: [{ id: "fr-fr", name: "French (France)" }],
languages: [{ id: "fr-fr", name: "French (France)", is_master: true }],
});

const redirect = await createLocaleRedirect(config);
Expand Down
Loading