import React, {PureComponent} from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

class ToolbarTitle extends PureComponent {
  static displayName = 'ToolbarTitle'

  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    tagName: PropTypes.oneOf(['span', 'div']),
  }

  static defaultProps = {
    tagName: 'span',
  }

  render() {
    const {
      children,
      className,
      tagName,
      ...otherProps,
    } = this.props
    const cssClasses = classNames('mdc-toolbar__title', className)
    return React.createElement(
      tagName,
      {...otherProps, className: cssClasses},
      children
    )
  }
}

export default ToolbarTitle

import React, {PureComponent} from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

class ToolbarTitle extends PureComponent {
  static displayName = 'ToolbarTitle'

  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    tagName: PropTypes.oneOf(['span', 'div']),
  }

  static defaultProps = {
    tagName: 'span',
  }

  render() {
    const {
      children,
      className,
      tagName,
      ...otherProps,
    } = this.props
    const cssClasses = classNames('mdc-toolbar__title', className)
    return React.isValidElement(children) ? React.cloneElement(children, {
      className: classNames('mdc-toolbar__title', children.props.className),
    }) : React.createElement(
      tagName,
      {...otherProps, className: cssClasses},
      children
    )
  }
}

export default ToolbarTitle

Allow to pass an element to ToolbarTitle