Skip to content

Commit caad579

Browse files
committed
added new calback function
1 parent b91c438 commit caad579

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

packages/web-components/src/components/notice-choice/notice-choice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) {
729729
// 5. permission/suppression logic
730730
if (!inNoticeOnly) {
731731
const checked = hasEmail;
732-
if (this.showCheckBox || this.showCustomNotice) {
732+
if (this.showCheckBox) {
733733
return this.renderCheckbox(preText, checked);
734734
}
735735
}

packages/web-components/src/components/notice-choice/utils.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,23 @@ export function processCustomText({
7171
return '';
7272
}
7373

74-
const replaceTag = (
75-
str: string,
76-
tag: string,
77-
href: string | undefined,
78-
part: string
79-
) =>
80-
href
81-
? str.replace(
82-
new RegExp(`<${tag}>(.*?)</${tag}>`, 'g'),
83-
`<a href="${href}" part="${part}" target="_blank" aria-label="$1 (opens in new tab)" class="cds-inline">$1</a>`
84-
)
85-
: str.replace(new RegExp(`<${tag}>(.*?)</${tag}>`, 'g'), '$1');
86-
87-
return [
74+
const linkMap = [
8875
{ tag: 'optout', link: optOutLink, part: 'nc-opt-out' },
8976
{ tag: 'ps', link: psLink, part: 'nc-privacy-statement' },
9077
{ tag: 'ccpa', link: ccpaLink, part: 'nc-ccpa-link' },
91-
].reduce(
92-
(acc, { tag, link, part }) => replaceTag(acc, tag, link, part),
93-
text
94-
);
78+
];
79+
80+
let result = text;
81+
82+
for (const { tag, link, part } of linkMap) {
83+
const regex = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`, 'gi');
84+
85+
result = result.replace(regex, (_match, inner) =>
86+
link
87+
? `<a href="${link}" part="${part}" target="_blank" aria-label="${inner} (opens in new tab)" class="cds-inline">${inner}</a>`
88+
: inner
89+
);
90+
}
91+
92+
return result;
9593
}

0 commit comments

Comments
 (0)