Skip to content

The open alternative to Salesforce, designed for AI.

1.3 KB
Raw Blame
import { LEGEND_HIGHLIGHT_DIMMED_OPACITY } from '@/page-layout/widgets/graph/constants/LegendHighlightDimmedOpacity';
import { graphWidgetHighlightedLegendIdComponentState } from '@/page-layout/widgets/graph/states/graphWidgetHighlightedLegendIdComponentState';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAnimatedPath } from '@nivo/core';
import { animated } from '@react-spring/web';
import { isDefined } from 'twenty-shared/utils';
import { doNotTranslate } from 'twenty-shared/i18n';

type LineAnimatedAreaPathProps = {
  id: string;
  path: string;
  fillId: string;
};

export const LineAnimatedAreaPath = ({
  id,
  path,
  fillId,
}: LineAnimatedAreaPathProps) => {
  const animatedPath = useAnimatedPath(path);

  const graphWidgetHighlightedLegendId = useAtomComponentStateValue(
    graphWidgetHighlightedLegendIdComponentState,
  );

  const isDimmed =
    isDefined(graphWidgetHighlightedLegendId) &&
    graphWidgetHighlightedLegendId !== id;

  return (
    <animated.path
      d={animatedPath}
      fill={`url(#${fillId})`}
      strokeWidth={0}
      opacity={isDimmed ? LEGEND_HIGHLIGHT_DIMMED_OPACITY : 1}
      style={{
        transition: doNotTranslate('opacity 0.15s ease-in-out'),
      }}
    />
  );
};