/**
 * imui.Form.Label
 * @author moxhe
 * @date 2016-08-07
 */
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
// @require '../style/index.scss'

export default function Label(props) {
  const { prefixCls, className, help, htmlFor, required } = props;

  const clsStr = {
    [className]: !!className,
    [prefixCls]: true
  };

  return (
    <label htmlFor={htmlFor} className={classnames(clsStr)}>
      {required ? <span className={`${prefixCls}-required`}>*</span> : null}
      {props.children}
      {help ? <span className={`${prefixCls}-help`}>[<a href={help} target="_blank">?</a>]</span> : null}
    </label>
  );
}

Label.propTypes = {
  /**
   * 原生label元素的for属性，应为对应表单组件的name
   */
  help: PropTypes.string,
  /**
   * 是否显示帮助链接(target都是_blank)
   */
  htmlFor: PropTypes.string,
  /**
   * 是否显示必填标志
   */
  required: PropTypes.bool
};

Label.defaultProps = {
  prefixCls: 'im-label',
  htmlFor: ''
};
