Files
powerpoint-toolbox/src/taskpane/components/ActionButton.tsx
T
schihei 50966867b2 Improve TypeScript types and error handling
- Created proper TypeScript types for Office API operations
- Replaced 'any' casts with appropriate types
- Added type-safe utility functions in office-types.ts
- Improved error handling with proper unknown type
- Added helper functions for PowerPoint shape operations
- Created proper TypeScript interface for webpack HMR

These changes improve code quality, maintainability, and help catch potential bugs at compile time rather than runtime.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-15 00:02:35 +01:00

64 lines
1.5 KiB
TypeScript

import * as React from "react";
import { Button, ButtonProps } from "@fluentui/react-components";
import { useStatusContext } from "./App";
import { useCommonStyles } from "./commonStyles";
import { getErrorMessage } from "../types/office-types";
export interface ActionButtonProps {
icon: ButtonProps["icon"];
onClick: () => Promise<void>;
disabled?: boolean;
title: string;
appearance?: "primary" | "secondary" | "outline" | "subtle";
className?: string;
}
/**
* Reusable action button component with consistent styling and error handling
*/
export const ActionButton: React.FC<ActionButtonProps> = ({
icon,
onClick,
disabled = false,
title,
appearance = "primary",
className = "",
}) => {
const styles = useCommonStyles();
const {
setStatusMessage,
setStatusType,
isProcessing,
setIsProcessing
} = useStatusContext();
const handleClick = async () => {
if (isProcessing) return;
setIsProcessing(true);
try {
await onClick();
} catch (error: unknown) {
const errorMessage = getErrorMessage(error);
setStatusMessage(`Error: ${errorMessage}`);
setStatusType("error");
console.error(`Error in ${title} action:`, error);
} finally {
setIsProcessing(false);
}
};
return (
<Button
appearance={appearance}
className={`${styles.actionButton} ${className}`}
onClick={handleClick}
icon={icon}
disabled={disabled || isProcessing}
>
{title}
</Button>
);
};
export default ActionButton;