import { observer } from "mobx-react"; import * as React from "react"; import type { Props as TooltipProps } from "~/components/Tooltip"; import Tooltip from "~/components/Tooltip"; import { performAction, resolve } from "~/actions"; 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; /** The button type, defaults to "button" */ type?: "button" | "submit" | "reset"; }; /** * Button that can be used to trigger an action definition. */ function ActionButton({ action, tooltip, hideOnActionDisabled, ref, type = "button", ...rest }: Props & { ref?: React.Ref }) { const actionContext = useActionContext({ isButton: true, }); const [executing, setExecuting] = React.useState(false); if (!actionContext || !action) { // oxlint-disable-next-line react/button-has-type -- type defaults to "button" return ); if (tooltip) { return {button}; } return button; } export default observer(ActionButton);