mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 07:53:54 +00:00
b7e758bf24
* chore: add typescript and dependencies * refactor: remove react imports * refactor: fix entrypoint * chore: upgrade chakra and deps * chore: configure eslint
37 lines
980 B
React
37 lines
980 B
React
import { useCallback, useState } from 'react';
|
|
import { IconButton } from '@chakra-ui/button';
|
|
import { Tooltip } from '@chakra-ui/tooltip';
|
|
import PropTypes from 'prop-types';
|
|
|
|
export default function TooltipLoadingActionBtn(props) {
|
|
const { clickHandler, icon, color, size = 'xs', tooltip, ...rest } = props;
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const handleClick = useCallback(() => {
|
|
setLoading(true);
|
|
clickHandler();
|
|
},[clickHandler, setLoading]);
|
|
|
|
return (
|
|
<Tooltip label={tooltip} shouldWrapChildren={loading}>
|
|
<IconButton
|
|
aria-label={tooltip}
|
|
size={size}
|
|
icon={icon}
|
|
onClick={handleClick}
|
|
disabled={loading}
|
|
isLoading={loading}
|
|
{...rest}
|
|
/>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
TooltipLoadingActionBtn.propTypes = {
|
|
clickHandler: PropTypes.func,
|
|
icon: PropTypes.element,
|
|
color: PropTypes.string,
|
|
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg']),
|
|
tooltip: PropTypes.string,
|
|
};
|