Skip to content

Commit

Permalink
feat: supported events in onClick callbacks (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: sunduckcow <[email protected]>
  • Loading branch information
sunduckcow and sunduckcow authored Aug 15, 2023
1 parent 4bac263 commit a861031
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/components/AsideHeader/AsideHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ export class AsideHeader extends React.Component<AsideHeaderInnerProps> {
this.props.onClosePanel?.();
};

private onItemClick = (item: MenuItem, collapsed: boolean) => {
private onItemClick = (
item: MenuItem,
collapsed: boolean,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
this.props.onClosePanel?.();
item.onItemClick?.(item, collapsed);
item.onItemClick?.(item, collapsed, event);
};

private onLogoClick = (event: React.MouseEvent<HTMLElement, MouseEvent>) => {
Expand Down
10 changes: 7 additions & 3 deletions src/components/CompositeBar/CompositeBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const b = block('composite-bar');

interface CompositeBarBaseProps {
items: MenuItem[];
onItemClick?: (item: MenuItem, collapsed: boolean) => void;
onItemClick?: (
item: MenuItem,
collapsed: boolean,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => void;
multipleTooltip?: boolean;
}

Expand Down Expand Up @@ -117,7 +121,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({

const onItemClickByIndex = useCallback(
(itemIndex): ItemProps['onItemClick'] =>
(item, collapsed) => {
(item, collapsed, event) => {
if (
compact &&
multipleTooltip &&
Expand All @@ -129,7 +133,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
active: false,
});
}
onItemClick?.(item, collapsed);
onItemClick?.(item, collapsed, event);
},
[lastClickedItemIndex, setMultipleTooltipContextValue],
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {block} from '../utils/cn';
import {LogoProps} from '../types';
import {Button, Icon} from '@gravity-ui/uikit';

import './Logo.scss';
import {useAsideHeaderContext} from '../AsideHeader/AsideHeaderContext';

import './Logo.scss';

const b = block('logo');

export const Logo: React.FC<LogoProps> = ({
Expand Down
6 changes: 5 additions & 1 deletion src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export interface MenuItem {
link?: string;
current?: boolean;
pinned?: boolean;
onItemClick?: (item: MenuItem, collapsed: boolean) => void;
onItemClick?: (
item: MenuItem,
collapsed: boolean,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => void;
itemWrapper?: (
p: MakeItemParams,
makeItem: (p: MakeItemParams) => React.ReactNode,
Expand Down

0 comments on commit a861031

Please sign in to comment.