{"size": 815, "ext": "js", "max_stars_repo_path": "src/components/mediabox/mediabox_header.js", "max_stars_repo_name": "charleyw/react-weui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/mediabox/mediabox_header.js", "max_issues_repo_name": "charleyw/react-weui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/mediabox/mediabox_header.js", "max_forks_repo_name": "charleyw/react-weui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.1851851852, "max_line_length": 100, "alphanum_fraction": 0.5840490798}
import React from 'react';
import classNames from 'classnames';

/**
 * Header of MediaBox, if detects Img tag inside content will automatically adds corresponding class
 *
 */
export default class MediaBoxHeader extends React.Component {
    render() {
        const {children, className, ...others} = this.props;
        const clz = classNames({
            'weui-media-box__hd': true
        }, className);

        let childrenWithProps = React.Children.map(children, child => {
            if(child.type == 'img' && !child.props.className){
              return React.cloneElement(child, { className: 'weui-media-box__thumb' });
            }else{
              return child;
            }
        });

        return (
            <div className={clz} {...others}>{childrenWithProps}</div>
        );
    }
};