import { Gridicon } from '@automattic/components'; import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component } from 'react'; import titlecase from 'to-title-case'; import { gaRecordEvent } from 'calypso/lib/analytics/ga'; class StatsModuleHeader extends Component { static displayName = 'StatsModuleHeader'; static propTypes = { siteId: PropTypes.number, path: PropTypes.string, title: PropTypes.string, titleLink: PropTypes.string, showInfo: PropTypes.bool, showModule: PropTypes.bool, isCollapsed: PropTypes.bool, showActions: PropTypes.bool, showCollapse: PropTypes.bool, onActionClick: PropTypes.func, }; static defaultProps = { showCollapse: true, showModule: true, showActions: true, onActionClick: () => {}, }; toggleInfo = ( event ) => { event.stopPropagation(); event.preventDefault(); const { path, onActionClick, showInfo } = this.props; const gaEvent = showInfo ? 'Closed' : 'Opened'; if ( path ) { gaRecordEvent( 'Stats', gaEvent + ' More Information Panel', titlecase( path ) ); } onActionClick( { showInfo: ! showInfo, } ); }; toggleModule = ( event ) => { event.preventDefault(); const { path, onActionClick, showModule } = this.props; const gaEvent = showModule ? 'Collapsed' : 'Expanded'; if ( path ) { gaRecordEvent( 'Stats', gaEvent + ' Module', titlecase( path ) ); } onActionClick( { showModule: ! showModule, } ); }; renderActions = () => { const { showCollapse, showInfo, showActions } = this.props; const infoIcon = showInfo ? 'info' : 'info-outline'; if ( ! showActions ) { return null; } return ( ); }; renderChevron = () => { return (
  • { /* eslint-disable-next-line jsx-a11y/anchor-is-valid */ }
  • ); }; renderTitle = () => { const { title, titleLink } = this.props; if ( titleLink ) { return (

    { title }

    ); } return

    { title }

    ; }; render() { return (
    { this.renderTitle() } { this.renderActions() }
    ); } } export default localize( StatsModuleHeader );