File size: 1,168 Bytes
c390d22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1c2b86
 
 
 
 
 
 
 
 
 
 
c390d22
 
 
 
 
 
 
 
 
f1c2b86
 
 
 
c390d22
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
}) => (
    <div
        className={classNames(
            styles.container,
            className,
            disabled ? styles.disabled : null
        )}
        role="button"
        onClick={disabled ? null : onClick}
    >
        {typeof img === 'string' ? (
            <img
                className={styles.icon}
                draggable={false}
                src={img}
                alt=""
            />
        ) : (
            // Reactコンポーネントとして描画
            React.cloneElement(img, { className: styles.icon })
        )}
        <div className={styles.title}>
            {title}
        </div>
    </div>
);

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;