Left menu and chip links (#12294)
Small optimization for faster loading (gaining ~80ms - average time of a click) It might seem a little over-engineered but there are a lot of edge cases and I couldn't find a simpler solution I also tried to tackle Link Chips but it's more complex so this will be for another PR
This commit is contained in:
@ -3,6 +3,7 @@ import { AvatarChipsCommonProps } from '@ui/components/avatar-chip/types/AvatarC
|
||||
import { AvatarChipVariant } from '@ui/components/avatar-chip/types/AvatarChipsVariant.type';
|
||||
import { ChipVariant } from '@ui/components/chip/Chip';
|
||||
import { LinkChip, LinkChipProps } from '@ui/components/chip/LinkChip';
|
||||
import { TriggerEventType } from '@ui/utilities';
|
||||
|
||||
export type LinkAvatarChipProps = Omit<
|
||||
AvatarChipsCommonProps,
|
||||
@ -10,8 +11,10 @@ export type LinkAvatarChipProps = Omit<
|
||||
> & {
|
||||
to: string;
|
||||
onClick?: LinkChipProps['onClick'];
|
||||
onMouseDown?: LinkChipProps['onMouseDown'];
|
||||
variant?: AvatarChipVariant;
|
||||
isLabelHidden?: boolean;
|
||||
triggerEvent?: TriggerEventType;
|
||||
};
|
||||
|
||||
export const LinkAvatarChip = ({
|
||||
@ -29,6 +32,7 @@ export const LinkAvatarChip = ({
|
||||
size,
|
||||
variant,
|
||||
isLabelHidden,
|
||||
triggerEvent,
|
||||
}: LinkAvatarChipProps) => (
|
||||
<LinkChip
|
||||
to={to}
|
||||
@ -55,5 +59,6 @@ export const LinkAvatarChip = ({
|
||||
}
|
||||
className={className}
|
||||
maxWidth={maxWidth}
|
||||
triggerEvent={triggerEvent}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -6,6 +6,8 @@ import {
|
||||
ChipSize,
|
||||
ChipVariant,
|
||||
} from '@ui/components/chip/Chip';
|
||||
import { LINK_CHIP_CLICK_OUTSIDE_ID } from '@ui/components/chip/constants/LinkChipClickOutsideId';
|
||||
import { TriggerEventType, useMouseDownNavigation } from '@ui/utilities';
|
||||
import { MouseEvent } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
@ -14,7 +16,9 @@ export type LinkChipProps = Omit<
|
||||
'onClick' | 'disabled' | 'clickable'
|
||||
> & {
|
||||
to: string;
|
||||
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
||||
onClick?: (event: MouseEvent<HTMLElement>) => void;
|
||||
onMouseDown?: (event: MouseEvent<HTMLElement>) => void;
|
||||
triggerEvent?: TriggerEventType;
|
||||
};
|
||||
|
||||
const StyledLink = styled(Link)`
|
||||
@ -34,9 +38,25 @@ export const LinkChip = ({
|
||||
className,
|
||||
maxWidth,
|
||||
onClick,
|
||||
triggerEvent,
|
||||
}: LinkChipProps) => {
|
||||
const { onClick: onClickHandler, onMouseDown: onMouseDownHandler } =
|
||||
useMouseDownNavigation({
|
||||
to: to,
|
||||
onClick: onClick,
|
||||
triggerEvent,
|
||||
});
|
||||
|
||||
return (
|
||||
<StyledLink to={to} onClick={onClick}>
|
||||
<StyledLink
|
||||
to={to}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onClickHandler(event);
|
||||
}}
|
||||
onMouseDown={onMouseDownHandler}
|
||||
data-click-outside-id={LINK_CHIP_CLICK_OUTSIDE_ID}
|
||||
>
|
||||
<Chip
|
||||
size={size}
|
||||
label={label}
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export const LINK_CHIP_CLICK_OUTSIDE_ID = 'link-chip-click-outside-id';
|
||||
@ -17,6 +17,7 @@ export type { AvatarChipsCommonProps } from './avatar-chip/types/AvatarChipsComm
|
||||
export { AvatarChipVariant } from './avatar-chip/types/AvatarChipsVariant.type';
|
||||
export type { ChipProps } from './chip/Chip';
|
||||
export { ChipSize, ChipAccent, ChipVariant, Chip } from './chip/Chip';
|
||||
export { LINK_CHIP_CLICK_OUTSIDE_ID } from './chip/constants/LinkChipClickOutsideId';
|
||||
export type { LinkChipProps } from './chip/LinkChip';
|
||||
export { LinkChip } from './chip/LinkChip';
|
||||
export { Pill } from './Pill/Pill';
|
||||
|
||||
Reference in New Issue
Block a user