Skip to content

The open alternative to Salesforce, designed for AI.

1.3 KB
Raw Blame
import { useJsonTreeContextOrThrow } from '@ui/components/data-display/JsonTree/internal/hooks/useJsonTreeContextOrThrow';
import { IconChevronDown } from '@ui/icon';
import { VisuallyHidden } from '@ui/primitives/accessibility/components/VisuallyHidden';
import { themeCssVariables, useTheme } from '@ui/theme';
import { clsx } from 'clsx';

import styles from './JsonArrow.module.scss';

export const JsonArrow = ({
  isOpen,
  onClick,
  variant,
}: {
  isOpen: boolean;
  onClick: () => void;
  variant?: 'blue' | 'red';
}) => {
  const theme = useTheme();
  const { arrowButtonCollapsedLabel, arrowButtonExpandedLabel } =
    useJsonTreeContextOrThrow();

  const iconColor =
    variant === 'blue'
      ? themeCssVariables.color.blue
      : variant === 'red'
        ? themeCssVariables.font.color.danger
        : themeCssVariables.font.color.secondary;

  return (
    <button
      className={clsx(styles.button, variant === 'red' && styles.red)}
      onClick={onClick}
    >
      <VisuallyHidden>
        {isOpen ? arrowButtonExpandedLabel : arrowButtonCollapsedLabel}
      </VisuallyHidden>

      <div className={styles.chevron} data-open={isOpen || undefined}>
        <IconChevronDown size={theme.icon.size.md} color={iconColor} />
      </div>
    </button>
  );
};