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 #23

Merged
merged 8 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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.3.0-alpha.0](https://github.com/prismicio/prismic-svelte/compare/v1.2.0...v1.3.0-alpha.0) (2024-09-10)


### Features

* support link text ([04d6a51](https://github.com/prismicio/prismic-svelte/commit/04d6a510f4629faed0cf9c8a1afa4e24b8819537))

## [1.2.0](https://github.com/prismicio/prismic-svelte/compare/v1.1.1...v1.2.0) (2024-05-28)


Expand Down
167 changes: 23 additions & 144 deletions package-lock.json

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

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/svelte",
"version": "1.2.0",
"version": "1.3.0-alpha.0",
"description": "Svelte components to present Prismic content.",
"keywords": [
"typescript",
Expand Down Expand Up @@ -65,8 +65,8 @@
"esm-env": "^1.0.0"
},
"devDependencies": {
"@prismicio/client": "^7.4.0",
"@prismicio/mock": "^0.3.1",
"@prismicio/client": "7.9.0-alpha.3",
"@prismicio/mock": "0.3.8-alpha.2",
"@size-limit/preset-small-lib": "^11.0.1",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/package": "^2.2.3",
Expand Down Expand Up @@ -106,5 +106,9 @@
},
"publishConfig": {
"access": "public"
},
"overrides": {
"@prismicio/client": "7.9.0-alpha.3",
"@prismicio/mock": "0.3.8-alpha.2"
}
}
8 changes: 4 additions & 4 deletions src/PrismicLink.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import {
asLinkAttrs,
isFilled,
angeloashmore marked this conversation as resolved.
Show resolved Hide resolved
type AsLinkAttrsConfig,
type LinkField,
type PrismicDocument,
Expand Down Expand Up @@ -41,6 +42,7 @@
});

$: resolvedRel = typeof rel === "string" ? rel : linkAttrs.rel;
$: resolvedText = field?.text;
angeloashmore marked this conversation as resolved.
Show resolved Hide resolved
</script>

<!--
Expand All @@ -49,9 +51,7 @@

@example Rendering a Link field:
```svelte
<PrismicLink field={document.data.example_link}>
Example anchor text.
</PrismicLink>
<PrismicLink field={document.data.example_link} />
angeloashmore marked this conversation as resolved.
Show resolved Hide resolved
```
-->

Expand All @@ -62,5 +62,5 @@
on:click
{...$$restProps}
>
<slot />
<slot>{resolvedText}</slot>
</a>
33 changes: 33 additions & 0 deletions test/PrismicLink.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @vitest-environment happy-dom
import { expect, it } from "vitest";

import { render } from "@testing-library/svelte";

import PrismicLinkTestWrapper from "./PrismicLinkTestWrapper.svelte";

it("renders the link's text if no children are provided", (ctx) => {
const model = ctx.mock.model.link({
allowText: true,
allowTargetBlank: false,
});
const field = ctx.mock.value.link({ type: "Web", model, withText: true });
const { container } = render(PrismicLinkTestWrapper, { field });

expect(container.innerHTML).toBe(
`<div><a href="${field.url}" rel="noreferrer">${field.text}</a></div>`,
);
});

it("renders the given children, overriding the link's text", (ctx) => {
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 { container } = render(PrismicLinkTestWrapper, { field, children });

expect(container.innerHTML).toBe(
`<div><a href="${field.url}" rel="noreferrer">${children}</a></div>`,
);
});
Loading
Loading