Skip to content

Commit ea84d9d

Browse files
authored
Merge pull request #2619 from navikt/ny/draggable-panel
Resizing av meldingpanel
2 parents 6fff947 + c7f05c2 commit ea84d9d

File tree

5 files changed

+95
-43
lines changed

5 files changed

+95
-43
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"react-hook-form": "^7.54.1",
111111
"react-modal": "^3.16.3",
112112
"react-redux": "^7.2.0",
113+
"react-resizable-panels": "^2.1.7",
113114
"redux": "^4.2.1",
114115
"redux-thunk": "^2.4.2",
115116
"styled-components": "^6.1.15",

pnpm-lock.yaml

+23-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+55-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { ChatIcon, MinusIcon } from '@navikt/aksel-icons';
2-
import { Box, Button, HStack } from '@navikt/ds-react';
1+
import { ChatIcon, ExpandIcon, MinusIcon, ShrinkIcon } from '@navikt/aksel-icons';
2+
import { Box, Button, HStack, VStack } from '@navikt/ds-react';
33
import { useAtomValue } from 'jotai';
4-
import { useEffect, useState } from 'react';
4+
import { useCallback, useEffect, useRef, useState } from 'react';
5+
import { type ImperativePanelHandle, Panel } from 'react-resizable-panels';
56
import { dialogUnderArbeidAtom } from 'src/lib/state/dialog';
67
import { SendMelding } from './SendMelding';
78

9+
const PANEL_SIZE = 30;
10+
const LARGE_SIZE = 50;
11+
812
export function LukkbarNyMelding() {
13+
const panelRef = useRef<ImperativePanelHandle>(null);
14+
const [isLarge, setIsLarge] = useState((panelRef.current?.getSize() ?? PANEL_SIZE) > PANEL_SIZE);
915
const [isOpen, setIsOpen] = useState(localStorage.getItem('ny-melding-is-open') !== 'false');
1016

1117
useEffect(() => {
@@ -19,31 +25,56 @@ export function LukkbarNyMelding() {
1925
}
2026
}, [oppgave]);
2127

28+
const onExpand = useCallback(() => {
29+
if (!panelRef.current) return;
30+
31+
setIsLarge(panelRef.current.getSize() > PANEL_SIZE);
32+
}, []);
33+
34+
if (!isOpen) {
35+
return (
36+
<Box>
37+
<Button
38+
type="button"
39+
icon={<ChatIcon title="Skriv ny melding" />}
40+
size="small"
41+
onClick={() => setIsOpen(true)}
42+
/>
43+
</Box>
44+
);
45+
}
46+
2247
return (
23-
<HStack flexGrow="1">
24-
{!isOpen && (
25-
<Box>
26-
<Button
27-
type="button"
28-
icon={<ChatIcon title="Skriv ny melding" />}
29-
size="small"
30-
onClick={() => setIsOpen(true)}
31-
/>
32-
</Box>
33-
)}
34-
{isOpen && (
48+
<Panel onResize={onExpand} ref={panelRef} defaultSize={PANEL_SIZE} minSize={20} maxSize={60} order={2}>
49+
<VStack height="100%">
3550
<SendMelding
3651
lukkeKnapp={
37-
<Button
38-
type="button"
39-
icon={<MinusIcon title="Lukk" />}
40-
variant="tertiary"
41-
size="small"
42-
onClick={() => setIsOpen(false)}
43-
/>
52+
<HStack gap="2">
53+
<Button
54+
aria-hidden
55+
type="button"
56+
icon={isLarge ? <ShrinkIcon title="Minimer" /> : <ExpandIcon title="Ekspander" />}
57+
variant="tertiary"
58+
size="small"
59+
onClick={() => {
60+
if (!panelRef.current) return;
61+
62+
const newSize = isLarge ? PANEL_SIZE : LARGE_SIZE;
63+
panelRef.current.resize(newSize);
64+
}}
65+
/>
66+
<Button
67+
aria-hidden
68+
type="button"
69+
icon={<MinusIcon title="Lukk" />}
70+
variant="tertiary"
71+
size="small"
72+
onClick={() => setIsOpen(false)}
73+
/>
74+
</HStack>
4475
}
4576
/>
46-
)}
47-
</HStack>
77+
</VStack>
78+
</Panel>
4879
);
4980
}

src/components/melding/SendMelding.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const SendMeldingContent = ({ lukkeKnapp }: Props) => {
4545
);
4646

4747
return (
48-
<Card padding="2" maxWidth="30vw" minWidth="24em">
48+
<Card padding="2">
4949
<HStack justify="space-between">
5050
<Heading level="1" size="medium">
5151
{oppgave ? continueText : 'Send ny dialog'}

src/routes/new/person.lazy.tsx

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Box, HStack, VStack } from '@navikt/ds-react';
22
import { Navigate, Outlet, createLazyFileRoute } from '@tanstack/react-router';
33
import { useAtomValue } from 'jotai';
44
import { Suspense } from 'react';
5+
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
56
import { PersonLinje } from 'src/components/PersonLinje';
67
import { PersonSidebarMenu } from 'src/components/PersonSidebar';
78
import { LukkbarNyMelding } from 'src/components/melding/LukkbarNyMelding';
@@ -27,19 +28,20 @@ function PersonLayout() {
2728
<VStack>
2829
<PersonSidebarMenu />
2930
</VStack>
30-
<HStack gap="2" flexGrow="1" className="flex-nowrap">
31-
<VStack gap="2" flexGrow="1">
32-
<Box flexGrow="0">
33-
<PersonLinje />
34-
</Box>
35-
<Suspense>
36-
<Outlet />
37-
</Suspense>
38-
</VStack>
39-
<VStack flexGrow="0">
40-
<LukkbarNyMelding />
41-
</VStack>
42-
</HStack>
31+
<PanelGroup direction="horizontal" autoSaveId="person-content">
32+
<Panel order={1} className="mr-2">
33+
<VStack gap="2" height="100%">
34+
<Box flexGrow="0">
35+
<PersonLinje />
36+
</Box>
37+
<Suspense>
38+
<Outlet />
39+
</Suspense>
40+
</VStack>
41+
</Panel>
42+
<PanelResizeHandle className="hover:bg-surface-neutral-subtle-hover w-1 focus:bg-blue-50" />
43+
<LukkbarNyMelding />
44+
</PanelGroup>
4345
</HStack>
4446
);
4547
}

0 commit comments

Comments
 (0)