-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathManchette.stories.tsx
101 lines (89 loc) · 2.69 KB
/
Manchette.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { useRef, useState } from 'react';
import '@osrd-project/ui-core/dist/theme.css';
import '@osrd-project/ui-manchette/dist/theme.css';
import { EyeClosed, Telescope } from '@osrd-project/ui-icons';
import type { Meta, StoryObj } from '@storybook/react';
import { SAMPLE_PATH_PROPERTIES_DATA } from './assets/sampleData';
import Menu, { type MenuItem } from './components/Menu';
import Manchette from '../components/Manchette';
import { type StyledOperationalPointType } from '../types';
const OperationalPointListData: StyledOperationalPointType[] =
SAMPLE_PATH_PROPERTIES_DATA.operational_points?.map((op) => ({ ...op, display: true })) ?? [];
const meta: Meta<typeof Manchette> = {
component: Manchette,
title: 'Manchette/Manchette',
tags: ['autodocs'],
argTypes: {
operationalPoints: {
control: {
type: 'object',
},
},
zoomYIn: {
action: 'zoomYIn',
},
zoomYOut: {
action: 'zoomYOut',
},
},
};
const ManchetteWithWaypointMenu = () => {
const [menuPosition, setMenuPosition] = useState<{ top: number; left: number } | null>(null);
const [activeOperationalPointId, setActiveOperationalPointId] = useState<string>();
const menuRef = useRef<HTMLDivElement>(null);
const menuItems: MenuItem[] = [
{
title: 'Action 1',
icon: <EyeClosed />,
onClick: () => {
setMenuPosition(null);
setActiveOperationalPointId(undefined);
},
},
{
title: 'Action 2',
icon: <Telescope />,
onClick: () => {
setMenuPosition(null);
setActiveOperationalPointId(undefined);
},
},
];
const handleWaypointClick = (id: string, ref: HTMLDivElement | null) => {
if (!ref) return;
const position = ref.getBoundingClientRect();
setMenuPosition({ top: position.bottom - 2, left: position.left });
setActiveOperationalPointId(id);
};
return (
<Manchette
operationalPoints={OperationalPointListData.map((op) => ({
...op,
onClick: (id, ref) => {
handleWaypointClick(id, ref);
},
}))}
zoomYIn={() => {}}
zoomYOut={() => {}}
resetZoom={() => {}}
toggleMode={() => {}}
activeOperationalPointId={activeOperationalPointId}
>
{menuPosition && (
<Menu
menuRef={menuRef}
items={menuItems}
style={{ width: '305px', top: menuPosition.top, left: menuPosition.left }}
/>
)}
</Manchette>
);
};
export default meta;
type Story = StoryObj<typeof ManchetteWithWaypointMenu>;
export const Default: Story = {
args: {
operationalPoints: OperationalPointListData,
},
};
export const WaypointMenu = () => <ManchetteWithWaypointMenu />;