Skip to content

Commit 27d5df5

Browse files
committed
Funksjon for å vise html i fullskjerm
1 parent dad2fe6 commit 27d5df5

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

src/components/main-section/content-view/ContentView.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Props = {
1515
};
1616

1717
export const ContentView = ({ content }: Props) => {
18-
const { html, xmlAsString } = content;
18+
const { html, xmlAsString, versionKey } = content;
1919
const [viewState, setViewState] = useState<ViewState>(getDefaultViewState(content));
2020

2121
useEffect(() => {
@@ -39,7 +39,7 @@ export const ContentView = ({ content }: Props) => {
3939
<VersionSelector content={content} />
4040
</div>
4141
<XmlView xml={xmlAsString} hidden={viewState !== 'xml'} />
42-
{html && <HtmlView html={html} hidden={viewState !== 'html'} />}
42+
{html && <HtmlView html={html} versionKey={versionKey} hidden={viewState !== 'html'} />}
4343
{content.binaries && (
4444
<FilesView binaries={content.binaries} hidden={viewState !== 'files'} />
4545
)}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
.html {
1+
.wrapper {
2+
position: relative;
3+
height: 100%;
4+
width: 100%;
5+
}
6+
7+
.htmlFrame {
28
width: 100%;
39
height: 100%;
410
border: none;
511
}
612

13+
.fullscreenButton {
14+
position: absolute;
15+
top: 0.25rem;
16+
left: 0.25rem;
17+
background-color: var(--a-white);
18+
}
19+
720
.hidden {
821
display: none;
922
}

src/components/main-section/content-view/html-view/HtmlView.tsx

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
import React, { useRef } from 'react';
22
import { classNames } from '../../../../utils/classNames';
3+
import { Button } from '@navikt/ds-react';
4+
import { useAppState } from '../../../../state/useAppState';
35

46
import style from './HtmlView.module.css';
57

68
type Props = {
79
html: string;
10+
versionKey: string;
811
hidden: boolean;
912
};
1013

11-
export const HtmlView = ({ html, hidden }: Props) => {
14+
export const HtmlView = ({ html, versionKey, hidden }: Props) => {
15+
const { appContext } = useAppState();
1216
const ref = useRef<HTMLIFrameElement>(null);
1317

18+
const fullscreenPath = `${appContext.basePath}/html/${versionKey}`;
19+
1420
return (
15-
<iframe
16-
srcDoc={html}
17-
className={classNames(style.html, hidden && style.hidden)}
18-
ref={ref}
19-
onLoad={(e) => disableLinksAndEventListeners(e.currentTarget)}
20-
/>
21+
<div className={classNames(style.wrapper, hidden && style.hidden)}>
22+
<Button
23+
size={'small'}
24+
variant={'tertiary'}
25+
as={'a'}
26+
href={fullscreenPath}
27+
className={style.fullscreenButton}
28+
onClick={(e) => {
29+
e.preventDefault();
30+
window.open(fullscreenPath, '_blank');
31+
}}
32+
>
33+
{'Åpne i fullskjerm'}
34+
</Button>
35+
<iframe
36+
src={html}
37+
className={classNames(style.htmlFrame)}
38+
ref={ref}
39+
onLoad={(e) => disableLinksAndEventListeners(e.currentTarget)}
40+
/>
41+
</div>
2142
);
2243
};
2344

0 commit comments

Comments
 (0)