<commit_before>import React, { useState, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

import Icon from '../../base/icons/Icon';
import Button from '../../controls/buttons/Button';
import Popup from './Popup';

const Container = styled.div`
  display: inline-block;
`;

const PopoverContainer = styled.div`
  background: ${props => props.theme.colors.white};
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  min-width: 270px;
`;

const PopoverHeader = styled.div`
  background-color: ${props =>
    props.hasTitle ? props.theme.colors.popoverHeader : 'none'};
  color: ${props => props.theme.colors.white};
  display: flex;
  justify-content: space-between;
  line-height: ${props => props.theme.sizes.baseLineHeight};
  outline: none;
`;

const TitleBar = styled.h3`
  font-size: 18px;
  margin: 0;
  padding: 8px 14px;
`;

const PopoverBody = styled.div`
  color: ${props => props.theme.colors.gray8};
  font-size: 18px;
  font-weight: normal;
  line-height: ${props => props.theme.sizes.baseLineHeight};
  padding: ${props =>
    props.hasAltCloseWithNoTitle ? '0 14px 8px' : '8px 14px'};
  text-align: right;
`;

const PopoverContent = styled.div`
  margin-bottom: ${props => (props.showCloseButton ? '8px' : '0')};
  text-align: left;
`;

const PopoverCloseButton = styled(Button)`
  display: inline-block;
  width: auto;
`;

const AlternateCloseButton = styled(PopoverCloseButton)`
  background: transparent;
  border: none;
  box-shadow: none;
  color: ${props =>
    props.hasTitle ? props.theme.colors.white : props.theme.colors.grayDark};
  margin: 0;
  margin-left: auto;
  padding: 0 8px;

  &:hover {
    background: transparent;
  }
`;

const CloseHelpText = styled.span`
  color: transparent;
  height: 1px;
  outline: 0;
  width: 1px;
`;

function Popover(props) {
  const {
    name,
    title,
    content,
    placement,
    arrowSize,
    renderTrigger,
    hasCloseButton,
    hasAltCloseButton,
    disableRootClose,
    disableFlipping
  } = props;

  const hasTitle = title !== undefined;
  const hasAltCloseWithNoTitle = !hasTitle && hasAltCloseButton;
  const showCloseButton = hasCloseButton && !hasAltCloseButton;

  const closeBtnRef = useRef(null);
  const triggerBtnRef = useRef(null);
  const popperRef = useRef(null);
  const contentRef = useRef(null);
  const headerRef = useRef(null);

  const [isOpen, setIsOpen] = useState(false);

  function toggleShow() {
    setTimeout(() => {
      if (contentRef.current) {
        const focusableContent = contentRef.current.querySelector('a, button');
        if (focusableContent) {
          focusableContent.focus();
        } else {
          headerRef.current.focus();
        }
      }
    }, 200);
    if (closeBtnRef.current) {
      triggerBtnRef.current.focus();
    }
    setIsOpen(!isOpen);
  }

  function hidePopover(event) {
    if (isOpen) {
      if (event.type !== 'click') {<commit_msg>Fix: popovers in labels should properly activate cross-browsers<commit_after>import React, { useState, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

import Icon from '../../base/icons/Icon';
import Button from '../../controls/buttons/Button';
import Popup from './Popup';

const Container = styled.div`
  display: inline-block;
`;

const PopoverContainer = styled.div`
  background: ${props => props.theme.colors.white};
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  min-width: 270px;
`;

const PopoverHeader = styled.div`
  background-color: ${props =>
    props.hasTitle ? props.theme.colors.popoverHeader : 'none'};
  color: ${props => props.theme.colors.white};
  display: flex;
  justify-content: space-between;
  line-height: ${props => props.theme.sizes.baseLineHeight};
  outline: none;
`;

const TitleBar = styled.h3`
  font-size: 18px;
  margin: 0;
  padding: 8px 14px;
`;

const PopoverBody = styled.div`
  color: ${props => props.theme.colors.gray8};
  font-size: 18px;
  font-weight: normal;
  line-height: ${props => props.theme.sizes.baseLineHeight};
  padding: ${props =>
    props.hasAltCloseWithNoTitle ? '0 14px 8px' : '8px 14px'};
  text-align: right;
`;

const PopoverContent = styled.div`
  margin-bottom: ${props => (props.showCloseButton ? '8px' : '0')};
  text-align: left;
`;

const PopoverCloseButton = styled(Button)`
  display: inline-block;
  width: auto;
`;

const AlternateCloseButton = styled(PopoverCloseButton)`
  background: transparent;
  border: none;
  box-shadow: none;
  color: ${props =>
    props.hasTitle ? props.theme.colors.white : props.theme.colors.grayDark};
  margin: 0;
  margin-left: auto;
  padding: 0 8px;

  &:hover {
    background: transparent;
  }
`;

const CloseHelpText = styled.span`
  color: transparent;
  height: 1px;
  outline: 0;
  width: 1px;
`;

function Popover(props) {
  const {
    name,
    title,
    content,
    placement,
    arrowSize,
    renderTrigger,
    hasCloseButton,
    hasAltCloseButton,
    disableRootClose,
    disableFlipping
  } = props;

  const hasTitle = title !== undefined;
  const hasAltCloseWithNoTitle = !hasTitle && hasAltCloseButton;
  const showCloseButton = hasCloseButton && !hasAltCloseButton;

  const closeBtnRef = useRef(null);
  const triggerBtnRef = useRef(null);
  const popperRef = useRef(null);
  const contentRef = useRef(null);
  const headerRef = useRef(null);

  const [isOpen, setIsOpen] = useState(false);

  function toggleShow(event) {
    event.preventDefault();
    event.stopPropagation();

    setTimeout(() => {
      if (contentRef.current) {
        const focusableContent = contentRef.current.querySelector('a, button');
        if (focusableContent) {
          focusableContent.focus();
        } else {
          headerRef.current.focus();
        }
      }
    }, 200);
    if (closeBtnRef.current) {
      triggerBtnRef.current.focus();
    }
    setIsOpen(!isOpen);
  }

  function hidePopover(event) {
    if (isOpen) {
      if (event.type !== 'click') {
{'fraction_non_alphanumeric': 0.14008163265306123, 'fraction_numerical': 0.016, 'mean_word_length': 3.517699115044248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4740818', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2041, 'n_words': 475}