Skip to content

Commit

Permalink
fixup! Contextual consent
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgirault committed Feb 10, 2025
1 parent 918915e commit a2a2c88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
6 changes: 5 additions & 1 deletion site/features/contextual.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
purposes: [
{
id: 'youtube',
title: 'YouTube'
title: 'YouTube videos'
},
{
id: 'other',
title: 'Another purpose'
}
],
privacyPolicyUrl: '#'
Expand Down
10 changes: 7 additions & 3 deletions src/ui/components/types/ContextualNotice.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import {FunctionComponent} from 'preact';
import {Purpose} from '../../types';

export type ContextualNoticeOptions = Record<string, string>;
export interface ContextualNoticeOptions extends Record<string, string> {
titleLevel?: '1' | '2' | '3' | '4' | '5' | '6';
}

export interface ContextualNoticeProps<Data extends ContextualNoticeOptions> {
export interface ContextualNoticeProps<
Data extends ContextualNoticeOptions
> {
purpose: Purpose;
data: Data;
onAccept: () => void;
}

export type ContextualNoticeComponent<
Data extends ContextualNoticeOptions
Data extends ContextualNoticeOptions = ContextualNoticeOptions
> = FunctionComponent<ContextualNoticeProps<Data>>;
11 changes: 5 additions & 6 deletions src/ui/themes/dsfr/ContextualNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import type {
} from '../../components/types/ContextualNotice';
import {template} from '../../utils/template';

interface DsfrContextualNoticeData extends ContextualNoticeOptions {
titleLevel?: string;
}

const ContextualNotice: ContextualNoticeComponent<DsfrContextualNoticeData> = ({
const ContextualNotice: ContextualNoticeComponent = ({
purpose,
data,
onAccept
}) => {
const t = useTranslations();
const {titleLevel} = data;
const TitleTag = titleLevel ? `h${titleLevel}` : 'h4';
const TitleTag: `h${ContextualNoticeOptions['titleLevel']}` = titleLevel
? `h${titleLevel}`
: 'h4';

const templateProps = {
purpose: purpose.title
};
Expand Down
10 changes: 4 additions & 6 deletions src/ui/themes/standard/ContextualNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import type {
} from '../../components/types/ContextualNotice';
import {template} from '../../utils/template';

interface StandardContextualNoticeOptions extends ContextualNoticeOptions {
titleLevel?: string;
}

const ContextualNotice: ContextualNoticeComponent<StandardContextualNoticeOptions> = ({
const ContextualNotice: ContextualNoticeComponent = ({
purpose,
data,
onAccept
}) => {
const t = useTranslations();
const {titleLevel} = data;
const TitleTag = titleLevel ? `h${data.titleLevel}` : 'h2';
const TitleTag:
| `h${ContextualNoticeOptions['titleLevel']}`
| 'strong' = titleLevel ? `h${titleLevel}` : 'strong';
const templateProps = {
purpose: purpose.title
};
Expand Down

0 comments on commit a2a2c88

Please sign in to comment.