import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const propTypes = {
  children: PropTypes.node,
  className: PropTypes.string,
  defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
  /**
   * The component used for the root node.
   * Either a string to use a DOM element or a component.
   */
  tag: PropTypes.elementType,
};

const defaultProps = {
  children: '',
  className: '',
  defaultClassName: 'sui-o-datalist__title',
  tag: 'div',
};

export const DatalistTitle = ({
  children,
  className,
  defaultClassName,
  tag: Tag,
  ...props
}) => {
  const classes = classnames(
    defaultClassName,
    className,
  );

  return (
    <Tag className={classes} {...props}>
      { children }
    </Tag>
  );
};

DatalistTitle.propTypes = propTypes;
DatalistTitle.defaultProps = defaultProps;
