cinny/src/app/atoms/button/IconButton.jsx

60 lines
1.5 KiB
React
Raw Normal View History

2021-07-28 22:15:52 +09:00
import React from 'react';
import PropTypes from 'prop-types';
import './IconButton.scss';
import RawIcon from '../system-icons/RawIcon';
2021-08-10 20:28:16 +09:00
import Tooltip from '../tooltip/Tooltip';
2021-07-28 22:15:52 +09:00
import { blurOnBubbling } from './script';
import Text from '../text/Text';
const IconButton = React.forwardRef(({
variant, size, type,
tooltip, tooltipPlacement, src, onClick, tabIndex,
2021-09-02 22:47:33 +09:00
}, ref) => {
const btn = (
2021-07-28 22:15:52 +09:00
<button
ref={ref}
2021-09-05 17:34:51 +09:00
className={`ic-btn ic-btn-${variant}`}
2021-07-28 22:15:52 +09:00
onMouseUp={(e) => blurOnBubbling(e, `.ic-btn-${variant}`)}
onClick={onClick}
// eslint-disable-next-line react/button-has-type
type={type}
tabIndex={tabIndex}
2021-07-28 22:15:52 +09:00
>
<RawIcon size={size} src={src} />
</button>
2021-09-02 22:47:33 +09:00
);
if (tooltip === null) return btn;
return (
<Tooltip
placement={tooltipPlacement}
content={<Text variant="b2">{tooltip}</Text>}
>
{btn}
</Tooltip>
);
});
2021-07-28 22:15:52 +09:00
IconButton.defaultProps = {
variant: 'surface',
size: 'normal',
type: 'button',
2021-09-02 22:47:33 +09:00
tooltip: null,
2021-07-28 22:15:52 +09:00
tooltipPlacement: 'top',
onClick: null,
tabIndex: 0,
2021-07-28 22:15:52 +09:00
};
IconButton.propTypes = {
variant: PropTypes.oneOf(['surface', 'primary', 'positive', 'caution', 'danger']),
2021-07-28 22:15:52 +09:00
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
type: PropTypes.oneOf(['button', 'submit', 'reset']),
2021-09-02 22:47:33 +09:00
tooltip: PropTypes.string,
2021-07-28 22:15:52 +09:00
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
src: PropTypes.string.isRequired,
onClick: PropTypes.func,
tabIndex: PropTypes.number,
2021-07-28 22:15:52 +09:00
};
export default IconButton;