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