Skip to content

Commit c84a8e8

Browse files
committed
Toggle for collapsible XML
1 parent fac1765 commit c84a8e8

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
.container {
2+
position: relative;
3+
overflow: hidden;
4+
}
5+
6+
.xmlContainer {
27
font-size: 0.75rem;
3-
overflow-y: auto;
8+
overflow-y: scroll;
9+
height: 100%;
10+
scrollbar-width: thin;
411
}
512

613
.hidden {
714
display: none;
15+
}
16+
17+
.toggle {
18+
position: absolute;
19+
right: 1.5rem;
20+
bottom: 0.5rem;
821
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import XMLViewer from 'react-xml-viewer';
3-
import { Alert } from '@navikt/ds-react';
3+
import { Alert, Switch, Tooltip } from '@navikt/ds-react';
44
import { classNames } from '../../../../utils/classNames';
55

66
import style from './XmlView.module.css';
@@ -11,17 +11,31 @@ type Props = {
1111
};
1212

1313
export const XmlView = ({ xml, hidden = false }: Props) => {
14+
const [collapsible, setCollapsible] = useState(false);
15+
1416
return (
1517
<div className={classNames(style.container, hidden && style.hidden)}>
16-
<XMLViewer
17-
xml={xml}
18-
collapsible={true}
19-
invalidXml={
20-
<Alert variant={'error'}>
21-
{'Feil: fant ingen XML for dette innholdet!'}
22-
</Alert>
23-
}
24-
/>
18+
<Tooltip content={'Toggle ekspanderbare elementer'}>
19+
<Switch
20+
size={'small'}
21+
checked={collapsible}
22+
position={'right'}
23+
hideLabel={true}
24+
onClick={() => setCollapsible(!collapsible)}
25+
className={style.toggle}
26+
>
27+
{'Expand/collapse'}
28+
</Switch>
29+
</Tooltip>
30+
<div className={style.xmlContainer}>
31+
<XMLViewer
32+
xml={xml}
33+
collapsible={collapsible}
34+
invalidXml={
35+
<Alert variant={'error'}>{'Parsing av XML for innholdet feilet!'}</Alert>
36+
}
37+
/>
38+
</div>
2539
</div>
2640
);
2741
};

0 commit comments

Comments
 (0)