Skip to content

Commit 7e62fec

Browse files
committed
fix: iframeable link
1 parent c9a5a1b commit 7e62fec

29 files changed

Lines changed: 160 additions & 167 deletions

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const eslintConfig = [
4747
'playwright.config.js',
4848
'public/**',
4949
'integrabook/**',
50+
'prisma/generated/**',
5051
],
5152
},
5253
]

src/components/Notion/DynamicNotion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ExtendedRecordMap } from 'notion-types'
33
import { ReactNode, useEffect, useRef } from 'react'
44
import { NotionRenderer } from 'react-notion-x'
55
import { Collection } from 'react-notion-x/build/third-party/collection'
6-
import IframeableLink from 'components/base/IframeableLink'
6+
import Link from '../base/buttons/Link'
77
import NotionErrorBoundary from './NotionErrorBoundary'
88
import { improveAccessibility } from './utils'
99
import 'react-notion-x/src/styles.css'
@@ -26,9 +26,9 @@ const DynamicNotion = ({ recordMap }: DynamicNotionProps) => {
2626
Link: ({ href, children, ...props }: LinkProps & { children: ReactNode }) => {
2727
return (
2828
// @ts-expect-error: notion type error
29-
<IframeableLink href={href} {...props} target='_blank' rel='noopener noreferrer'>
29+
<Link href={href} {...props} target='_blank' rel='noopener noreferrer'>
3030
{children}
31-
</IframeableLink>
31+
</Link>
3232
)
3333
},
3434
}}

src/components/Notion/Notion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ReactNode, useEffect, useRef } from 'react'
77
import { Collection } from 'react-notion-x/build/third-party/collection'
88
import Breadcrumbs from 'components/breadcrumbs/Breadcrumbs'
99
import Block from 'components/layout/Block'
10-
import IframeableLink from '../base/IframeableLink'
10+
import Link from '../base/buttons/Link'
1111
import NotionErrorBoundary from './NotionErrorBoundary'
1212
import { improveAccessibility } from './utils'
1313
import styles from './Notion.module.css'
@@ -67,9 +67,9 @@ const Notion = ({
6767
}
6868
return (
6969
// @ts-expect-error: notion type error
70-
<IframeableLink href={href} {...props} target='_blank' rel='noopener noreferrer'>
70+
<Link href={href} {...props} target='_blank' rel='noopener noreferrer'>
7171
{children}
72-
</IframeableLink>
72+
</Link>
7373
)
7474
},
7575
Collection,

src/components/base/Logo/Logos.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import classNames from 'classnames'
22
import { buildCurrentUrlFor } from 'utils/urls'
3-
import IframeableLink from '../IframeableLink'
3+
import Link from '../buttons/Link'
44
import Ademe from './Ademe'
55
import Logo from './ImpactCO2'
66
import Marianne from './Marianne'
@@ -11,13 +11,13 @@ const Logos = ({ small }: { small?: boolean }) => {
1111
<div className={classNames(styles.logos, { [styles.small]: small })}>
1212
<Marianne small={small} />
1313
<Ademe small={small} />
14-
<IframeableLink
14+
<Link
1515
href={buildCurrentUrlFor('/')}
1616
className={styles.link}
1717
data-testid='impactco2-logos'
1818
title="Voir la page d'accueil du site Impact CO2">
1919
<Logo small={small} />
20-
</IframeableLink>
20+
</Link>
2121
</div>
2222
)
2323
}

src/components/base/Markdown.jsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/components/base/Markdown.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use client'
2+
3+
import MarkdownToJsx, { MarkdownToJSX } from 'markdown-to-jsx'
4+
import { ReactNode } from 'react'
5+
import Link from './buttons/Link'
6+
7+
export default function Markdown({
8+
children,
9+
components = {},
10+
...otherProps
11+
}: {
12+
children: string | null | undefined
13+
components?: Record<string, ReactNode>
14+
options?: MarkdownToJSX.Options
15+
}) {
16+
return (
17+
<MarkdownToJsx
18+
{...otherProps}
19+
options={{
20+
...otherProps.options,
21+
forceBlock: true,
22+
overrides: {
23+
a: Link,
24+
...components,
25+
},
26+
}}>
27+
{children}
28+
</MarkdownToJsx>
29+
)
30+
}

src/components/base/Resource.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import { useTranslations } from 'next-intl'
44
import Image from 'next/image'
55
import { track } from 'utils/matomo'
6-
import IframeableLink from './IframeableLink'
76
import NewTabIcon from './NewTabIcon'
7+
import Link from './buttons/Link'
88
import styles from './Resource.module.css'
99

1010
const Resource = ({
@@ -24,7 +24,7 @@ const Resource = ({
2424
}) => {
2525
const t = useTranslations('ressources')
2626
return (
27-
<IframeableLink
27+
<Link
2828
className={styles.linkContainer}
2929
href={href}
3030
target='_blank'
@@ -50,7 +50,7 @@ const Resource = ({
5050
</p>
5151
)}
5252
</div>
53-
</IframeableLink>
53+
</Link>
5454
)
5555
}
5656

src/components/base/Sources.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import classNames from 'classnames'
44
import { track } from 'utils/matomo'
5-
import IframeableLink from './IframeableLink'
5+
import Link from './buttons/Link'
66
import styles from './Sources.module.css'
77

88
const Sources = ({
@@ -19,9 +19,9 @@ const Sources = ({
1919
Source{sources.length > 1 ? 's' : ''} :{' '}
2020
{sources
2121
.flatMap((source) => [
22-
<IframeableLink key={source.label} href={source.href} onClick={() => track(tracking, 'Source', source.href)}>
22+
<Link key={source.label} href={source.href} onClick={() => track(tracking, 'Source', source.href)}>
2323
{source.label}
24-
</IframeableLink>,
24+
</Link>,
2525
<span key={`${source.label}-separator`}></span>,
2626
])
2727
.slice(0, sources.length * 2 - 1)}
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import classNames from 'classnames'
22
import { LinkProps } from 'next/link'
3-
import { AnchorHTMLAttributes } from 'react'
3+
import { AnchorHTMLAttributes, ForwardedRef, forwardRef } from 'react'
44
import IframeableLink from '../IframeableLink'
55
import NewTabIcon from '../NewTabIcon'
66
import buttonStyles from './Button.module.css'
77
import linkStyles from './Link.module.css'
88

9-
const Link = ({
10-
asButton,
11-
internal,
12-
noIcon,
13-
children,
14-
className,
15-
...rest
16-
}: {
17-
asButton?: boolean
18-
size?: 'sm' | 'lg'
19-
internal?: boolean
20-
noIcon?: boolean
21-
} & LinkProps &
22-
AnchorHTMLAttributes<HTMLAnchorElement>) => {
9+
const Link = (
10+
{
11+
asButton,
12+
internal,
13+
noIcon,
14+
children,
15+
className,
16+
...rest
17+
}: {
18+
asButton?: boolean
19+
size?: 'sm' | 'lg'
20+
internal?: boolean
21+
noIcon?: boolean
22+
} & LinkProps &
23+
AnchorHTMLAttributes<HTMLAnchorElement>,
24+
ref: ForwardedRef<HTMLAnchorElement>
25+
) => {
2326
const external = !internal && (rest.href.includes(':') || rest.href.includes('.') || rest.href.includes('#'))
2427
return (
2528
<IframeableLink
29+
ref={ref}
2630
className={classNames(asButton ? buttonStyles.button : linkStyles.link, className, {
2731
[buttonStyles.small]: rest.size === 'sm',
2832
})}
29-
target={external ? '_blank' : '_self'}
33+
target={external ? '_blank' : undefined}
3034
rel={external ? 'noreferrer noopener' : undefined}
3135
{...rest}>
3236
{children}
@@ -35,4 +39,4 @@ const Link = ({
3539
)
3640
}
3741

38-
export default Link
42+
export default forwardRef(Link)

src/components/base/publicode/DocumentationUsageNumerique.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RulePage } from '@publicodes/react-ui'
22
import { Children, ReactNode } from 'react'
33
import useUsageNumeriqueContext from 'src/providers/UsageNumeriqueProvider'
4-
import IframeableLink from '../IframeableLink'
54
import Markdown from '../Markdown'
5+
import Link from '../buttons/Link'
66
import styles from './Documentation.module.css'
77

88
export default function DocumentationUsageNumerique({ slug }: { slug: string }) {
@@ -27,9 +27,9 @@ export default function DocumentationUsageNumerique({ slug }: { slug: string })
2727
return null
2828
},
2929
Link: ({ to, children }) => (
30-
<IframeableLink href={to || '/'} prefetch={false}>
30+
<Link href={to || '/'} prefetch={false}>
3131
{children}
32-
</IframeableLink>
32+
</Link>
3333
),
3434
Text: ({ children }) => <Markdown>{children}</Markdown>,
3535
}}

0 commit comments

Comments
 (0)