Skip to content

Commit 54d11da

Browse files
committed
ui-manchette: fix waypoint menu position
- Move the menu next to its related waypoint so it can always be positioned relatively to it - Rename some props to be more neutral Signed-off-by: SharglutDev <[email protected]>
1 parent e74d151 commit 54d11da

File tree

9 files changed

+75
-95
lines changed

9 files changed

+75
-95
lines changed

ui-manchette/src/components/OperationalPoint.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ import React, { useRef } from 'react';
22

33
import cx from 'classnames';
44

5-
import type { WaypointMenuItem, StyledOperationalPointType } from '../types';
5+
import type { StyledOperationalPointType } from '../types';
66
import '@osrd-project/ui-core/dist/theme.css';
77
import { positionMmToKm } from '../utils';
8-
import WaypointMenu from './WaypointMenu';
98

109
type OperationalPointProps = {
1110
operationalPoint: StyledOperationalPointType;
1211
isActive: boolean;
13-
waypointMenuItems?: WaypointMenuItem[];
14-
waypointMenuClassName?: string;
12+
waypointMenu?: React.ReactNode;
1513
index: number;
1614
};
1715

1816
const OperationalPoint = ({
1917
operationalPoint: { extensions, id, position, display, onClick },
2018
isActive,
21-
waypointMenuItems,
22-
waypointMenuClassName,
19+
waypointMenu,
2320
index,
2421
}: OperationalPointProps) => {
2522
const opRef = useRef<HTMLDivElement>(null);
@@ -46,9 +43,7 @@ const OperationalPoint = ({
4643

4744
<div className="op-type"></div>
4845
<div className="op-separator"></div>
49-
{isActive && waypointMenuItems && (
50-
<WaypointMenu items={waypointMenuItems} className={waypointMenuClassName} />
51-
)}
46+
{waypointMenu && isActive && waypointMenu}
5247
</div>
5348
);
5449
};

ui-manchette/src/components/OperationalPointList.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import OperationalPoint from './OperationalPoint';
4-
import type { WaypointMenuData, StyledOperationalPointType } from '../types';
4+
import type { StyledOperationalPointType, WaypointMenuData } from '../types';
55

66
type OperationalPointListProps = {
77
operationalPoints: StyledOperationalPointType[];
@@ -22,8 +22,7 @@ const OperationalPointList = ({
2222
<OperationalPoint
2323
operationalPoint={op}
2424
isActive={waypointMenuData?.activeWaypointIndex === index}
25-
waypointMenuItems={waypointMenuData?.waypointMenuItems}
26-
waypointMenuClassName={waypointMenuData?.waypointMenuClassName}
25+
waypointMenu={waypointMenuData?.menu}
2726
index={index}
2827
/>
2928
</div>

ui-manchette/src/components/WaypointMenu.tsx

-33
This file was deleted.

ui-manchette/src/stories/Manchette.stories.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type { Meta, StoryObj } from '@storybook/react';
77

88
import { SAMPLE_PATH_PROPERTIES_DATA } from './assets/sampleData';
99
import Manchette from '../components/Manchette';
10-
import type { WaypointMenuItem, StyledOperationalPointType } from '../types';
10+
import type { StyledOperationalPointType } from '../types';
11+
import Menu, { type MenuItem } from './components/Menu';
1112

1213
const operationalPointListData: StyledOperationalPointType[] =
1314
SAMPLE_PATH_PROPERTIES_DATA.operational_points?.map((op) => ({ ...op, display: true })) ?? [];
@@ -34,7 +35,7 @@ const meta: Meta<typeof Manchette> = {
3435
const ManchetteWithWaypointMenu = () => {
3536
const [activeWaypointIndex, setActiveWaypointPointIndex] = useState<number>();
3637

37-
const menuItems: WaypointMenuItem[] = [
38+
const menuItems: MenuItem[] = [
3839
{
3940
title: 'Action 1',
4041
icon: <EyeClosed />,
@@ -69,8 +70,7 @@ const ManchetteWithWaypointMenu = () => {
6970
toggleMode={() => {}}
7071
waypointMenuData={{
7172
activeWaypointIndex,
72-
waypointMenuItems: menuItems,
73-
waypointMenuClassName: 'menu',
73+
menu: <Menu items={menuItems} />,
7474
}}
7575
/>
7676
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
export type MenuItem = {
4+
title: string;
5+
icon: React.ReactNode;
6+
onClick: (e: React.MouseEvent) => void;
7+
};
8+
9+
type MenuProps = {
10+
items: MenuItem[];
11+
};
12+
13+
/**
14+
* Example of waypoint menu that could be passed to the manchette as props
15+
*/
16+
const Menu = ({ items }: MenuProps) => (
17+
<div className="menu">
18+
{items.map(({ title, icon, onClick }) => (
19+
<button key={title} type="button" className="menu-item" onClick={onClick}>
20+
<span className="icon">{icon}</span>
21+
<span>{title}</span>
22+
</button>
23+
))}
24+
</div>
25+
);
26+
27+
export default Menu;

ui-manchette/src/styles/main.css

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
@import 'tailwindcss/components';
33
@import 'tailwindcss/utilities';
44
@import 'manchette.css';
5+
@import 'menu.css';
56
@import 'operational-point.css';
67
@import 'operational-point-list.css';

ui-manchette/src/styles/manchette.css

-38
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,4 @@
11
.manchette-container {
2-
.menu {
3-
position: absolute;
4-
z-index: 10;
5-
@apply bg-grey-5;
6-
width: 305px;
7-
top: 30px;
8-
left: 0;
9-
border: 0.0625rem solid #b6b2af;
10-
border-radius: 0.5rem;
11-
box-shadow:
12-
0 0.375rem 1.3125rem -0.3125rem rgba(101, 169, 232, 0.341810533216783),
13-
0 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.2),
14-
0 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.1),
15-
inset 0 0 0 0.0625rem #ffffff;
16-
17-
/* .menu-item { */
18-
button {
19-
width: 100%;
20-
height: 2.75rem;
21-
font-size: 0.875rem;
22-
display: flex;
23-
align-items: center;
24-
25-
&:not(:first-child) {
26-
border-top: 0.0625rem solid #ffffff;
27-
}
28-
29-
&:not(:only-of-type, :last-child) {
30-
border-bottom: 0.0625rem solid #d3d1cf;
31-
}
32-
33-
/* .icon { */
34-
span:first-child {
35-
@apply text-primary-40;
36-
padding-inline: 1rem;
37-
}
38-
}
39-
}
402
.manchette-actions {
413
z-index: 11;
424
align-items: center;

ui-manchette/src/styles/menu.css

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.menu {
2+
position: absolute;
3+
z-index: 10;
4+
@apply bg-grey-5;
5+
width: 305px;
6+
top: 30px;
7+
left: 0;
8+
border: 0.0625rem solid #b6b2af;
9+
border-radius: 0.5rem;
10+
box-shadow:
11+
0 0.375rem 1.3125rem -0.3125rem rgba(101, 169, 232, 0.341810533216783),
12+
0 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.2),
13+
0 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.1),
14+
inset 0 0 0 0.0625rem #ffffff;
15+
16+
.menu-item {
17+
width: 100%;
18+
height: 2.75rem;
19+
font-size: 0.875rem;
20+
display: flex;
21+
align-items: center;
22+
23+
&:not(:first-child) {
24+
border-top: 0.0625rem solid #ffffff;
25+
}
26+
27+
&:not(:only-of-type, :last-child) {
28+
border-bottom: 0.0625rem solid #d3d1cf;
29+
}
30+
31+
.icon {
32+
@apply text-primary-40;
33+
padding-inline: 1rem;
34+
}
35+
}
36+
}

ui-manchette/src/types.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,8 @@ export type StyledOperationalPointType = OperationalPointType & {
5555
};
5656

5757
export type WaypointMenuData = {
58+
menu: React.ReactNode;
5859
activeWaypointIndex?: number;
59-
waypointMenuItems?: WaypointMenuItem[];
60-
waypointMenuClassName?: string;
61-
};
62-
63-
export type WaypointMenuItem = {
64-
title: string;
65-
icon: React.ReactNode;
66-
onClick: (e: React.MouseEvent) => void;
6760
};
6861

6962
export type ProjectPathTrainResult = {

0 commit comments

Comments
 (0)