/* oxlint-disable react/prop-types */ import * as React from "react"; import type { Props as TooltipProps } from "~/components/Tooltip"; import Tooltip from "~/components/Tooltip"; import { performAction, resolve } from "~/actions"; import useIsMounted from "~/hooks/useIsMounted"; import useActionContext from "~/hooks/useActionContext"; import type { ActionVariant, ActionWithChildren } 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?: Exclude; /** 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, tooltip, hideOnActionDisabled, ...rest }: Props, ref: React.Ref ) { const actionContext = useActionContext({ isButton: true, }); const isMounted = useIsMounted(); const [executing, setExecuting] = React.useState(false); if (!actionContext || !action) { return ); if (tooltip) { return {button}; } return button; } ); export default ActionButton;