From 3cc7d3e6b97c9da0d5c29307b0a101827d5d2a12 Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 17 Mar 2022 11:31:09 +0100 Subject: [PATCH] Make PrivacyLink HTML attributes a separate prop. --- source/links/privacy-link.ts | 6 ++---- tests/links/privacy-link.test.ts | 16 +++++++--------- tests/links/snapshots/privacy-link.test.ts.md | 2 +- tests/links/snapshots/privacy-link.test.ts.snap | Bin 302 -> 302 bytes 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/source/links/privacy-link.ts b/source/links/privacy-link.ts index 3ec09aa..61dfb74 100644 --- a/source/links/privacy-link.ts +++ b/source/links/privacy-link.ts @@ -5,9 +5,8 @@ import {Component, ComponentChildren, VNode} from 'preact'; * Component properties for {@linkcode PrivacyLink}. */ export type PrivacyLinkProps = { + attributes: Record; children: ComponentChildren; - class: string; - href: string; }; /** @@ -18,8 +17,7 @@ export type PrivacyLinkProps = { export class PrivacyLink extends Component { render(): VNode { const props: Record = { - class: this.props.class, - href: this.props.href, + ...this.props.attributes, rel: 'noopener noreferrer', target: '_blank', }; diff --git a/tests/links/privacy-link.test.ts b/tests/links/privacy-link.test.ts index 1a06f7c..bc44977 100644 --- a/tests/links/privacy-link.test.ts +++ b/tests/links/privacy-link.test.ts @@ -7,15 +7,18 @@ import {PrivacyLink} from '../../source/gram.js'; test('PrivacyLink', (t) => { t.snapshot(render(html`<${PrivacyLink} />`), 'Empty'); + const attributes: Record = { + href: 'https://example.org', + }; t.snapshot( - render(html`<${PrivacyLink} href="https://example.org">Example`), + render(html`<${PrivacyLink} attributes=${attributes}>Example`), 'Text children', ); t.snapshot( render( html` - <${PrivacyLink} href="https://example.org"> + <${PrivacyLink} attributes=${attributes}> Example with children `, @@ -23,14 +26,9 @@ test('PrivacyLink', (t) => { 'HTML children', ); + attributes.class = 'bold italic'; t.snapshot( - render( - html` - <${PrivacyLink} class="bold italic" href="https://example.org"> - Example - - `, - ), + render(html`<${PrivacyLink} attributes=${attributes}>Example`), 'CSS class', ); }); diff --git a/tests/links/snapshots/privacy-link.test.ts.md b/tests/links/snapshots/privacy-link.test.ts.md index 6c88c42..0a4ff9c 100644 --- a/tests/links/snapshots/privacy-link.test.ts.md +++ b/tests/links/snapshots/privacy-link.test.ts.md @@ -20,4 +20,4 @@ Generated by [AVA](https://avajs.dev). > CSS class - 'Example' + 'Example' diff --git a/tests/links/snapshots/privacy-link.test.ts.snap b/tests/links/snapshots/privacy-link.test.ts.snap index 5858066b8cc08e0ba8364bfa7e5c37642f158eba..8751ae0c7c4e6c2da2885f7e75d5b0355519793e 100644 GIT binary patch literal 302 zcmV+}0nz?JRzVEyfs#Ym<0Aw=}Z$_K^;G9zmxz#U4d?;8T&>#E41LV^Yfr$dz09tk64 zy+PUyqtsR;ri(nsB@B`9EO4iPVVmyGzNEt(m!gby)H3?L{B0zE{%5%=QUtFIK}w}= z0=2q&a$-L#ihR3p@R{LyelzHq)$ literal 302 zcmV+}0nz?JRzVV>@#Ynk!-UoEZ%6Y~WG9zmxz%5FyA1eaa=^{&^K!OShXMK>(0SO~y zIUvoz$h8p(@j6X$4SgV-dT#YEY_t8@kF;OnT2yT;HH_{c{}{<%|5&cF7{IBTAjVu* zo*G@eSTWxfS-M*|`b