@datalayer/core
Version:
**Datalayer Core**
25 lines (24 loc) • 1.04 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/
import { useCallback, useState } from 'react';
import { IconButton, Spinner } from '@primer/react';
/**
* Icon button displaying a spinner while its callback is running.
*/
export function LongActionButton(props) {
const { label, disabled, onClick, icon, inProgress } = props;
const [internalInProgress, setInternalInProgress] = useState(false);
const handleClick = useCallback(async () => {
setInternalInProgress(true);
try {
await onClick();
}
finally {
setInternalInProgress(false);
}
}, [onClick, setInternalInProgress]);
return (_jsx(IconButton, { "aria-label": label, title: label, disabled: disabled || internalInProgress || inProgress, icon: internalInProgress || inProgress ? () => _jsx(Spinner, { size: "small" }) : icon, size: "small", variant: "invisible", onClick: handleClick }));
}