Files
wanderer/assets/js/hooks/Mapper/components/ui-kit/WdImgButton/WdImgButton.tsx
Aleksei Chichenkov b2ae5a33ae System comments & refactoring (#253)
* feat(Map): Add widget for comments. Refactor design of Signatures widget. Refactor a lot of code. Add Transition component in ui-kit. Sync versions of react.

---------

Co-authored-by: Dmitry Popov <dmitriypopovsamara@gmail.com>
Co-authored-by: achichenkov <aleksei.chichenkov@telleqt.ai>
2025-03-14 15:34:12 +04:00

60 lines
1.5 KiB
TypeScript

import classes from './WdImgButton.module.scss';
import clsx from 'clsx';
import { WithClassName } from '@/hooks/Mapper/types/common.ts';
import { HTMLProps, MouseEvent } from 'react';
import { WdTooltipWrapper, WdTooltipWrapperProps } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
export enum WdImageSize {
off = 'off',
small = 'small',
normal = 'normal',
large = 'large',
}
export type WdImgButtonProps = {
onClick?(e: MouseEvent): void;
source?: string;
width?: number;
height?: number;
tooltip?: Pick<WdTooltipWrapperProps, 'content' | 'position' | 'offset' | 'className'>;
textSize?: WdImageSize;
} & WithClassName &
HTMLProps<HTMLDivElement>;
export const WdImgButton = ({
onClick,
className,
source,
width = 20,
height = 20,
textSize = WdImageSize.normal,
tooltip,
disabled,
...props
}: WdImgButtonProps) => {
const content = (
<div
{...props}
className={clsx(
classes.WdImgButtonRoot,
{
[classes.Normal]: textSize === WdImageSize.normal,
[classes.Large]: textSize === WdImageSize.large,
[classes.Disabled]: disabled,
},
'pi cursor-pointer',
className,
)}
onClick={disabled ? undefined : onClick}
>
{source && <img src={source} width={width} height={height} className="external-icon" />}
</div>
);
if (tooltip) {
return <WdTooltipWrapper {...tooltip}>{content}</WdTooltipWrapper>;
}
return content;
};