Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/ui/components/ContextualNoticeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const ContextualNoticeContainer = ({
purpose={purpose}
data={data}
privacyPolicyUrl={config.privacyPolicyUrl}
privacyPolicyLinkAttributes={config.privacyPolicyLinkAttributes}
onAccept={() => {
manager.setConsent(purpose.id, true);
setIsBeingDisabled(true);
Expand Down
6 changes: 6 additions & 0 deletions src/ui/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const Main = ({apiRef}: MainProps) => {
needsUpdate={manager.needsUpdate()}
purposeTitles={config.purposes.map(({title}) => title)}
privacyPolicyUrl={config.privacyPolicyUrl}
privacyPolicyLinkAttributes={
config.privacyPolicyLinkAttributes
}
logo={config.logo}
onConfigure={openModal}
onAccept={() => {
Expand All @@ -74,6 +77,9 @@ const Main = ({apiRef}: MainProps) => {
isForced={config.forceModal && manager.isDirty()}
needsUpdate={manager.needsUpdate()}
privacyPolicyUrl={config.privacyPolicyUrl}
privacyPolicyLinkAttributes={
config.privacyPolicyLinkAttributes
}
onClose={closeModal}
onSave={commit}
>
Expand Down
33 changes: 33 additions & 0 deletions src/ui/components/PrivacyPolicyLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {AnchorHTMLAttributes} from 'preact';
import {useTranslations} from '../utils/hooks';

interface PrivacyPolicyLinkProps extends AnchorHTMLAttributes {
label: string;
onExit?: () => void;
}

const PrivacyPolicyLink = ({
label,
onExit,
...props
}: PrivacyPolicyLinkProps) => {
const t = useTranslations();
const isBlank = props?.target === '_blank';
const title = isBlank ? `${label} (${t.misc.newWindowTitle})` : null;

return (
<a
{...props}
title={title}
onClick={() => {
if (onExit && !isBlank) {
onExit();
}
}}
>
{label}
</a>
);
};

export default PrivacyPolicyLink;
3 changes: 2 additions & 1 deletion src/ui/components/types/Banner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {FunctionComponent} from 'preact';
import {AnchorHTMLAttributes, FunctionComponent} from 'preact';
import {ImageDescriptor} from '../../types';

export interface BannerProps {
isHidden: boolean;
needsUpdate: boolean;
purposeTitles: string[];
privacyPolicyUrl: string;
privacyPolicyLinkAttributes?: AnchorHTMLAttributes;
logo?: ImageDescriptor;
onAccept: () => void;
onDecline: () => void;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/types/ContextualNotice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {FunctionComponent} from 'preact';
import {AnchorHTMLAttributes, FunctionComponent} from 'preact';
import {Purpose} from '../../types';

export interface ContextualNoticeOptions extends Record<string, string> {
Expand All @@ -9,6 +9,7 @@ export interface ContextualNoticeProps<Data extends ContextualNoticeOptions> {
purpose: Purpose;
data: Data;
privacyPolicyUrl: string;
privacyPolicyLinkAttributes?: AnchorHTMLAttributes;
onAccept: () => void;
}

Expand Down
7 changes: 6 additions & 1 deletion src/ui/components/types/Modal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {ComponentChildren, FunctionComponent} from 'preact';
import {
AnchorHTMLAttributes,
ComponentChildren,
FunctionComponent
} from 'preact';

export interface ModalProps {
isForced: boolean;
needsUpdate: boolean;
privacyPolicyUrl: string;
privacyPolicyLinkAttributes?: AnchorHTMLAttributes;
onClose: () => void;
onSave: () => void;
children: ComponentChildren;
Expand Down
11 changes: 8 additions & 3 deletions src/ui/themes/dsfr/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {useRef} from 'preact/hooks';
import type {BannerComponent} from '../../components/types/Banner';
import {useNonObscuringElement, useTranslations} from '../../utils/hooks';
import {template} from '../../utils/template';
import PrivacyPolicyLink from '../../components/PrivacyPolicyLink';

const Banner: BannerComponent = ({
needsUpdate,
isHidden,
purposeTitles,
privacyPolicyUrl,
privacyPolicyLinkAttributes,
onAccept,
onDecline,
onConfigure
Expand All @@ -28,9 +30,12 @@ const Banner: BannerComponent = ({
<strong key="purposes">{purposeTitles.join(', ')}</strong>
),
privacyPolicy: (
<a key="privacyPolicyUrl" href={privacyPolicyUrl}>
{t.banner.privacyPolicyLabel}
</a>
<PrivacyPolicyLink
{...privacyPolicyLinkAttributes}
key="privacyPolicyLink"
href={privacyPolicyUrl}
label={t.banner.privacyPolicyLabel}
/>
)
})}
</p>
Expand Down
12 changes: 7 additions & 5 deletions src/ui/themes/dsfr/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {template} from '../../utils/template';
import Dialog from '../../components/Dialog';
import PoweredByLink from '../../components/PoweredByLink';
import type {ModalComponent} from '../../components/types/Modal';
import PrivacyPolicyLink from '../../components/PrivacyPolicyLink';

const Modal: ModalComponent = ({
isForced,
needsUpdate,
privacyPolicyUrl,
privacyPolicyLinkAttributes,
onClose,
onSave,
children
Expand Down Expand Up @@ -57,13 +59,13 @@ const Modal: ModalComponent = ({
<p>
{template(t.modal.description, {
privacyPolicy: (
<a
<PrivacyPolicyLink
{...privacyPolicyLinkAttributes}
key="privacyPolicyLink"
href={privacyPolicyUrl}
onClick={onClose}
>
{t.modal.privacyPolicyLabel}
</a>
label={t.modal.privacyPolicyLabel}
onExit={onClose}
/>
)
})}
</p>
Expand Down
10 changes: 6 additions & 4 deletions src/ui/themes/standard/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {BannerComponent} from '../../components/types/Banner';
import {imageAttributes} from '../../utils/config';
import {useNonObscuringElement, useTranslations} from '../../utils/hooks';
import {template} from '../../utils/template';
import PrivacyPolicyLink from '../../components/PrivacyPolicyLink';

const Banner: BannerComponent = ({
isHidden,
needsUpdate,
purposeTitles,
privacyPolicyUrl,
privacyPolicyLinkAttributes,
logo,
onAccept: onSaveRequest,
onDecline: onDeclineRequest,
Expand Down Expand Up @@ -57,13 +59,13 @@ const Banner: BannerComponent = ({
</strong>
),
privacyPolicy: (
<a
<PrivacyPolicyLink
{...privacyPolicyLinkAttributes}
key="privacyPolicyLink"
className="orejime-Banner-privacyPolicyLink"
href={privacyPolicyUrl}
>
{t.banner.privacyPolicyLabel}
</a>
label={t.banner.privacyPolicyLabel}
/>
)
})}
</p>
Expand Down
13 changes: 9 additions & 4 deletions src/ui/themes/standard/ContextualNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import type {
ContextualNoticeOptions
} from '../../components/types/ContextualNotice';
import {template} from '../../utils/template';
import PrivacyPolicyLink from '../../components/PrivacyPolicyLink';

const ContextualNotice: ContextualNoticeComponent = ({
purpose,
data,
onAccept,
privacyPolicyUrl
privacyPolicyUrl,
privacyPolicyLinkAttributes
}) => {
const t = useTranslations();
const {titleLevel} = data;
Expand All @@ -18,9 +20,12 @@ const ContextualNotice: ContextualNoticeComponent = ({
const templateProps = {
purpose: purpose.title,
privacyPolicy: (
<a key="privacyPolicyUrl" href={privacyPolicyUrl}>
{t.contextual.privacyPolicyLabel}
</a>
<PrivacyPolicyLink
{...privacyPolicyLinkAttributes}
key="privacyPolicyLink"
href={privacyPolicyUrl}
label={t.contextual.privacyPolicyLabel}
/>
)
};

Expand Down
16 changes: 8 additions & 8 deletions src/ui/themes/standard/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import {template} from '../../utils/template';
import {useTranslations} from '../../utils/hooks';
import {ModalComponent} from '../../components/types/Modal';
import PoweredByLink from '../../components/PoweredByLink';
import PrivacyPolicyLink from '../../components/PrivacyPolicyLink';

const Modal: ModalComponent = ({
isForced,
needsUpdate,
privacyPolicyUrl,
privacyPolicyLinkAttributes,
onClose,
onSave,
children
}) => {
const t = useTranslations();

console.log(privacyPolicyLinkAttributes);
return (
<Dialog
isAlert={isForced}
Expand Down Expand Up @@ -52,16 +54,14 @@ const Modal: ModalComponent = ({

{template(t.modal.description, {
privacyPolicy: (
<a
<PrivacyPolicyLink
{...privacyPolicyLinkAttributes}
key="privacyPolicyLink"
className="orejime-Modal-privacyPolicyLink"
onClick={(e) => {
onClose();
}}
href={privacyPolicyUrl}
>
{t.modal.privacyPolicyLabel}
</a>
label={t.modal.privacyPolicyLabel}
onExit={onClose}
/>
)
})}
</p>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {AnchorHTMLAttributes} from 'preact';
import {CookieOptions, Purpose as CorePurpose} from '../core/types';
import {Theme} from './components/types/Theme';

Expand Down Expand Up @@ -96,5 +97,6 @@ export interface Config {
forceBanner: boolean;
forceModal: boolean;
privacyPolicyUrl: string;
privacyPolicyLinkAttributes?: AnchorHTMLAttributes;
translations: Translations;
}
Loading