Skip to content

Commit ff3335f

Browse files
committed
fix: Adjust function declarations
1 parent b77b8ea commit ff3335f

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

src/components/ContextMenu.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const ContextMenu = ({
4747

4848
const contextMenuRef = useRef<HTMLDivElement>(null);
4949

50-
const show = (event: MouseEvent) => {
50+
function show(event: MouseEvent) {
5151
let position = getCursorPosition(event);
5252
position = validateMenuPosition(position, contextMenuRef.current);
5353

@@ -57,18 +57,18 @@ const ContextMenu = ({
5757
event.preventDefault();
5858

5959
setState((prev) => ({ ...prev, active: true, position }));
60-
};
60+
}
6161

62-
const hide = () => {
62+
function hide() {
6363
if (animateExit) setState((prev) => ({ ...prev, leaving: true }));
6464
else setState((prev) => ({ ...prev, active: false }));
65-
};
65+
}
6666

67-
const handleAnimationEnd = () => {
67+
function handleAnimationEnd() {
6868
const { leaving, active } = state;
6969

7070
if (leaving && active) setState(() => ({ position: { x: 0, y: 0 }, active: false, leaving: false }));
71-
};
71+
}
7272

7373
useEffect(() => {
7474
const { position } = state;

src/components/MenuItem.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useCallback, ButtonHTMLAttributes, useContext } from 'react';
1+
import { useState, ButtonHTMLAttributes, useContext } from 'react';
22
import cx from 'clsx';
33

44
import { ContextMenuContext } from '../context';
@@ -14,21 +14,20 @@ const MenuItem = ({ children, onClick, className, disabled = false, ...rest }: M
1414
const context = useContext(ContextMenuContext);
1515
const [state, setState] = useState<MenuItemState>({ clicked: false, eventRef: null });
1616

17-
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
17+
function handleClick(event: React.MouseEvent<HTMLButtonElement>) {
1818
event.stopPropagation();
1919

2020
if (onClick) setState({ clicked: true, eventRef: event });
21-
};
21+
}
2222

23-
const handleAnimationEnd = useCallback(() => {
23+
function handleAnimationEnd() {
2424
setState((prev) => ({ ...prev, clicked: false }));
2525

2626
if (state.clicked && state.eventRef) {
2727
context?.hide();
2828
onClick!(state.eventRef);
2929
}
30-
// eslint-disable-next-line react-hooks/exhaustive-deps
31-
}, [state.clicked, state.eventRef]);
30+
}
3231

3332
const classNames = cx('react-context-menu__item', className, {
3433
'react-context-menu__item--disabled': disabled,

src/components/SubMenu.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const SubMenu = ({
3737
};
3838
}, []);
3939

40-
const clearTimer = () => {
40+
function clearTimer() {
4141
if (timeoutRef.current) clearTimeout(timeoutRef.current);
42-
};
42+
}
4343

44-
const calculatePosition = () => {
44+
function calculatePosition() {
4545
if (subMenuRef.current && itemRef.current) {
4646
clearTimer();
4747
setActive(true);
@@ -59,15 +59,15 @@ const SubMenu = ({
5959
subMenuRef.current.classList.add(BOTTOM_CLASS);
6060
}
6161
}
62-
};
62+
}
6363

64-
const onLeave = () => {
64+
function onLeave() {
6565
clearTimer();
6666

6767
timeoutRef.current = setTimeout(() => {
6868
setActive(false);
6969
}, CLOSE_DELAY);
70-
};
70+
}
7171

7272
const classNames = cx('react-context-menu__item', className, {
7373
'react-context-menu__item--disabled': disabled,

src/stories/ContextMenu.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,21 @@ export const SubMenu: Story = {
120120
</StoryWrapper>
121121
),
122122
};
123+
124+
export const SubMenuIndicator: Story = {
125+
args: {
126+
children: [
127+
<ContextMenu.Item onClick={() => clickFunction()}>Item 1</ContextMenu.Item>,
128+
<ContextMenu.Separator />,
129+
<ContextMenu.SubMenu label="Sub Menu" iconElement={<span></span>}>
130+
<ContextMenu.Item onClick={() => clickFunction()}>Sub item 2</ContextMenu.Item>
131+
<ContextMenu.Item onClick={() => clickFunction()}>Sub item 3</ContextMenu.Item>
132+
</ContextMenu.SubMenu>,
133+
],
134+
},
135+
render: (args) => (
136+
<StoryWrapper triggerId={TRIGGER_ID}>
137+
<ContextMenu {...args} />
138+
</StoryWrapper>
139+
),
140+
};

0 commit comments

Comments
 (0)