import PropTypes from 'prop-types'; import React from 'react'; import classNames from 'classnames'; import styles from './icon-button.css'; const IconButton = ({ img, disabled, className, title, onClick }) => (
{typeof img === 'string' ? ( ) : ( // Reactコンポーネントとして描画 React.cloneElement(img, { className: styles.icon }) )}
{title}
); IconButton.propTypes = { className: PropTypes.string, disabled: PropTypes.bool, img: PropTypes.oneOfType([ PropTypes.string, PropTypes.element ]), onClick: PropTypes.func.isRequired, title: PropTypes.node.isRequired }; export default IconButton;