The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { css } from '@linaria/core';
import { type LinkChipProps } from './types/LinkChipProps';
import { LINK_CHIP_CLICK_OUTSIDE_ID } from '@/ui/navigation/link/constants/LinkChipClickOutsideId';
import { useMouseDownNavigation } from '@/ui/navigation/hooks/useMouseDownNavigation';
import { Chip } from 'twenty-ui/primitives/data-display';
const styles = {
linkContainer: css`
& {
display: inline-flex;
min-width: 0;
vertical-align: middle;
}
`,
};
export const LinkChip = ({
to,
target,
onClick,
onMouseDown,
triggerEvent,
ref,
...props
}: LinkChipProps) => {
const { onClick: onClickHandler, onMouseDown: onMouseDownHandler } =
useMouseDownNavigation({ to, onClick, triggerEvent });
return (
<span className={styles.linkContainer}>
<Chip
clickable
{...props}
render={
<a
href={to}
ref={ref}
onClick={(event) => {
event.stopPropagation();
const isKeyboardClick = event.detail === 0;
if (isKeyboardClick && triggerEvent !== 'CLICK') {
onMouseDownHandler(event);
}
onClickHandler(event);
}}
onMouseDown={(event) => {
onMouseDown?.(event);
if (!event.defaultPrevented) {
onMouseDownHandler(event);
}
}}
data-click-outside-id={LINK_CHIP_CLICK_OUTSIDE_ID}
target={target}
rel={target === '_blank' ? 'noopener noreferrer' : undefined}
/>
}
/>
</span>
);
};