<commit_before>import React, {
  useCallback,
  useContext,
  useEffect,
  useState,
  useMemo,
  Fragment,
} from 'react';
import styled, { ThemeContext } from 'styled-components';
import { defaultProps } from '../../default-props';

import { Anchor } from '../Anchor';
import { Box } from '../Box';
import { Button } from '../Button';
import { Layer } from '../Layer';
import { Paragraph } from '../Paragraph';
import { Text } from '../Text';

import { NotificationType } from './propTypes';

const adaptThemeStyle = (value, theme) => {
  let textStyle = value;
  let closeButtonStyle = value;

  if (typeof value === 'string' && theme.global.edgeSize[value]) {
    textStyle = {
      vertical: value,
      left: value,
      right: undefined,
    };
    closeButtonStyle = { vertical: value, right: value };
  } else if (typeof value === 'object') {
    const { left, right, top, bottom, horizontal, vertical } = value;
    textStyle = {
      top: top || vertical,
      bottom: bottom || vertical,
      left: left || horizontal,
      right: undefined,
    };
    closeButtonStyle = {
      top: top || vertical,
      bottom: bottom || vertical,
      right: right || horizontal,
    };
  }

  return [textStyle, closeButtonStyle];
};

const NotificationAnchor = styled(Anchor)`
  white-space: nowrap;
`;

const Notification = ({
  actions: actionsProp,
  message: messageProp,
  onClose,
  id,
  global,
  status,
  title,
  toast,
}) => {
  const autoClose =
    toast && toast?.autoClose === undefined ? true : toast.autoClose;
  const theme = useContext(ThemeContext) || defaultProps.theme;
  const [visible, setVisible] = useState(true);
  const position = useMemo(() => (toast && toast?.position) || 'top', [toast]);

  const close = useCallback(() => {
    setVisible(false);
    if (onClose) onClose();
  }, [onClose]);

  useEffect(() => {
    if (autoClose) {
      const timer = setTimeout(
        close,
        theme.notification.toast.time || theme.notification.time,
      );

      return () => clearTimeout(timer);
    }
    return undefined;
  }, [
    autoClose,
    close,
    theme.notification.toast.time,
    theme.notification.time,
  ]);

  const { icon: CloseIcon } = theme.notification.close;
  const { icon: StatusIcon, color } = theme.notification[status];
  const { color: closeIconColor } = theme.notification.close;
<commit_msg>Changed Notification to include event in onClose (#5975)<commit_after>import React, {
  useCallback,
  useContext,
  useEffect,
  useState,
  useMemo,
  Fragment,
} from 'react';
import styled, { ThemeContext } from 'styled-components';
import { defaultProps } from '../../default-props';

import { Anchor } from '../Anchor';
import { Box } from '../Box';
import { Button } from '../Button';
import { Layer } from '../Layer';
import { Paragraph } from '../Paragraph';
import { Text } from '../Text';

import { NotificationType } from './propTypes';

const adaptThemeStyle = (value, theme) => {
  let textStyle = value;
  let closeButtonStyle = value;

  if (typeof value === 'string' && theme.global.edgeSize[value]) {
    textStyle = {
      vertical: value,
      left: value,
      right: undefined,
    };
    closeButtonStyle = { vertical: value, right: value };
  } else if (typeof value === 'object') {
    const { left, right, top, bottom, horizontal, vertical } = value;
    textStyle = {
      top: top || vertical,
      bottom: bottom || vertical,
      left: left || horizontal,
      right: undefined,
    };
    closeButtonStyle = {
      top: top || vertical,
      bottom: bottom || vertical,
      right: right || horizontal,
    };
  }

  return [textStyle, closeButtonStyle];
};

const NotificationAnchor = styled(Anchor)`
  white-space: nowrap;
`;

const Notification = ({
  actions: actionsProp,
  message: messageProp,
  onClose,
  id,
  global,
  status,
  title,
  toast,
}) => {
  const autoClose =
    toast && toast?.autoClose === undefined ? true : toast.autoClose;
  const theme = useContext(ThemeContext) || defaultProps.theme;
  const [visible, setVisible] = useState(true);
  const position = useMemo(() => (toast && toast?.position) || 'top', [toast]);

  const close = useCallback((event) => {
    setVisible(false);
    if (onClose) onClose(event);
  }, [onClose]);

  useEffect(() => {
    if (autoClose) {
      const timer = setTimeout(
        close,
        theme.notification.toast.time || theme.notification.time,
      );

      return () => clearTimeout(timer);
    }
    return undefined;
  }, [
    autoClose,
    close,
    theme.notification.toast.time,
    theme.notification.time,
  ]);

  const { icon: CloseIcon } = theme.notification.close;
  const { icon: StatusIcon, color } = theme.notification[status];
  const { color: closeIconColor } = theme.notification.close;

{'fraction_non_alphanumeric': 0.14834133110786563, 'fraction_numerical': 0.0008345503859795535, 'mean_word_length': 3.1044520547945207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2971593', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1420, 'n_words': 385}