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

69 lines
1.7 KiB
React
Raw Normal View History

2021-07-28 18:45:52 +05:30
import React from 'react';
import PropTypes from 'prop-types';
import './IconButton.scss';
import RawIcon from '../system-icons/RawIcon';
2021-08-10 16:58:16 +05:30
import Tooltip from '../tooltip/Tooltip';
2021-07-28 18:45:52 +05:30
import { blurOnBubbling } from './script';
import Text from '../text/Text';
const IconButton = React.forwardRef(({
variant, size, type,
2021-12-24 15:05:56 +05:30
tooltip, tooltipPlacement, src,
2021-12-30 12:44:14 +05:30
onClick, tabIndex, disabled, isImage,
2022-04-24 11:23:10 +01:00
className,
2021-09-02 19:17:33 +05:30
}, ref) => {
const btn = (
2021-07-28 18:45:52 +05:30
<button
ref={ref}
2022-04-24 11:23:10 +01:00
className={`ic-btn ic-btn-${variant} ${className}`}
2021-07-28 18:45:52 +05:30
onMouseUp={(e) => blurOnBubbling(e, `.ic-btn-${variant}`)}
onClick={onClick}
2021-10-22 17:13:57 +05:30
// eslint-disable-next-line react/button-has-type
type={type}
2021-12-10 17:22:53 +05:30
tabIndex={tabIndex}
2021-12-24 15:05:56 +05:30
disabled={disabled}
2021-07-28 18:45:52 +05:30
>
2021-12-30 12:44:14 +05:30
<RawIcon size={size} src={src} isImage={isImage} />
2021-07-28 18:45:52 +05:30
</button>
2021-09-02 19:17:33 +05:30
);
if (tooltip === null) return btn;
return (
<Tooltip
placement={tooltipPlacement}
content={<Text variant="b2">{tooltip}</Text>}
>
{btn}
</Tooltip>
);
});
2021-07-28 18:45:52 +05:30
IconButton.defaultProps = {
variant: 'surface',
size: 'normal',
type: 'button',
2021-09-02 19:17:33 +05:30
tooltip: null,
2021-07-28 18:45:52 +05:30
tooltipPlacement: 'top',
onClick: null,
2021-12-10 17:22:53 +05:30
tabIndex: 0,
2021-12-24 15:05:56 +05:30
disabled: false,
2021-12-30 12:44:14 +05:30
isImage: false,
2022-04-24 11:23:10 +01:00
className: '',
2021-07-28 18:45:52 +05:30
};
IconButton.propTypes = {
2021-12-03 18:26:18 +05:30
variant: PropTypes.oneOf(['surface', 'primary', 'positive', 'caution', 'danger']),
2021-07-28 18:45:52 +05:30
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
2021-10-22 17:13:57 +05:30
type: PropTypes.oneOf(['button', 'submit', 'reset']),
2021-09-02 19:17:33 +05:30
tooltip: PropTypes.string,
2021-07-28 18:45:52 +05:30
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
src: PropTypes.string.isRequired,
onClick: PropTypes.func,
2021-12-10 17:22:53 +05:30
tabIndex: PropTypes.number,
2021-12-24 15:05:56 +05:30
disabled: PropTypes.bool,
2021-12-30 12:44:14 +05:30
isImage: PropTypes.bool,
2022-04-24 11:23:10 +01:00
className: PropTypes.string,
2021-07-28 18:45:52 +05:30
};
export default IconButton;