/* eslint-disable react/prop-types */ import * as React from "react"; import Tooltip, { Props as TooltipProps } from "~/components/Tooltip"; import { performAction } from "~/actions"; import useIsMounted from "~/hooks/useIsMounted"; import { Action, ActionContext } from "~/types"; export type Props = React.HTMLAttributes & { /** Show the button in a disabled state */ disabled?: boolean; /** Hide the button entirely if action is not applicable */ hideOnActionDisabled?: boolean; /** Action to use on button */ action?: Action; /** Context of action, must be provided with action */ context?: ActionContext; /** If tooltip props are provided the button will be wrapped in a tooltip */ tooltip?: Omit; }; /** * Button that can be used to trigger an action definition. */ const ActionButton = React.forwardRef( function _ActionButton( { action, context, tooltip, hideOnActionDisabled, ...rest }: Props, ref: React.Ref ) { const isMounted = useIsMounted(); const [executing, setExecuting] = React.useState(false); const disabled = rest.disabled; if (action && !context) { throw new Error("Context must be provided with action"); } if (!context || !action) { return ); if (tooltip) { return {button}; } return button; } ); export default ActionButton;