Skip to content

Commit d95080f

Browse files
Merge pull request #2155 from navikt/consent-banner-link
Consent banner link
2 parents 3f59dad + cbf0eb5 commit d95080f

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

src/components/macros/MacroMapper.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { MacroIngress } from './ingress/MacroIngress';
2828
import { MacroAlertBox } from './alert-box/MacroAlertBox';
2929
import { MacroSaksbehandlingstid } from './saksbehandlingstid/MacroSaksbehandlingstid';
3030
import { MacroPayoutDates } from './payout-dates/MacroPayoutDates';
31+
import { MacroConsentBannerLink } from './consent-banner-link/MacroConsentBannerLink';
3132

3233
const macroComponents: {
3334
[key in MacroType]: React.FunctionComponent<MacroPropsCommon>;
@@ -37,6 +38,7 @@ const macroComponents: {
3738
[MacroType.ButtonBlue]: MacroButton,
3839
[MacroType.Saksbehandlingstid]: MacroSaksbehandlingstid,
3940
[MacroType.ChatbotLink]: MacroChatbotLink,
41+
[MacroType.ConsentBannerLink]: MacroConsentBannerLink,
4042
[MacroType.ChevronLinkExternal]: MacroChevronLinkExternal,
4143
[MacroType.ChevronLinkInternal]: MacroChevronLinkInternal,
4244
[MacroType.Fotnote]: MacroFotnote,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { LenkeInline } from 'components/_common/lenke/lenkeInline/LenkeInline';
3+
import { Button } from 'components/_common/button/Button';
4+
import { MacroConsentBannerLinkProps } from 'types/macro-props/consent-banner-link';
5+
6+
type ExtraProps = {
7+
variant?: 'secondary';
8+
};
9+
10+
export const MacroConsentBannerLink = ({ config }: MacroConsentBannerLinkProps) => {
11+
if (!config?.consent_banner_link) {
12+
return null;
13+
}
14+
15+
const { text, presentation = 'link' } = config.consent_banner_link;
16+
17+
const Element = presentation === 'link' ? LenkeInline : Button;
18+
const extraProps: ExtraProps = presentation === 'link' ? {} : { variant: 'secondary' };
19+
20+
return (
21+
<Element
22+
href={'/'}
23+
onClick={(e) => {
24+
e.preventDefault();
25+
window.webStorageController?.showConsentBanner();
26+
}}
27+
{...extraProps}
28+
>
29+
{text}
30+
</Element>
31+
);
32+
};

src/types/macro-props/_macros-common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export enum MacroType {
33
Button = 'button',
44
ButtonBlue = 'button-blue',
55
ChatbotLink = 'chatbot-link',
6+
ConsentBannerLink = 'consent-banner-link',
67
ChevronLinkInternal = 'chevron-link-internal',
78
ChevronLinkExternal = 'chevron-link-external',
89
Fotnote = 'fotnote',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { MacroPropsCommon, MacroType } from './_macros-common';
2+
3+
export interface MacroConsentBannerLinkProps extends MacroPropsCommon {
4+
name: MacroType.ChevronLinkExternal;
5+
config: {
6+
consent_banner_link: {
7+
text: string;
8+
presentation: 'button' | 'link';
9+
};
10+
};
11+
}

src/window.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare global {
1010
destroy: (widgetId: string, deleteElement?: boolean) => any;
1111
widgets: (widgetId: string) => any;
1212
};
13+
webStorageController: any;
1314
}
1415

1516
interface WindowEventMap {

0 commit comments

Comments
 (0)