Skip to content

The open alternative to Salesforce, designed for AI.

2.4 KB
Raw Blame
import { useRender } from '@base-ui/react/use-render';
import { clsx } from 'clsx';

import { IconHelp, IconX } from '@ui/icon/components/TablerIcons';
import { Button } from '@ui/primitives/input/Button/Button';
import { FEEDBACK_STATUS_COLORS } from '@ui/primitives/feedback/internal/constants/FeedbackStatusColors';
import { themeCssVariables } from '@ui/theme';
import { isRenderableSlot } from '@ui/utilities/internal/isRenderableSlot';
import { isDefined } from '@ui/utilities/utils/isDefined';

import styles from '../Callout.module.scss';
import { type CalloutProps } from '../types/CalloutProps';
import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';

export const CalloutComponent = ({
  status = 'info',
  variant = 'soft',
  color = FEEDBACK_STATUS_COLORS[status],
  title,
  description,
  fullWidth = false,
  icon = <IconHelp size={themeCssVariables.icon.size.md} aria-hidden="true" />,
  action,
  closeLabel = doNotTranslate('Close'),
  onDismiss,
  className,
  render,
  ref,
  ...props
}: CalloutProps) => {
  const hasIcon = isRenderableSlot(icon);
  const hasAction = isRenderableSlot(action);

  return useRender({
    render,
    ref,
    state: { status, variant, color },
    props: {
      ...props,
      className: clsx(
        styles.container,
        fullWidth && styles.containerFullWidth,
        className,
      ),
      children: (
        <>
          <div className={styles.header}>
            {hasIcon && <div className={styles.iconContainer}>{icon}</div>}
            <div className={styles.title}>{title}</div>
            {isDefined(onDismiss) && (
              <Button
                type="button"
                startIcon={<IconX aria-hidden="true" />}
                className={styles.closeButton}
                variant="ghost"
                size="sm"
                aria-label={closeLabel}
                onClick={() => onDismiss()}
              />
            )}
          </div>
          {isRenderableSlot(description) && (
            <div
              className={clsx(
                styles.descriptionWrapper,
                hasIcon && styles.descriptionWrapperWithIcon,
                hasAction && styles.descriptionWrapperWithAction,
              )}
            >
              <div className={styles.description}>{description}</div>
            </div>
          )}
          {hasAction && <div className={styles.footer}>{action}</div>}
        </>
      ),
    },
  });
};